From 8bc425ff48b7a874ca0fb9d2285044c75f3010ab Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 13 Feb 2010 15:04:58 -0700 Subject: Make NPC dialogs instance instead of global This change allows players to talk to multiple NPCs at a time (if the server agrees). Manaserv's netcode allows multiple commerce instances too. eAthena's is limited to one commerce instance, due to protocol limitations. --- src/gui/buysell.cpp | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'src/gui/buysell.cpp') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 1258e1d5..8a149a2d 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -32,12 +32,16 @@ #include "utils/gettext.h" -BuySellDialog::BuySellDialog(): +BuySellDialog::DialogList BuySellDialog::instances; + +BuySellDialog::BuySellDialog(int npcId): Window(_("Shop")), + mNpcId(npcId), mBuyButton(0) { setWindowName("BuySell"); - setupWindow->registerWindowForReset(this); + //setupWindow->registerWindowForReset(this); + setCloseButton(true); static const char *buttonNames[] = { N_("Buy"), N_("Sell"), N_("Cancel"), 0 @@ -60,14 +64,14 @@ BuySellDialog::BuySellDialog(): center(); setDefaultSize(); loadWindowState(); + + instances.push_back(this); + setVisible(true); } -void BuySellDialog::logic() +BuySellDialog::~BuySellDialog() { - Window::logic(); - - if (isVisible() && !current_npc) - setVisible(false); + instances.remove(this); } void BuySellDialog::setVisible(bool visible) @@ -75,24 +79,36 @@ void BuySellDialog::setVisible(bool visible) Window::setVisible(visible); if (visible) + { mBuyButton->requestFocus(); + } + else + { + scheduleDelete(); + } } void BuySellDialog::action(const gcn::ActionEvent &event) { - setVisible(false); - if (event.getId() == "Buy") { - Net::getNpcHandler()->buy(current_npc); + Net::getNpcHandler()->buy(mNpcId); } else if (event.getId() == "Sell") { - Net::getNpcHandler()->sell(current_npc); + Net::getNpcHandler()->sell(mNpcId); } - else if (event.getId() == "Cancel") + + close(); +} + +void BuySellDialog::closeAll() +{ + DialogList::iterator it = instances.begin(); + DialogList::iterator it_end = instances.end(); + + for (; it != it_end; it++) { - current_npc = 0; - return; + (*it)->close(); } } -- cgit v1.2.3-60-g2f50