From 860c60be6c7a925bb4d8db291b771a6044d20308 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 7 May 2012 20:20:09 +0300 Subject: Add getName property to item and flooritem. --- src/actorspritemanager.cpp | 42 +++++++++---------------------------- src/flooritem.cpp | 9 ++++++++ src/flooritem.h | 2 ++ src/gui/popupmenu.cpp | 52 +++++++--------------------------------------- src/item.cpp | 11 ++++++++++ src/item.h | 2 ++ 6 files changed, 42 insertions(+), 76 deletions(-) (limited to 'src') diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 2f1628986..bae34cd98 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -519,15 +519,9 @@ bool ActorSpriteManager::pickUpAll(int x1, int y1, int x2, int y2, && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2)) { FloorItem *item = static_cast(*it); - const ItemInfo &info = item->getInfo(); - std::string name; - if (serverVersion > 0) - name = info.getName(item->getColor()); - else - name = info.getName(); if (allowAll) { - if (mIgnorePickupItemsSet.find(name) + if (mIgnorePickupItemsSet.find(item->getName()) == mIgnorePickupItemsSet.end()) { if (player_node->pickUp(item)) @@ -536,7 +530,8 @@ bool ActorSpriteManager::pickUpAll(int x1, int y1, int x2, int y2, } else { - if (mPickupItemsSet.find(name) != mPickupItemsSet.end()) + if (mPickupItemsSet.find(item->getName()) + != mPickupItemsSet.end()) { if (player_node->pickUp(item)) finded = true; @@ -561,15 +556,9 @@ bool ActorSpriteManager::pickUpAll(int x1, int y1, int x2, int y2, FloorItem *tempItem = static_cast(*it); if (tempItem->getPickupCount() < cnt) { - const ItemInfo &info = tempItem->getInfo(); - std::string name; - if (serverVersion > 0) - name = info.getName(tempItem->getColor()); - else - name = info.getName(); if (allowAll) { - if (mIgnorePickupItemsSet.find(name) + if (mIgnorePickupItemsSet.find(tempItem->getName()) == mIgnorePickupItemsSet.end()) { item = tempItem; @@ -584,7 +573,7 @@ bool ActorSpriteManager::pickUpAll(int x1, int y1, int x2, int y2, } else { - if (mPickupItemsSet.find(name) + if (mPickupItemsSet.find(tempItem->getName()) != mPickupItemsSet.end()) { item = tempItem; @@ -633,14 +622,9 @@ bool ActorSpriteManager::pickUpNearest(int x, int y, int maxdist) item->getTileY()))) { const ItemInfo &info = item->getInfo(); - std::string name; - if (serverVersion > 0) - name = info.getName(item->getColor()); - else - name = info.getName(); if (allowAll) { - if (mIgnorePickupItemsSet.find(name) + if (mIgnorePickupItemsSet.find(item->getName()) == mIgnorePickupItemsSet.end()) { dist = d; @@ -649,7 +633,8 @@ bool ActorSpriteManager::pickUpNearest(int x, int y, int maxdist) } else { - if (mPickupItemsSet.find(name) != mPickupItemsSet.end()) + if (mPickupItemsSet.find(item->getName()) + != mPickupItemsSet.end()) { dist = d; closestItem = item; @@ -1634,19 +1619,12 @@ void ActorSpriteManager::storeAttackList() bool ActorSpriteManager::checkForPickup(FloorItem *item) { - const ItemInfo &info = item->getInfo(); - std::string name; - if (serverVersion > 0) - name = info.getName(item->getColor()); - else - name = info.getName(); - if (mPickupItemsSet.find("") != mPickupItemsSet.end()) { - if (mIgnorePickupItemsSet.find(name) == mIgnorePickupItemsSet.end()) + if (mIgnorePickupItemsSet.find(item->getName()) == mIgnorePickupItemsSet.end()) return true; } - else if (mPickupItemsSet.find(name) != mPickupItemsSet.end()) + else if (mPickupItemsSet.find(item->getName()) != mPickupItemsSet.end()) { return true; } diff --git a/src/flooritem.cpp b/src/flooritem.cpp index f126f336b..acbfe8363 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -75,6 +75,15 @@ const ItemInfo &FloorItem::getInfo() const return ItemDB::get(mItemId); } +std::string FloorItem::getName() +{ + const ItemInfo &info = ItemDB::get(mItemId); + if (serverVersion > 0) + return info.getName(mColor); + else + return info.getName(); +} + bool FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const { if (!mMap) diff --git a/src/flooritem.h b/src/flooritem.h index 791b125f1..817fa0317 100644 --- a/src/flooritem.h +++ b/src/flooritem.h @@ -66,6 +66,8 @@ class FloorItem : public ActorSprite */ const ItemInfo &getInfo() const; + std::string getName(); + virtual int getTileX() const { return mX; } diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index eb57dd845..436fd93b1 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -282,15 +282,8 @@ void PopupMenu::showPopup(int x, int y, std::vector &beings) else if (actor->getType() == ActorSprite::FLOOR_ITEM) { FloorItem *floorItem = static_cast(actor); - const ItemInfo &info = floorItem->getInfo(); - std::string name; - - if (serverVersion > 0) - name = info.getName(floorItem->getColor()); - else - name = info.getName(); mBrowserBox->addRow(strprintf("@@flooritem_%u|%s >@@", - actor->getId(), name.c_str())); + actor->getId(), floorItem->getName().c_str())); } } mBrowserBox->addRow("##3---"); @@ -383,15 +376,8 @@ void PopupMenu::showPopup(int x, int y, FloorItem *floorItem) mX = x; mY = y; mType = Being::FLOOR_ITEM; - const ItemInfo &info = floorItem->getInfo(); mBrowserBox->clearRows(); - std::string name; - - // Floor item can be picked up (single option, candidate for removal) - if (serverVersion > 0) - name = info.getName(floorItem->getColor()); - else - name = info.getName(); + std::string name = floorItem->getName(); mNick = name; mBrowserBox->addRow(name); @@ -1687,16 +1673,9 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item, } if (config.getBoolValue("enablePickupFilter")) { - const ItemInfo &info = item->getInfo(); - std::string name; - - if (serverVersion > 0) - name = info.getName(item->getColor()); - else - name = info.getName(); - mNick = name; + mNick = item->getName(); mBrowserBox->addRow("##3---"); - addPickupFilter(name); + addPickupFilter(mNick); } mBrowserBox->addRow("chat", _("Add to chat")); mBrowserBox->addRow("##3---"); @@ -1784,17 +1763,10 @@ void PopupMenu::showItemPopup(int x, int y, Item *item) if (config.getBoolValue("enablePickupFilter")) { - const ItemInfo &info = item->getInfo(); - std::string name; - - if (serverVersion > 0) - name = info.getName(item->getColor()); - else - name = info.getName(); - mNick = name; + mNick = item->getName(); mBrowserBox->addRow("##3---"); - addPickupFilter(name); + addPickupFilter(mNick); } } mBrowserBox->addRow("##3---"); @@ -1846,17 +1818,9 @@ void PopupMenu::showDropPopup(int x, int y, Item *item) mBrowserBox->addRow("chat", _("Add to chat")); if (config.getBoolValue("enablePickupFilter")) { - const ItemInfo &info = item->getInfo(); - std::string name; - - if (serverVersion > 0) - name = info.getName(item->getColor()); - else - name = info.getName(); - mNick = name; - + mNick = item->getName(); mBrowserBox->addRow("##3---"); - addPickupFilter(name); + addPickupFilter(mNick); } } mBrowserBox->addRow("##3---"); diff --git a/src/item.cpp b/src/item.cpp index cc7d666b5..fda05aa30 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -31,6 +31,8 @@ #include "debug.h" +extern int serverVersion; + Item::Item(int id, int quantity, int refine, unsigned char color, bool equipment, bool equipped): mImage(nullptr), @@ -113,3 +115,12 @@ Image *Item::getImage(int id, unsigned char color) image = Theme::getImageFromTheme("unknown-item.png"); return image; } + +std::string Item::getName() +{ + const ItemInfo &info = ItemDB::get(mId); + if (serverVersion > 0) + return info.getName(mColor); + else + return info.getName(); +} diff --git a/src/item.h b/src/item.h index ad051846d..4683f8816 100644 --- a/src/item.h +++ b/src/item.h @@ -154,6 +154,8 @@ class Item const ItemInfo &getInfo() const { return ItemDB::get(mId); } + std::string getName(); + static Image *getImage(int id, unsigned char color); bool isHaveTag(int tagId); -- cgit v1.2.3-60-g2f50