From 53c24ef91d7980f38defc705140cd2ab68e9c0ff Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 14 Feb 2015 00:20:50 +0300 Subject: Add basic support for buying store. --- src/gui/windows/shopwindow.cpp | 115 ++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index 63bef3d55..307c6ac61 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -61,6 +61,7 @@ #include "enums/being/attributes.h" #include "net/chathandler.h" +#include "net/buyingstorehandler.h" #include "net/serverfeatures.h" #include "net/tradehandler.h" #include "net/vendinghandler.h" @@ -279,39 +280,53 @@ void ShopWindow::action(const ActionEvent &event) #ifdef EATHENA_SUPPORT else if (eventId == "publish") { - if (mEnableVending) + if (isBuySelected) { - vendingHandler->close(); - VendingModeListener::distributeEvent(false); + std::vector &items = mBuyShopItems->items(); + if (!items.empty()) + { + buyingStoreHandler->create(mSellShopName, + PlayerInfo::getAttribute(Attributes::MONEY), + true, + items); + } } else { - 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; - if (!item) - continue; - // +++ 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); + } + else + { + 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; + if (!item) + continue; + // +++ 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(mSellShopName, true, items); } - if (!items.empty()) - vendingHandler->createShop(mSellShopName, true, items); } } else if (eventId == "rename") @@ -393,6 +408,12 @@ void ShopWindow::updateButtonsAndLabels() allowAdd = !mEnableVending; allowDel = mBuyShopItemList->getSelected() != -1 && mBuyShopItems->getNumberOfElements() > 0; + if (mPublishButton) + { + mPublishButton->setCaption(_("Publish")); + mPublishButton->adjustSize(); + mPublishButton->setEnabled(true); + } } else { @@ -400,29 +421,29 @@ void ShopWindow::updateButtonsAndLabels() allowDel = !mEnableVending && mSellShopItemList->getSelected() != -1 && sellNotEmpty; - } - mAddButton->setEnabled(allowAdd); - mDeleteButton->setEnabled(allowDel); - if (mPublishButton) - { - if (mEnableVending) - mPublishButton->setCaption(_("Unpublish")); - else - mPublishButton->setCaption(_("Publish")); - mPublishButton->adjustSize(); - if (!isBuySelected - && sellNotEmpty - && mSellShopSize > 0 - && localPlayer - && localPlayer->getHaveCart()) - { - mPublishButton->setEnabled(true); - } - else + if (mPublishButton) { - mPublishButton->setEnabled(false); + if (mEnableVending) + mPublishButton->setCaption(_("Unpublish")); + else + mPublishButton->setCaption(_("Publish")); + mPublishButton->adjustSize(); + if (!isBuySelected + && sellNotEmpty + && mSellShopSize > 0 + && localPlayer + && localPlayer->getHaveCart()) + { + mPublishButton->setEnabled(true); + } + else + { + mPublishButton->setEnabled(false); + } } } + mAddButton->setEnabled(allowAdd); + mDeleteButton->setEnabled(allowDel); if (mRenameButton) mRenameButton->setEnabled(!mEnableVending); } -- cgit v1.2.3-70-g09d2