From 07c9e6360ac16c96b8624a4b0bf4557ae295699d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 8 Mar 2011 06:06:50 +0200 Subject: Replace %color% and %Color% constants in item names/descriptions. --- src/resources/iteminfo.cpp | 36 +++++++++++++++++++++++++++++++++++- src/resources/iteminfo.h | 10 +++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'src/resources') 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 ::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; -- cgit v1.2.3-60-g2f50