summaryrefslogtreecommitdiff
path: root/src/gui/sell.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/sell.cpp')
-rw-r--r--src/gui/sell.cpp46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 92669ab6..62fc2586 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -28,7 +28,7 @@
#include <guichan/widgets/label.hpp>
#include "button.h"
-#include "listbox.h"
+#include "shoplistbox.h"
#include "scrollarea.h"
#include "shop.h"
#include "slider.h"
@@ -51,11 +51,11 @@ SellDialog::SellDialog(Network *network):
{
mShopItems = new ShopItems();
- mItemList = new ListBox(mShopItems);
- ScrollArea *scrollArea = new ScrollArea(mItemList);
+ mShopItemList = new ShopListBox(mShopItems, mShopItems);
+ ScrollArea *scrollArea = new ScrollArea(mShopItemList);
mSlider = new Slider(1.0);
mQuantityLabel = new gcn::Label("0");
- mMoneyLabel = new gcn::Label("Price: 0");
+ mMoneyLabel = new gcn::Label("Money: 0 GP / Total: 0 GP");
mItemDescLabel = new gcn::Label("Description:");
mItemEffectLabel = new gcn::Label("Effect:");
mIncreaseButton = new Button("+", "+", this);
@@ -67,7 +67,7 @@ SellDialog::SellDialog(Network *network):
setContentSize(260, 210);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
scrollArea->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);
@@ -91,11 +91,13 @@ SellDialog::SellDialog(Network *network):
quitButton->setPosition(208, 186);
- mItemList->setEventId("item");
+ mShopItemList->setEventId("item");
mSlider->setEventId("mSlider");
- mItemList->addActionListener(this);
- mItemList->addSelectionListener(this);
+ mShopItemList->setPriceCheck(false);
+
+ mShopItemList->addActionListener(this);
+ mShopItemList->addSelectionListener(this);
mSlider->addActionListener(this);
add(scrollArea);
@@ -125,13 +127,14 @@ void SellDialog::reset()
mQuantityLabel->setCaption("0");
mQuantityLabel->adjustSize();
- mMoneyLabel->setCaption("Price: 0");
+ mMoneyLabel->setCaption("Money: 0 GP / Total: "
+ + toString(mPlayerMoney) + " GP");
mMoneyLabel->adjustSize();
mItemDescLabel->setCaption("");
mItemEffectLabel->setCaption("");
// Reset Previous Selected Items to prevent failing asserts
- mItemList->setSelected(-1);
+ mShopItemList->setSelected(-1);
mIncreaseButton->setEnabled(false);
mDecreaseButton->setEnabled(false);
}
@@ -148,14 +151,15 @@ void SellDialog::addItem(Item *item, int price)
item_shop.index = item->getInvIndex();
item_shop.id = item->getId();
item_shop.quantity = item->getQuantity();
+ item_shop.image = item->getInfo().getImage();
mShopItems->push_back(item_shop);
- mItemList->adjustSize();
+ mShopItemList->adjustSize();
}
void SellDialog::action(const std::string& eventId, gcn::Widget* widget)
{
- int selectedItem = mItemList->getSelected();
+ int selectedItem = mShopItemList->getSelected();
if (eventId == "item")
{
@@ -166,7 +170,8 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget)
mQuantityLabel->setCaption("0");
mQuantityLabel->adjustSize();
- mMoneyLabel->setCaption("Price: 0");
+ mMoneyLabel->setCaption("Money: 0 GP / Total: "
+ + toString(mPlayerMoney) + " GP");
mMoneyLabel->adjustSize();
if (selectedItem > -1) {
@@ -232,8 +237,8 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget)
// All were sold
if (!mMaxItems) {
- mItemList->setSelected(-1);
- mShopItems->mItemsShop.erase(mShopItems->mItemsShop.begin() + selectedItem);
+ mShopItemList->setSelected(-1);
+ mShopItems->getShop().erase(mShopItems->getShop().begin() + selectedItem);
}
// Update only when there are items left, the entry doesn't exist
@@ -249,7 +254,8 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget)
mQuantityLabel->adjustSize();
int price = mAmountItems * mShopItems->at(selectedItem).price;
- mMoneyLabel->setCaption("Price: " + toString(price));
+ mMoneyLabel->setCaption("Money: " + toString(price) + " GP / Total: "
+ + toString(price + mPlayerMoney) + " GP");
mMoneyLabel->adjustSize();
// Update Buttons
@@ -261,7 +267,7 @@ void SellDialog::action(const std::string& eventId, gcn::Widget* widget)
void SellDialog::selectionChanged(const SelectionEvent &event)
{
- int selectedItem = mItemList->getSelected();
+ int selectedItem = mShopItemList->getSelected();
if (selectedItem > -1)
{
@@ -277,3 +283,9 @@ void SellDialog::selectionChanged(const SelectionEvent &event)
mItemEffectLabel->setCaption("Effect");
}
}
+
+void SellDialog::setMoney(int amount)
+{
+ mPlayerMoney = amount;
+ mShopItemList->setPlayersMoney(amount);
+}