summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp130
-rw-r--r--src/gui/gui.h25
-rw-r--r--src/gui/inventorywindow.cpp4
-rw-r--r--src/gui/popupmenu.h2
4 files changed, 141 insertions, 20 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index bf35e3ec..25b794ec 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -34,6 +34,7 @@
#include <guichan/sdl/sdlinput.hpp>
#include "focushandler.h"
+#include "popupmenu.h"
#include "window.h"
#include "windowcontainer.h"
@@ -41,6 +42,7 @@
#include "../configlistener.h"
#include "../configuration.h"
#include "../engine.h"
+#include "../floor_item.h"
#include "../game.h"
#include "../graphics.h"
#include "../log.h"
@@ -87,7 +89,8 @@ class GuiConfigListener : public ConfigListener
Gui::Gui(Graphics *graphics):
mHostImageLoader(NULL),
mMouseCursor(NULL),
- mCustomCursor(false)
+ mCustomCursor(false),
+ mPopupActive(false)
{
// Set graphics
setGraphics(graphics);
@@ -168,10 +171,14 @@ Gui::Gui(Graphics *graphics):
setUseCustomCursor(config.getValue("customcursor", 1) == 1);
mConfigListener = new GuiConfigListener(this);
config.addListener("customcursor", mConfigListener);
+
+ mPopup = new PopupMenu();
}
Gui::~Gui()
{
+ delete mPopup;
+
config.removeListener("customcursor", mConfigListener);
delete mConfigListener;
@@ -231,21 +238,100 @@ Gui::mousePress(int mx, int my, int button)
{
// Mouse pressed on window container (basically, the map)
- // When conditions for walking are met, set new player destination
- if (player_node &&
- player_node->action != Being::DEAD &&
- current_npc == 0 &&
- button == gcn::MouseInput::LEFT)
+ // Are we in-game yet?
+ if (state != GAME_STATE)
+ return;
+
+ // Check if we are alive and kickin'
+ if (!player_node || player_node->action == Being::DEAD)
+ return;
+
+ // Check if we are busy
+ if (current_npc)
+ return;
+
+ int tilex = mx / 32 + camera_x;
+ int tiley = my / 32 + camera_y;
+
+ // Right click might open a popup
+ if (button == gcn::MouseInput::RIGHT)
{
- Map *tiledMap = engine->getCurrentMap();
- int tilex = mx / 32 + camera_x;
- int tiley = my / 32 + camera_y;
+ Being *being;
+ FloorItem *floorItem;
- if (state == GAME_STATE && tiledMap->getWalk(tilex, tiley)) {
- walk(tilex, tiley, 0);
- player_node->setDestination(tilex, tiley);
+ if ((being = findNode(tilex, tiley)) && being != player_node)
+ {
+ showPopup(mx, my, being);
+ return;
+ }
+ else if(floorItem = find_floor_item_by_id(
+ find_floor_item_by_cor(mx, my)))
+ {
+ showPopup(mx, my, floorItem);
+ return;
+ }
+ }
+
+ // If a popup is active, just remove it
+ if (mPopupActive)
+ {
+ mPopup->setVisible(false);
+ mPopupActive = false;
+ return;
+ }
+
+ // Left click can cause different actions
+ if (button == gcn::MouseInput::LEFT)
+ {
+ Being *being;
+ Uint32 floorItemId;
- autoTarget = NULL;
+ // Interact with some being
+ if (being = findNode(tilex, tiley))
+ {
+ switch (being->getType())
+ {
+ case Being::NPC:
+ talk(being);
+ current_npc = being->getId();
+ break;
+
+ case Being::MONSTER:
+ case Being::PLAYER:
+ if (being->action == Being::MONSTER_DEAD ||
+ player_node->action != Being::STAND ||
+ being == player_node)
+ break;
+
+ autoTarget = being;
+ attack(being);
+ break;
+
+ default:
+ break;
+ }
+ }
+ // Pick up some item
+ else if (floorItemId = find_floor_item_by_cor(tilex, tiley))
+ {
+ int dx = tilex - player_node->x;
+ int dy = tiley - player_node->y;
+
+ if ((dx * dx + dy * dy) < 4)
+ pickUp(floorItemId);
+ }
+ // Just walk around
+ else if (engine->getCurrentMap()->getWalk(tilex, tiley))
+ {
+ // XXX XXX XXX REALLY UGLY!
+ Uint8 *keys = SDL_GetKeyState(NULL);
+ if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]))
+ {
+ walk(tilex, tiley, 0);
+ player_node->setDestination(tilex, tiley);
+
+ autoTarget = NULL;
+ }
}
}
}
@@ -282,3 +368,21 @@ Gui::setUseCustomCursor(bool customCursor)
}
}
}
+
+void Gui::showPopup(int x, int y, Item *item)
+{
+ mPopup->showPopup(x, y, item);
+ mPopupActive = true;
+}
+
+void Gui::showPopup(int x, int y, FloorItem *floorItem)
+{
+ mPopup->showPopup(x, y, floorItem);
+ mPopupActive = true;
+}
+
+void Gui::showPopup(int x, int y, Being *being)
+{
+ mPopup->showPopup(x, y, being);
+ mPopupActive = true;
+}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 238ee38e..83f731db 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -29,9 +29,13 @@
#include "../guichanfwd.h"
+class Being;
+class FloorItem;
class GuiConfigListener;
class Graphics;
class Image;
+class Item;
+class PopupMenu;
class WindowContainer;
/**
@@ -92,10 +96,22 @@ class Gui : public gcn::Gui, public gcn::MouseListener
setUseCustomCursor(bool customCursor);
/**
- * ConfigListener method.
+ * Shows a popup for an item
+ * TODO Find some way to get rid of Item here
*/
- void
- optionChanged(const std::string &name);
+ void showPopup(int x, int y, Item *item);
+
+ /**
+ * Shows a popup for a floor item
+ * TODO Find some way to get rid of FloorItem here
+ */
+ void showPopup(int x, int y, FloorItem *floorItem);
+
+ /**
+ * Shows a popup for a being
+ * TODO Find some way to get rid of Being here
+ */
+ void showPopup(int x, int y, Being *being);
private:
GuiConfigListener *mConfigListener;
@@ -104,6 +120,9 @@ class Gui : public gcn::Gui, public gcn::MouseListener
gcn::Font *mGuiFont; /**< The global GUI font */
Image *mMouseCursor; /**< Mouse cursor image */
bool mCustomCursor; /**< Show custom cursor */
+
+ PopupMenu *mPopup; /**< Popup window */
+ bool mPopupActive;
};
extern Gui *gui; /**< The GUI system */
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 35809bdd..0b8a37a7 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -31,9 +31,9 @@
#include <guichan/widgets/label.hpp>
#include "button.h"
+#include "gui.h"
#include "item_amount.h"
#include "itemcontainer.h"
-#include "popupmenu.h"
#include "scrollarea.h"
#include "../inventory.h"
@@ -162,7 +162,7 @@ void InventoryWindow::mouseClick(int x, int y, int button, int count)
*/
int mx = x + getX();
int my = y + getY();
- popupMenu->showPopup(mx, my, item);
+ gui->showPopup(mx, my, item);
}
}
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 97cadf38..dfbb2e92 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -79,6 +79,4 @@ class PopupMenu : public Window, public LinkHandler
void showPopup(int x, int y);
};
-extern PopupMenu *popupMenu;
-
#endif