summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-08 06:06:50 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-08 06:06:50 +0200
commit07c9e6360ac16c96b8624a4b0bf4557ae295699d (patch)
tree718cbc1e2cd21b13239d7bca4be9a04d811e4c48 /src
parentc17acf93cb4ebe698b0af8a38a1fd6d49a6be3cc (diff)
downloadplus-07c9e6360ac16c96b8624a4b0bf4557ae295699d.tar.gz
plus-07c9e6360ac16c96b8624a4b0bf4557ae295699d.tar.bz2
plus-07c9e6360ac16c96b8624a4b0bf4557ae295699d.tar.xz
plus-07c9e6360ac16c96b8624a4b0bf4557ae295699d.zip
Replace %color% and %Color% constants in item names/descriptions.
Diffstat (limited to 'src')
-rw-r--r--src/gui/itempopup.cpp41
-rw-r--r--src/gui/itempopup.h2
-rw-r--r--src/item.h4
-rw-r--r--src/resources/iteminfo.cpp36
-rw-r--r--src/resources/iteminfo.h10
5 files changed, 85 insertions, 8 deletions
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index d7f67ff0c..1a8dcc35d 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -23,6 +23,7 @@
#include "gui/itempopup.h"
+#include "client.h"
#include "graphics.h"
#include "item.h"
#include "units.h"
@@ -46,7 +47,9 @@
ItemPopup::ItemPopup():
Popup("ItemPopup"),
- mIcon(0)
+ mIcon(0),
+ mLastName(""),
+ mLastColor(1)
{
// Item Name
mItemName = new gcn::Label;
@@ -100,8 +103,18 @@ void ItemPopup::setItem(const Item *item, bool showImage)
setItem(ii, item->getColor(), showImage);
if (item->getRefine() > 0)
{
- mItemName->setCaption(strprintf("%s (+%d), %d", ii.getName().c_str(),
- item->getRefine(), ii.getId()));
+ mLastName = item->getId();
+ mLastColor = item->getColor();
+ if (serverVersion > 0)
+ {
+ mItemName->setCaption(strprintf("%s (+%d), %d", ii.getName(
+ item->getColor()).c_str(), item->getRefine(), ii.getId()));
+ }
+ else
+ {
+ mItemName->setCaption(strprintf("%s (+%d), %d",
+ ii.getName().c_str(), item->getRefine(), ii.getId()));
+ }
mItemName->adjustSize();
int minWidth = mItemName->getWidth() + 8;
if (getWidth() < minWidth)
@@ -112,7 +125,7 @@ void ItemPopup::setItem(const Item *item, bool showImage)
void ItemPopup::setItem(const ItemInfo &item, unsigned char color,
bool showImage)
{
- if (!mIcon || item.getName() == mItemName->getCaption())
+ if (!mIcon || (item.getName() == mLastName && color == mLastColor))
return;
int space = 0;
@@ -147,12 +160,26 @@ void ItemPopup::setItem(const ItemInfo &item, unsigned char color,
mItemType = item.getType();
- mItemName->setCaption(item.getName() + _(", ") + toString(item.getId()));
+ mLastName = item.getName();
+ mLastColor = color;
+
+ if (serverVersion > 0)
+ {
+ mItemName->setCaption(item.getName(color) + _(", ")
+ + toString(item.getId()));
+ mItemDesc->setTextWrapped(item.getDescription(color), 196);
+ }
+ else
+ {
+ mItemName->setCaption(item.getName() + _(", ")
+ + toString(item.getId()));
+ mItemDesc->setTextWrapped(item.getDescription(), 196);
+ }
+
mItemName->adjustSize();
mItemName->setForegroundColor(getColor(mItemType));
mItemName->setPosition(getPadding() + space, getPadding());
- mItemDesc->setTextWrapped(item.getDescription(), 196);
mItemEffect->setTextWrapped(item.getEffect(), 196);
mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
Units::formatWeight(item.getWeight()).c_str()),
@@ -240,4 +267,6 @@ void ItemPopup::mouseMoved(gcn::MouseEvent &event)
// When the mouse moved on top of the popup, hide it
setVisible(false);
+ mLastName = "";
+ mLastColor = 1;
} \ No newline at end of file
diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h
index aeda26a0d..70664e022 100644
--- a/src/gui/itempopup.h
+++ b/src/gui/itempopup.h
@@ -66,6 +66,8 @@ class ItemPopup : public Popup
TextBox *mItemWeight;
ItemType mItemType;
Icon *mIcon;
+ std::string mLastName;
+ unsigned char mLastColor;
static gcn::Color getColor(ItemType type);
};
diff --git a/src/item.h b/src/item.h
index a5982c98e..29700f27a 100644
--- a/src/item.h
+++ b/src/item.h
@@ -161,6 +161,9 @@ class Item
unsigned char getColor() const
{ return mColor; }
+ std::string &getDescription()
+ { return mDescription; }
+
protected:
int mId; /**< Item type id. */
Image *mImage; /**< Item image. */
@@ -171,6 +174,7 @@ class Item
bool mInEquipment; /**< Item is in equipment */
int mRefine; /**< Item refine level. */
int mInvIndex; /**< Inventory index. */
+ std::string mDescription;
unsigned char mColor;
std::map <int, int> mTags;
};
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 990c78f45..667037c58 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -106,4 +106,38 @@ std::string ItemInfo::getDyeColorsString(int color) const
return "";
return it->second.color;
-} \ No newline at end of file
+}
+
+const std::string ItemInfo::getDescription(unsigned char color) const
+{
+ return replaceColors(mDescription, color);
+}
+
+const std::string ItemInfo::getName(unsigned char color) const
+{
+ return replaceColors(mName, color);
+}
+
+const std::string ItemInfo::replaceColors(std::string str,
+ unsigned char color) const
+{
+ std::string name;
+ if (mColors && !mColorList.empty())
+ {
+ std::map <int, ColorDB::ItemColor>::iterator it = mColors->find(color);
+ if (it == mColors->end())
+ name = "unknown";
+ else
+ name = it->second.name;
+ }
+ else
+ {
+ name = "unknown";
+ }
+
+ str = replaceAll(str, "%color%", name);
+ if (name.size() > 0)
+ name[0] = toupper(name[0]);
+
+ return replaceAll(str, "%Color%", name);
+}
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 297c1b036..8b276601c 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -130,10 +130,13 @@ class ItemInfo
const std::string &getName() const
{ return mName; }
+ const std::string getName(unsigned char color) const;
+
void setParticleEffect(const std::string &particleEffect)
{ mParticle = particleEffect; }
- std::string getParticleEffect() const { return mParticle; }
+ std::string getParticleEffect() const
+ { return mParticle; }
void setDisplay(SpriteDisplay display)
{ mDisplay = display; }
@@ -147,6 +150,8 @@ class ItemInfo
const std::string &getDescription() const
{ return mDescription; }
+ const std::string getDescription(unsigned char color) const;
+
void setEffect(const std::string &effect)
{ mEffect = effect; }
@@ -243,6 +248,9 @@ class ItemInfo
bool isHaveColors()
{ return !mColorList.empty(); }
+ const std::string replaceColors(std::string str,
+ unsigned char color) const;
+
protected:
SpriteDisplay mDisplay; /**< Display info (like icon) */
std::string mName;