summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-09-28 20:48:05 +0300
committerAndrei Karas <akaras@inbox.ru>2011-09-28 21:00:55 +0300
commitb22ce8d250b1fa995f76c337e1cba6a4b164fe23 (patch)
treeb6761c8bfb0c396750d009b0d38d2060822ea86a /src/gui
parent36f19b67df5ba7b00e91d9a234088f276b8bf513 (diff)
downloadmv-b22ce8d250b1fa995f76c337e1cba6a4b164fe23.tar.gz
mv-b22ce8d250b1fa995f76c337e1cba6a4b164fe23.tar.bz2
mv-b22ce8d250b1fa995f76c337e1cba6a4b164fe23.tar.xz
mv-b22ce8d250b1fa995f76c337e1cba6a4b164fe23.zip
Add amount text field to buy dialog.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/buydialog.cpp51
-rw-r--r--src/gui/buydialog.h6
-rw-r--r--src/gui/widgets/inttextfield.cpp5
-rw-r--r--src/gui/widgets/textfield.cpp4
-rw-r--r--src/gui/widgets/textfield.h7
5 files changed, 62 insertions, 11 deletions
diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp
index 8628afc6e..7fad622df 100644
--- a/src/gui/buydialog.cpp
+++ b/src/gui/buydialog.cpp
@@ -22,6 +22,7 @@
#include "gui/buydialog.h"
+#include "keyboardconfig.h"
#include "shopitem.h"
#include "units.h"
@@ -29,6 +30,7 @@
#include "gui/tradewindow.h"
#include "gui/widgets/button.h"
+#include "gui/widgets/inttextfield.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/scrollarea.h"
@@ -77,6 +79,9 @@ void BuyDialog::init()
setMinHeight(230);
setDefaultSize(260, 230, ImageRect::CENTER);
+ mEnabledKeyboard = keyboard.isEnabled();
+ keyboard.setEnabled(false);
+
mShopItems = new ShopItems;
mShopItemList = new ShopListBox(mShopItems, mShopItems);
@@ -89,6 +94,15 @@ void BuyDialog::init()
mMoneyLabel = new Label(strprintf(_("Price: %s / Total: %s"),
"", ""));
+ mAmountField = new IntTextField(1, 1, 123);
+ mAmountField->setActionEventId("amount");
+ mAmountField->addActionListener(this);
+ mAmountField->setSendAlwaysEvents(true);
+ mAmountField->setEnabled(false);
+
+ mAmountLabel = new Label(_("Amount:"));
+ mAmountLabel->adjustSize();
+
// TRANSLATORS: This is a narrow symbol used to denote 'increasing'.
// You may change this symbol if your language uses another.
mIncreaseButton = new Button(_("+"), "inc", this);
@@ -114,15 +128,17 @@ void BuyDialog::init()
ContainerPlacer placer;
placer = getPlacer(0, 0);
- placer(0, 0, mScrollArea, 8, 5).setPadding(3);
+ placer(0, 0, mScrollArea, 9, 5).setPadding(3);
placer(0, 5, mDecreaseButton);
- placer(1, 5, mSlider, 3);
- placer(4, 5, mIncreaseButton);
- placer(5, 5, mQuantityLabel, 2);
- placer(7, 5, mAddMaxButton);
- placer(0, 6, mMoneyLabel, 8);
- placer(6, 7, mBuyButton);
- placer(7, 7, mQuitButton);
+ placer(1, 5, mSlider, 4);
+ placer(5, 5, mIncreaseButton);
+ placer(6, 5, mQuantityLabel, 2);
+ placer(8, 5, mAddMaxButton);
+ placer(0, 6, mAmountLabel, 2);
+ placer(2, 6, mAmountField, 2);
+ placer(0, 7, mMoneyLabel, 8);
+ placer(7, 8, mBuyButton);
+ placer(8, 8, mQuitButton);
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
@@ -188,24 +204,34 @@ void BuyDialog::action(const gcn::ActionEvent &event)
if (event.getId() == "slider")
{
mAmountItems = static_cast<int>(mSlider->getValue());
+ mAmountField->setValue(mAmountItems);
updateButtonsAndLabels();
}
else if (event.getId() == "inc" && mAmountItems < mMaxItems)
{
mAmountItems++;
mSlider->setValue(mAmountItems);
+ mAmountField->setValue(mAmountItems);
updateButtonsAndLabels();
}
else if (event.getId() == "dec" && mAmountItems > 1)
{
mAmountItems--;
mSlider->setValue(mAmountItems);
+ mAmountField->setValue(mAmountItems);
updateButtonsAndLabels();
}
else if (event.getId() == "max")
{
mAmountItems = mMaxItems;
mSlider->setValue(mAmountItems);
+ mAmountField->setValue(mAmountItems);
+ updateButtonsAndLabels();
+ }
+ else if (event.getId() == "amount")
+ {
+ mAmountItems = mAmountField->getValue();
+ mSlider->setValue(mAmountItems);
updateButtonsAndLabels();
}
// TODO: Actually we'd have a bug elsewhere if this check for the number
@@ -256,6 +282,8 @@ void BuyDialog::valueChanged(const gcn::SelectionEvent &event A_UNUSED)
updateButtonsAndLabels();
mSlider->gcn::Slider::setScale(1, mMaxItems);
+ mAmountField->setRange(1, mMaxItems);
+ mAmountField->setValue(1);
}
void BuyDialog::updateButtonsAndLabels()
@@ -297,6 +325,7 @@ void BuyDialog::updateButtonsAndLabels()
mDecreaseButton->setEnabled(mAmountItems > 1);
mBuyButton->setEnabled(mAmountItems > 0);
mSlider->setEnabled(mMaxItems > 1);
+ mAmountField->setEnabled(mAmountItems > 0);
// Update quantity and money labels
mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems));
@@ -326,3 +355,9 @@ void BuyDialog::closeAll()
(*it)->close();
}
}
+
+void BuyDialog::scheduleDelete()
+{
+ keyboard.setEnabled(mEnabledKeyboard);
+ Window::scheduleDelete();
+}
diff --git a/src/gui/buydialog.h b/src/gui/buydialog.h
index 0ba2e5cb3..53d20e1e5 100644
--- a/src/gui/buydialog.h
+++ b/src/gui/buydialog.h
@@ -38,6 +38,7 @@
class ShopItems;
class ShopListBox;
+class IntTextField;
class ListBox;
/**
@@ -124,6 +125,8 @@ class BuyDialog : public Window, public gcn::ActionListener,
*/
static void closeAll();
+ void scheduleDelete();
+
private:
typedef std::list<BuyDialog*> DialogList;
static DialogList instances;
@@ -140,6 +143,8 @@ class BuyDialog : public Window, public gcn::ActionListener,
gcn::Label *mMoneyLabel;
gcn::Label *mQuantityLabel;
gcn::Slider *mSlider;
+ gcn::Label *mAmountLabel;
+ IntTextField *mAmountField;
ShopItems *mShopItems;
@@ -147,6 +152,7 @@ class BuyDialog : public Window, public gcn::ActionListener,
int mAmountItems;
int mMaxItems;
std::string mNick;
+ bool mEnabledKeyboard;
};
#endif
diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp
index 021340fbe..89544e108 100644
--- a/src/gui/widgets/inttextfield.cpp
+++ b/src/gui/widgets/inttextfield.cpp
@@ -50,6 +50,9 @@ void IntTextField::keyPressed(gcn::KeyEvent &event)
key.getValue() == Key::DELETE)
{
setText(std::string());
+ if (mSendAlwaysEvents)
+ distributeActionEvent();
+
event.consume();
}
@@ -62,6 +65,8 @@ void IntTextField::keyPressed(gcn::KeyEvent &event)
int i;
s >> i;
setValue(i);
+ if (mSendAlwaysEvents)
+ distributeActionEvent();
}
void IntTextField::setRange(int min, int max)
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 5d4fbc0b4..6ce4cbf3b 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -51,11 +51,11 @@ TextField::TextField(const std::string &text, bool loseFocusOnTab,
gcn::ActionListener* listener, std::string eventId,
bool sendAlwaysEvents):
gcn::TextField(text),
+ mSendAlwaysEvents(sendAlwaysEvents),
mNumeric(false),
mMinimum(0),
mMaximum(0),
- mLastEventPaste(false),
- mSendAlwaysEvents(sendAlwaysEvents)
+ mLastEventPaste(false)
{
setFrameSize(2);
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index 7e19099e8..93f970168 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -96,6 +96,12 @@ class TextField : public gcn::TextField
*/
int getValue() const;
+ void setSendAlwaysEvents(bool b)
+ { mSendAlwaysEvents = b; }
+
+ protected:
+ bool mSendAlwaysEvents;
+
private:
void handlePaste();
@@ -109,7 +115,6 @@ class TextField : public gcn::TextField
int mMaximum;
bool mLoseFocusOnTab;
int mLastEventPaste;
- bool mSendAlwaysEvents;
};
#endif