summaryrefslogtreecommitdiff
path: root/src/gui/sell.cpp
diff options
context:
space:
mode:
authorMajin Sniper <majinsniper@gmx.de>2009-02-23 19:19:55 +0100
committerJared Adams <jaxad0127@gmail.com>2009-02-23 17:19:56 -0700
commite15b8c360ac5171fe73b8b73fbe00eedba8970ff (patch)
treeec7d2129c8dc35c3cdf7669a08beb71c30a7760c /src/gui/sell.cpp
parentc54b987a4e4d28d35e8bafb03e1dba33b5fda4ab (diff)
downloadmana-e15b8c360ac5171fe73b8b73fbe00eedba8970ff.tar.gz
mana-e15b8c360ac5171fe73b8b73fbe00eedba8970ff.tar.bz2
mana-e15b8c360ac5171fe73b8b73fbe00eedba8970ff.tar.xz
mana-e15b8c360ac5171fe73b8b73fbe00eedba8970ff.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.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 20a2a786..14620aa6 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);
@@ -252,7 +265,7 @@ void SellDialog::updateButtonsAndLabels()
mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems));
mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
Units::formatCurrency(income).c_str(),
- Units::formatCurrency(mPlayerMoney - income).c_str()));
+ Units::formatCurrency(mPlayerMoney + income).c_str()));
}
void SellDialog::logic()