diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-02-17 15:41:47 +0000 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-02-17 15:41:47 +0000 |
commit | 66d2c83cf1197b0c22be070ff2c594a0a37ecfac (patch) | |
tree | 5a8e5ea093c7b567ddeda10084b70b5de1cdaebc | |
parent | 366e0b120624cb382fd3b233b8ec7a75c31a2da4 (diff) | |
download | mana-66d2c83cf1197b0c22be070ff2c594a0a37ecfac.tar.gz mana-66d2c83cf1197b0c22be070ff2c594a0a37ecfac.tar.bz2 mana-66d2c83cf1197b0c22be070ff2c594a0a37ecfac.tar.xz mana-66d2c83cf1197b0c22be070ff2c594a0a37ecfac.zip |
Reduce NpcTextDialog to one action
This allows external classes (like game.cpp) to send actions to it
without them having to know about it's internal state.
-rw-r--r-- | src/gui/npc_text.cpp | 36 | ||||
-rw-r--r-- | src/gui/npc_text.h | 7 |
2 files changed, 29 insertions, 14 deletions
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index ea5dbd4c..0a8a4e4d 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -31,7 +31,8 @@ #include "../utils/gettext.h" NpcTextDialog::NpcTextDialog(): - Window(_("NPC")) + Window(_("NPC")), + mState(NPC_TEXT_STATE_WAITING) { setResizable(true); @@ -45,7 +46,7 @@ NpcTextDialog::NpcTextDialog(): mTextBox->setOpaque(false); mScrollArea = new ScrollArea(mTextBox); - mButton = new Button(_("Waiting for server"), "", this); + mButton = new Button(_("Waiting for server"), "ok", this); mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mScrollArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); @@ -75,33 +76,40 @@ void NpcTextDialog::addText(const std::string &text) void NpcTextDialog::showNextButton() { mButton->setCaption(_("Next")); - mButton->setActionEventId("next"); + mState = NPC_TEXT_STATE_NEXT; mButton->setEnabled(true); } void NpcTextDialog::showCloseButton() { mButton->setCaption(_("Close")); - mButton->setActionEventId("close"); + mState = NPC_TEXT_STATE_CLOSE; mButton->setEnabled(true); } void NpcTextDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "next") + if (event.getId() == "ok") { - current_npc->nextDialog(); - addText("\n> Next\n"); - } - else if (event.getId() == "close") - { - setText(""); - setVisible(false); - current_npc = NULL; + switch (mState) { + case NPC_TEXT_STATE_NEXT: + current_npc->nextDialog(); + addText("\n> Next\n"); + break; + case NPC_TEXT_STATE_CLOSE: + setText(""); + setVisible(false); + current_npc = NULL; + break; + default: + return; + } } + else return; + mButton->setEnabled(false); mButton->setCaption(_("Waiting for server")); - mButton->setActionEventId(""); + mState = NPC_TEXT_STATE_WAITING; } void NpcTextDialog::widgetResized(const gcn::Event &event) diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 604212d2..a1373830 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -87,6 +87,13 @@ class NpcTextDialog : public Window, public gcn::ActionListener gcn::Button *mButton; std::string mText; + + enum NPCTextState { + NPC_TEXT_STATE_WAITING, + NPC_TEXT_STATE_NEXT, + NPC_TEXT_STATE_CLOSE + }; + int mState; }; #endif // NPC_TEXT_H |