diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-11-03 21:54:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-11-04 02:14:03 +0300 |
commit | 2288a403ad4377fbb552243e805aaf0b5a4f5a0d (patch) | |
tree | ad081047290fb6cc101f43833de6f565a368cf29 /src/gui | |
parent | cd636f7e367cfb7fa2c348d00071301a480d62c3 (diff) | |
download | manaplus-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.gz manaplus-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.bz2 manaplus-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.tar.xz manaplus-2288a403ad4377fbb552243e805aaf0b5a4f5a0d.zip |
Allow buy from npc shop or from market more than one of item at one transaction.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/windows/buydialog.cpp | 67 | ||||
-rw-r--r-- | src/gui/windows/buydialog.h | 4 |
2 files changed, 62 insertions, 9 deletions
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index 667867ff4..a7769482a 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -180,11 +180,12 @@ BuyDialog::BuyDialog() : mSortDropDown(nullptr), mFilterTextField(new TextField(this, "", true, this, "namefilter", true)), mFilterLabel(nullptr), + mNick(), mNpcId(fromInt(Items, BeingId)), mMoney(0), mAmountItems(0), mMaxItems(0), - mNick() + mAdvanced(false) { init(); } @@ -198,11 +199,12 @@ BuyDialog::BuyDialog(const BeingId npcId) : mSortDropDown(nullptr), mFilterTextField(new TextField(this, "", true, this, "namefilter", true)), mFilterLabel(nullptr), + mNick(), mNpcId(npcId), mMoney(0), mAmountItems(0), mMaxItems(0), - mNick() + mAdvanced(serverFeatures ? serverFeatures->haveAdvancedBuySell() : false) { init(); } @@ -217,11 +219,12 @@ BuyDialog::BuyDialog(std::string nick) : Modal_false, this, "sort")), mFilterTextField(new TextField(this, "", true, this, "namefilter", true)), mFilterLabel(nullptr), + mNick(nick), mNpcId(fromInt(Nick, BeingId)), mMoney(0), mAmountItems(0), mMaxItems(0), - mNick(nick) + mAdvanced(false) { init(); } @@ -236,6 +239,13 @@ void BuyDialog::init() setMinHeight(220); setDefaultSize(260, 230, ImageRect::CENTER); + // reset advance flag for personal shops and cash shop + if (mAdvanced && + (mNpcId == fromInt(Nick, BeingId) || mNpcId == fromInt(Cash, BeingId))) + { + mAdvanced = false; + } + if (setupWindow) setupWindow->registerWindowForReset(this); @@ -270,9 +280,19 @@ void BuyDialog::init() // TRANSLATORS: This is a narrow symbol used to denote 'decreasing'. // You may change this symbol if your language uses another. mDecreaseButton = new Button(this, _("-"), "dec", this); - // TRANSLATORS: buy dialog button mBuyButton = new Button(this, mNpcId == fromInt(Items, BeingId) - ? _("Create") :_("Buy"), "buy", this); + // TRANSLATORS: buy dialog button + ? _("Create") : (mAdvanced ? _("Add") : _("Buy")), "buy", this); + if (mAdvanced) + { + // TRANSLATORS: buy dialog button + mConfirmButton = new Button(this, _("Buy"), "confirm", this); + mConfirmButton->setEnabled(false); + } + else + { + mConfirmButton = nullptr; + } // TRANSLATORS: buy dialog button mQuitButton = new Button(this, _("Quit"), "quit", this); // TRANSLATORS: buy dialog button @@ -318,7 +338,15 @@ void BuyDialog::init() placer(0, 8, mFilterLabel, 2); } placer(2, 8, mFilterTextField, 2); - placer(7, 8, mBuyButton); + if (mAdvanced) + { + placer(6, 8, mBuyButton); + placer(7, 8, mConfirmButton); + } + else + { + placer(7, 8, mBuyButton); + } placer(8, 8, mQuitButton); Layout &layout = getLayout(); @@ -498,8 +526,15 @@ void BuyDialog::action(const ActionEvent &event) } else if (mNpcId != fromInt(Nick, BeingId)) { + if (mAdvanced) + { + item->increaseUsedQuantity(mAmountItems); + item->update(); + if (mConfirmButton) + mConfirmButton->setEnabled(true); + } #ifdef EATHENA_SUPPORT - if (mNpcId == fromInt(Market, BeingId)) + else if (mNpcId == fromInt(Market, BeingId)) { marketHandler->buyItem(item->getId(), item->getType(), @@ -515,8 +550,8 @@ void BuyDialog::action(const ActionEvent &event) item->getColor(), mAmountItems); } - else #endif + else { npcHandler->buyItem(mNpcId, item->getId(), @@ -554,6 +589,22 @@ void BuyDialog::action(const ActionEvent &event) } } } + else if (eventId == "confirm") + { + std::vector<ShopItem*> &items = mShopItems->allItems(); + +#ifdef EATHENA_SUPPORT + if (mNpcId == fromInt(Market, BeingId)) + { + marketHandler->buyItems(items); + } +#endif + else + { + npcHandler->buyItems(items); + } + close(); + } } void BuyDialog::updateSlider(const int selectedItem) diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h index dbb84b0ef..b74680509 100644 --- a/src/gui/windows/buydialog.h +++ b/src/gui/windows/buydialog.h @@ -159,6 +159,7 @@ class BuyDialog final : public Window, static DialogList instances; Button *mBuyButton A_NONNULLPOINTER; + Button *mConfirmButton A_NONNULLPOINTER; Button *mQuitButton A_NONNULLPOINTER; Button *mAddMaxButton A_NONNULLPOINTER; Button *mIncreaseButton A_NONNULLPOINTER; @@ -176,11 +177,12 @@ class BuyDialog final : public Window, TextField *mFilterTextField A_NONNULLPOINTER; Label *mFilterLabel; + std::string mNick; BeingId mNpcId; int mMoney; int mAmountItems; int mMaxItems; - std::string mNick; + bool mAdvanced; }; #endif // GUI_WINDOWS_BUYDIALOG_H |