diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-02-01 23:48:15 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-02-02 22:48:03 +0300 |
commit | 6dc1f5e0b68cf390f7938329b50a9b28bd187862 (patch) | |
tree | 29e30e48cc03d95aeff278f6842f3a15de8f4106 /src/gui | |
parent | c8c51d7550adf9c952a4be54398df7e7a6f341a8 (diff) | |
download | manaplus-6dc1f5e0b68cf390f7938329b50a9b28bd187862.tar.gz manaplus-6dc1f5e0b68cf390f7938329b50a9b28bd187862.tar.bz2 manaplus-6dc1f5e0b68cf390f7938329b50a9b28bd187862.tar.xz manaplus-6dc1f5e0b68cf390f7938329b50a9b28bd187862.zip |
Set correct vending status to local player.
Allow buy from vending shop.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/models/shopitems.cpp | 45 | ||||
-rw-r--r-- | src/gui/models/shopitems.h | 34 | ||||
-rw-r--r-- | src/gui/windows/buydialog.cpp | 41 | ||||
-rw-r--r-- | src/gui/windows/buydialog.h | 11 | ||||
-rw-r--r-- | src/gui/windows/shopwindow.cpp | 91 | ||||
-rw-r--r-- | src/gui/windows/shopwindow.h | 5 |
6 files changed, 139 insertions, 88 deletions
diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp index e154c0b2e..52a0d60b2 100644 --- a/src/gui/models/shopitems.cpp +++ b/src/gui/models/shopitems.cpp @@ -50,32 +50,38 @@ std::string ShopItems::getElementAt(int i) return mShopItems.at(i)->getDisplayName(); } -void ShopItems::addItem(const int id, - const int type, - const unsigned char color, - const int amount, - const int price) +ShopItem *ShopItems::addItem(const int id, + const int type, + const unsigned char color, + const int amount, + const int price) { - mShopItems.push_back(new ShopItem(-1, id, type, color, amount, price)); + ShopItem *const item = new ShopItem(-1, id, type, color, amount, price); + mShopItems.push_back(item); + return item; } -void ShopItems::addItemNoDup(const int id, - const int type, - const unsigned char color, - const int amount, - const int price) +ShopItem *ShopItems::addItemNoDup(const int id, + const int type, + const unsigned char color, + const int amount, + const int price) { - const ShopItem *const item = findItem(id, color); + ShopItem *item = findItem(id, color); if (!item) - mShopItems.push_back(new ShopItem(-1, id, type, color, amount, price)); + { + item = new ShopItem(-1, id, type, color, amount, price); + mShopItems.push_back(item); + } + return item; } -void ShopItems::addItem2(const int inventoryIndex, - const int id, - const int type, - const unsigned char color, - const int quantity, - const int price) +ShopItem *ShopItems::addItem2(const int inventoryIndex, + const int id, + const int type, + const unsigned char color, + const int quantity, + const int price) { ShopItem *item = nullptr; if (mMergeDuplicates) @@ -90,6 +96,7 @@ void ShopItems::addItem2(const int inventoryIndex, item = new ShopItem(inventoryIndex, id, type, color, quantity, price); mShopItems.push_back(item); } + return item; } ShopItem *ShopItems::at(unsigned int i) const diff --git a/src/gui/models/shopitems.h b/src/gui/models/shopitems.h index f0db94e3a..d3d4a44fc 100644 --- a/src/gui/models/shopitems.h +++ b/src/gui/models/shopitems.h @@ -59,11 +59,11 @@ class ShopItems final : public ListModel /** * Adds an item to the list. */ - void addItem(const int id, - const int type, - const unsigned char color, - const int amount, - const int price); + ShopItem *addItem(const int id, + const int type, + const unsigned char color, + const int amount, + const int price); /** * Adds an item to the list (used by sell dialog). Looks for @@ -74,18 +74,18 @@ class ShopItems final : public ListModel * @param quantity number of available copies of the item * @param price price of the item */ - void addItem2(const int inventoryIndex, - const int id, - const int type, - const unsigned char color, - const int amount, - const int price); - - void addItemNoDup(const int id, - const int type, - const unsigned char color, - const int amount, - const int price); + ShopItem *addItem2(const int inventoryIndex, + const int id, + const int type, + const unsigned char color, + const int amount, + const int price); + + ShopItem *addItemNoDup(const int id, + const int type, + const unsigned char color, + const int amount, + const int price); /** * Returns the number of items in the shop. diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index b0564eb52..068440c65 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -22,6 +22,7 @@ #include "gui/windows/buydialog.h" +#include "actormanager.h" #include "configuration.h" #include "shopitem.h" #include "units.h" @@ -48,6 +49,8 @@ #include "net/cashshophandler.h" #include "net/markethandler.h" #include "net/npchandler.h" +#include "net/serverfeatures.h" +#include "net/vendinghandler.h" #include "resources/iteminfo.h" @@ -336,14 +339,15 @@ void BuyDialog::reset() setMoney(0); } -void BuyDialog::addItem(const int id, - const int type, - const unsigned char color, - const int amount, - const int price) +ShopItem *BuyDialog::addItem(const int id, + const int type, + const unsigned char color, + const int amount, + const int price) { - mShopItems->addItem(id, type, color, amount, price); + ShopItem *const item = mShopItems->addItem(id, type, color, amount, price); mShopItemList->adjustSize(); + return item; } void BuyDialog::sort() @@ -478,14 +482,27 @@ void BuyDialog::action(const ActionEvent &event) mSlider->setScale(1, mMaxItems); mSlider->setValue(1); } - else if (tradeWindow) + else if (mNpcId == Nick) { - if (item) + if (serverFeatures->haveVending()) { - buySellHandler->sendBuyRequest(mNick, - item, mAmountItems); - tradeWindow->addAutoMoney(mNick, - item->getPrice() * mAmountItems); + Being *const being = actorManager->findBeingByName(mNick); + if (being) + { + vendingHandler->buy(being, + item->getInvIndex(), + mAmountItems); + } + } + else if (tradeWindow) + { + if (item) + { + buySellHandler->sendBuyRequest(mNick, + item, mAmountItems); + tradeWindow->addAutoMoney(mNick, + item->getPrice() * mAmountItems); + } } } } diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h index 06e169c92..d697eff5d 100644 --- a/src/gui/windows/buydialog.h +++ b/src/gui/windows/buydialog.h @@ -30,6 +30,7 @@ class Button; class DropDown; +class ShopItem; class ShopItems; class ShopListBox; class SortListModelBuy; @@ -99,11 +100,11 @@ class BuyDialog final : public Window, /** * Adds an item to the shop inventory. */ - void addItem(const int id, - const int type, - const unsigned char color, - const int amount, - const int price); + ShopItem *addItem(const int id, + const int type, + const unsigned char color, + const int amount, + const int price); /** * Called when receiving actions from the widgets. diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index 5d013430a..2541ae247 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -82,6 +82,7 @@ ShopWindow::ShopWindow() : Window(_("Personal Shop"), false, nullptr, "shop.xml"), ActionListener(), SelectionListener(), + VendingModeListener(), VendingSlotsListener(), // TRANSLATORS: shop window button mCloseButton(new Button(this, _("Close"), "close", this)), @@ -111,7 +112,8 @@ ShopWindow::ShopWindow() : mTradeMoney(0), mSellShopSize(0), isBuySelected(true), - mHaveVending(serverFeatures->haveVending()) + mHaveVending(serverFeatures->haveVending()), + mEnableVending(false) { mBuyShopItemList->postInit(); mSellShopItemList->postInit(); @@ -270,32 +272,37 @@ void ShopWindow::action(const ActionEvent &event) } else if (eventId == "publish") { - std::vector<ShopItem*> &oldItems = mSellShopItems->items(); - std::vector<ShopItem*> items; - Inventory *const inv = PlayerInfo::getCartInventory(); - if (!inv) - return; - FOR_EACH (std::vector<ShopItem*>::iterator, it, oldItems) + if (mEnableVending) { - ShopItem *const item = *it; - // +++ need add colors - Item *const cartItem = inv->findItem(item->getId(), 1); - if (!cartItem) - continue; - item->setInvIndex(cartItem->getInvIndex()); - const int amount = cartItem->getQuantity(); - if (!amount) - continue; - if (item->getQuantity() < amount) - item->setQuantity(amount); - items.push_back(item); - if (static_cast<signed int>(items.size()) >= mSellShopSize) - break; + vendingHandler->close(); + VendingModeListener::distributeEvent(false); } - if (!items.empty()) + else { - vendingHandler->createShop("test shop", true, items); - mSellShopSize = 0; + std::vector<ShopItem*> &oldItems = mSellShopItems->items(); + std::vector<ShopItem*> items; + Inventory *const inv = PlayerInfo::getCartInventory(); + if (!inv) + return; + FOR_EACH (std::vector<ShopItem*>::iterator, it, oldItems) + { + ShopItem *const item = *it; + // +++ need add colors + Item *const cartItem = inv->findItem(item->getId(), 1); + if (!cartItem) + continue; + item->setInvIndex(cartItem->getInvIndex()); + const int amount = cartItem->getQuantity(); + if (!amount) + continue; + if (item->getQuantity() < amount) + item->setQuantity(amount); + items.push_back(item); + if (static_cast<signed int>(items.size()) >= mSellShopSize) + break; + } + if (!items.empty()) + vendingHandler->createShop("test shop", true, items); } } @@ -369,18 +376,25 @@ void ShopWindow::updateButtonsAndLabels() allowDel = mSellShopItemList->getSelected() != -1 && sellNotEmpty; } mDeleteButton->setEnabled(allowDel); - if (mPublishButton - && !isBuySelected - && sellNotEmpty - && mSellShopSize > 0 - && localPlayer - && localPlayer->getHaveCart()) + if (mPublishButton) { - mPublishButton->setEnabled(true); - } - else - { - mPublishButton->setEnabled(false); + if (mEnableVending) + mPublishButton->setCaption(_("Close shop")); + else + mPublishButton->setCaption(_("Publish")); + mPublishButton->adjustSize(); + if (!isBuySelected + && sellNotEmpty + && mSellShopSize > 0 + && localPlayer + && localPlayer->getHaveCart()) + { + mPublishButton->setEnabled(true); + } + else + { + mPublishButton->setEnabled(false); + } } } @@ -958,3 +972,10 @@ void ShopWindow::vendingSlotsChanged(const int slots) { mSellShopSize = slots; } + +void ShopWindow::vendingEnabled(const bool b) +{ + mEnableVending = b; + updateButtonsAndLabels(); + localPlayer->enableShop(b); +} diff --git a/src/gui/windows/shopwindow.h b/src/gui/windows/shopwindow.h index 06f0a997d..c746bff17 100644 --- a/src/gui/windows/shopwindow.h +++ b/src/gui/windows/shopwindow.h @@ -27,6 +27,7 @@ #include "listeners/actionlistener.h" #include "listeners/selectionlistener.h" +#include "listeners/vendingmodelistener.h" #include "listeners/vendingslotslistener.h" class Button; @@ -46,6 +47,7 @@ class TabStrip; class ShopWindow final : public Window, public ActionListener, public SelectionListener, + public VendingModeListener, public VendingSlotsListener { public: @@ -141,6 +143,8 @@ class ShopWindow final : public Window, void vendingSlotsChanged(const int slots) override final; + void vendingEnabled(const bool b) override final; + private: void startTrade(); @@ -176,6 +180,7 @@ class ShopWindow final : public Window, int mSellShopSize; bool isBuySelected; bool mHaveVending; + bool mEnableVending; }; extern ShopWindow *shopWindow; |