diff options
author | Joshua Langley <joshlangley[at]optusnet.com.au> | 2007-08-19 09:21:10 +0000 |
---|---|---|
committer | Joshua Langley <joshlangley[at]optusnet.com.au> | 2007-08-19 09:21:10 +0000 |
commit | 7425393f7cb404e4fc09f9f7db4b0f9b951772f9 (patch) | |
tree | 033e9cc0b08d770a1b2abde26a8238dffbf5d14b | |
parent | fd168c24b9bc45c4bc6c092d072fef835063918e (diff) | |
download | mana-7425393f7cb404e4fc09f9f7db4b0f9b951772f9.tar.gz mana-7425393f7cb404e4fc09f9f7db4b0f9b951772f9.tar.bz2 mana-7425393f7cb404e4fc09f9f7db4b0f9b951772f9.tar.xz mana-7425393f7cb404e4fc09f9f7db4b0f9b951772f9.zip |
buy/sell fixed minimum quantity 1.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/gui/buy.cpp | 32 | ||||
-rw-r--r-- | src/gui/sell.cpp | 32 |
3 files changed, 35 insertions, 35 deletions
@@ -1,6 +1,10 @@ 2007-08-19 Joshua Langley <joshlangley[at]optusnet.com.au> - * src/keyboardconfig.cpp, src/keyboardconfig.h - minor cleanup. + * src/gui/buy.cpp, src/gui/sell.cpp: buy/sell fixed minimum quantity 1. + +2007-08-19 Joshua Langley <joshlangley[at]optusnet.com.au> + + * src/keyboardconfig.cpp, src/keyboardconfig.h: minor cleanup. 2007-08-17 Bjørn Lindeijer <bjorn@lindeijer.nl> diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index b3f97e57..ea477e07 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -39,7 +39,6 @@ #include "../utils/tostring.h" - BuyDialog::BuyDialog(Network *network): Window("Buy"), mNetwork(network), mMoney(0), mAmountItems(0), mMaxItems(0) @@ -123,7 +122,7 @@ void BuyDialog::reset() mShopItems->clear(); mShopItemList->adjustSize(); mMoney = 0; - mSlider->setValue(0.0); + mSlider->setValue(0); // Reset Previous Selected Items to prevent failing asserts mShopItemList->setSelected(-1); @@ -145,6 +144,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) { setVisible(false); current_npc = 0; + return; } // The following actions require a valid selection @@ -156,21 +156,19 @@ void BuyDialog::action(const gcn::ActionEvent &event) if (event.getId() == "slider") { - mAmountItems = (int)(mSlider->getValue() * mMaxItems); + mAmountItems = (int) mSlider->getValue(); updateButtonsAndLabels(); } else if (event.getId() == "+" && mAmountItems < mMaxItems) { mAmountItems++; - - mSlider->setValue((double) mAmountItems / (double) mMaxItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } - else if (event.getId() == "-" && mAmountItems > 0) + else if (event.getId() == "-" && mAmountItems > 1) { mAmountItems--; - - mSlider->setValue((double) mAmountItems / (double) mMaxItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } // TODO: Actually we'd have a bug elsewhere if this check for the number @@ -190,8 +188,9 @@ void BuyDialog::action(const gcn::ActionEvent &event) mMaxItems -= mAmountItems; // Reset selection - mAmountItems = 0; - mSlider->setValue(0.0); + mAmountItems = 1; + mSlider->setValue(1); + mSlider->gcn::Slider::setScale(1, mMaxItems); updateButtonsAndLabels(); } @@ -199,11 +198,13 @@ void BuyDialog::action(const gcn::ActionEvent &event) void BuyDialog::selectionChanged(const SelectionEvent &event) { + // Reset amount of items and update labels - mAmountItems = 0; - mSlider->setValue(0.0); + mAmountItems = 1; + mSlider->setValue(1); updateButtonsAndLabels(); + mSlider->gcn::Slider::setScale(1, mMaxItems); } void @@ -239,12 +240,13 @@ BuyDialog::updateButtonsAndLabels() // Enable or disable buttons and slider mIncreaseButton->setEnabled(mAmountItems < mMaxItems); - mDecreaseButton->setEnabled(mAmountItems > 0); + mDecreaseButton->setEnabled(mAmountItems > 1); mBuyButton->setEnabled(mAmountItems > 0); - mSlider->setEnabled(mMaxItems > 0); + mSlider->setEnabled(mMaxItems > 1); // Update quantity and money labels - mQuantityLabel->setCaption(toString(mAmountItems)); + mQuantityLabel->setCaption( + toString(mAmountItems) + " / " + toString(mMaxItems)); mQuantityLabel->adjustSize(); mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " + toString(mMoney - price) + " GP" ); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 7cb49686..399ae62b 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -122,7 +122,7 @@ SellDialog::~SellDialog() void SellDialog::reset() { mShopItems->clear(); - mSlider->setValue(0.0); + mSlider->setValue(0); // Reset previous selected item to prevent failing asserts mShopItemList->setSelected(-1); @@ -153,16 +153,11 @@ void SellDialog::action(const gcn::ActionEvent &event) { int selectedItem = mShopItemList->getSelected(); - if (event.getId() == "item") - { - mAmountItems = 0; - mSlider->setValue(0); - updateButtonsAndLabels(); - } - else if (event.getId() == "quit") + if (event.getId() == "quit") { setVisible(false); current_npc = 0; + return; } // The following actions require a valid item selection @@ -174,21 +169,19 @@ void SellDialog::action(const gcn::ActionEvent &event) if (event.getId() == "slider") { - mAmountItems = (int) (mSlider->getValue() * mMaxItems); + mAmountItems = (int) mSlider->getValue(); updateButtonsAndLabels(); } else if (event.getId() == "+" && mAmountItems < mMaxItems) { mAmountItems++; - - mSlider->setValue((double) mAmountItems /(double) mMaxItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } - else if (event.getId() == "-" && mAmountItems > 0) + else if (event.getId() == "-" && mAmountItems > 1) { mAmountItems--; - - mSlider->setValue((double) mAmountItems / (double) mMaxItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } else if (event.getId() == "sell" && mAmountItems > 0 @@ -204,8 +197,7 @@ void SellDialog::action(const gcn::ActionEvent &event) mMaxItems -= mAmountItems; mShopItems->getShop()->at(selectedItem).quantity = mMaxItems; mPlayerMoney += (mAmountItems * mShopItems->at(selectedItem).price); - mAmountItems = 0; - mSlider->setValue(0); + mAmountItems = 1; if (!mMaxItems) { @@ -216,6 +208,7 @@ void SellDialog::action(const gcn::ActionEvent &event) } else { + mSlider->gcn::Slider::setScale(1, mMaxItems); // Update only when there are items left, the entry doesn't exist // otherwise and can't be updated updateButtonsAndLabels(); @@ -226,10 +219,11 @@ void SellDialog::action(const gcn::ActionEvent &event) void SellDialog::selectionChanged(const SelectionEvent &event) { // Reset amount of items and update labels - mAmountItems = 0; + mAmountItems = 1; mSlider->setValue(0); updateButtonsAndLabels(); + mSlider->gcn::Slider::setScale(1, mMaxItems); } void SellDialog::setMoney(int amount) @@ -268,9 +262,9 @@ SellDialog::updateButtonsAndLabels() // Update Buttons and slider mSellButton->setEnabled(mAmountItems > 0); - mDecreaseButton->setEnabled(mAmountItems > 0); + mDecreaseButton->setEnabled(mAmountItems > 1); mIncreaseButton->setEnabled(mAmountItems < mMaxItems); - mSlider->setEnabled(selectedItem > -1); + mSlider->setEnabled(mMaxItems > 1); // Update the quantity and money labels mQuantityLabel->setCaption( |