summaryrefslogtreecommitdiff
path: root/src/gui/windows
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-11-04 02:03:03 +0300
committerAndrei Karas <akaras@inbox.ru>2015-11-04 02:40:04 +0300
commit5cfc73dc5c0093a96c45f604a028ecca21a01af8 (patch)
tree4916b602dfa9b5caee28252515a45215008b8d71 /src/gui/windows
parent2288a403ad4377fbb552243e805aaf0b5a4f5a0d (diff)
downloadmanaverse-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.gz
manaverse-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.bz2
manaverse-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.xz
manaverse-5cfc73dc5c0093a96c45f604a028ecca21a01af8.zip
Allow sell to npc many items at one time (hercules).halloween2015
Diffstat (limited to 'src/gui/windows')
-rw-r--r--src/gui/windows/buyingstoreselldialog.cpp2
-rw-r--r--src/gui/windows/eggselectiondialog.cpp2
-rw-r--r--src/gui/windows/insertcarddialog.cpp2
-rw-r--r--src/gui/windows/npcselldialog.cpp44
-rw-r--r--src/gui/windows/npcselldialog.h4
-rw-r--r--src/gui/windows/shopselldialog.cpp2
6 files changed, 48 insertions, 8 deletions
diff --git a/src/gui/windows/buyingstoreselldialog.cpp b/src/gui/windows/buyingstoreselldialog.cpp
index 9de82994d..af3d9d8ff 100644
--- a/src/gui/windows/buyingstoreselldialog.cpp
+++ b/src/gui/windows/buyingstoreselldialog.cpp
@@ -38,7 +38,7 @@
BuyingStoreSellDialog::BuyingStoreSellDialog(const BeingId accountId,
const int storeId) :
- SellDialog(true),
+ SellDialog(true, false),
mAccountId(accountId),
mStoreId(storeId)
{
diff --git a/src/gui/windows/eggselectiondialog.cpp b/src/gui/windows/eggselectiondialog.cpp
index 2b5f088be..266e3519b 100644
--- a/src/gui/windows/eggselectiondialog.cpp
+++ b/src/gui/windows/eggselectiondialog.cpp
@@ -36,7 +36,7 @@
#include "debug.h"
EggSelectionDialog::EggSelectionDialog() :
- SellDialog(false)
+ SellDialog(false, false)
{
// TRANSLATORS: egg selection dialog name
setWindowName(_("Select egg"));
diff --git a/src/gui/windows/insertcarddialog.cpp b/src/gui/windows/insertcarddialog.cpp
index 570f87666..8620b06f7 100644
--- a/src/gui/windows/insertcarddialog.cpp
+++ b/src/gui/windows/insertcarddialog.cpp
@@ -38,7 +38,7 @@
InsertCardDialog::InsertCardDialog(const int itemIndex,
const Item *const item) :
- SellDialog(false),
+ SellDialog(false, false),
mItemIndex(itemIndex)
{
// TRANSLATORS: insert card dialog name
diff --git a/src/gui/windows/npcselldialog.cpp b/src/gui/windows/npcselldialog.cpp
index 2645f4798..ab9ae47d0 100644
--- a/src/gui/windows/npcselldialog.cpp
+++ b/src/gui/windows/npcselldialog.cpp
@@ -28,12 +28,14 @@
#include "gui/models/shopitems.h"
+#include "gui/widgets/button.h"
#include "gui/widgets/createwidget.h"
#include "gui/widgets/shoplistbox.h"
#include "gui/widgets/slider.h"
#include "net/buysellhandler.h"
#include "net/npchandler.h"
+#include "net/serverfeatures.h"
#include "resources/iteminfo.h"
@@ -43,23 +45,25 @@
#include "debug.h"
NpcSellDialog::NpcSellDialog(const BeingId npcId) :
- SellDialog(true),
+ SellDialog(true,
+ serverFeatures ? serverFeatures->haveAdvancedBuySell() : false),
mNpcId(npcId)
{
}
void NpcSellDialog::sellAction(const ActionEvent &event)
{
- if (mAmountItems <= 0 || mAmountItems > mMaxItems)
- return;
-
const std::string &eventId = event.getId();
const int selectedItem = mShopItemList->getSelected();
ShopItem *const item = mShopItems->at(selectedItem);
if (!item || PlayerInfo::isItemProtected(item->getId()))
return;
+
if (eventId == "presell")
{
+ if (mAmountItems <= 0 || mAmountItems > mMaxItems)
+ return;
+
const ItemInfo &info = ItemDB::get(item->getId());
if (info.isProtected())
{
@@ -76,6 +80,38 @@ void NpcSellDialog::sellAction(const ActionEvent &event)
return;
}
}
+
+ if (mAdvanced)
+ sellManyItems(event.getId());
+ else
+ sellOneItem();
+}
+
+void NpcSellDialog::sellManyItems(const std::string &eventId)
+{
+ if (eventId == "confirm")
+ {
+ npcHandler->sellItems(mShopItems->allItems());
+ close();
+ }
+ else
+ {
+ const int selectedItem = mShopItemList->getSelected();
+ ShopItem *const item = mShopItems->at(selectedItem);
+ item->increaseUsedQuantity(mAmountItems);
+ item->update();
+ if (mConfirmButton)
+ mConfirmButton->setEnabled(true);
+ }
+}
+
+void NpcSellDialog::sellOneItem()
+{
+ if (mAmountItems <= 0 || mAmountItems > mMaxItems)
+ return;
+
+ const int selectedItem = mShopItemList->getSelected();
+ ShopItem *const item = mShopItems->at(selectedItem);
// Attempt sell
mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice();
mMaxItems -= mAmountItems;
diff --git a/src/gui/windows/npcselldialog.h b/src/gui/windows/npcselldialog.h
index af611f8f1..e50ec3fab 100644
--- a/src/gui/windows/npcselldialog.h
+++ b/src/gui/windows/npcselldialog.h
@@ -49,6 +49,10 @@ class NpcSellDialog final : public SellDialog
protected:
void sellAction(const ActionEvent &event) override final;
+ void sellOneItem();
+
+ void sellManyItems(const std::string &eventId);
+
BeingId mNpcId;
};
diff --git a/src/gui/windows/shopselldialog.cpp b/src/gui/windows/shopselldialog.cpp
index d4683eedf..081ffea7f 100644
--- a/src/gui/windows/shopselldialog.cpp
+++ b/src/gui/windows/shopselldialog.cpp
@@ -35,7 +35,7 @@
#include "debug.h"
ShopSellDialog::ShopSellDialog(const std::string &nick) :
- SellDialog(true),
+ SellDialog(true, false),
mNick(nick)
{
}