summaryrefslogtreecommitdiff
path: root/src/gui/windows/shopwindow.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-02-14 00:20:50 +0300
committerAndrei Karas <akaras@inbox.ru>2015-02-14 19:39:48 +0300
commit53c24ef91d7980f38defc705140cd2ab68e9c0ff (patch)
tree63c8ae458e23444631fc9f7b35df237c2d4395d9 /src/gui/windows/shopwindow.cpp
parentffda42bb5e2062f43a55026d949ac1dcad3826e0 (diff)
downloadmv-53c24ef91d7980f38defc705140cd2ab68e9c0ff.tar.gz
mv-53c24ef91d7980f38defc705140cd2ab68e9c0ff.tar.bz2
mv-53c24ef91d7980f38defc705140cd2ab68e9c0ff.tar.xz
mv-53c24ef91d7980f38defc705140cd2ab68e9c0ff.zip
Add basic support for buying store.
Diffstat (limited to 'src/gui/windows/shopwindow.cpp')
-rw-r--r--src/gui/windows/shopwindow.cpp115
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);
}