From 6dc1f5e0b68cf390f7938329b50a9b28bd187862 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 1 Feb 2015 23:48:15 +0300 Subject: Set correct vending status to local player. Allow buy from vending shop. --- src/gui/windows/shopwindow.cpp | 91 ++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 35 deletions(-) (limited to 'src/gui/windows/shopwindow.cpp') 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 &oldItems = mSellShopItems->items(); - std::vector items; - Inventory *const inv = PlayerInfo::getCartInventory(); - if (!inv) - return; - FOR_EACH (std::vector::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(items.size()) >= mSellShopSize) - break; + vendingHandler->close(); + VendingModeListener::distributeEvent(false); } - if (!items.empty()) + else { - vendingHandler->createShop("test shop", true, items); - mSellShopSize = 0; + std::vector &oldItems = mSellShopItems->items(); + std::vector items; + Inventory *const inv = PlayerInfo::getCartInventory(); + if (!inv) + return; + FOR_EACH (std::vector::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(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); +} -- cgit v1.2.3-60-g2f50