From 3a274b8e8c1183e2ef37a5ac0d75849db5560fb3 Mon Sep 17 00:00:00 2001 From: Blue Date: Sun, 3 May 2009 23:30:41 +0200 Subject: NPC Integer input plus and minus Added plus and minus buttons on NPC Integer input. No server side modifications. --- src/gui/npcdialog.cpp | 30 ++++++++++++++++++++++-------- src/gui/npcdialog.h | 6 ++++-- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 6c42695e..5b1d1a07 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -45,7 +45,7 @@ #define CAPTION_SUBMIT _("Submit") NpcDialog::NpcDialog() - : Window(_("NPC")), + : Window(_("NPC")), mActionState(NPC_ACTION_WAIT), mInputState(NPC_INPUT_NONE), mNpcId(0), @@ -92,6 +92,10 @@ NpcDialog::NpcDialog() // Setup button mButton = new Button("", "ok", this); + //Setup more and less buttons (int input) + mPlusButton = new Button(_("+"), "plus", this); + mMinusButton = new Button(_("-"), "minus", this); + int width = std::max(mButton->getFont()->getWidth(CAPTION_WAITING), mButton->getFont()->getWidth(CAPTION_NEXT)); width = std::max(width, mButton->getFont()->getWidth(CAPTION_CLOSE)); @@ -139,19 +143,19 @@ void NpcDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") { - if (mActionState == NPC_ACTION_NEXT) + if (mActionState == NPC_ACTION_NEXT) { nextDialog(); addText("\n> Next\n"); - } + } else if (mActionState == NPC_ACTION_CLOSE) { - if (current_npc) + if (current_npc) closeDialog(); setVisible(false); current_npc = 0; NPC::isTalking = false; - } + } else if (mActionState == NPC_ACTION_INPUT) { std::string printText = ""; // Text that will get printed in the textbox @@ -180,7 +184,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) } // addText will auto remove the input layout addText( strprintf("\n> \"%s\"\n", printText.c_str()) ); - } + } } else if (event.getId() == "reset") { @@ -193,6 +197,14 @@ void NpcDialog::action(const gcn::ActionEvent &event) mIntField->setValue(mDefaultInt); } } + else if(event.getId() == "plus") + { + mIntField->setValue(mIntField->getValue() + 1); + } + else if(event.getId() == "minus") + { + mIntField->setValue(mIntField->getValue() - 1); + } } void NpcDialog::nextDialog() @@ -308,12 +320,14 @@ void NpcDialog::buildLayout() else if(mInputState == NPC_INPUT_INTEGER) { place(0, 0, mScrollArea, 5, 3); - place(0, 3, mIntField, 3); + place(0, 3, mMinusButton, 1); + place(1, 3, mIntField, 3); + place(4, 3, mPlusButton, 1); place(0, 4, mResetButton, 2); place(3, 4, mButton, 2); } } - + Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index 7741f35c..2adcc9c1 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -163,17 +163,19 @@ class NpcDialog : public Window, public gcn::ActionListener, ListBox *mItemList; gcn::ScrollArea *mListScrollArea; std::vector mItems; - + // Used for string and integer input TextField *mTextField; IntTextField *mIntField; + Button *mPlusButton; + Button *mMinusButton; // Used for the button Button *mButton; // Will reset the text and integer input to the provided default Button *mResetButton; - + enum NPCInputState { NPC_INPUT_NONE, NPC_INPUT_LIST, -- cgit v1.2.3-70-g09d2