From c075c0daa245819d0a07fea6695f233fd329e397 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 8 Dec 2011 00:43:21 +0300 Subject: Add to combined menu also floor items. --- src/actorspritemanager.cpp | 26 ++++++++++++-------------- src/actorspritemanager.h | 2 +- src/gui/popupmenu.cpp | 40 +++++++++++++++++++++++++++++++++++----- src/gui/popupmenu.h | 4 +++- src/gui/viewport.cpp | 2 +- 5 files changed, 52 insertions(+), 22 deletions(-) (limited to 'src') 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 &beings, +void ActorSpriteManager::findBeingsByPixel(std::vector &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 &beings, if (!*it) continue; - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - || (*it)->getType() == ActorSprite::PORTAL) - { + if ((*it)->getType() == ActorSprite::PORTAL) continue; - } - Being *being = static_cast(*it); + Being *being = dynamic_cast(*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 &beings, int x, int y, + void findBeingsByPixel(std::vector &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 &beings) +void PopupMenu::showPopup(int x, int y, std::vector &beings) { mX = x; mY = y; mBrowserBox->clearRows(); - mBrowserBox->addRow("Players"); - std::vector::const_iterator it, it_end; + mBrowserBox->addRow(_("Players")); + std::vector::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(*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(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 #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 &beings); + void showPopup(int x, int y, std::vector &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 beings; + std::vector beings; const int x = getMouseX() + static_cast(mPixelViewX); const int y = getMouseY() + static_cast(mPixelViewY); actorSpriteManager->findBeingsByPixel(beings, x, y, true); -- cgit v1.2.3-70-g09d2