diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-02-13 15:04:58 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-02-13 15:08:54 -0700 |
commit | 8bc425ff48b7a874ca0fb9d2285044c75f3010ab (patch) | |
tree | 5904c7f53cde9ffbe7df2a63f088561141e06b66 /src/gui/npcdialog.cpp | |
parent | 28c9cec5d39c9a1b98694eba9a28281cf111e34a (diff) | |
download | mana-8bc425ff48b7a874ca0fb9d2285044c75f3010ab.tar.gz mana-8bc425ff48b7a874ca0fb9d2285044c75f3010ab.tar.bz2 mana-8bc425ff48b7a874ca0fb9d2285044c75f3010ab.tar.xz mana-8bc425ff48b7a874ca0fb9d2285044c75f3010ab.zip |
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.
Diffstat (limited to 'src/gui/npcdialog.cpp')
-rw-r--r-- | src/gui/npcdialog.cpp | 74 |
1 files changed, 67 insertions, 7 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index ae96c352..f1b671b1 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -46,9 +46,11 @@ #define CAPTION_CLOSE _("Close") #define CAPTION_SUBMIT _("Submit") -NpcDialog::NpcDialog() +NpcDialog::DialogList NpcDialog::instances; + +NpcDialog::NpcDialog(int npcId) : Window(_("NPC")), - mNpcId(0), + mNpcId(npcId), mDefaultInt(0), mInputState(NPC_INPUT_NONE), mActionState(NPC_ACTION_WAIT) @@ -56,7 +58,8 @@ NpcDialog::NpcDialog() // Basic Window Setup setWindowName("NpcText"); setResizable(true); - setupWindow->registerWindowForReset(this); + //setupWindow->registerWindowForReset(this); + setFocusable(true); setMinWidth(200); setMinHeight(150); @@ -111,17 +114,24 @@ NpcDialog::NpcDialog() center(); loadWindowState(); + + instances.push_back(this); + setVisible(true); + requestFocus(); } NpcDialog::~NpcDialog() { // These might not actually be in the layout, so lets be safe + delete mScrollArea; delete mItemList; delete mTextField; delete mIntField; delete mResetButton; delete mPlusButton; delete mMinusButton; + + instances.remove(this); } void NpcDialog::setText(const std::string &text) @@ -162,10 +172,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) } else if (mActionState == NPC_ACTION_CLOSE) { - if (current_npc) - closeDialog(); - setVisible(false); - current_npc = 0; + closeDialog(); } else if (mActionState == NPC_ACTION_INPUT) { @@ -276,6 +283,22 @@ bool NpcDialog::isInputFocused() const return mTextField->isFocused() || mIntField->isFocused(); } +bool NpcDialog::isAnyInputFocused() +{ + DialogList::iterator it = instances.begin(); + DialogList::iterator it_end = instances.end(); + + for (; it != it_end; it++) + { + if ((*it)->isInputFocused()) + { + return true; + } + } + + return false; +} + void NpcDialog::integerRequest(int defaultValue, int min, int max) { mActionState = NPC_ACTION_INPUT; @@ -312,6 +335,43 @@ void NpcDialog::widgetResized(const gcn::Event &event) setText(mText); } +void NpcDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (!visible) + { + scheduleDelete(); + } +} + +NpcDialog *NpcDialog::getActive() +{ + DialogList::iterator it = instances.begin(); + DialogList::iterator it_end = instances.end(); + + for (; it != it_end; it++) + { + if ((*it)->isFocused()) + { + return (*it); + } + } + + return NULL; +} + +void NpcDialog::closeAll() +{ + DialogList::iterator it = instances.begin(); + DialogList::iterator it_end = instances.end(); + + for (; it != it_end; it++) + { + (*it)->close(); + } +} + void NpcDialog::buildLayout() { clearLayout(); |