summaryrefslogtreecommitdiff
path: root/src/gui
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
parent2288a403ad4377fbb552243e805aaf0b5a4f5a0d (diff)
downloadmv-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.gz
mv-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.bz2
mv-5cfc73dc5c0093a96c45f604a028ecca21a01af8.tar.xz
mv-5cfc73dc5c0093a96c45f604a028ecca21a01af8.zip
Allow sell to npc many items at one time (hercules).halloween2015
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/widgets/selldialog.cpp38
-rw-r--r--src/gui/widgets/selldialog.h5
-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
8 files changed, 84 insertions, 15 deletions
diff --git a/src/gui/widgets/selldialog.cpp b/src/gui/widgets/selldialog.cpp
index 827d1c3ea..3ad8e5e7e 100644
--- a/src/gui/widgets/selldialog.cpp
+++ b/src/gui/widgets/selldialog.cpp
@@ -47,13 +47,15 @@
SellDialog::DialogList SellDialog::instances;
-SellDialog::SellDialog(const bool isSell) :
+SellDialog::SellDialog(const bool isSell,
+ const bool advanced) :
// TRANSLATORS: sell dialog name
Window(_("Sell"), Modal_false, nullptr, "sell.xml"),
ActionListener(),
SelectionListener(),
mSellButton(nullptr),
mQuitButton(nullptr),
+ mConfirmButton(nullptr),
mAddMaxButton(nullptr),
mIncreaseButton(nullptr),
mDecreaseButton(nullptr),
@@ -66,7 +68,8 @@ SellDialog::SellDialog(const bool isSell) :
mPlayerMoney(0),
mMaxItems(0),
mAmountItems(0),
- mIsSell(isSell)
+ mIsSell(isSell),
+ mAdvanced(advanced)
{
}
@@ -86,6 +89,9 @@ void SellDialog::postInit()
// Create a ShopItems instance, that is aware of duplicate entries.
mShopItems = new ShopItems(true);
+ if (mAdvanced)
+ mShopItems->setMergeDuplicates(false);
+
mShopItemList = CREATEWIDGETR(ShopListBox,
this,
mShopItems,
@@ -95,8 +101,11 @@ void SellDialog::postInit()
getOptionBool("showbackground"), "sell_background.xml");
mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- // TRANSLATORS: sell dialog button
- mSellButton = new Button(this, _("Sell"), "presell", this);
+ mSellButton = new Button(this,
+ // TRANSLATORS: sell dialog button
+ mAdvanced ? _("Add") : _("Sell"),
+ "presell",
+ this);
// TRANSLATORS: sell dialog button
mQuitButton = new Button(this, _("Quit"), "quit", this);
@@ -129,6 +138,12 @@ void SellDialog::postInit()
// TRANSLATORS: sell dialog label
mMoneyLabel = new Label(this, strprintf(_("Price: %s / Total: %s"),
"", ""));
+ if (mAdvanced)
+ {
+ // TRANSLATORS: sell dialog button
+ mConfirmButton = new Button(this, _("Sell"), "confirm", this);
+ mConfirmButton->setEnabled(false);
+ }
mDecreaseButton->adjustSize();
mDecreaseButton->setWidth(mIncreaseButton->getWidth());
@@ -145,7 +160,15 @@ void SellDialog::postInit()
placer(5, 5, mQuantityLabel, 2);
placer(7, 5, mAddMaxButton);
placer(0, 6, mMoneyLabel, 8);
- placer(6, 7, mSellButton);
+ if (mAdvanced)
+ {
+ placer(5, 7, mSellButton);
+ placer(6, 7, mConfirmButton);
+ }
+ else
+ {
+ placer(6, 7, mSellButton);
+ }
placer(7, 7, mQuitButton);
}
else
@@ -252,7 +275,10 @@ void SellDialog::action(const ActionEvent &event)
mSlider->setValue(mAmountItems);
updateButtonsAndLabels();
}
- else if (eventId == "presell" || eventId == "sell" || eventId == "yes")
+ else if (eventId == "presell" ||
+ eventId == "sell" ||
+ eventId == "yes" ||
+ eventId == "confirm")
{
sellAction(event);
}
diff --git a/src/gui/widgets/selldialog.h b/src/gui/widgets/selldialog.h
index b5e91f67d..92008df38 100644
--- a/src/gui/widgets/selldialog.h
+++ b/src/gui/widgets/selldialog.h
@@ -51,7 +51,8 @@ class SellDialog notfinal : public Window,
/**
* Constructor.
*/
- explicit SellDialog(const bool isSell);
+ SellDialog(const bool isSell,
+ const bool advanced);
A_DELETE_COPY(SellDialog)
@@ -127,6 +128,7 @@ class SellDialog notfinal : public Window,
Button *mSellButton A_NONNULLPOINTER;
Button *mQuitButton A_NONNULLPOINTER;
+ Button *mConfirmButton A_NONNULLPOINTER;
Button *mAddMaxButton;
Button *mIncreaseButton;
Button *mDecreaseButton;
@@ -142,6 +144,7 @@ class SellDialog notfinal : public Window,
int mAmountItems;
bool mIsSell;
+ bool mAdvanced;
};
#endif // GUI_WIDGETS_SELLDIALOG_H
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)
{
}