diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-12-16 23:18:55 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-12-16 23:18:55 +0000 |
commit | dc53baaaf65943c6768e3ad209129609334133e8 (patch) | |
tree | cfd4ba52d94e2f2238195addaa53f80f4013f36a /src/gui/buy.cpp | |
parent | 35afca876ece89be5b282c73a200d0d3c5d27fe0 (diff) | |
download | mana-dc53baaaf65943c6768e3ad209129609334133e8.tar.gz mana-dc53baaaf65943c6768e3ad209129609334133e8.tar.bz2 mana-dc53baaaf65943c6768e3ad209129609334133e8.tar.xz mana-dc53baaaf65943c6768e3ad209129609334133e8.zip |
Subclassed ShopListBox from ListBox to get rid of some duplicated code, and
fixed a problem with scrolling to the current selection. Also aligned the text
a bit better and put the price in parenthesis.
Diffstat (limited to 'src/gui/buy.cpp')
-rw-r--r-- | src/gui/buy.cpp | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 91488595..c701499c 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -88,7 +88,6 @@ BuyDialog::BuyDialog(Network *network): mShopItemList->setEventId("item"); mSlider->setEventId("slider"); - mShopItemList->addActionListener(this); mShopItemList->addSelectionListener(this); mSlider->addActionListener(this); @@ -115,7 +114,7 @@ void BuyDialog::setMoney(int amount) { mMoney = amount; mShopItemList->setPlayersMoney(amount); - mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); + mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); mMoneyLabel->adjustSize(); } @@ -132,7 +131,7 @@ void BuyDialog::reset() mDecreaseButton->setEnabled(false); mQuantityLabel->setCaption("0"); mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); + mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); mMoneyLabel->adjustSize(); mItemDescLabel->setCaption(""); mItemEffectLabel->setCaption(""); @@ -148,31 +147,7 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) { int selectedItem = mShopItemList->getSelected(); - if (eventId == "item") - { - // Reset amount of items and update labels - mAmountItems = 0; - mSlider->setValue(0); - mQuantityLabel->setCaption("0"); - mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); - mMoneyLabel->adjustSize(); - - // Disable buttons for buying and decreasing - mBuyButton->setEnabled(false); - mDecreaseButton->setEnabled(false); - - // If no item was selected, none can be bought, otherwise - // calculate how many the player can afford - mMaxItems = (mShopItemList->getSelected() == -1) ? 0 : - mMoney / mShopItems->at(selectedItem).price; - - // When at least one item can be bought, enable the slider and the - // increase button - mIncreaseButton->setEnabled(mMaxItems > 0); - mSlider->setEnabled(mMaxItems > 0); - } - else if (eventId == "quit") + if (eventId == "quit") { setVisible(false); current_npc = 0; @@ -254,7 +229,7 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) mQuantityLabel->adjustSize(); int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Price : " + toString(price) + " GP / " + mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " + toString(mMoney) + " GP" ); mMoneyLabel->adjustSize(); } @@ -262,19 +237,39 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) void BuyDialog::selectionChanged(const SelectionEvent &event) { + // Reset amount of items and update labels + mAmountItems = 0; + mSlider->setValue(0); + mQuantityLabel->setCaption("0"); + mQuantityLabel->adjustSize(); + mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP"); + mMoneyLabel->adjustSize(); + + // Disable buttons for buying and decreasing + mBuyButton->setEnabled(false); + mDecreaseButton->setEnabled(false); + int selectedItem = mShopItemList->getSelected(); if (selectedItem > -1) { - const ItemInfo &info = - ItemDB::get(mShopItems->at(selectedItem).id); + const ItemInfo &info = ItemDB::get(mShopItems->at(selectedItem).id); mItemDescLabel->setCaption("Description: " + info.getDescription()); mItemEffectLabel->setCaption("Effect: " + info.getEffect()); + + // Calculate how many the player can afford + mMaxItems = mMoney / mShopItems->at(selectedItem).price; } else { mItemDescLabel->setCaption("Description:"); mItemEffectLabel->setCaption("Effect:"); + mMaxItems = 0; } + + // When at least one item can be bought, enable the slider and the + // increase button + mIncreaseButton->setEnabled(mMaxItems > 0); + mSlider->setEnabled(mMaxItems > 0); } |