summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-02-14 23:28:02 +0300
committerAndrei Karas <akaras@inbox.ru>2015-02-14 23:28:02 +0300
commitc7f54151ba693e7f57378b77cc567d5aa26cf4cf (patch)
tree653165d368da9fc58c9dbb5a8161e4e420a0b37c
parentc26624e72bb8d60bc1fa13cd5a178e06579e49a4 (diff)
downloadManaVerse-c7f54151ba693e7f57378b77cc567d5aa26cf4cf.tar.gz
ManaVerse-c7f54151ba693e7f57378b77cc567d5aa26cf4cf.tar.bz2
ManaVerse-c7f54151ba693e7f57378b77cc567d5aa26cf4cf.tar.xz
ManaVerse-c7f54151ba693e7f57378b77cc567d5aa26cf4cf.zip
Enable publish button in personal buy shop only if it allowed by server.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/windows/shopwindow.cpp16
-rw-r--r--src/gui/windows/shopwindow.h7
-rw-r--r--src/listeners/buyingstoreslotslistener.cpp36
-rw-r--r--src/listeners/buyingstoreslotslistener.h38
-rw-r--r--src/net/eathena/buyingstorehandler.cpp5
7 files changed, 100 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1bd78b525..1820c1412 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/buyingstoreslotslistener.cpp
+ listeners/buyingstoreslotslistener.h
listeners/charrenamelistener.cpp
listeners/charrenamelistener.h
actormanager.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 38a6753b7..993ee575f 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/buyingstoreslotslistener.cpp \
+ listeners/buyingstoreslotslistener.h \
listeners/charrenamelistener.cpp \
listeners/charrenamelistener.h \
actormanager.cpp \
diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp
index 307c6ac61..6490ff746 100644
--- a/src/gui/windows/shopwindow.cpp
+++ b/src/gui/windows/shopwindow.cpp
@@ -88,6 +88,7 @@ ShopWindow::ShopWindow() :
SelectionListener(),
VendingModeListener(),
VendingSlotsListener(),
+ BuyingStoreSlotsListener(),
// TRANSLATORS: shop window button
mCloseButton(new Button(this, _("Close"), "close", this)),
mBuyShopItems(new ShopItems),
@@ -117,6 +118,7 @@ ShopWindow::ShopWindow() :
mRandCounter(0),
mTradeMoney(0),
mSellShopSize(0),
+ mBuyShopSize(0),
isBuySelected(true),
mHaveVending(serverFeatures->haveVending()),
mEnableVending(false)
@@ -412,7 +414,10 @@ void ShopWindow::updateButtonsAndLabels()
{
mPublishButton->setCaption(_("Publish"));
mPublishButton->adjustSize();
- mPublishButton->setEnabled(true);
+ if (mBuyShopSize > 0)
+ mPublishButton->setEnabled(true);
+ else
+ mPublishButton->setEnabled(false);
}
}
else
@@ -428,8 +433,7 @@ void ShopWindow::updateButtonsAndLabels()
else
mPublishButton->setCaption(_("Publish"));
mPublishButton->adjustSize();
- if (!isBuySelected
- && sellNotEmpty
+ if (sellNotEmpty
&& mSellShopSize > 0
&& localPlayer
&& localPlayer->getHaveCart())
@@ -1053,3 +1057,9 @@ void ShopWindow::setShopName(const std::string &name)
serverConfig.setValue("sellShopName", mSellShopName);
updateShopName();
}
+
+void ShopWindow::buyingStoreSlotsChanged(const int slots)
+{
+ mBuyShopSize = slots;
+ updateButtonsAndLabels();
+}
diff --git a/src/gui/windows/shopwindow.h b/src/gui/windows/shopwindow.h
index 0acc814b1..e3398d093 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/buyingstoreslotslistener.h"
#include "listeners/selectionlistener.h"
#include "listeners/vendingmodelistener.h"
#include "listeners/vendingslotslistener.h"
@@ -48,7 +49,8 @@ class ShopWindow final : public Window,
public ActionListener,
public SelectionListener,
public VendingModeListener,
- public VendingSlotsListener
+ public VendingSlotsListener,
+ public BuyingStoreSlotsListener
{
public:
enum ShopMode
@@ -143,6 +145,8 @@ class ShopWindow final : public Window,
void vendingSlotsChanged(const int slots) override final;
+ void buyingStoreSlotsChanged(const int slots) override final;
+
void vendingEnabled(const bool b) override final;
void setShopName(const std::string &name);
@@ -184,6 +188,7 @@ class ShopWindow final : public Window,
int mRandCounter;
int mTradeMoney;
int mSellShopSize;
+ int mBuyShopSize;
bool isBuySelected;
bool mHaveVending;
bool mEnableVending;
diff --git a/src/listeners/buyingstoreslotslistener.cpp b/src/listeners/buyingstoreslotslistener.cpp
new file mode 100644
index 000000000..0ab1155df
--- /dev/null
+++ b/src/listeners/buyingstoreslotslistener.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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "listeners/buyingstoreslotslistener.h"
+
+#include "debug.h"
+
+defineListener(BuyingStoreSlotsListener)
+
+void BuyingStoreSlotsListener::distributeEvent(const int slots)
+{
+ FOR_EACH (std::vector<BuyingStoreSlotsListener*>::iterator,
+ it, mListeners)
+ {
+ BuyingStoreSlotsListener *const listener = *it;
+ if (listener)
+ listener->buyingStoreSlotsChanged(slots);
+ }
+}
diff --git a/src/listeners/buyingstoreslotslistener.h b/src/listeners/buyingstoreslotslistener.h
new file mode 100644
index 000000000..dc180a9cc
--- /dev/null
+++ b/src/listeners/buyingstoreslotslistener.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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LISTENERS_BUYINGSTORESLOTSLISTENER_H
+#define LISTENERS_BUYINGSTORESLOTSLISTENER_H
+
+#include "listeners/baselistener.hpp"
+
+#include "localconsts.h"
+
+class BuyingStoreSlotsListener notfinal
+{
+ public:
+ virtual void buyingStoreSlotsChanged(const int slots) = 0;
+
+ static void distributeEvent(const int slots);
+
+ defineListenerHeader(BuyingStoreSlotsListener)
+};
+
+#endif // LISTENERS_BUYINGSTORESLOTSLISTENER_H
diff --git a/src/net/eathena/buyingstorehandler.cpp b/src/net/eathena/buyingstorehandler.cpp
index 649b2b39e..8781a13ee 100644
--- a/src/net/eathena/buyingstorehandler.cpp
+++ b/src/net/eathena/buyingstorehandler.cpp
@@ -25,6 +25,8 @@
#include "being/being.h"
+#include "listeners/buyingstoreslotslistener.h"
+
#include "net/ea/eaprotocol.h"
#include "net/eathena/messageout.h"
@@ -111,8 +113,7 @@ void BuyingStoreHandler::handleMessage(Net::MessageIn &msg)
void BuyingStoreHandler::processBuyingStoreOpen(Net::MessageIn &msg)
{
- // +++ need create store dialog
- msg.readUInt8("slots");
+ BuyingStoreSlotsListener::distributeEvent(msg.readUInt8("slots"));
}
void BuyingStoreHandler::processBuyingStoreCreateFailed(Net::MessageIn &msg)