diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-02-01 00:43:24 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-02-01 00:45:05 +0300 |
commit | 2c273a20b2cd3e1628840f2d87df16f0cce9ad33 (patch) | |
tree | 853d172e0fd05117d84eda712912ba2843bb87e2 /src | |
parent | 35481061f62111f916a39ce3cac6a314579418f9 (diff) | |
download | plus-2c273a20b2cd3e1628840f2d87df16f0cce9ad33.tar.gz plus-2c273a20b2cd3e1628840f2d87df16f0cce9ad33.tar.bz2 plus-2c273a20b2cd3e1628840f2d87df16f0cce9ad33.tar.xz plus-2c273a20b2cd3e1628840f2d87df16f0cce9ad33.zip |
Set currency to buy dialog based on selected npc type id.
For now this type never set.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/const/resources/currency.h | 28 | ||||
-rw-r--r-- | src/gui/windows/buydialog.cpp | 12 | ||||
-rw-r--r-- | src/gui/windows/buydialog.h | 10 | ||||
-rw-r--r-- | src/gui/windows/shopwindow.cpp | 6 | ||||
-rw-r--r-- | src/net/eathena/buysellrecv.cpp | 30 | ||||
-rw-r--r-- | src/net/eathena/cashshoprecv.cpp | 27 | ||||
-rw-r--r-- | src/net/eathena/marketrecv.cpp | 28 | ||||
-rw-r--r-- | src/net/eathena/npcrecv.cpp | 4 | ||||
-rw-r--r-- | src/net/eathena/npcrecv.h | 4 | ||||
-rw-r--r-- | src/net/eathena/vendingrecv.cpp | 4 | ||||
-rw-r--r-- | src/net/tmwa/buysellrecv.cpp | 7 | ||||
-rw-r--r-- | src/resources/db/unitsdb.cpp | 6 |
14 files changed, 151 insertions, 17 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5a1afb416..750e38e8e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -803,6 +803,7 @@ SET(SRCS resources/skill/skilltypeentry.h resources/skill/skilltypelist.h const/net/skill.h + const/resources/currency.h const/resources/skill.h enums/resources/skill/skillowner.h enums/resources/skill/skillsettype.h diff --git a/src/Makefile.am b/src/Makefile.am index 21a08ef6e..0f0bae0f0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -474,6 +474,7 @@ BASE_SRC += events/actionevent.h \ resources/skill/skilltypeentry.h \ resources/skill/skilltypelist.h \ const/net/skill.h \ + const/resources/currency.h \ const/resources/skill.h \ enums/resources/skill/skillowner.h \ enums/resources/skill/skillsettype.h \ diff --git a/src/const/resources/currency.h b/src/const/resources/currency.h new file mode 100644 index 000000000..e5f6cfccf --- /dev/null +++ b/src/const/resources/currency.h @@ -0,0 +1,28 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2017 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 CONST_RESOURCES_SKILL_H +#define CONST_RESOURCES_SKILL_H + +#include <string> + +const std::string DEFAULT_CURRENCY = "default"; + +#endif // CONST_RESOURCES_SKILL_H diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index c5fdac885..620c95817 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -203,7 +203,8 @@ BuyDialog::BuyDialog() : init(); } -BuyDialog::BuyDialog(const BeingId npcId) : +BuyDialog::BuyDialog(const BeingId npcId, + const std::string ¤cy) : // TRANSLATORS: buy dialog name Window(_("Buy"), Modal_false, nullptr, "buy.xml"), ActionListener(), @@ -214,6 +215,7 @@ BuyDialog::BuyDialog(const BeingId npcId) : this, "namefilter", true)), mFilterLabel(nullptr), mNick(), + mCurrency(currency), mNpcId(npcId), mMoney(0), mAmountItems(0), @@ -224,7 +226,8 @@ BuyDialog::BuyDialog(const BeingId npcId) : } #ifdef TMWA_SUPPORT -BuyDialog::BuyDialog(std::string nick) : +BuyDialog::BuyDialog(const std::string &nick, + const std::string ¤cy) : // TRANSLATORS: buy dialog name Window(_("Buy"), Modal_false, nullptr, "buy.xml"), ActionListener(), @@ -236,6 +239,7 @@ BuyDialog::BuyDialog(std::string nick) : this, "namefilter", true)), mFilterLabel(nullptr), mNick(nick), + mCurrency(currency), mNpcId(fromInt(Nick, BeingId)), mMoney(0), mAmountItems(0), @@ -246,7 +250,8 @@ BuyDialog::BuyDialog(std::string nick) : } #endif // TMWA_SUPPORT -BuyDialog::BuyDialog(const Being *const being) : +BuyDialog::BuyDialog(const Being *const being, + const std::string ¤cy) : // TRANSLATORS: buy dialog name Window(_("Buy"), Modal_false, nullptr, "buy.xml"), ActionListener(), @@ -258,6 +263,7 @@ BuyDialog::BuyDialog(const Being *const being) : this, "namefilter", true)), mFilterLabel(nullptr), mNick(being ? being->getName() : std::string()), + mCurrency(currency), mNpcId(fromInt(Vending, BeingId)), mMoney(0), mAmountItems(0), diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h index 4fdd4f210..7914c0ef3 100644 --- a/src/gui/windows/buydialog.h +++ b/src/gui/windows/buydialog.h @@ -68,7 +68,8 @@ class BuyDialog final : public Window, * * @see Window::Window */ - explicit BuyDialog(const BeingId npcId); + BuyDialog(const BeingId npcId, + const std::string ¤cy); #ifdef TMWA_SUPPORT /** @@ -76,7 +77,8 @@ class BuyDialog final : public Window, * * @see Window::Window */ - explicit BuyDialog(std::string nick); + BuyDialog(const std::string &nick, + const std::string ¤cy); #endif // TMWA_SUPPORT /** @@ -84,7 +86,8 @@ class BuyDialog final : public Window, * * @see Window::Window */ - explicit BuyDialog(const Being *const being); + BuyDialog(const Being *const being, + const std::string ¤cy); A_DELETE_COPY(BuyDialog) @@ -193,6 +196,7 @@ class BuyDialog final : public Window, Label *mFilterLabel; std::string mNick; + std::string mCurrency; BeingId mNpcId; int mMoney; int mAmountItems; diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index d7b629a4e..b09b44a46 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -23,6 +23,8 @@ #include "gui/windows/shopwindow.h" #ifdef TMWA_SUPPORT +#include "const/resources/currency.h" + #include "gui/windows/buydialog.h" #include "gui/windows/chatwindow.h" #include "gui/windows/confirmdialog.h" @@ -829,7 +831,7 @@ void ShopWindow::showList(const std::string &nick, std::string data) if (data.find("B1") == 0) { data = data.substr(2); - CREATEWIDGETV(buyDialog, BuyDialog, nick); + CREATEWIDGETV(buyDialog, BuyDialog, nick, DEFAULT_CURRENCY); } else if (data.find("S1") == 0) { @@ -854,7 +856,6 @@ void ShopWindow::showList(const std::string &nick, std::string data) const int id = decodeStr(data.substr(f, 2)); const int price = decodeStr(data.substr(f + 2, 4)); int amount = decodeStr(data.substr(f + 6, 3)); - // +++ need impliment colors? if (buyDialog && amount > 0) { buyDialog->addItem(id, @@ -865,7 +866,6 @@ void ShopWindow::showList(const std::string &nick, std::string data) } if (sellDialog) { - // +++ need support for colors const Item *const item = inv->findItem(id, ItemColor_zero); if (item) { diff --git a/src/net/eathena/buysellrecv.cpp b/src/net/eathena/buysellrecv.cpp index f817813c6..2984eac97 100644 --- a/src/net/eathena/buysellrecv.cpp +++ b/src/net/eathena/buysellrecv.cpp @@ -26,15 +26,23 @@ #include "being/playerinfo.h" +#include "const/resources/currency.h" + #include "enums/resources/notifytypes.h" #include "gui/windows/buydialog.h" #include "gui/widgets/createwidget.h" +#include "net/messagein.h" + #include "net/ea/buysellrecv.h" -#include "net/messagein.h" +#include "net/eathena/npcrecv.h" + +#include "resources/beinginfo.h" + +#include "resources/db/npcdb.h" #include "debug.h" @@ -46,8 +54,26 @@ void BuySellRecv::processNpcBuy(Net::MessageIn &msg) msg.readInt16("len"); const int sz = 11; const int n_items = (msg.getLength() - 4) / sz; + + const BeingTypeId npcId = NpcRecv::mNpcTypeId; + std::string currency; + + if (npcId != BeingTypeId_zero) + { + const BeingInfo *info = NPCDB::get(npcId); + if (info) + currency = info->getCurrency(); + else + currency = DEFAULT_CURRENCY; + } + else + { + currency = DEFAULT_CURRENCY; + } + CREATEWIDGETV(Ea::BuySellRecv::mBuyDialog, BuyDialog, - Ea::BuySellRecv::mNpcId); + Ea::BuySellRecv::mNpcId, + currency); Ea::BuySellRecv::mBuyDialog->setMoney( PlayerInfo::getAttribute(Attributes::MONEY)); diff --git a/src/net/eathena/cashshoprecv.cpp b/src/net/eathena/cashshoprecv.cpp index e051f8ba0..fefe422f1 100644 --- a/src/net/eathena/cashshoprecv.cpp +++ b/src/net/eathena/cashshoprecv.cpp @@ -24,6 +24,8 @@ #include "being/playerinfo.h" +#include "const/resources/currency.h" + #include "enums/resources/notifytypes.h" #include "gui/windows/buydialog.h" @@ -32,6 +34,12 @@ #include "net/messagein.h" +#include "net/eathena/npcrecv.h" + +#include "resources/beinginfo.h" + +#include "resources/db/npcdb.h" + #include "debug.h" extern int packetVersion; @@ -52,7 +60,24 @@ void CashShopRecv::processCashShopOpen(Net::MessageIn &msg) else count = (msg.readInt16("len") - 8) / 11; - CREATEWIDGETV(mBuyDialog, BuyDialog, fromInt(BuyDialog::Cash, BeingId)); + const BeingTypeId npcId = NpcRecv::mNpcTypeId; + std::string currency; + + if (npcId != BeingTypeId_zero) + { + const BeingInfo *info = NPCDB::get(npcId); + if (info) + currency = info->getCurrency(); + else + currency = DEFAULT_CURRENCY; + } + else + { + currency = DEFAULT_CURRENCY; + } + CREATEWIDGETV(mBuyDialog, BuyDialog, + fromInt(BuyDialog::Cash, BeingId), + currency); const int points = msg.readInt32("cash points"); mBuyDialog->setMoney(points); diff --git a/src/net/eathena/marketrecv.cpp b/src/net/eathena/marketrecv.cpp index c3ac370ff..82775acff 100644 --- a/src/net/eathena/marketrecv.cpp +++ b/src/net/eathena/marketrecv.cpp @@ -24,6 +24,8 @@ #include "being/playerinfo.h" +#include "const/resources/currency.h" + #include "enums/resources/notifytypes.h" #include "gui/windows/buydialog.h" @@ -32,6 +34,12 @@ #include "net/messagein.h" +#include "net/eathena/npcrecv.h" + +#include "resources/beinginfo.h" + +#include "resources/db/npcdb.h" + #include "debug.h" namespace EAthena @@ -47,7 +55,25 @@ void MarketRecv::processMarketOpen(Net::MessageIn &msg) { const int len = (msg.readInt16("len") - 4) / 13; - CREATEWIDGETV(mBuyDialog, BuyDialog, fromInt(BuyDialog::Market, BeingId)); + const BeingTypeId npcId = NpcRecv::mNpcTypeId; + std::string currency; + + if (npcId != BeingTypeId_zero) + { + const BeingInfo *info = NPCDB::get(npcId); + if (info) + currency = info->getCurrency(); + else + currency = DEFAULT_CURRENCY; + } + else + { + currency = DEFAULT_CURRENCY; + } + + CREATEWIDGETV(mBuyDialog, BuyDialog, + fromInt(BuyDialog::Market, BeingId), + currency); mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY)); for (int f = 0; f < len; f ++) diff --git a/src/net/eathena/npcrecv.cpp b/src/net/eathena/npcrecv.cpp index d67c4f880..c23d9d11b 100644 --- a/src/net/eathena/npcrecv.cpp +++ b/src/net/eathena/npcrecv.cpp @@ -37,6 +37,10 @@ namespace EAthena { +namespace NpcRecv +{ + BeingTypeId mNpcTypeId = BeingTypeId_zero; +} // namespace NpcRecv void NpcRecv::processNpcCutin(Net::MessageIn &msg) { diff --git a/src/net/eathena/npcrecv.h b/src/net/eathena/npcrecv.h index 2cdd42719..c89d5f2f0 100644 --- a/src/net/eathena/npcrecv.h +++ b/src/net/eathena/npcrecv.h @@ -21,6 +21,8 @@ #ifndef NET_EATHENA_NPCRECV_H #define NET_EATHENA_NPCRECV_H +#include "enums/simpletypes/beingtypeid.h" + namespace Net { class MessageIn; @@ -30,6 +32,8 @@ namespace EAthena { namespace NpcRecv { + extern BeingTypeId mNpcTypeId; + void processNpcCutin(Net::MessageIn &msg); void processNpcViewPoint(Net::MessageIn &msg); void processNpcShowProgressBar(Net::MessageIn &msg); diff --git a/src/net/eathena/vendingrecv.cpp b/src/net/eathena/vendingrecv.cpp index f5168abac..6d583bca6 100644 --- a/src/net/eathena/vendingrecv.cpp +++ b/src/net/eathena/vendingrecv.cpp @@ -24,6 +24,8 @@ #include "itemcolormanager.h" #include "notifymanager.h" +#include "const/resources/currency.h" + #include "being/localplayer.h" #include "being/playerinfo.h" @@ -109,7 +111,7 @@ void VendingRecv::processItemsList(Net::MessageIn &msg) if (!being) return; int cards[maxCards]; - CREATEWIDGETV(mBuyDialog, BuyDialog, being); + CREATEWIDGETV(mBuyDialog, BuyDialog, being, DEFAULT_CURRENCY); mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY)); if (msg.getVersion() >= 20100105) msg.readInt32("vender id"); diff --git a/src/net/tmwa/buysellrecv.cpp b/src/net/tmwa/buysellrecv.cpp index 6a30f7bc6..7f4ed9de8 100644 --- a/src/net/tmwa/buysellrecv.cpp +++ b/src/net/tmwa/buysellrecv.cpp @@ -26,6 +26,8 @@ #include "being/playerinfo.h" +#include "const/resources/currency.h" + #include "enums/resources/notifytypes.h" #include "gui/windows/buydialog.h" @@ -36,6 +38,8 @@ #include "net/ea/buysellrecv.h" +#include "resources/db/npcdb.h" + #include "debug.h" namespace TmwAthena @@ -46,7 +50,8 @@ void BuySellRecv::processNpcBuy(Net::MessageIn &msg) msg.readInt16("len"); const unsigned int n_items = (msg.getLength() - 4U) / 11; CREATEWIDGETV(Ea::BuySellRecv::mBuyDialog, BuyDialog, - Ea::BuySellRecv::mNpcId); + Ea::BuySellRecv::mNpcId, + DEFAULT_CURRENCY); Ea::BuySellRecv::mBuyDialog->setMoney( PlayerInfo::getAttribute(Attributes::MONEY)); diff --git a/src/resources/db/unitsdb.cpp b/src/resources/db/unitsdb.cpp index 94d055ffd..7b56e8721 100644 --- a/src/resources/db/unitsdb.cpp +++ b/src/resources/db/unitsdb.cpp @@ -25,6 +25,8 @@ #include "configuration.h" #include "logger.h" +#include "const/resources/currency.h" + #include "utils/checkutils.h" #include "resources/beingcommon.h" @@ -181,7 +183,7 @@ static void loadCurrencies(XmlNodePtr parentNode) continue; } mCurrencies[name] = loadUnit(node); - if (name == "default") + if (name == DEFAULT_CURRENCY) defaultCurrency = mCurrencies[name]; } } @@ -220,7 +222,7 @@ void UnitsDb::loadXmlFile(const std::string &fileName, else if (type == "currency") { defaultCurrency = ud; - mCurrencies["default"] = ud; + mCurrencies[DEFAULT_CURRENCY] = ud; } else { |