summaryrefslogtreecommitdiff
path: root/src/gui/sell.cpp
diff options
context:
space:
mode:
authorMajin Sniper <majinsniper@gmx.de>2009-02-23 19:19:55 +0100
committerIra Rice <irarice@gmail.com>2009-02-23 18:32:06 -0700
commitf65c1e48107fa2cc615c86d8f6829b50c05baa3f (patch)
tree81e95de6b7f9b53208d0c57072ef74a0941c22e8 /src/gui/sell.cpp
parent48fb40dba78a5b748b53abfa79f8c0442a72a9c7 (diff)
downloadmana-f65c1e48107fa2cc615c86d8f6829b50c05baa3f.tar.gz
mana-f65c1e48107fa2cc615c86d8f6829b50c05baa3f.tar.bz2
mana-f65c1e48107fa2cc615c86d8f6829b50c05baa3f.tar.xz
mana-f65c1e48107fa2cc615c86d8f6829b50c05baa3f.zip
Allow to sell non-stackable items like stackables
Make it possible to sell non-stackable items all at once by introducing "Duplicate Items" and a Shop that can handle them. Also fix a trivial bug to correctly preview you money while selling.
Diffstat (limited to 'src/gui/sell.cpp')
-rw-r--r--src/gui/sell.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index fd271c63..f974f247 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -50,7 +50,8 @@ SellDialog::SellDialog(Network *network):
setMinHeight(230);
setDefaultSize(0, 0, 260, 230);
- mShopItems = new ShopItems();
+ // Create a ShopItems instance, that is aware of duplicate entries.
+ mShopItems = new ShopItems(true);
mShopItemList = new ShopListBox(mShopItems, mShopItems);
mScrollArea = new ScrollArea(mShopItemList);
@@ -115,10 +116,11 @@ void SellDialog::reset()
void SellDialog::addItem(const Item *item, int price)
{
if (!item)
+ {
return;
+ }
- mShopItems->addItem(
- item->getInvIndex(), item->getId(),
+ mShopItems->addItem(item->getInvIndex(), item->getId(),
item->getQuantity(), price);
mShopItemList->adjustSize();
@@ -164,23 +166,34 @@ void SellDialog::action(const gcn::ActionEvent &event)
{
// Attempt sell
MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_NPC_SELL_REQUEST);
- outMsg.writeInt16(8);
- outMsg.writeInt16(mShopItems->at(selectedItem)->getInvIndex());
- outMsg.writeInt16(mAmountItems);
+ ShopItem* item = mShopItems->at(selectedItem);
+ int sellCount;
+ mPlayerMoney +=
+ mAmountItems * mShopItems->at(selectedItem)->getPrice();
mMaxItems -= mAmountItems;
- mShopItems->getShop()->at(selectedItem)->setQuantity(mMaxItems);
+ while (mAmountItems > 0) {
+ outMsg.writeInt16(CMSG_NPC_SELL_REQUEST);
+ outMsg.writeInt16(8);
+ outMsg.writeInt16(item->getCurrentInvIndex());
+ // This order is important, item->getCurrentInvIndex() would return
+ // the inventory index of the next Duplicate otherwise.
+ sellCount = item->sellCurrentDuplicate(mAmountItems);
+ mAmountItems -= sellCount;
+ outMsg.writeInt16(sellCount);
+ }
+
mPlayerMoney +=
mAmountItems * mShopItems->at(selectedItem)->getPrice();
mAmountItems = 1;
+ mSlider->setValue(0);
if (!mMaxItems)
{
// All were sold
mShopItemList->setSelected(-1);
- mShopItems->getShop()->erase(
- mShopItems->getShop()->begin() + selectedItem);
+ delete mShopItems->at(selectedItem);
+ mShopItems->erase(selectedItem);
gcn::Rectangle scroll;
scroll.y = mShopItemList->getRowHeight() * (selectedItem + 1);