From 26a52e8f74306b6e13e7a2029c19d8c7e1efd23a Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 16 Feb 2009 18:52:54 +0000 Subject: Allow setting default values for NPC dialogs --- src/gui/npcintegerdialog.cpp | 5 +++++ src/gui/npcintegerdialog.h | 7 +++++++ src/gui/npcstringdialog.cpp | 3 ++- src/gui/npcstringdialog.h | 1 + src/net/npchandler.cpp | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index b05e77ba..6b26349a 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -109,6 +109,11 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) } } +void NpcIntegerDialog::setDefaultValue(const int value) +{ + mValueField->setDefaultValue(value); +} + bool NpcIntegerDialog::isInputFocused() { return mValueField->isFocused(); diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index a8ffcf0f..7c064ca6 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -61,6 +61,13 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener */ void setRange(const int min, const int max); + /** + * Sets the default value. + * + * @param value The new default value + */ + void setDefaultValue(const int value); + /** * Checks whether NpcStringDialog is Focused or not. */ diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index dc5893f8..f2ccc3cf 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -57,13 +57,14 @@ std::string NpcStringDialog::getValue() void NpcStringDialog::setValue(const std::string &value) { mValueField->setText(value); + mDefault = value; } void NpcStringDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "cancel") { - mValueField->setText(""); + mValueField->setText(mDefault); npcTextDialog->addText(_("\n> Cancel\n")); } else diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index 960f8cec..0faaf203 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -70,6 +70,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener private: gcn::TextField *mValueField; + std::string mDefault; }; #endif // GUI_NPCSTRINGDIALOG_H diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 3080bcf8..a6dc216b 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -94,6 +94,7 @@ void NPCHandler::handleMessage(MessageIn *msg) id = msg->readInt32(); current_npc = dynamic_cast(beingManager->findBeing(id)); npcIntegerDialog->setRange(0, 2147483647); + npcIntegerDialog->setDefaultValue(0); npcIntegerDialog->setVisible(true); npcIntegerDialog->requestFocus(); break; -- cgit v1.2.3-70-g09d2