summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-07-28 12:32:12 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-07-28 12:32:12 +0000
commit51b75feaefd132ee0b7992a10dbe79bfa92e6d91 (patch)
tree91b1d54ae1ec29cc835f7d5198a04115c1874894 /src/gui
parent227aeae87bcca1ecb0183530a4cca1b038863635 (diff)
downloadmana-client-51b75feaefd132ee0b7992a10dbe79bfa92e6d91.tar.gz
mana-client-51b75feaefd132ee0b7992a10dbe79bfa92e6d91.tar.bz2
mana-client-51b75feaefd132ee0b7992a10dbe79bfa92e6d91.tar.xz
mana-client-51b75feaefd132ee0b7992a10dbe79bfa92e6d91.zip
Cleaned up the showPopup() code, moved "map"-related code into game.cpp, made the popup show up at mouse coordinates instead of being aligned to tiles.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/inventorywindow.cpp7
-rw-r--r--src/gui/popupmenu.cpp119
-rw-r--r--src/gui/popupmenu.h22
3 files changed, 73 insertions, 75 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 377acc1f..28dbd35e 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -25,7 +25,6 @@
#include "popupmenu.h"
#include "../playerinfo.h"
#include "../inventory.h"
-#include "../engine.h"
#include "button.h"
#include "scrollarea.h"
#include "item_amount.h"
@@ -148,10 +147,10 @@ void InventoryWindow::mouseClick(int x, int y, int button, int count)
{
/*
* convert relative to the window coordinates to
- * absolute tile coordinates
+ * absolute screen coordinates
*/
- int mx = (x + getX()) / 32 + camera_x;
- int my = (y + getY()) / 32 + camera_y;
+ int mx = x + getX();
+ int my = y + getY();
popupMenu->showPopup(mx, my, item);
}
}
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 32690bdb..e852e9aa 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -29,7 +29,6 @@
#include "item_amount.h"
#include "../graphics.h"
#include "../game.h"
-#include "../engine.h"
#include "../net/network.h"
#include "../resources/itemmanager.h"
#include "../item.h"
@@ -52,8 +51,6 @@ PopupMenu::PopupMenu():
being = NULL;
floorItem = NULL;
- mX = -1;
- mY = -1;
}
PopupMenu::~PopupMenu()
@@ -62,68 +59,58 @@ PopupMenu::~PopupMenu()
delete floorItem;
}
-void PopupMenu::showPopup(int mx, int my)
+void PopupMenu::showPopup(int x, int y, Being *being)
{
- being = findNode(mx, my);
- floorItem = find_floor_item_by_id(find_floor_item_by_cor(mx, my));
- mX = mx;
- mY = my;
+ std::string name;
+
+ this->being = being;
browserBox->clearRows();
- if (being) {
- std::string name;
- switch (being->getType())
- {
- case Being::PLAYER:
- // Players can be traded with. Later also attack, follow and
- // add as buddy will be options in this menu.
-
- name = being->name;
- //browserBox->addRow("@@attack|Attack " + name + "@@");
- browserBox->addRow("@@trade|Trade With " + name + "@@");
- //browserBox->addRow("@@follow|Follow " + name + "@@");
- //browserBox->addRow("@@buddy|Add " + name + " to Buddy List@@");
- break;
-
- case Being::NPC:
- // NPCs can be talked to (single option, candidate for removal
- // unless more options would be added)
- browserBox->addRow("@@talk|Talk To NPC@@");
- break;
-
- default:
- /* Other beings aren't interesting... */
- break;
- }
- }
- else if (floorItem)
- {
- // Floor item can be picked up (single option, candidate for removal)
- std::string name = itemDb->getItemInfo(floorItem->id)->getName();
- browserBox->addRow("@@pickup|Pick Up " + name + "@@");
- }
- else
+ switch (being->getType())
{
- // If there is nothing of interest, don't display menu.
- // Hide it, because it may have been visible.
- setVisible(false);
- return;
+ case Being::PLAYER:
+ // Players can be traded with. Later also attack, follow and
+ // add as buddy will be options in this menu.
+
+ name = being->name;
+ //browserBox->addRow("@@attack|Attack " + name + "@@");
+ browserBox->addRow("@@trade|Trade With " + name + "@@");
+ //browserBox->addRow("@@follow|Follow " + name + "@@");
+ //browserBox->addRow("@@buddy|Add " + name + " to Buddy List@@");
+ break;
+
+ case Being::NPC:
+ // NPCs can be talked to (single option, candidate for removal
+ // unless more options would be added)
+ browserBox->addRow("@@talk|Talk To NPC@@");
+ break;
+
+ default:
+ /* Other beings aren't interesting... */
+ break;
}
//browserBox->addRow("@@look|Look To@@");
browserBox->addRow("##3---");
browserBox->addRow("@@cancel|Cancel@@");
- setContentSize(browserBox->getWidth() + 8, browserBox->getHeight() + 8);
- mx = (mx - camera_x) * 32 + 25;
- my = (my - camera_y) * 32 + 25;
- if (guiGraphics->getWidth() < (mx + getWidth() + 5))
- mx -= (getWidth() + 50);
- if (guiGraphics->getHeight() < (my + getHeight() + 5))
- my -= (getHeight() + 50);
- setPosition(mx, my);
- setVisible(true);
- requestMoveToTop();
+ showPopup(x, y);
+}
+
+void PopupMenu::showPopup(int x, int y, FloorItem *floorItem)
+{
+ this->floorItem = floorItem;
+ browserBox->clearRows();
+
+ // Floor item can be picked up (single option, candidate for removal)
+ std::string name = itemDb->getItemInfo(floorItem->id)->getName();
+ browserBox->addRow("@@pickup|Pick Up " + name + "@@");
+
+ //browserBox->addRow("@@look|Look To@@");
+ browserBox->addRow("##3---");
+ browserBox->addRow("@@cancel|Cancel@@");
+
+ showPopup(x, y);
}
void PopupMenu::handleLink(const std::string& link)
@@ -224,11 +211,9 @@ void PopupMenu::handleLink(const std::string& link)
being = NULL;
floorItem = NULL;
m_item = NULL;
- mX = -1;
- mY = -1;
}
-void PopupMenu::showPopup(int mx, int my, Item *item)
+void PopupMenu::showPopup(int x, int y, Item *item)
{
assert(item);
m_item = item;
@@ -249,15 +234,17 @@ void PopupMenu::showPopup(int mx, int my, Item *item)
browserBox->addRow("##3---");
browserBox->addRow("@@cancel|Cancel@@");
+ showPopup(x, y);
+}
+
+void PopupMenu::showPopup(int x, int y)
+{
setContentSize(browserBox->getWidth() + 8, browserBox->getHeight() + 8);
- mx = (mx - camera_x) * 32 + 25;
- my = (my - camera_y) * 32 + 25;
- if (guiGraphics->getWidth() < (mx + getWidth() + 5))
- mx -= (getWidth() + 50);
- if (guiGraphics->getHeight() < (my + getHeight() + 5))
- my -= (getHeight() + 50);
- setPosition(mx, my);
+ if (guiGraphics->getWidth() < (x + getWidth() + 5))
+ x -= (getWidth() + 50);
+ if (guiGraphics->getHeight() < (y + getHeight() + 5))
+ y -= (getHeight() + 50);
+ setPosition(x, y);
setVisible(true);
requestMoveToTop();
}
-
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 45c5c446..f1bebabc 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -29,6 +29,7 @@
#include "linkhandler.h"
#include "browserbox.h"
#include "../being.h"
+#include "../item.h"
#include "../floor_item.h"
/**
@@ -48,14 +49,21 @@ class PopupMenu : public Window, public LinkHandler
~PopupMenu();
/**
- * Shows the related popup menu specifies by the mouse click coords.
+ * Shows the being related popup menu at the specified mouse coords.
*/
- void showPopup(int mx, int my);
+ void showPopup(int x, int y, Being *being);
+
+ /**
+ * Shows the floor item related popup menu at the specified
+ * mouse coords.
+ */
+ void showPopup(int x, int y, FloorItem *floorItem);
/**
* Shows the related popup menu when right click on the inventory
+ * at the specified mouse coordinates.
*/
- void showPopup(int mx, int my, class Item *item);
+ void showPopup(int x, int y, Item *item);
/**
* Handles link action.
@@ -64,12 +72,16 @@ class PopupMenu : public Window, public LinkHandler
private:
BrowserBox* browserBox;
- int mX, mY;
Being* being;
FloorItem* floorItem;
- class Item *m_item;
+ Item *m_item;
+
+ /**
+ * Shared code for the various showPopup functions.
+ */
+ void showPopup(int x, int y);
};
extern PopupMenu *popupMenu;