summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-05-07 20:20:09 +0300
committerAndrei Karas <akaras@inbox.ru>2012-05-07 20:20:09 +0300
commit860c60be6c7a925bb4d8db291b771a6044d20308 (patch)
treeddeb0b2bd54a4b66bd699b220050e4f952bb429f /src
parent6f9d0494f09833e29a05a2c06287fbee73cb7421 (diff)
downloadmanaverse-860c60be6c7a925bb4d8db291b771a6044d20308.tar.gz
manaverse-860c60be6c7a925bb4d8db291b771a6044d20308.tar.bz2
manaverse-860c60be6c7a925bb4d8db291b771a6044d20308.tar.xz
manaverse-860c60be6c7a925bb4d8db291b771a6044d20308.zip
Add getName property to item and flooritem.
Diffstat (limited to 'src')
-rw-r--r--src/actorspritemanager.cpp42
-rw-r--r--src/flooritem.cpp9
-rw-r--r--src/flooritem.h2
-rw-r--r--src/gui/popupmenu.cpp52
-rw-r--r--src/item.cpp11
-rw-r--r--src/item.h2
6 files changed, 42 insertions, 76 deletions
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<FloorItem*>(*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<FloorItem*>(*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<ActorSprite*> &beings)
else if (actor->getType() == ActorSprite::FLOOR_ITEM)
{
FloorItem *floorItem = static_cast<FloorItem*>(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);