From beaddb973febb0570a9d035c2221e4fd06e3ac47 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Sep 2014 14:25:57 +0300 Subject: Move shop sell code from SellDialog into ShopSellDialog. --- src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/gui/windows/selldialog.cpp | 14 +------ src/gui/windows/selldialog.h | 3 +- src/gui/windows/shopselldialog.cpp | 75 ++++++++++++++++++++++++++++++++++++++ src/gui/windows/shopselldialog.h | 49 +++++++++++++++++++++++++ src/gui/windows/shopwindow.cpp | 4 +- 7 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 src/gui/windows/shopselldialog.cpp create mode 100644 src/gui/windows/shopselldialog.h 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 . + */ + +#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 . + */ + +#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 { -- cgit v1.2.3-60-g2f50