diff options
Diffstat (limited to 'src/gui/item_amount.cpp')
-rw-r--r-- | src/gui/item_amount.cpp | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 191c7b8b..48b0e601 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -25,6 +25,8 @@ #include "slider.h" #include "trade.h" +#include "widgets/layout.h" + #include "../item.h" #include "../localplayer.h" @@ -34,38 +36,37 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), mItem(item) { + const int maxRange = mItem->getQuantity(); + // Integer field mItemAmountTextBox = new IntTextBox(1); - mItemAmountTextBox->setRange(1, mItem->getQuantity()); + mItemAmountTextBox->setRange(1, maxRange); + mItemAmountTextBox->setWidth(30); + mItemAmountTextBox->setActionEventId("Dummy"); + mItemAmountTextBox->addActionListener(this); // Slider - mItemAmountSlide = new Slider(1.0, mItem->getQuantity()); + mItemAmountSlide = new Slider(1.0, maxRange); + mItemAmountSlide->setHeight(10); mItemAmountSlide->setActionEventId("Slide"); mItemAmountSlide->addActionListener(this); // 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); // Set positions - mItemAmountTextBox->setPosition(35, 10); - mItemAmountTextBox->setSize(24, 16); - plusButton->setPosition(60, 5); - minusButton->setPosition(10, 5); - mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10)); - 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); + 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(); @@ -82,7 +83,6 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): break; } - setContentSize(200, 80); setLocationRelativeTo(getParentWindow()); setVisible(true); } @@ -100,16 +100,6 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) { scheduleDelete(); } - else if (event.getId() == "Drop") - { - player_node->dropItem(mItem, mItemAmountTextBox->getInt()); - scheduleDelete(); - } - else if (event.getId() == "AddTrade") - { - tradeWindow->tradeItem(mItem, mItemAmountTextBox->getInt()); - scheduleDelete(); - } else if (event.getId() == "Plus") { amount++; @@ -122,7 +112,16 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) { amount = static_cast<int>(mItemAmountSlide->getValue()); } + else if (event.getId() == "Drop") + { + player_node->dropItem(mItem, mItemAmountTextBox->getInt()); + scheduleDelete(); + } + else if (event.getId() == "AddTrade") + { + tradeWindow->tradeItem(mItem, mItemAmountTextBox->getInt()); + scheduleDelete(); + } mItemAmountTextBox->setInt(amount); mItemAmountSlide->setValue(amount); } - |