From d34decaf8b2b4cbffca970e9059e1a2b4f463055 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Sep 2014 14:04:40 +0300 Subject: Move npc sell code from SellDialog into NpcSellDialog. --- src/gui/windows/selldialog.cpp | 59 +++--------------------------------------- 1 file changed, 3 insertions(+), 56 deletions(-) (limited to 'src/gui/windows/selldialog.cpp') diff --git a/src/gui/windows/selldialog.cpp b/src/gui/windows/selldialog.cpp index fc9ec4b66..cd8c03bdc 100644 --- a/src/gui/windows/selldialog.cpp +++ b/src/gui/windows/selldialog.cpp @@ -247,60 +247,7 @@ void SellDialog::action(const ActionEvent &event) { if (mNpcId != -1) { - ShopItem *const item = mShopItems->at(selectedItem); - if (PlayerInfo::isItemProtected(item->getId())) - return; - if (eventId == "presell") - { - const ItemInfo &info = ItemDB::get(item->getId()); - if (info.isProtected()) - { - ConfirmDialog *const dialog = new ConfirmDialog( - // TRANSLATORS: sell confirmation header - _("sell item"), - // TRANSLATORS: sell confirmation message - strprintf(_("Do you really want to sell %s?"), - info.getName().c_str()), SOUND_REQUEST, false, true); - dialog->postInit(); - dialog->addActionListener(this); - return; - } - } - // Attempt sell - mPlayerMoney += - mAmountItems * mShopItems->at(selectedItem)->getPrice(); - mMaxItems -= mAmountItems; - while (mAmountItems > 0) - { - // This order is important, item->getCurrentInvIndex() would - // return the inventory index of the next Duplicate otherwise. - const int itemIndex = item->getCurrentInvIndex(); - const int sellCount = item->sellCurrentDuplicate(mAmountItems); - npcHandler->sellItem(mNpcId, itemIndex, sellCount); - mAmountItems -= sellCount; - } - - mPlayerMoney += - mAmountItems * mShopItems->at(selectedItem)->getPrice(); - mAmountItems = 1; - mSlider->setValue(0); - - if (mMaxItems) - { - updateButtonsAndLabels(); - } - else - { - // All were sold - mShopItemList->setSelected(-1); - delete mShopItems->at(selectedItem); - mShopItems->erase(selectedItem); - - Rect scroll; - scroll.y = mShopItemList->getRowHeight() * (selectedItem + 1); - scroll.height = mShopItemList->getRowHeight(); - mShopItemList->showPart(scroll); - } + sellAction(event); } else { @@ -368,8 +315,8 @@ void SellDialog::updateButtonsAndLabels() mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); // TRANSLATORS: sell dialog label mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"), - Units::formatCurrency(income).c_str(), - Units::formatCurrency(mPlayerMoney + income).c_str())); + Units::formatCurrency(income).c_str(), + Units::formatCurrency(mPlayerMoney + income).c_str())); if (item) item->update(); } -- cgit v1.2.3-70-g09d2