From c2f007b58743491dc9250f09137ad847043b840d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 15 Feb 2015 00:14:39 +0300 Subject: eathena: impliment packet SMSG_BUYINGSTORE_OWN_ITEMS. --- src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/gui/windows/shopwindow.cpp | 11 +++++++++ src/gui/windows/shopwindow.h | 5 ++++ src/listeners/buyingstoremodelistener.cpp | 36 +++++++++++++++++++++++++++++ src/listeners/buyingstoremodelistener.h | 38 +++++++++++++++++++++++++++++++ src/net/eathena/buyingstorehandler.cpp | 4 ++++ 7 files changed, 98 insertions(+) create mode 100644 src/listeners/buyingstoremodelistener.cpp create mode 100644 src/listeners/buyingstoremodelistener.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1820c1412..10384a26b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -822,6 +822,8 @@ SET(SRCS listeners/banklistener.cpp listeners/banklistener.h listeners/baselistener.hpp + listeners/buyingstoremodelistener.cpp + listeners/buyingstoremodelistener.h listeners/buyingstoreslotslistener.cpp listeners/buyingstoreslotslistener.h listeners/charrenamelistener.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 993ee575f..b14c4f99e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -951,6 +951,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ listeners/banklistener.cpp \ listeners/banklistener.h \ listeners/baselistener.hpp \ + listeners/buyingstoremodelistener.cpp \ + listeners/buyingstoremodelistener.h \ listeners/buyingstoreslotslistener.cpp \ listeners/buyingstoreslotslistener.h \ listeners/charrenamelistener.cpp \ diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index 6490ff746..bed828f0a 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -88,6 +88,7 @@ ShopWindow::ShopWindow() : SelectionListener(), VendingModeListener(), VendingSlotsListener(), + BuyingStoreModeListener(), BuyingStoreSlotsListener(), // TRANSLATORS: shop window button mCloseButton(new Button(this, _("Close"), "close", this)), @@ -121,6 +122,7 @@ ShopWindow::ShopWindow() : mBuyShopSize(0), isBuySelected(true), mHaveVending(serverFeatures->haveVending()), + mEnableBuyingStore(false), mEnableVending(false) { mBuyShopItemList->postInit(); @@ -1063,3 +1065,12 @@ void ShopWindow::buyingStoreSlotsChanged(const int slots) mBuyShopSize = slots; updateButtonsAndLabels(); } + +void ShopWindow::buyingStoreEnabled(const bool b) +{ + mEnableBuyingStore = b; + localPlayer->enableShop(b); + if (!b) + mBuyShopSize = 0; + updateButtonsAndLabels(); +} diff --git a/src/gui/windows/shopwindow.h b/src/gui/windows/shopwindow.h index e3398d093..313d3b4fb 100644 --- a/src/gui/windows/shopwindow.h +++ b/src/gui/windows/shopwindow.h @@ -26,6 +26,7 @@ #include "gui/widgets/window.h" #include "listeners/actionlistener.h" +#include "listeners/buyingstoremodelistener.h" #include "listeners/buyingstoreslotslistener.h" #include "listeners/selectionlistener.h" #include "listeners/vendingmodelistener.h" @@ -50,6 +51,7 @@ class ShopWindow final : public Window, public SelectionListener, public VendingModeListener, public VendingSlotsListener, + public BuyingStoreModeListener, public BuyingStoreSlotsListener { public: @@ -149,6 +151,8 @@ class ShopWindow final : public Window, void vendingEnabled(const bool b) override final; + void buyingStoreEnabled(const bool b) override final; + void setShopName(const std::string &name); private: @@ -191,6 +195,7 @@ class ShopWindow final : public Window, int mBuyShopSize; bool isBuySelected; bool mHaveVending; + bool mEnableBuyingStore; bool mEnableVending; }; diff --git a/src/listeners/buyingstoremodelistener.cpp b/src/listeners/buyingstoremodelistener.cpp new file mode 100644 index 000000000..217c19813 --- /dev/null +++ b/src/listeners/buyingstoremodelistener.cpp @@ -0,0 +1,36 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "listeners/buyingstoremodelistener.h" + +#include "debug.h" + +defineListener(BuyingStoreModeListener) + +void BuyingStoreModeListener::distributeEvent(const bool b) +{ + FOR_EACH (std::vector::iterator, + it, mListeners) + { + BuyingStoreModeListener *const listener = *it; + if (listener) + listener->buyingStoreEnabled(b); + } +} diff --git a/src/listeners/buyingstoremodelistener.h b/src/listeners/buyingstoremodelistener.h new file mode 100644 index 000000000..36d402d59 --- /dev/null +++ b/src/listeners/buyingstoremodelistener.h @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LISTENERS_BUYINGSTOREMODELISTENER_H +#define LISTENERS_BUYINGSTOREMODELISTENER_H + +#include "listeners/baselistener.hpp" + +#include "localconsts.h" + +class BuyingStoreModeListener notfinal +{ + public: + virtual void buyingStoreEnabled(const bool b) = 0; + + static void distributeEvent(const bool b); + + defineListenerHeader(BuyingStoreModeListener) +}; + +#endif // LISTENERS_BUYINGSTOREMODELISTENER_H diff --git a/src/net/eathena/buyingstorehandler.cpp b/src/net/eathena/buyingstorehandler.cpp index 8781a13ee..e0cd402a7 100644 --- a/src/net/eathena/buyingstorehandler.cpp +++ b/src/net/eathena/buyingstorehandler.cpp @@ -24,7 +24,9 @@ #include "shopitem.h" #include "being/being.h" +#include "being/playerinfo.h" +#include "listeners/buyingstoremodelistener.h" #include "listeners/buyingstoreslotslistener.h" #include "net/ea/eaprotocol.h" @@ -149,6 +151,8 @@ void BuyingStoreHandler::processBuyingStoreOwnItems(Net::MessageIn &msg) msg.readUInt8("item type"); msg.readInt16("item id"); } + PlayerInfo::enableVending(true); + BuyingStoreModeListener::distributeEvent(true); } void BuyingStoreHandler::processBuyingStoreShowBoard(Net::MessageIn &msg) -- cgit v1.2.3-70-g09d2