summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-07 22:16:38 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-07 22:16:38 +0300
commit09886752408b872218e0080d3a00095e3eaa146b (patch)
treeb0b1ea40842b5ef329b0f0af7a0692caf850e4d3 /src/gui
parentcc4ac1e1884378e861efd577507a28ae668156f1 (diff)
downloadmv-09886752408b872218e0080d3a00095e3eaa146b.tar.gz
mv-09886752408b872218e0080d3a00095e3eaa146b.tar.bz2
mv-09886752408b872218e0080d3a00095e3eaa146b.tar.xz
mv-09886752408b872218e0080d3a00095e3eaa146b.zip
improve itemamountwindow class.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/itemamountwindow.cpp27
-rw-r--r--src/gui/itemamountwindow.h3
2 files changed, 12 insertions, 18 deletions
diff --git a/src/gui/itemamountwindow.cpp b/src/gui/itemamountwindow.cpp
index 7f880dcd0..3df003bfb 100644
--- a/src/gui/itemamountwindow.cpp
+++ b/src/gui/itemamountwindow.cpp
@@ -63,8 +63,8 @@ public:
if (i->first < 0)
continue;
- const ItemInfo &info = (*i->second);
- std::string name = info.getName();
+ const ItemInfo &info = *i->second;
+ const std::string name = info.getName();
if (name != "unnamed" && !info.getName().empty()
&& info.getName() != "unnamed")
{
@@ -81,12 +81,12 @@ public:
virtual ~ItemsModal()
{ }
- virtual int getNumberOfElements()
+ virtual int getNumberOfElements() override
{
return static_cast<int>(mStrings.size());
}
- virtual std::string getElementAt(int i)
+ virtual std::string getElementAt(int i) override
{
if (i < 0 || i >= getNumberOfElements())
return "???";
@@ -149,8 +149,8 @@ ItemAmountWindow::ItemAmountWindow(const Usage usage, Window *const parent,
mItemPriceSlide(nullptr),
mItemDropDown(nullptr),
mItemsModal(nullptr),
- mEnabledKeyboard(keyboard.isEnabled()),
- mPrice(0)
+ mPrice(0),
+ mEnabledKeyboard(keyboard.isEnabled())
{
if (!mItem)
{
@@ -162,28 +162,23 @@ ItemAmountWindow::ItemAmountWindow(const Usage usage, Window *const parent,
else if (!mMax)
mMax = mItem->getQuantity();
- // Save keyboard state
keyboard.setEnabled(false);
- // Integer field
mItemAmountTextField->setRange(1, mMax);
mItemAmountTextField->setWidth(35);
mItemAmountTextField->addKeyListener(this);
- // Slider
mItemAmountSlide->setHeight(10);
mItemAmountSlide->setActionEventId("slide");
mItemAmountSlide->addActionListener(this);
if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd)
{
- // Integer field
mItemPriceTextField = new IntTextField(this, 1);
mItemPriceTextField->setRange(1, 10000000);
mItemPriceTextField->setWidth(35);
mItemPriceTextField->addKeyListener(this);
- // Slider
mItemPriceSlide = new Slider(1.0, 10000000);
mItemPriceSlide->setHeight(10);
mItemPriceSlide->setActionEventId("slidePrice");
@@ -200,7 +195,6 @@ ItemAmountWindow::ItemAmountWindow(const Usage usage, Window *const parent,
mItemDropDown->addActionListener(this);
}
-
// Buttons
// TRANSLATORS: item amount window button
Button *const minusAmountButton = new Button(this, _("-"), "dec", this);
@@ -366,9 +360,8 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event)
if (!mItemDropDown || !mItemsModal)
return;
- std::string str = mItemsModal->getElementAt(
- mItemDropDown->getSelected());
- const int id = ItemDB::get(str).getId();
+ const int id = ItemDB::get(mItemsModal->getElementAt(
+ mItemDropDown->getSelected())).getId();
mItem = new Item(id, 10000);
@@ -395,13 +388,13 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event)
if (mItemPriceTextField && mItemPriceSlide)
{
- int price = 0;
-
if (mPrice > 7)
mPrice = 7;
else if (mPrice < 0)
mPrice = 0;
+ int price = 0;
+
if (eventId == "incPrice")
{
mPrice++;
diff --git a/src/gui/itemamountwindow.h b/src/gui/itemamountwindow.h
index 1ed3f4e59..7ab8922f7 100644
--- a/src/gui/itemamountwindow.h
+++ b/src/gui/itemamountwindow.h
@@ -118,8 +118,9 @@ class ItemAmountWindow final : public Window,
ItemsModal *mItemsModal;
- bool mEnabledKeyboard;
int mPrice;
+
+ bool mEnabledKeyboard;
};
#endif // ITEM_AMOUNT_WINDOW_H