diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-02-04 19:06:32 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-02-04 19:06:32 +0200 |
commit | fcf12d937c55e115e80325f8fbd6069f27a667a3 (patch) | |
tree | 26203cd700697f30f9fb8b149b3658deae7db559 | |
parent | d6ef8f92a7abe1e4a635e86f1bcf2675ffbc6658 (diff) | |
download | manaverse-fcf12d937c55e115e80325f8fbd6069f27a667a3.tar.gz manaverse-fcf12d937c55e115e80325f8fbd6069f27a667a3.tar.bz2 manaverse-fcf12d937c55e115e80325f8fbd6069f27a667a3.tar.xz manaverse-fcf12d937c55e115e80325f8fbd6069f27a667a3.zip |
Update item amount in sell dialog.
-rw-r--r-- | src/gui/sell.cpp | 27 | ||||
-rw-r--r-- | src/shopitem.cpp | 19 | ||||
-rw-r--r-- | src/shopitem.h | 3 |
3 files changed, 41 insertions, 8 deletions
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 1b149cd48..c918971ab 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -234,7 +234,11 @@ void SellDialog::action(const gcn::ActionEvent &event) mAmountItems = 1; mSlider->setValue(0); - if (!mMaxItems) + if (mMaxItems) + { + updateButtonsAndLabels(); + } + else { // All were sold mShopItemList->setSelected(-1); @@ -280,14 +284,23 @@ void SellDialog::updateButtonsAndLabels() { int selectedItem = mShopItemList->getSelected(); int income = 0; + ShopItem *item = 0; if (selectedItem > -1 && mShopItems->at(selectedItem)) { - mMaxItems = mShopItems->at(selectedItem)->getQuantity(); - if (mAmountItems > mMaxItems) - mAmountItems = mMaxItems; - - income = mAmountItems * mShopItems->at(selectedItem)->getPrice(); + item = mShopItems->at(selectedItem); + if (item) + { + mMaxItems = item->getQuantity(); + if (mAmountItems > mMaxItems) + mAmountItems = mMaxItems; + income = mAmountItems * mShopItems->at(selectedItem)->getPrice(); + } + else + { + mMaxItems = 0; + mAmountItems = 0; + } } else { @@ -306,6 +319,8 @@ void SellDialog::updateButtonsAndLabels() mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"), Units::formatCurrency(income).c_str(), Units::formatCurrency(mPlayerMoney + income).c_str())); + if (item) + item->update(); } void SellDialog::setVisible(bool visible) diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 56fec1fac..4ed0459de 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -30,7 +30,8 @@ ShopItem::ShopItem(int inventoryIndex, int id, int quantity, int price) : Item(id, 0), - mPrice(price) + mPrice(price), + mShowQuantity(true) { mDisplayName = getInfo().getName() + " (" + Units::formatCurrency(mPrice).c_str() + ") "; @@ -41,7 +42,10 @@ ShopItem::ShopItem(int inventoryIndex, int id, addDuplicate(inventoryIndex, quantity); } -ShopItem::ShopItem (int id, int price) : Item (id, 0), mPrice(price) +ShopItem::ShopItem (int id, int price) : + Item (id, 0), + mPrice(price), + mShowQuantity(false) { mDisplayName = getInfo().getName() + " (" + Units::formatCurrency(mPrice).c_str() + ")"; @@ -59,6 +63,17 @@ ShopItem::~ShopItem() } } +void ShopItem::update() +{ + if (mShowQuantity) + { + mDisplayName = getInfo().getName() + " (" + + Units::formatCurrency(mPrice).c_str() + ") "; + if (mQuantity > 0) + mDisplayName += "[" + toString(mQuantity) + "]"; + } +} + void ShopItem::addDuplicate(int inventoryIndex, int quantity) { DuplicateItem* di = new DuplicateItem; diff --git a/src/shopitem.h b/src/shopitem.h index 04d26df8f..f2cd3d566 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -72,6 +72,8 @@ class ShopItem : public Item */ void addDuplicate(); + void update(); + /** * Gets the quantity of the currently topmost duplicate. * @@ -125,6 +127,7 @@ class ShopItem : public Item protected: int mPrice; std::string mDisplayName; + bool mShowQuantity; /** * Struct to keep track of duplicates. |