diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-11-14 10:07:55 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-11-14 10:07:55 +0000 |
commit | 69c147510bce9aa24be5ddcb3d050a5d52e3abe7 (patch) | |
tree | 99e7ae22cf75ed210e26e77137bf37d67353839e /src/gui | |
parent | cb04d148c9aed572fe6e66313100e2cd9b66f5d5 (diff) | |
download | mana-client-69c147510bce9aa24be5ddcb3d050a5d52e3abe7.tar.gz mana-client-69c147510bce9aa24be5ddcb3d050a5d52e3abe7.tar.bz2 mana-client-69c147510bce9aa24be5ddcb3d050a5d52e3abe7.tar.xz mana-client-69c147510bce9aa24be5ddcb3d050a5d52e3abe7.zip |
Improved item amount dialog box.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/inttextbox.cpp | 22 | ||||
-rw-r--r-- | src/gui/inttextbox.h | 4 | ||||
-rw-r--r-- | src/gui/item_amount.cpp | 61 |
3 files changed, 44 insertions, 43 deletions
diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextbox.cpp index 2a09f255..5ae3dd93 100644 --- a/src/gui/inttextbox.cpp +++ b/src/gui/inttextbox.cpp @@ -23,7 +23,7 @@ #include "inttextbox.h" -#include <guichan/key.hpp> +#include "sdlinput.h" #include "../utils/tostring.h" @@ -37,17 +37,21 @@ IntTextBox::keyPressed(gcn::KeyEvent &event) { const gcn::Key &key = event.getKey(); - if (key.isNumber() || key.getValue() == gcn::Key::BACKSPACE - || key.getValue() == gcn::Key::DELETE) + if (key.getValue() == Key::BACKSPACE || + key.getValue() == Key::DELETE) { - gcn::TextBox::keyPressed(event); + setText(std::string()); + event.consume(); } - std::stringstream s(gcn::TextBox::getText()); + if (!key.isNumber()) return; + TextField::keyPressed(event); + + std::istringstream s(getText()); int i; s >> i; - if (gcn::TextBox::getText() != "") - setInt(i); + setInt(i); + generateAction(); } void IntTextBox::setRange(int min, int max) @@ -58,9 +62,7 @@ void IntTextBox::setRange(int min, int max) int IntTextBox::getInt() { - if (gcn::TextBox::getText() == "") - return 0; - return mValue; + return getText().empty() ? mMin : mValue; } void IntTextBox::setInt(int i) diff --git a/src/gui/inttextbox.h b/src/gui/inttextbox.h index b5d339ac..219c6018 100644 --- a/src/gui/inttextbox.h +++ b/src/gui/inttextbox.h @@ -24,12 +24,12 @@ #ifndef INTTEXTBOX_H #define INTTEXTBOX_H -#include "textbox.h" +#include "textfield.h" /** * TextBox which only accepts numbers as input. */ -class IntTextBox : public TextBox +class IntTextBox : public TextField { public: /** diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 33a45fe7..6f1c8ae6 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -28,6 +28,8 @@ #include "slider.h" #include "trade.h" +#include "widgets/layout.h" + #include "../item.h" #include "../localplayer.h" @@ -38,47 +40,45 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item, Window("", true, parent), mItem(item) { - // New labels - mItemAmountTextBox = new IntTextBox(1); - - // New buttons - Button *minusButton = new Button("-", "Minus", this); - Button *plusButton = new Button("+", "Plus", this); - Button *okButton = new Button(_("Ok"), "Drop", this); - Button *cancelButton = new Button(_("Cancel"), "Cancel", this); - if (!maxRange) { + if (!maxRange) + { maxRange = mItem->getQuantity(); } - mItemAmountSlide = new Slider(1.0, maxRange); + // Integer field + mItemAmountTextBox = new IntTextBox(1); mItemAmountTextBox->setRange(1, maxRange); - mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10)); + mItemAmountTextBox->setWidth(30); + mItemAmountTextBox->setActionEventId("Dummy"); + mItemAmountTextBox->addActionListener(this); - // Set button events Id + // Slider + mItemAmountSlide = new Slider(1.0, maxRange); + mItemAmountSlide->setHeight(10); mItemAmountSlide->setActionEventId("Slide"); + mItemAmountSlide->addActionListener(this); - // Set position - mItemAmountTextBox->setPosition(35, 10); - mItemAmountTextBox->setSize(24, 16); - plusButton->setPosition(60, 5); - minusButton->setPosition(10, 5); - mItemAmountSlide->setPosition(10, 35); - okButton->setPosition(10, 50); - cancelButton->setPosition(60, 50); - - // Assemble - add(mItemAmountTextBox); - add(plusButton); - add(minusButton); - add(mItemAmountSlide); - add(okButton); - add(cancelButton); + // Buttons + Button *minusButton = new Button("-", "Minus", this); + minusButton->setSize(20, 20); + Button *plusButton = new Button("+", "Plus", this); + plusButton->setSize(20, 20); + Button *okButton = new Button(_("Ok"), "Drop", this); + Button *cancelButton = new Button(_("Cancel"), "Cancel", this); - mItemAmountSlide->addActionListener(this); + // Set positions + place(0, 0, minusButton); + place(1, 0, mItemAmountTextBox).setPadding(2); + place(2, 0, plusButton); + place(0, 1, mItemAmountSlide, 6); + place(4, 2, okButton); + place(5, 2, cancelButton); + reflowLayout(250, 0); resetAmount(); - switch (usage) { + switch (usage) + { case AMOUNT_TRADE_ADD: setCaption(_("Select amount of items to trade.")); okButton->setActionEventId("AddTrade"); @@ -95,7 +95,6 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item, break; } - setContentSize(200, 80); setLocationRelativeTo(getParentWindow()); setVisible(true); } |