summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-01-28 21:27:04 +0300
committerAndrei Karas <akaras@inbox.ru>2015-02-02 00:13:44 +0300
commitb6a0e05498b2b1a64d9b407fb2416dbaa0faf407 (patch)
tree7a1023dabcdf250e0983edff3ab1a2a14226f300 /src
parent6930045257ca767dbfc095f95a440028d5b2213e (diff)
downloadmanaverse-b6a0e05498b2b1a64d9b407fb2416dbaa0faf407.tar.gz
manaverse-b6a0e05498b2b1a64d9b407fb2416dbaa0faf407.tar.bz2
manaverse-b6a0e05498b2b1a64d9b407fb2416dbaa0faf407.tar.xz
manaverse-b6a0e05498b2b1a64d9b407fb2416dbaa0faf407.zip
eathena: add support for creating vending shop.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/windows/shopwindow.cpp101
-rw-r--r--src/gui/windows/shopwindow.h10
-rw-r--r--src/listeners/vendingslotslistener.cpp36
-rw-r--r--src/listeners/vendingslotslistener.h38
-rw-r--r--src/net/eathena/vendinghandler.cpp4
7 files changed, 175 insertions, 18 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e10873bea..f39580294 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1145,6 +1145,8 @@ SET(SRCS
listeners/updatestatuslistener.h
listeners/uploadlistener.cpp
listeners/uploadlistener.h
+ listeners/vendingslotslistener.cpp
+ listeners/vendingslotslistener.h
utils/sdlpixel.h
gui/widgets/widget.h
listeners/weightlistener.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 46a7b6877..11dc8364a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -223,6 +223,8 @@ manaplus_SOURCES += events/actionevent.h \
listeners/updatestatuslistener.h \
listeners/uploadlistener.cpp \
listeners/uploadlistener.h \
+ listeners/vendingslotslistener.cpp \
+ listeners/vendingslotslistener.h \
utils/sdlpixel.h \
gui/widgets/widget.h \
listeners/weightlistener.h \
diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp
index 9240b8e8c..5d013430a 100644
--- a/src/gui/windows/shopwindow.cpp
+++ b/src/gui/windows/shopwindow.cpp
@@ -58,7 +58,9 @@
#include "enums/being/attributes.h"
#include "net/chathandler.h"
+#include "net/serverfeatures.h"
#include "net/tradehandler.h"
+#include "net/vendinghandler.h"
#include "resources/iteminfo.h"
@@ -80,6 +82,7 @@ ShopWindow::ShopWindow() :
Window(_("Personal Shop"), false, nullptr, "shop.xml"),
ActionListener(),
SelectionListener(),
+ VendingSlotsListener(),
// TRANSLATORS: shop window button
mCloseButton(new Button(this, _("Close"), "close", this)),
mBuyShopItems(new ShopItems),
@@ -94,21 +97,21 @@ ShopWindow::ShopWindow() :
mAddButton(new Button(this, _("Add"), "add", this)),
// TRANSLATORS: shop window label
mDeleteButton(new Button(this, _("Delete"), "delete", this)),
- // TRANSLATORS: shop window label
- mAnnounceButton(new Button(this, _("Announce"), "announce", this)),
- // TRANSLATORS: shop window checkbox
- mAnnounceLinks(new CheckBox(this, _("Show links in announce"), false,
- this, "link announce")),
+ mAnnounceButton(nullptr),
+ mPublishButton(nullptr),
+ mAnnounceLinks(nullptr),
mTabs(nullptr),
- mAcceptPlayer(""),
- mTradeNick(""),
+ mAcceptPlayer(),
+ mTradeNick(),
mSelectedItem(-1),
mAnnonceTime(0),
mLastRequestTimeList(0),
mLastRequestTimeItem(0),
mRandCounter(0),
mTradeMoney(0),
- isBuySelected(true)
+ mSellShopSize(0),
+ isBuySelected(true),
+ mHaveVending(serverFeatures->haveVending())
{
mBuyShopItemList->postInit();
mSellShopItemList->postInit();
@@ -138,8 +141,6 @@ ShopWindow::ShopWindow() :
// TRANSLATORS: shop window tab name
mTabs->addButton(_("Sell"), "sell", false);
- mAnnounceCounter[BUY] = 0;
- mAnnounceCounter[SELL] = 0;
loadList();
@@ -156,11 +157,27 @@ ShopWindow::ShopWindow() :
placer(0, 0, mTabs, 8).setPadding(3);
+ if (isBuySelected)
+ {
+ // TRANSLATORS: shop window button
+ mPublishButton = new Button(this, _("Publish"), "publish", this);
+ placer(2, 6, mPublishButton);
+ }
+ else
+ {
+ // TRANSLATORS: shop window button
+ mAnnounceButton = new Button(this, _("Announce"), "announce", this);
+ // TRANSLATORS: shop window checkbox
+ mAnnounceLinks = new CheckBox(this, _("Show links in announce"), false,
+ this, "link announce");
+
+ placer(2, 6, mAnnounceButton);
+ placer(0, 7, mAnnounceLinks, 7);
+ }
+
placer(0, 1, mScrollArea, 8, 5).setPadding(3);
placer(0, 6, mAddButton);
placer(1, 6, mDeleteButton);
- placer(2, 6, mAnnounceButton);
- placer(0, 7, mAnnounceLinks, 7);
placer(7, 7, mCloseButton);
Layout &layout = getLayout();
@@ -251,11 +268,42 @@ void ShopWindow::action(const ActionEvent &event)
isBuySelected = false;
updateSelection();
}
+ else if (eventId == "publish")
+ {
+ 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;
+ // +++ 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("test shop", true, items);
+ mSellShopSize = 0;
+ }
+ }
if (mSelectedItem < 1)
return;
- const Inventory *const inv = PlayerInfo::getInventory();
+ const Inventory *const inv = mHaveVending
+ ? PlayerInfo::getCartInventory() : PlayerInfo::getInventory();
if (!inv)
return;
@@ -310,6 +358,7 @@ void ShopWindow::updateButtonsAndLabels()
{
mAddButton->setEnabled(mSelectedItem != -1);
bool allowDel(false);
+ const bool sellNotEmpty = mSellShopItems->getNumberOfElements() > 0;
if (isBuySelected)
{
allowDel = mBuyShopItemList->getSelected() != -1
@@ -317,10 +366,22 @@ void ShopWindow::updateButtonsAndLabels()
}
else
{
- allowDel = mSellShopItemList->getSelected() != -1
- && mSellShopItems->getNumberOfElements() > 0;
+ allowDel = mSellShopItemList->getSelected() != -1 && sellNotEmpty;
}
mDeleteButton->setEnabled(allowDel);
+ if (mPublishButton
+ && !isBuySelected
+ && sellNotEmpty
+ && mSellShopSize > 0
+ && localPlayer
+ && localPlayer->getHaveCart())
+ {
+ mPublishButton->setEnabled(true);
+ }
+ else
+ {
+ mPublishButton->setEnabled(false);
+ }
}
void ShopWindow::setVisible(bool visible)
@@ -795,6 +856,11 @@ void ShopWindow::processRequest(const std::string &nick, std::string data,
void ShopWindow::updateTimes()
{
BLOCK_START("ShopWindow::updateTimes")
+ if (!mAnnounceButton)
+ {
+ BLOCK_END("ShopWindow::updateTimes")
+ return;
+ }
if (mAnnonceTime + (2 * 60) < cur_time
|| mAnnonceTime > cur_time)
{
@@ -887,3 +953,8 @@ void ShopWindow::updateSelection()
mScrollArea->setContent(mCurrentShopItemList);
updateButtonsAndLabels();
}
+
+void ShopWindow::vendingSlotsChanged(const int slots)
+{
+ mSellShopSize = slots;
+}
diff --git a/src/gui/windows/shopwindow.h b/src/gui/windows/shopwindow.h
index a3409bbe7..06f0a997d 100644
--- a/src/gui/windows/shopwindow.h
+++ b/src/gui/windows/shopwindow.h
@@ -27,6 +27,7 @@
#include "listeners/actionlistener.h"
#include "listeners/selectionlistener.h"
+#include "listeners/vendingslotslistener.h"
class Button;
class CheckBox;
@@ -44,7 +45,8 @@ class TabStrip;
*/
class ShopWindow final : public Window,
public ActionListener,
- public SelectionListener
+ public SelectionListener,
+ public VendingSlotsListener
{
public:
enum ShopMode
@@ -137,6 +139,8 @@ class ShopWindow final : public Window,
bool isShopEmpty() const A_WARN_UNUSED;
+ void vendingSlotsChanged(const int slots) override final;
+
private:
void startTrade();
@@ -158,6 +162,7 @@ class ShopWindow final : public Window,
Button *mAddButton;
Button *mDeleteButton;
Button *mAnnounceButton;
+ Button *mPublishButton;
CheckBox *mAnnounceLinks;
TabStrip *mTabs;
std::string mAcceptPlayer;
@@ -168,8 +173,9 @@ class ShopWindow final : public Window,
int mLastRequestTimeItem;
int mRandCounter;
int mTradeMoney;
- int mAnnounceCounter[2];
+ int mSellShopSize;
bool isBuySelected;
+ bool mHaveVending;
};
extern ShopWindow *shopWindow;
diff --git a/src/listeners/vendingslotslistener.cpp b/src/listeners/vendingslotslistener.cpp
new file mode 100644
index 000000000..5a60e9807
--- /dev/null
+++ b/src/listeners/vendingslotslistener.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/vendingslotslistener.h"
+
+#include "debug.h"
+
+defineListener(VendingSlotsListener)
+
+void VendingSlotsListener::distributeEvent(const int slots)
+{
+ FOR_EACH (std::vector<VendingSlotsListener*>::iterator,
+ it, mListeners)
+ {
+ VendingSlotsListener *const listener = *it;
+ if (listener)
+ listener->vendingSlotsChanged(slots);
+ }
+}
diff --git a/src/listeners/vendingslotslistener.h b/src/listeners/vendingslotslistener.h
new file mode 100644
index 000000000..98b4ae49a
--- /dev/null
+++ b/src/listeners/vendingslotslistener.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_VENDINGSLOTSLISTENER_H
+#define LISTENERS_VENDINGSLOTSLISTENER_H
+
+#include "listeners/baselistener.hpp"
+
+#include "localconsts.h"
+
+class VendingSlotsListener notfinal
+{
+ public:
+ virtual void vendingSlotsChanged(const int slots) = 0;
+
+ static void distributeEvent(const int slots);
+
+ defineListenerHeader(VendingSlotsListener)
+};
+
+#endif // LISTENERS_VENDINGSLOTSLISTENER_H
diff --git a/src/net/eathena/vendinghandler.cpp b/src/net/eathena/vendinghandler.cpp
index 3228cf0db..54f1b74c1 100644
--- a/src/net/eathena/vendinghandler.cpp
+++ b/src/net/eathena/vendinghandler.cpp
@@ -24,6 +24,8 @@
#include "being/being.h"
+#include "listeners/vendingslotslistener.h"
+
#include "net/ea/eaprotocol.h"
#include "net/eathena/messageout.h"
@@ -92,7 +94,7 @@ void VendingHandler::handleMessage(Net::MessageIn &msg)
void VendingHandler::processOpenReq(Net::MessageIn &msg)
{
- msg.readInt16("slots allowed");
+ VendingSlotsListener::distributeEvent(msg.readInt16("slots allowed"));
}
void VendingHandler::processShowBoard(Net::MessageIn &msg)