diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-02-14 00:20:50 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-02-14 19:39:48 +0300 |
commit | 53c24ef91d7980f38defc705140cd2ab68e9c0ff (patch) | |
tree | 63c8ae458e23444631fc9f7b35df237c2d4395d9 | |
parent | ffda42bb5e2062f43a55026d949ac1dcad3826e0 (diff) | |
download | manaverse-53c24ef91d7980f38defc705140cd2ab68e9c0ff.tar.gz manaverse-53c24ef91d7980f38defc705140cd2ab68e9c0ff.tar.bz2 manaverse-53c24ef91d7980f38defc705140cd2ab68e9c0ff.tar.xz manaverse-53c24ef91d7980f38defc705140cd2ab68e9c0ff.zip |
Add basic support for buying store.
-rw-r--r-- | src/gui/windows/shopwindow.cpp | 115 |
1 files changed, 68 insertions, 47 deletions
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<ShopItem*> &items = mBuyShopItems->items(); + if (!items.empty()) + { + buyingStoreHandler->create(mSellShopName, + PlayerInfo::getAttribute(Attributes::MONEY), + true, + items); + } } else { - 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; - 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<signed int>(items.size()) >= mSellShopSize) - break; + vendingHandler->close(); + VendingModeListener::distributeEvent(false); + } + else + { + 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; + 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<signed int>(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); } |