diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-11-05 15:22:13 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-11-05 15:22:13 +0000 |
commit | 6374ef220d8f46647190074338f868b5d6bb4a45 (patch) | |
tree | a833453c2e712c3e992f71433f6d21c8c379ad15 /src/gui/buy.cpp | |
parent | de61b658590630cfc59960c012c8e533b361a8b0 (diff) | |
download | mana-6374ef220d8f46647190074338f868b5d6bb4a45.tar.gz mana-6374ef220d8f46647190074338f868b5d6bb4a45.tar.bz2 mana-6374ef220d8f46647190074338f868b5d6bb4a45.tar.xz mana-6374ef220d8f46647190074338f868b5d6bb4a45.zip |
Merged 0.0 changes from revision 2800 to 2825 to trunk.
Diffstat (limited to 'src/gui/buy.cpp')
-rw-r--r-- | src/gui/buy.cpp | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 73f696b7..b681b683 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -26,14 +26,12 @@ #include <guichan/widgets/label.hpp> #include "button.h" -#include "listbox.h" #include "scrollarea.h" #include "shop.h" #include "slider.h" #include "../npc.h" -#include "../resources/iteminfo.h" #include "../resources/itemmanager.h" #include "../utils/tostring.h" @@ -45,8 +43,8 @@ BuyDialog::BuyDialog(): { mShopItems = new ShopItems; - mItemList = new ListBox(mShopItems); - mScrollArea = new ScrollArea(mItemList); + mShopItemList = new ShopListBox(mShopItems, mShopItems); + mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); mQuantityLabel = new gcn::Label("0"); mMoneyLabel = new gcn::Label("Price : 0 GP / 0 GP"); @@ -60,7 +58,7 @@ BuyDialog::BuyDialog(): setContentSize(260, 210); mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mScrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110)); - mItemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); + mShopItemList->setDimension(gcn::Rectangle(5, 5, 238, 110)); mSlider->setDimension(gcn::Rectangle(5, 120, 200, 10)); mSlider->setEnabled(false); @@ -84,11 +82,11 @@ BuyDialog::BuyDialog(): mItemEffectLabel->setDimension(gcn::Rectangle(5, 150, 240, 14)); mItemDescLabel->setDimension(gcn::Rectangle(5, 169, 240, 14)); - mItemList->setEventId("item"); + mShopItemList->setEventId("item"); mSlider->setEventId("slider"); - mItemList->addActionListener(this); - mItemList->addSelectionListener(this); + mShopItemList->addActionListener(this); + mShopItemList->addSelectionListener(this); mSlider->addActionListener(this); add(mScrollArea); @@ -113,6 +111,7 @@ BuyDialog::~BuyDialog() void BuyDialog::setMoney(int amount) { mMoney = amount; + mShopItemList->setPlayersMoney(amount); mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); mMoneyLabel->adjustSize(); } @@ -125,7 +124,7 @@ void BuyDialog::reset() mAmountItems = 0; // Reset Previous Selected Items to prevent failing asserts - mItemList->setSelected(-1); + mShopItemList->setSelected(-1); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); mQuantityLabel->setCaption("0"); @@ -138,20 +137,13 @@ void BuyDialog::reset() void BuyDialog::addItem(short id, int price) { - ITEM_SHOP item_shop; - - item_shop.name = itemDb->getItemInfo(id).getName() + " " - + toString(price) + " GP"; - item_shop.price = price; - item_shop.id = id; - - mShopItems->push_back(item_shop); - mItemList->adjustSize(); + mShopItems->addItem(id, price); + mShopItemList->adjustSize(); } void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) { - int selectedItem = mItemList->getSelected(); + int selectedItem = mShopItemList->getSelected(); if (eventId == "item") { @@ -169,7 +161,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) // If no item was selected, none can be bought, otherwise // calculate how many the player can afford - mMaxItems = (mItemList->getSelected() == -1) ? 0 : + mMaxItems = (mShopItemList->getSelected() == -1) ? 0 : mMoney / mShopItems->at(selectedItem).price; // When at least one item can be bought, enable the slider and the @@ -184,7 +176,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) } // The following actions require a valid selection - if (selectedItem < 0 || selectedItem >= int(mShopItems->size())) + if (selectedItem < 0 || selectedItem >= int(mShopItems->getNumberOfElements())) { return; } @@ -269,7 +261,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) void BuyDialog::selectionChanged(const SelectionEvent &event) { - int selectedItem = mItemList->getSelected(); + int selectedItem = mShopItemList->getSelected(); if (selectedItem > -1) { |