diff options
author | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-06-16 08:30:34 +0000 |
---|---|---|
committer | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-06-16 08:30:34 +0000 |
commit | 8d801b2c43f7dfd0b279bb263480d38f5694ac06 (patch) | |
tree | 82b3382ad67d297373cec74a74d7db60b3dd4def /src | |
parent | 06afc063b8538b90b8dd8eb662a9ae0e11812963 (diff) | |
download | mana-8d801b2c43f7dfd0b279bb263480d38f5694ac06.tar.gz mana-8d801b2c43f7dfd0b279bb263480d38f5694ac06.tar.bz2 mana-8d801b2c43f7dfd0b279bb263480d38f5694ac06.tar.xz mana-8d801b2c43f7dfd0b279bb263480d38f5694ac06.zip |
Added action menu (moved trading to menu)
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 48 | ||||
-rw-r--r-- | src/game.cpp | 14 | ||||
-rw-r--r-- | src/gui/menu.cpp | 14 | ||||
-rw-r--r-- | src/gui/menu.h | 13 |
4 files changed, 73 insertions, 16 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index bca79219..64015153 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -87,6 +87,37 @@ char hairtable[16][4][2] = { { { 0, 16}, {-1, 6}, {-1, 6}, { 0, 6} } // DEAD }; +/** + * Listener used for trading request + */ +class tradeItemListener : public gcn::MouseListener +{ + void mouseClick(int x, int y, int button, int count) + { + Being *target = menu->getBeing(); + + // Begin a trade + WFIFOW(0) = net_w_value(0x00e4); + WFIFOL(2) = net_l_value(target->id); + WFIFOSET(6); + std::cout << "Clicked trade" << std::endl; + menu->setVisible(!menu->isVisible()); + } +}; + +/** + * Listener used for buddy request + */ +class buddyItemListener : public gcn::MouseListener +{ + void mouseClick(int x, int y, int button, int count) + { + std::cout << "Clicked buddy" << std::endl; + //buddyWindow->setVisible(!buddyWindow->isVisible()); + menu->setVisible(!menu->isVisible()); + } +}; + int get_x_offset(Being *being) { int offset = 0; @@ -165,11 +196,20 @@ Engine::Engine(): buddyWindow = new BuddyWindow(); helpWindow = new HelpWindow(); - /* Menu items */ + /** + * Menu items + */ std::vector<MenuItem*> items; - items.push_back(new MenuItem("First")); - items.push_back(new MenuItem("Second")); - menu = new Menu("Menu", items); + + MenuItem *tradeItem = new MenuItem("Trade"); + tradeItem->addMouseListener(new tradeItemListener()); + items.push_back(tradeItem); + + MenuItem *buddyItem = new MenuItem("Buddy"); + buddyItem->addMouseListener(new buddyItemListener()); + items.push_back(buddyItem); + + menu = new Menu(items); // Initialize window posisitons chatWindow->setPosition(0, screen->h - chatWindow->getHeight()); diff --git a/src/game.cpp b/src/game.cpp index f6a2133f..95a74568 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -61,6 +61,8 @@ Engine *engine = NULL; OkDialog *deathNotice = NULL; ConfirmDialog *exitConfirm = NULL; +Being *target = NULL; + #define EMOTION_TIME 150 #define MAX_TIME 10000 @@ -322,10 +324,6 @@ void do_input() // buddyWindow->setVisible(!buddyWindow->isVisible()); // used = true; //} - //else if (keysym.sym == SDLK_m) { - // menu->setVisible(!menu->isVisible()); - // used = true; - //} } if (event.key.keysym.sym == SDLK_ESCAPE) @@ -416,10 +414,10 @@ void do_input() attack(target); } else if (target->isPlayer()) { - // Begin a trade - WFIFOW(0) = net_w_value(0x00e4); - WFIFOL(2) = net_l_value(target->id); - WFIFOSET(6); + // Show menu + menu->setVisible(!menu->isVisible()); + // Pass target to menu + menu->setBeing(target); } } } diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 9c648db4..d8b2e6de 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -23,8 +23,8 @@ #include "menu.h" -Menu::Menu(const std::string& menulabel, std::vector<MenuItem *> items): - Window(menulabel) +Menu::Menu(std::vector<MenuItem *> items): + Window("") { setContentSize(52,60); fill(items); @@ -52,3 +52,13 @@ void Menu::fill(std::vector<MenuItem *> items) resizeToContent(); } +void Menu::setBeing(Being *target) +{ + where = target; +} + +Being * Menu::getBeing() +{ + return where; +} + diff --git a/src/gui/menu.h b/src/gui/menu.h index 5d905c86..040c9a9d 100644 --- a/src/gui/menu.h +++ b/src/gui/menu.h @@ -25,15 +25,16 @@ #define _TMW_MENU_H #include <guichan.hpp> -#include "menuitem.h" #include "window.h" +#include "menuitem.h" +#include "../being.h" class Menu : public Window { public: /** * Constructor. */ - Menu(const std::string& menulabel, std::vector<MenuItem *> items); + Menu(std::vector<MenuItem *> items); /** * Destructor. @@ -45,6 +46,14 @@ class Menu : public Window { */ void fill(std::vector<MenuItem *> items); + /** + * Set/get begin + */ + void setBeing(Being *target); + Being * getBeing(void); + + private: + Being *where; // Where to display }; #endif /* _TMW_MENU_H */ |