summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-22 14:25:57 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-22 14:25:57 +0300
commitbeaddb973febb0570a9d035c2221e4fd06e3ac47 (patch)
treef4a6aec77bd0ffd1afb3f06429777b27ccfec42f /src
parentd34decaf8b2b4cbffca970e9059e1a2b4f463055 (diff)
downloadmv-beaddb973febb0570a9d035c2221e4fd06e3ac47.tar.gz
mv-beaddb973febb0570a9d035c2221e4fd06e3ac47.tar.bz2
mv-beaddb973febb0570a9d035c2221e4fd06e3ac47.tar.xz
mv-beaddb973febb0570a9d035c2221e4fd06e3ac47.zip
Move shop sell code from SellDialog into ShopSellDialog.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/windows/selldialog.cpp14
-rw-r--r--src/gui/windows/selldialog.h3
-rw-r--r--src/gui/windows/shopselldialog.cpp75
-rw-r--r--src/gui/windows/shopselldialog.h49
-rw-r--r--src/gui/windows/shopwindow.cpp4
7 files changed, 132 insertions, 17 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f8f63f26c..8bd4bf57a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -415,6 +415,8 @@ SET(SRCS
gui/windows/serverdialog.h
gui/windows/setupwindow.cpp
gui/windows/setupwindow.h
+ gui/windows/shopselldialog.cpp
+ gui/windows/shopselldialog.h
gui/widgets/tabs/setup_audio.cpp
gui/widgets/tabs/setup_audio.h
gui/widgets/tabs/setup_colors.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 693901ce3..3179d5c13 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -537,6 +537,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
gui/windows/serverdialog.h \
gui/windows/setupwindow.cpp \
gui/windows/setupwindow.h \
+ gui/windows/shopselldialog.cpp \
+ gui/windows/shopselldialog.h \
gui/widgets/tabs/setup_audio.cpp \
gui/widgets/tabs/setup_audio.h \
gui/widgets/tabs/setup_colors.cpp \
diff --git a/src/gui/windows/selldialog.cpp b/src/gui/windows/selldialog.cpp
index cd8c03bdc..32ee2e827 100644
--- a/src/gui/windows/selldialog.cpp
+++ b/src/gui/windows/selldialog.cpp
@@ -245,19 +245,7 @@ void SellDialog::action(const ActionEvent &event)
else if ((eventId == "presell" || eventId == "sell" || eventId == "yes")
&& mAmountItems > 0 && mAmountItems <= mMaxItems)
{
- if (mNpcId != -1)
- {
- sellAction(event);
- }
- else
- {
- ShopItem *const item = mShopItems->at(selectedItem);
- buySellHandler->sendSellRequest(mNick,
- item, mAmountItems);
-
- if (tradeWindow)
- tradeWindow->addAutoItem(mNick, item, mAmountItems);
- }
+ sellAction(event);
}
}
diff --git a/src/gui/windows/selldialog.h b/src/gui/windows/selldialog.h
index 81aaabbb2..471ae74f2 100644
--- a/src/gui/windows/selldialog.h
+++ b/src/gui/windows/selldialog.h
@@ -122,8 +122,7 @@ class SellDialog notfinal : public Window,
*/
void updateButtonsAndLabels();
- virtual void sellAction(const ActionEvent &event A_UNUSED)
- { }
+ virtual void sellAction(const ActionEvent &event) = 0;
std::string mNick;
diff --git a/src/gui/windows/shopselldialog.cpp b/src/gui/windows/shopselldialog.cpp
new file mode 100644
index 000000000..71775e726
--- /dev/null
+++ b/src/gui/windows/shopselldialog.cpp
@@ -0,0 +1,75 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 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 "gui/windows/shopselldialog.h"
+
+#include "shopitem.h"
+#include "units.h"
+
+#include "being/playerinfo.h"
+
+#include "gui/windows/confirmdialog.h"
+#include "gui/windows/setupwindow.h"
+#include "gui/windows/tradewindow.h"
+
+#include "gui/models/shopitems.h"
+
+#include "gui/widgets/button.h"
+#include "gui/widgets/containerplacer.h"
+#include "gui/widgets/label.h"
+#include "gui/widgets/layout.h"
+#include "gui/widgets/layouttype.h"
+#include "gui/widgets/scrollarea.h"
+#include "gui/widgets/shoplistbox.h"
+#include "gui/widgets/slider.h"
+
+#include "net/buysellhandler.h"
+#include "net/net.h"
+#include "net/npchandler.h"
+
+#include "resources/iteminfo.h"
+
+#include "utils/delete2.h"
+#include "utils/gettext.h"
+
+#include "debug.h"
+
+ShopSellDialog::ShopSellDialog(const std::string &nick) :
+ SellDialog(nick)
+{
+}
+
+void ShopSellDialog::sellAction(const ActionEvent &event)
+{
+ if (mAmountItems <= 0 || mAmountItems > mMaxItems)
+ return;
+
+ const std::string &eventId = event.getId();
+ const int selectedItem = mShopItemList->getSelected();
+ ShopItem *const item = mShopItems->at(selectedItem);
+ if (!item || PlayerInfo::isItemProtected(item->getId()))
+ return;
+ buySellHandler->sendSellRequest(mNick, item, mAmountItems);
+
+ if (tradeWindow)
+ tradeWindow->addAutoItem(mNick, item, mAmountItems);
+}
diff --git a/src/gui/windows/shopselldialog.h b/src/gui/windows/shopselldialog.h
new file mode 100644
index 000000000..bec840409
--- /dev/null
+++ b/src/gui/windows/shopselldialog.h
@@ -0,0 +1,49 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 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 GUI_WINDOWS_SHOPSELLDIALOG_H
+#define GUI_WINDOWS_SHOPSELLDIALOG_H
+
+#include "gui/windows/selldialog.h"
+
+/**
+ * The sell dialog.
+ *
+ * \ingroup Interface
+ */
+class ShopSellDialog final : public SellDialog
+{
+ public:
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
+ explicit ShopSellDialog(const std::string &nick);
+
+ A_DELETE_COPY(ShopSellDialog)
+
+ protected:
+ void sellAction(const ActionEvent &event) override final;
+};
+
+#endif // GUI_WINDOWS_SHOPSELLDIALOG_H
diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp
index a78a8fbcd..0fb2a952f 100644
--- a/src/gui/windows/shopwindow.cpp
+++ b/src/gui/windows/shopwindow.cpp
@@ -28,7 +28,7 @@
#include "gui/windows/chatwindow.h"
#include "gui/windows/confirmdialog.h"
#include "gui/windows/itemamountwindow.h"
-#include "gui/windows/selldialog.h"
+#include "gui/windows/shopselldialog.h"
#include "gui/windows/setupwindow.h"
#include "gui/windows/tradewindow.h"
@@ -652,7 +652,7 @@ void ShopWindow::showList(const std::string &nick, std::string data)
else if (data.find("S1") == 0)
{
data = data.substr(2);
- sellDialog = new SellDialog(nick);
+ sellDialog = new ShopSellDialog(nick);
}
else
{