From 45ba0e489cf85d957c26f1e5895399953c203cd9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 2 Feb 2015 00:05:22 +0300 Subject: update items amount in shop dialog after buy from vending shop. --- src/gui/windows/buydialog.cpp | 27 +++++++++++++++++---------- src/gui/windows/buydialog.h | 2 ++ 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index 068440c65..a71759840 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -471,16 +471,7 @@ void BuyDialog::action(const ActionEvent &event) mAmountItems); } - // Update money and adjust the max number of items - // that can be bought - mMaxItems -= mAmountItems; - setMoney(mMoney - - mAmountItems * mShopItems->at(selectedItem)->getPrice()); - - // Reset selection - mAmountItems = 1; - mSlider->setScale(1, mMaxItems); - mSlider->setValue(1); + updateSlider(selectedItem); } else if (mNpcId == Nick) { @@ -492,6 +483,9 @@ void BuyDialog::action(const ActionEvent &event) vendingHandler->buy(being, item->getInvIndex(), mAmountItems); + item->increaseQuantity(-mAmountItems); + item->update(); + updateSlider(selectedItem); } } else if (tradeWindow) @@ -508,6 +502,19 @@ void BuyDialog::action(const ActionEvent &event) } } +void BuyDialog::updateSlider(const int selectedItem) +{ + // Update money and adjust the max number of items + // that can be bought + mMaxItems -= mAmountItems; + setMoney(mMoney - mAmountItems * mShopItems->at(selectedItem)->getPrice()); + + // Reset selection + mAmountItems = 1; + mSlider->setScale(1, mMaxItems); + mSlider->setValue(1); +} + void BuyDialog::valueChanged(const SelectionEvent &event A_UNUSED) { // Reset amount of items and update labels diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h index d697eff5d..78df8ebf8 100644 --- a/src/gui/windows/buydialog.h +++ b/src/gui/windows/buydialog.h @@ -145,6 +145,8 @@ class BuyDialog final : public Window, static void closeAll(); private: + void updateSlider(const int selectedItem); + typedef std::list DialogList; static DialogList instances; -- cgit v1.2.3-60-g2f50