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/windows/shopwindow.cpp | |
parent | c8c51d7550adf9c952a4be54398df7e7a6f341a8 (diff) | |
download | manaverse-6dc1f5e0b68cf390f7938329b50a9b28bd187862.tar.gz manaverse-6dc1f5e0b68cf390f7938329b50a9b28bd187862.tar.bz2 manaverse-6dc1f5e0b68cf390f7938329b50a9b28bd187862.tar.xz manaverse-6dc1f5e0b68cf390f7938329b50a9b28bd187862.zip |
Set correct vending status to local player.
Allow buy from vending shop.
Diffstat (limited to 'src/gui/windows/shopwindow.cpp')
-rw-r--r-- | src/gui/windows/shopwindow.cpp | 91 |
1 files changed, 56 insertions, 35 deletions
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); +} |