diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-09-03 21:25:02 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-09-03 21:25:02 +0000 |
commit | 22aca668b53786dc00ff43764e61980e6499ec30 (patch) | |
tree | 9deb46fb98db77b556d579ce9eeaf4baa80a75e5 /src/gui/buy.cpp | |
parent | fe3ecae6936b41045b405fb5055a9ad754ddec3b (diff) | |
download | mana-22aca668b53786dc00ff43764e61980e6499ec30.tar.gz mana-22aca668b53786dc00ff43764e61980e6499ec30.tar.bz2 mana-22aca668b53786dc00ff43764e61980e6499ec30.tar.xz mana-22aca668b53786dc00ff43764e61980e6499ec30.zip |
Fixed updating of labels in buy and sell dialogs. Also made our listbox respond
to mouse dragging to change the selection.
Diffstat (limited to 'src/gui/buy.cpp')
-rw-r--r-- | src/gui/buy.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 20ceca92..ddbfe90a 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -91,6 +91,7 @@ BuyDialog::BuyDialog(Network *network): mSlider->setEventId("slider"); mItemList->addActionListener(this); + mItemList->addSelectionListener(this); mSlider->addActionListener(this); add(mScrollArea); @@ -153,7 +154,8 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) { int selectedItem = mItemList->getSelected(); - if (eventId == "item") { + if (eventId == "item") + { // Reset amount of items and update labels mAmountItems = 0; mSlider->setValue(0); @@ -176,23 +178,27 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) mIncreaseButton->setEnabled(mMaxItems > 0); mSlider->setEnabled(mMaxItems > 0); } - else if (eventId == "quit") { + else if (eventId == "quit") + { setVisible(false); current_npc = 0; } // The following actions require a valid selection - if (selectedItem < 0 || selectedItem >= int(mShopItems->size())) { + if (selectedItem < 0 || selectedItem >= int(mShopItems->size())) + { return; } bool updateButtonsAndLabels = false; - if (eventId == "slider") { + if (eventId == "slider") + { mAmountItems = (int)(mSlider->getValue() * mMaxItems); updateButtonsAndLabels = true; } - else if (eventId == "+") { + else if (eventId == "+") + { if (mAmountItems < mMaxItems) { mAmountItems++; } else { @@ -202,7 +208,8 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) mSlider->setValue(double(mAmountItems)/double(mMaxItems)); updateButtonsAndLabels = true; } - else if (eventId == "-") { + else if (eventId == "-") + { if (mAmountItems > 0) { mAmountItems--; } else { @@ -212,11 +219,12 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) mSlider->setValue(double(mAmountItems)/double(mMaxItems)); updateButtonsAndLabels = true; } - // TODO Actually we'd have a bug elsewhere if this check for the number + // TODO: Actually we'd have a bug elsewhere if this check for the number // of items to be bought ever fails, Bertram removed the assertions, is // there a better way to ensure this fails in an _obivous_ way in C++? else if (eventId == "buy" && (mAmountItems > 0 && - mAmountItems <= mMaxItems)) { + mAmountItems <= mMaxItems)) + { MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_BUY_REQUEST); outMsg.writeInt16(8); @@ -240,7 +248,8 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) } // If anything has changed, we have to update the buttons and labels - if (updateButtonsAndLabels) { + if (updateButtonsAndLabels) + { // Update buttons mIncreaseButton->setEnabled(mAmountItems < mMaxItems); mDecreaseButton->setEnabled(mAmountItems > 0); @@ -256,11 +265,10 @@ void BuyDialog::action(const std::string& eventId, gcn::Widget* widget) } } -void BuyDialog::mouseClick(int x, int y, int button, int count) +void BuyDialog::selectionChanged(const SelectionEvent &event) { - Window::mouseClick(x, y, button, count); - int selectedItem = mItemList->getSelected(); + if (selectedItem > -1) { const ItemInfo &info = @@ -269,4 +277,9 @@ void BuyDialog::mouseClick(int x, int y, int button, int count) mItemDescLabel->setCaption("Description: " + info.getDescription()); mItemEffectLabel->setCaption("Effect: " + info.getEffect()); } + else + { + mItemDescLabel->setCaption("Description:"); + mItemEffectLabel->setCaption("Effect:"); + } } |