diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-02-16 14:41:24 +0000 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-02-16 14:43:19 +0000 |
commit | 9dfc4ea2f30f43fb5ffd239b90b2a7259fbe0330 (patch) | |
tree | 37b2da3fc74946fb180b8e60d6e32b1190775a3f /src | |
parent | a1a5ebb9ef14e013ae63a71c2c28609f2a65cdaa (diff) | |
download | mana-9dfc4ea2f30f43fb5ffd239b90b2a7259fbe0330.tar.gz mana-9dfc4ea2f30f43fb5ffd239b90b2a7259fbe0330.tar.bz2 mana-9dfc4ea2f30f43fb5ffd239b90b2a7259fbe0330.tar.xz mana-9dfc4ea2f30f43fb5ffd239b90b2a7259fbe0330.zip |
Add next/close buttons for NPCs
And keep the text dialog open for the whole transaction, logging user
input and keep a full record of text from the NPC (for the current
transaction only).
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/npc_text.cpp | 33 | ||||
-rw-r--r-- | src/gui/npc_text.h | 5 | ||||
-rw-r--r-- | src/gui/npcintegerdialog.cpp | 7 | ||||
-rw-r--r-- | src/gui/npclistdialog.cpp | 9 | ||||
-rw-r--r-- | src/gui/npcstringdialog.cpp | 11 | ||||
-rw-r--r-- | src/net/npchandler.cpp | 7 | ||||
-rw-r--r-- | src/npc.cpp | 4 |
7 files changed, 62 insertions, 14 deletions
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 3e40d1bb..19e46e6b 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -45,13 +45,13 @@ NpcTextDialog::NpcTextDialog(): mTextBox->setOpaque(false); mScrollArea = new ScrollArea(mTextBox); - gcn::Button *okButton = new Button(_("OK"), "ok", this); + mButton = new Button(_("Waiting for server"), "", this); mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mScrollArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); place(0, 0, mScrollArea, 5).setPadding(3); - place(4, 1, okButton); + place(4, 1, mButton); Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); @@ -69,18 +69,39 @@ void NpcTextDialog::setText(const std::string &text) void NpcTextDialog::addText(const std::string &text) { setText(mText + text + "\n"); + mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); +} + +void NpcTextDialog::showNextButton() +{ + mButton->setCaption(_("Next")); + mButton->setActionEventId("next"); + mButton->setEnabled(true); +} + +void NpcTextDialog::showCloseButton() +{ + mButton->setCaption(_("Close")); + mButton->setActionEventId("close"); + mButton->setEnabled(true); } void NpcTextDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "ok") + if (event.getId() == "next") + { + current_npc->nextDialog(); + npcTextDialog->addText("\n> Next\n"); + } + else if (event.getId() == "close") { setText(""); setVisible(false); - if (current_npc) - current_npc->nextDialog(); - current_npc = 0; + current_npc = NULL; } + mButton->setEnabled(false); + mButton->setCaption(_("Waiting for server")); + mButton->setActionEventId(""); } void NpcTextDialog::widgetResized(const gcn::Event &event) diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index cd1f58a5..604212d2 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -70,6 +70,10 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + void showNextButton(); + + void showCloseButton(); + /** * Called when resizing the window. * @@ -80,6 +84,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener private: gcn::ScrollArea *mScrollArea; TextBox *mTextBox; + gcn::Button *mButton; std::string mText; }; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 7e888d16..88d02311 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -21,6 +21,7 @@ #include "button.h" #include "inttextfield.h" +#include "npc_text.h" #include "npcintegerdialog.h" #include "widgets/layout.h" @@ -28,6 +29,9 @@ #include "../npc.h" #include "../utils/gettext.h" +#include "../utils/strprintf.h" + +extern NpcTextDialog *npcTextDialog; NpcIntegerDialog::NpcIntegerDialog(): Window(_("NPC Number Request")) @@ -76,11 +80,13 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (event.getId() == "ok") { finish = 1; + npcTextDialog->addText(strprintf("\n> %d\n", value)); } else if (event.getId() == "cancel") { finish = 1; mValueField->reset(); + npcTextDialog->addText(_("\n> Cancel\n")); } else if (event.getId() == "decvalue") { @@ -99,7 +105,6 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) { setVisible(false); current_npc->integerInput(mValueField->getValue()); - current_npc = 0; mValueField->reset(); } } diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index fe924da1..78d43fd2 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -23,6 +23,7 @@ #include "button.h" #include "listbox.h" +#include "npc_text.h" #include "npclistdialog.h" #include "scrollarea.h" @@ -31,6 +32,9 @@ #include "../npc.h" #include "../utils/gettext.h" +#include "../utils/strprintf.h" + +extern NpcTextDialog *npcTextDialog; NpcListDialog::NpcListDialog(): Window(_("NPC")) @@ -89,7 +93,6 @@ void NpcListDialog::reset() void NpcListDialog::action(const gcn::ActionEvent &event) { int choice = 0; - if (event.getId() == "ok") { // Send the selected index back to the server @@ -97,11 +100,14 @@ void NpcListDialog::action(const gcn::ActionEvent &event) if (selectedIndex > -1) { choice = selectedIndex + 1; + npcTextDialog->addText(strprintf("\n> \"%s\"\n", + mItems[selectedIndex].c_str())); } } else if (event.getId() == "cancel") { choice = 0xff; // 0xff means cancel + npcTextDialog->addText(_("\n> Cancel\n")); } if (choice) @@ -109,6 +115,5 @@ void NpcListDialog::action(const gcn::ActionEvent &event) setVisible(false); reset(); current_npc->dialogChoice(choice); - current_npc = 0; } } diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 02f4e4b9..dc5893f8 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -20,15 +20,19 @@ */ #include "button.h" +#include "npc_text.h" #include "npcstringdialog.h" #include "textfield.h" #include "../npc.h" #include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "widgets/layout.h" +extern NpcTextDialog *npcTextDialog; + NpcStringDialog::NpcStringDialog(): Window(_("NPC Text Request")) { @@ -60,11 +64,16 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) if (event.getId() == "cancel") { mValueField->setText(""); + npcTextDialog->addText(_("\n> Cancel\n")); + } + else + { + npcTextDialog->addText(strprintf("\n> \"%s\"\n", + mValueField->getText().c_str())); } setVisible(false); current_npc->stringInput(mValueField->getText()); - current_npc = 0; mValueField->setText(""); } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index ea03537f..3080bcf8 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -78,12 +78,15 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_CLOSE: id = msg->readInt32(); - if (current_npc == dynamic_cast<NPC*>(beingManager->findBeing(id))) - current_npc = NULL; + current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); + npcTextDialog->showCloseButton(); break; case SMSG_NPC_NEXT: // Next button in NPC dialog, currently unused + id = msg->readInt32(); + current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); + npcTextDialog->showNextButton(); break; case SMSG_NPC_INT_INPUT: diff --git a/src/npc.cpp b/src/npc.cpp index dfbc7d16..70b3ce13 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -144,10 +144,10 @@ void NPC::stringInput(const std::string &value) { MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 8); + outMsg.writeInt16(value.length() + 9); outMsg.writeInt32(mId); outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); // Just to be safe + outMsg.writeInt8(0); } /* |