diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-23 23:46:23 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-23 23:46:23 +0000 |
commit | 5c1093ffa9fea3d979a720169e97ed31725e95c4 (patch) | |
tree | 3f40c4000c2f0317e12640eb818a781c3a892497 | |
parent | 1fcefe616a39c2e572b8078c5c51c8e81a59c487 (diff) | |
download | mana-5c1093ffa9fea3d979a720169e97ed31725e95c4.tar.gz mana-5c1093ffa9fea3d979a720169e97ed31725e95c4.tar.bz2 mana-5c1093ffa9fea3d979a720169e97ed31725e95c4.tar.xz mana-5c1093ffa9fea3d979a720169e97ed31725e95c4.zip |
Committed patch by Mra, which fixes multiple NPCs talks in one window and
moves the action listener used with BuySellDialog into that class.
-rw-r--r-- | src/game.cpp | 34 | ||||
-rw-r--r-- | src/graphic/graphic.cpp | 24 | ||||
-rw-r--r-- | src/graphic/graphic.h | 8 | ||||
-rw-r--r-- | src/gui/buy.cpp | 3 | ||||
-rw-r--r-- | src/gui/buysell.cpp | 31 | ||||
-rw-r--r-- | src/gui/buysell.h | 10 | ||||
-rw-r--r-- | src/gui/npc.cpp | 3 | ||||
-rw-r--r-- | src/gui/npc_text.cpp | 1 | ||||
-rw-r--r-- | src/gui/sell.cpp | 3 |
9 files changed, 66 insertions, 51 deletions
diff --git a/src/game.cpp b/src/game.cpp index d53ddcc2..5feeeeb1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -45,9 +45,9 @@ bool refresh_beings = false; unsigned char keyb_state; volatile int tick_time; volatile bool action_time = false; -int current_npc, server_tick; +int server_tick; extern unsigned char screen_mode; -int fps = 0, frame = 0; +int fps = 0, frame = 0, current_npc = 0; bool displayPathToMouse = false; OkDialog *deathNotice = NULL; @@ -124,7 +124,7 @@ void game() { void do_init() { tiledMap = Map::load(map_path); - //tiledMap = MapReader::readMap("map/desert.tmx"); + //tiledMap = MapReader::readMap("core/maps/desert.tmx"); if (!tiledMap) { error("Could not find map file"); } @@ -288,10 +288,15 @@ void do_input() int id = find_npc(npc_x, npc_y); if (id != 0) { - WFIFOW(0) = net_w_value(0x0090); - WFIFOL(2) = net_l_value(id); - WFIFOB(6) = 0; - WFIFOSET(7); + // Check if no conflicting npc window is open + if (current_npc == 0) + { + WFIFOW(0) = net_w_value(0x0090); + WFIFOL(2) = net_l_value(id); + WFIFOB(6) = 0; + WFIFOSET(7); + current_npc = id; + } } } @@ -309,7 +314,7 @@ void do_input() Uint8* keys; keys = SDL_GetKeyState(NULL); - if (walk_status == 0 && player_node->action != DEAD) + if (walk_status == 0 && player_node->action != DEAD && current_npc == 0) { int x = player_node->x; int y = player_node->y; @@ -426,7 +431,7 @@ void do_parse() { FILE *file = fopen("./docs/packet.list", "a"); fprintf(file, "%x\n", RFIFOW(0)); fclose(file); -#endif +#endif // Parse packet based on their id switch (id) { // Received speech @@ -600,6 +605,7 @@ void do_parse() { npcTextDialog->addText(RFIFOP(8)); npcListDialog->setVisible(false); npcTextDialog->setVisible(true); + current_npc = RFIFOL(4); break; // Get the items case 0x01ee: @@ -625,8 +631,8 @@ void do_parse() { equipmentWindow->addEquipment(RFIFOB(4+loop*20), RFIFOW(4+loop*20+2)); inventoryWindow->items->setEquipped( - RFIFOW(4+loop*20), true); - } + RFIFOW(4+loop*20), true); + } } break; // Can I use the item? @@ -658,6 +664,7 @@ void do_parse() { add_node(temp); player_node = temp; player_node->action = STAND; + current_npc = 0; player_node->frame = 0; player_node->x = RFIFOW(18); player_node->y = RFIFOW(20); @@ -973,7 +980,6 @@ void do_parse() { // Close button in NPC dialog case 0x00b6: strcpy(npc_button, "Close"); - current_npc = RFIFOL(2); break; // List in NPC dialog case 0x00b7: @@ -999,7 +1005,7 @@ void do_parse() { case 0x00aa: if (RFIFOB(6) == 0) chatBox->chat_log("Unable to equip.", BY_SERVER); - else { + else { inventoryWindow->items->setEquipped(RFIFOW(2), true); equipmentWindow->addEquipment(RFIFOW(2), inventoryWindow->items->getId(RFIFOW(2))); @@ -1027,7 +1033,7 @@ void do_parse() { equipmentWindow->removeEquipment(RFIFOW(2)); inventoryWindow->items->setEquipped( inventoryWindow->items->getIndex(), false); - } + } break; // Manage non implemented packets default: diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp index 96f36bbd..8b13e0e9 100644 --- a/src/graphic/graphic.cpp +++ b/src/graphic/graphic.cpp @@ -75,28 +75,6 @@ void ChatListener::action(const std::string& eventId) } } -void BuySellListener::action(const std::string& eventId) -{ - int actionId = -1; - - if (eventId == "buy") { - actionId = 0; - } - else if (eventId == "sell") { - actionId = 1; - } - - if (actionId > -1) { - WFIFOW(0) = net_w_value(0x00c5); - WFIFOL(2) = net_l_value(current_npc); - WFIFOB(6) = net_b_value(actionId); - WFIFOSET(7); - } - - buySellDialog->setVisible(false); -} - - char hairtable[16][4][2] = { // S(x,y) W(x,y) N(x,y) E(x,y) { { 0, 0}, {-1, 2}, {-1, 2}, {0, 2} }, // STAND @@ -287,7 +265,7 @@ Engine::Engine() sellDialog = new SellDialog(); sellDialog->setVisible(false); - buySellDialog = new BuySellDialog(new BuySellListener()); + buySellDialog = new BuySellDialog(); buySellDialog->setVisible(false); inventoryWindow = new InventoryWindow(); diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h index 765a6318..c660f49c 100644 --- a/src/graphic/graphic.h +++ b/src/graphic/graphic.h @@ -88,14 +88,6 @@ class ChatListener : public gcn::ActionListener { }; /** - * The action listener for the buy or sell dialog. - */ -class BuySellListener : public gcn::ActionListener { - public: - void action(const std::string& eventId); -}; - -/** * 9 images defining a rectangle. 4 corners, 4 sides and a middle area. The * topology is as follows: * diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index ca76b40f..059ba4e8 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -26,6 +26,7 @@ #include "slider.h" #include "scrollarea.h" #include "listbox.h" +#include "../game.h" #include <sstream> @@ -140,9 +141,11 @@ void BuyDialog::action(const std::string& eventId) } } setVisible(false); + current_npc = 0; } else if (eventId == "cancel") { setVisible(false); + current_npc = 0; } } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index d522e6f2..29010afc 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -23,8 +23,9 @@ #include "buysell.h" #include "button.h" +#include "../game.h" -BuySellDialog::BuySellDialog(gcn::ActionListener *al): +BuySellDialog::BuySellDialog(): Window("Shop") { buyButton = new Button("Buy"); @@ -43,9 +44,9 @@ BuySellDialog::BuySellDialog(gcn::ActionListener *al): sellButton->setEventId("sell"); cancelButton->setEventId("cancel"); - buyButton->addActionListener(al); - sellButton->addActionListener(al); - cancelButton->addActionListener(al); + buyButton->addActionListener(this); + sellButton->addActionListener(this); + cancelButton->addActionListener(this); add(buyButton); add(sellButton); @@ -61,3 +62,25 @@ BuySellDialog::~BuySellDialog() delete sellButton; delete cancelButton; } + +void BuySellDialog::action(const std::string& eventId) +{ + int actionId = -1; + + if (eventId == "buy") { + actionId = 0; + } + else if (eventId == "sell") { + actionId = 1; + } else if (eventId == "cancel") { + current_npc = 0; + } + if (actionId > -1) { + WFIFOW(0) = net_w_value(0x00c5); + WFIFOL(2) = net_l_value(current_npc); + WFIFOB(6) = net_b_value(actionId); + WFIFOSET(7); + } + + setVisible(false); +} diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 2d1d3c29..19c1e859 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -31,7 +31,8 @@ * * \ingroup GUI */ -class BuySellDialog : public Window { +class BuySellDialog : public Window, public gcn::ActionListener +{ public: /** * Constructor. The action listener passed will receive "sell", "buy" @@ -39,12 +40,17 @@ class BuySellDialog : public Window { * * @see Window::Window */ - BuySellDialog(gcn::ActionListener *al); + BuySellDialog(); /** * Destructor. */ ~BuySellDialog(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const std::string& eventId); private: gcn::Button *buyButton; diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp index 4706112b..4049b061 100644 --- a/src/gui/npc.cpp +++ b/src/gui/npc.cpp @@ -108,7 +108,9 @@ void NpcListDialog::action(const std::string& eventId) WFIFOB(6) = net_b_value(selectedIndex + 1); WFIFOSET(7); setVisible(false); + current_npc = 0; reset(); + } } else if (eventId == "cancel") { @@ -119,5 +121,6 @@ void NpcListDialog::action(const std::string& eventId) WFIFOSET(7); setVisible(false); reset(); + current_npc = 0; } } diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 27c28512..e81d51a8 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -76,4 +76,5 @@ void NpcTextDialog::action(const std::string& eventId) WFIFOSET(6); setText(""); setVisible(false); + current_npc = 0; } diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b914d814..d8e6eb02 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -27,6 +27,7 @@ #include "scrollarea.h" #include "listbox.h" #include "../graphic/graphic.h" +#include "../game.h" #include <sstream> @@ -132,9 +133,11 @@ void SellDialog::action(const std::string& eventId) } } setVisible(false); + current_npc = 0; } else if (eventId == "cancel") { setVisible(false); + current_npc = 0; } } |