summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-12-08 00:43:21 +0300
committerAndrei Karas <akaras@inbox.ru>2011-12-08 00:43:21 +0300
commitc075c0daa245819d0a07fea6695f233fd329e397 (patch)
tree051f09fc1a5cf2ca256c50c9b77f246bb56b7b43
parent1ba2a5d3f3687976cefd8b12cd3d001f754b55e3 (diff)
downloadmv-c075c0daa245819d0a07fea6695f233fd329e397.tar.gz
mv-c075c0daa245819d0a07fea6695f233fd329e397.tar.bz2
mv-c075c0daa245819d0a07fea6695f233fd329e397.tar.xz
mv-c075c0daa245819d0a07fea6695f233fd329e397.zip
Add to combined menu also floor items.
-rw-r--r--src/actorspritemanager.cpp26
-rw-r--r--src/actorspritemanager.h2
-rw-r--r--src/gui/popupmenu.cpp40
-rw-r--r--src/gui/popupmenu.h4
-rw-r--r--src/gui/viewport.cpp2
5 files changed, 52 insertions, 22 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp
index 4403738f9..e0a59b349 100644
--- a/src/actorspritemanager.cpp
+++ b/src/actorspritemanager.cpp
@@ -406,13 +406,12 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y,
}
}
-void ActorSpriteManager::findBeingsByPixel(std::vector<Being*> &beings,
+void ActorSpriteManager::findBeingsByPixel(std::vector<ActorSprite*> &beings,
int x, int y, bool allPlayers) const
{
if (!mMap)
return;
- bool targetDead = mTargetDeadPlayers;
const int xtol = 16;
const int uptol = 32;
@@ -421,25 +420,24 @@ void ActorSpriteManager::findBeingsByPixel(std::vector<Being*> &beings,
if (!*it)
continue;
- if ((*it)->getType() == ActorSprite::FLOOR_ITEM
- || (*it)->getType() == ActorSprite::PORTAL)
- {
+ if ((*it)->getType() == ActorSprite::PORTAL)
continue;
- }
- Being *being = static_cast<Being*>(*it);
+ Being *being = dynamic_cast<Being*>(*it);
+ ActorSprite *actor = *it;
- if ((being->isAlive()
- || (targetDead && being->getType() == Being::PLAYER))
+ if ((being && (being->isAlive()
+ || (mTargetDeadPlayers && being->getType() == Being::PLAYER))
&& (allPlayers || being != player_node))
+ || actor->getType() == ActorSprite::FLOOR_ITEM)
{
- if ((being->getPixelX() - xtol <= x) &&
- (being->getPixelX() + xtol > x) &&
- (being->getPixelY() - uptol <= y) &&
- (being->getPixelY() > y))
+ if ((actor->getPixelX() - xtol <= x) &&
+ (actor->getPixelX() + xtol > x) &&
+ (actor->getPixelY() - uptol <= y) &&
+ (actor->getPixelY() > y))
{
- beings.push_back(being);
+ beings.push_back(actor);
}
}
}
diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h
index f1f83634d..08a255621 100644
--- a/src/actorspritemanager.h
+++ b/src/actorspritemanager.h
@@ -94,7 +94,7 @@ class ActorSpriteManager: public ConfigListener
/**
* Returns a beings at the specific pixel.
*/
- void findBeingsByPixel(std::vector<Being*> &beings, int x, int y,
+ void findBeingsByPixel(std::vector<ActorSprite*> &beings, int x, int y,
bool allPlayers) const;
/**
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index e49d5c451..15afc7600 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -350,22 +350,36 @@ void PopupMenu::showPopup(int x, int y, Being *being)
showPopup(x, y);
}
-void PopupMenu::showPopup(int x, int y, std::vector<Being*> &beings)
+void PopupMenu::showPopup(int x, int y, std::vector<ActorSprite*> &beings)
{
mX = x;
mY = y;
mBrowserBox->clearRows();
- mBrowserBox->addRow("Players");
- std::vector<Being*>::const_iterator it, it_end;
+ mBrowserBox->addRow(_("Players"));
+ std::vector<ActorSprite*>::const_iterator it, it_end;
for (it = beings.begin(), it_end = beings.end(); it != it_end; ++it)
{
- Being *being = *it;
- if (!being->getName().empty())
+ Being *being = dynamic_cast<Being*>(*it);
+ ActorSprite *actor = *it;
+ if (being && !being->getName().empty())
{
mBrowserBox->addRow(strprintf("@@player_%u|%s >@@",
being->getId(), (being->getName()
+ being->getGenderSignWithSpace()).c_str()));
}
+ 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()));
+ }
}
mBrowserBox->addRow("##3---");
mBrowserBox->addRow("cancel", _("Cancel"));
@@ -1685,6 +1699,22 @@ void PopupMenu::handleLink(const std::string &link,
}
}
}
+ else if (!link.compare(0, 10, "flooritem_"))
+ {
+ if (actorSpriteManager)
+ {
+ int id = atoi(link.substr(10).c_str());
+ if (id)
+ {
+ mFloorItem = actorSpriteManager->findItem(id);
+ if (mFloorItem)
+ {
+ showPopup(getX(), getY(), mFloorItem);
+ return;
+ }
+ }
+ }
+ }
else if (!link.compare(0, 12, "hide button_"))
{
if (windowMenu)
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 6dc9a953a..2db565ab7 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -26,6 +26,8 @@
#include "gui/widgets/linkhandler.h"
#include "gui/widgets/popup.h"
+#include "actorsprite.h"
+
#include <guichan/actionlistener.hpp>
#include "localconsts.h"
@@ -102,7 +104,7 @@ class PopupMenu : public Popup, public LinkHandler
/**
* Shows the beings related popup menu at the specified mouse coords.
*/
- void showPopup(int x, int y, std::vector<Being*> &beings);
+ void showPopup(int x, int y, std::vector<ActorSprite*> &beings);
void showPlayerPopup(int x, int y, std::string nick);
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 3086a027f..b6c55f2c4 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -432,7 +432,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
{
if (actorSpriteManager)
{
- std::vector<Being*> beings;
+ std::vector<ActorSprite*> beings;
const int x = getMouseX() + static_cast<int>(mPixelViewX);
const int y = getMouseY() + static_cast<int>(mPixelViewY);
actorSpriteManager->findBeingsByPixel(beings, x, y, true);