summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2006-11-05 01:47:44 +0000
committerYohann Ferreira <bertram@cegetel.net>2006-11-05 01:47:44 +0000
commit9e70df3a6ac53f9900f7e4cbf6dbe40e53e0ddc1 (patch)
treeba0bf36049b125030e0bb2e26e7f755fe8f98723 /src/gui
parent6a1702f014db23b5330e9b93e773b652d03c2ed1 (diff)
downloadmana-9e70df3a6ac53f9900f7e4cbf6dbe40e53e0ddc1.tar.gz
mana-9e70df3a6ac53f9900f7e4cbf6dbe40e53e0ddc1.tar.bz2
mana-9e70df3a6ac53f9900f7e4cbf6dbe40e53e0ddc1.tar.xz
mana-9e70df3a6ac53f9900f7e4cbf6dbe40e53e0ddc1.zip
Added item's pictures in sell dialogs, and precisions about the total money in it.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/sell.cpp46
-rw-r--r--src/gui/sell.h10
-rw-r--r--src/gui/shop.cpp5
-rw-r--r--src/gui/shop.h9
-rw-r--r--src/gui/shoplistbox.cpp13
-rw-r--r--src/gui/shoplistbox.h8
6 files changed, 68 insertions, 23 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);
+}
diff --git a/src/gui/sell.h b/src/gui/sell.h
index 12000bc3..f27a9751 100644
--- a/src/gui/sell.h
+++ b/src/gui/sell.h
@@ -34,7 +34,7 @@
class Item;
class Network;
class ShopItems;
-class ListBox;
+class ShopListBox;
/**
* The sell dialog.
@@ -78,12 +78,17 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener
*/
void selectionChanged(const SelectionEvent &event);
+ /**
+ * Gives Player's Money amount
+ */
+ void setMoney(int amount);
+
private:
Network *mNetwork;
gcn::Button *mSellButton;
gcn::Button *mIncreaseButton;
gcn::Button *mDecreaseButton;
- ListBox *mItemList;
+ ShopListBox *mShopItemList;
gcn::Label *mMoneyLabel;
gcn::Label *mItemDescLabel;
gcn::Label *mItemEffectLabel;
@@ -91,6 +96,7 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener
gcn::Slider *mSlider;
ShopItems *mShopItems;
+ int mPlayerMoney;
int mMaxItems;
int mAmountItems;
diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp
index 39c285d7..d15e7367 100644
--- a/src/gui/shop.cpp
+++ b/src/gui/shop.cpp
@@ -67,3 +67,8 @@ void ShopItems::clear()
{
mItemsShop.clear();
}
+
+std::vector<ITEM_SHOP> ShopItems::getShop()
+{
+ return mItemsShop;
+}
diff --git a/src/gui/shop.h b/src/gui/shop.h
index 0736003b..006c0146 100644
--- a/src/gui/shop.h
+++ b/src/gui/shop.h
@@ -73,11 +73,16 @@ class ShopItems : public gcn::ListModel
ITEM_SHOP at(int i);
/**
- * Clear the vector and delete the pictures' instances.
+ * Clear the vector.
*/
void clear();
-// private: // This is to be readded as soon as the sell dialog is redone.
+ /**
+ * Direct access to the vector
+ */
+ std::vector<ITEM_SHOP> getShop();
+
+ private:
std::vector<ITEM_SHOP> mItemsShop;
};
diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp
index 0aec33ed..6ddf863e 100644
--- a/src/gui/shoplistbox.cpp
+++ b/src/gui/shoplistbox.cpp
@@ -42,7 +42,7 @@ ShopListBox::ShopListBox(gcn::ListModel *listModel):
mPlayerMoney(0)
{
mRowHeight = getFont()->getHeight();
-
+ mPriceCheck = true;
}
ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel):
@@ -53,6 +53,7 @@ ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel):
{
mRowHeight = (getFont()->getHeight() > ITEM_SPRITE_HEIGHT ?
getFont()->getHeight() : ITEM_SPRITE_HEIGHT);
+ mPriceCheck = true;
}
@@ -75,7 +76,7 @@ void ShopListBox::draw(gcn::Graphics *graphics)
graphics->setColor(gcn::Color(0xffffff));
if (mShopItems)
{
- if(mPlayerMoney < mShopItems->at(i).price)
+ if(mPlayerMoney < mShopItems->at(i).price && mPriceCheck)
{
graphics->setColor(gcn::Color(0x919191));
}
@@ -142,6 +143,9 @@ void ShopListBox::mousePress(int x, int y, int button)
else // Old Behaviour
enoughMoney = true;
+ if (!mPriceCheck)
+ enoughMoney = true;
+
if (enoughMoney)
{
setSelected(y / mRowHeight);
@@ -189,3 +193,8 @@ void ShopListBox::adjustSize()
setHeight(mRowHeight * mListModel->getNumberOfElements());
}
}
+
+void ShopListBox::setPriceCheck(bool check)
+{
+ mPriceCheck = check;
+}
diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h
index 88e1c4b6..2dff8977 100644
--- a/src/gui/shoplistbox.h
+++ b/src/gui/shoplistbox.h
@@ -91,6 +91,12 @@ class ShopListBox : public gcn::ListBox
*/
void adjustSize();
+ /**
+ * Set on/off the disabling of too expensive items.
+ * (Good for selling mode.)
+ */
+ void setPriceCheck(bool check);
+
private:
/**
* Sends out selection events to the list of selection listeners.
@@ -111,6 +117,8 @@ class ShopListBox : public gcn::ListBox
int mRowHeight; /**< Row Height */
+ bool mPriceCheck;
+
};
#endif