diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-10-16 01:04:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-10-16 01:04:04 +0300 |
commit | 4b891f50dfc89318321eeac176415d1bef61aca6 (patch) | |
tree | f1da78c30374409d4f329faecb7e7b627674cf21 /src | |
parent | f8f1e69d820e49d93669b17363ab6225456515f7 (diff) | |
download | manaverse-4b891f50dfc89318321eeac176415d1bef61aca6.tar.gz manaverse-4b891f50dfc89318321eeac176415d1bef61aca6.tar.bz2 manaverse-4b891f50dfc89318321eeac176415d1bef61aca6.tar.xz manaverse-4b891f50dfc89318321eeac176415d1bef61aca6.zip |
Add bank window (hercules only).
also add banklistener to get changed bank balance.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/actions/windows.cpp | 12 | ||||
-rw-r--r-- | src/actions/windows.h | 1 | ||||
-rw-r--r-- | src/game.cpp | 3 | ||||
-rw-r--r-- | src/gui/windows/bankwindow.cpp | 101 | ||||
-rw-r--r-- | src/gui/windows/bankwindow.h | 64 | ||||
-rw-r--r-- | src/input/inputaction.h | 1 | ||||
-rw-r--r-- | src/input/inputactionmap.h | 11 | ||||
-rw-r--r-- | src/input/pages/windows.cpp | 6 | ||||
-rw-r--r-- | src/listeners/banklistener.cpp | 36 | ||||
-rw-r--r-- | src/listeners/banklistener.h | 38 | ||||
-rw-r--r-- | src/net/eathena/bankhandler.cpp | 11 |
13 files changed, 288 insertions, 4 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5fe7616c9..b8d6895fe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -397,6 +397,8 @@ SET(SRCS gui/windows/okdialog.h gui/windows/outfitwindow.cpp gui/windows/outfitwindow.h + gui/windows/bankwindow.cpp + gui/windows/bankwindow.h gui/windows/botcheckerwindow.cpp gui/windows/botcheckerwindow.h gui/windows/textcommandeditor.cpp @@ -801,6 +803,8 @@ SET(SRCS listeners/attributelistener.h listeners/awaylistener.cpp listeners/awaylistener.h + listeners/banklistener.cpp + listeners/banklistener.h listeners/baselistener.hpp listeners/charrenamelistener.cpp listeners/charrenamelistener.h diff --git a/src/Makefile.am b/src/Makefile.am index b79cbe16d..3c531a909 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -515,6 +515,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/windows/okdialog.h \ gui/windows/outfitwindow.cpp \ gui/windows/outfitwindow.h \ + gui/windows/bankwindow.cpp \ + gui/windows/bankwindow.h \ gui/windows/botcheckerwindow.cpp \ gui/windows/botcheckerwindow.h \ gui/windows/textcommandeditor.cpp \ @@ -919,6 +921,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ listeners/attributelistener.h \ listeners/awaylistener.cpp \ listeners/awaylistener.h \ + listeners/banklistener.cpp \ + listeners/banklistener.h \ listeners/baselistener.hpp \ listeners/charrenamelistener.cpp \ listeners/charrenamelistener.h \ diff --git a/src/actions/windows.cpp b/src/actions/windows.cpp index fae82261c..18a2c4773 100644 --- a/src/actions/windows.cpp +++ b/src/actions/windows.cpp @@ -24,6 +24,7 @@ #include "gui/dialogsmanager.h" +#include "gui/windows/bankwindow.h" #include "gui/windows/skilldialog.h" #include "gui/windows/socialwindow.h" #include "gui/windows/statuswindow.h" @@ -47,6 +48,8 @@ #include "gui/widgets/tabs/chat/chattab.h" #include "gui/widgets/tabs/chat/chattabtype.h" +#include "net/serverfeatures.h" + #include "debug.h" extern ShortcutWindow *spellShortcutWindow; @@ -247,6 +250,15 @@ impHandler0(questsWindowShow) return true; } +impHandler0(bankWindowShow) +{ + if (!serverFeatures->haveBankApi()) + return false; + + showHideWindow(bankWindow); + return true; +} + impHandler0(updaterWindowShow) { if (updaterWindow) diff --git a/src/actions/windows.h b/src/actions/windows.h index 1c8293334..dab926416 100644 --- a/src/actions/windows.h +++ b/src/actions/windows.h @@ -51,6 +51,7 @@ namespace Actions decHandler(didYouKnowWindowShow); decHandler(questsWindowShow); decHandler(updaterWindowShow); + decHandler(bankWindowShow); } // namespace Actions #undef decHandler diff --git a/src/game.cpp b/src/game.cpp index ad6c04a28..4292d00cc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -59,6 +59,7 @@ #include "gui/fonts/font.h" +#include "gui/windows/bankwindow.h" #include "gui/windows/botcheckerwindow.h" #include "gui/windows/chatwindow.h" #include "gui/windows/debugwindow.h" @@ -222,6 +223,7 @@ static void createGuiWindows() new SpellShortcutContainer(nullptr, f)); } + bankWindow = new BankWindow; botCheckerWindow = new BotCheckerWindow; whoIsOnline = new WhoIsOnline; whoIsOnline->postInit(); @@ -331,6 +333,7 @@ static void destroyGuiWindows() delete2(socialWindow) delete2(dropShortcutWindow); delete2(spellShortcutWindow); + delete2(bankWindow); delete2(botCheckerWindow); delete2(questsWindow); delete2(whoIsOnline); diff --git a/src/gui/windows/bankwindow.cpp b/src/gui/windows/bankwindow.cpp new file mode 100644 index 000000000..f3b46c6d4 --- /dev/null +++ b/src/gui/windows/bankwindow.cpp @@ -0,0 +1,101 @@ +/* + * The ManaPlus Client + * 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/bankwindow.h" + +#include "units.h" + +#include "net/bankhandler.h" + +#include "gui/windows/setupwindow.h" + +#include "gui/widgets/button.h" +#include "gui/widgets/containerplacer.h" +#include "gui/widgets/inttextfield.h" +#include "gui/widgets/label.h" + +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "debug.h" + +BankWindow *bankWindow = nullptr; + +BankWindow::BankWindow() : + // TRANSLATORS: bank window name + Window(_("Bank"), false, nullptr, "bank.xml"), + ActionListener(), + BankListener(), + // TRANSLATORS: bank window money label + mBankMoneyLabel(new Label(this, strprintf( + _("Money in bank: %s"), " "))), + mInputMoneyTextField(new IntTextField(this, 0, 0, 2147483647)), + // TRANSLATORS: bank window button + mWithdrawButton(new Button(this, _("Withdraw"), "withdraw", this)), + // TRANSLATORS: bank window button + mDepositButton(new Button(this, _("Deposit"), "deposit", this)) +{ + setWindowName("Bank"); + setCloseButton(true); + + if (setupWindow) + setupWindow->registerWindowForReset(this); + + mBankMoneyLabel->adjustSize(); + ContainerPlacer placer = getPlacer(0, 0); + placer(0, 0, mBankMoneyLabel, 7); + placer(0, 1, mInputMoneyTextField, 10); + placer(0, 2, mDepositButton, 5); + placer(5, 2, mWithdrawButton, 5); + + setContentSize(300, 100); + setDefaultSize(300, 100, ImageRect::CENTER, 0, 0); + + center(); + setDefaultSize(); + loadWindowState(); + reflowLayout(300); + enableVisibleSound(true); +} + +BankWindow::~BankWindow() +{ +} + +void BankWindow::widgetShown(const Event &event) +{ + if (event.getSource() == this) + bankHandler->check(); +} + +void BankWindow::bankMoneyChanged(const int money) +{ + mBankMoneyLabel->setCaption(strprintf(_("Money in bank: %s"), + Units::formatCurrency(money).c_str())); +} + +void BankWindow::action(const ActionEvent &event) +{ + const std::string &eventId = event.getId(); + if (eventId == "deposit") + bankHandler->deposit(mInputMoneyTextField->getValue()); + else if (eventId == "withdraw") + bankHandler->withdraw(mInputMoneyTextField->getValue()); +} diff --git a/src/gui/windows/bankwindow.h b/src/gui/windows/bankwindow.h new file mode 100644 index 000000000..739054a78 --- /dev/null +++ b/src/gui/windows/bankwindow.h @@ -0,0 +1,64 @@ +/* + * The ManaPlus Client + * 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_BANKWINDOW_H +#define GUI_WINDOWS_BANKWINDOW_H + +#include "gui/widgets/window.h" + +#include "listeners/actionlistener.h" +#include "listeners/banklistener.h" + +class Button; +class IntTextField; +class Label; + +/** + * A dialog to choose between buying or selling at a shop. + * + * \ingroup Interface + */ +class BankWindow final : public Window, + public ActionListener, + public BankListener +{ + public: + BankWindow(); + + A_DELETE_COPY(BankWindow) + + ~BankWindow(); + + void action(const ActionEvent &event) override final; + + void widgetShown(const Event &event) override final; + + void bankMoneyChanged(const int money); + + private: + Label *mBankMoneyLabel; + IntTextField *mInputMoneyTextField; + Button *mWithdrawButton; + Button *mDepositButton; +}; + +extern BankWindow *bankWindow; + +#endif // GUI_WINDOWS_BANKWINDOW_H diff --git a/src/input/inputaction.h b/src/input/inputaction.h index 77bed24b7..f049d209f 100644 --- a/src/input/inputaction.h +++ b/src/input/inputaction.h @@ -486,6 +486,7 @@ namespace InputAction PET_SET_NAME, HOMUNCULUS_SET_NAME, HOMUNCULUS_FIRE, + WINDOW_BANK, TOTAL }; } // namespace InputAction diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index 26a7f4a17..34171954c 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -4115,7 +4115,16 @@ static const InputActionData inputActionData[InputAction::TOTAL] = { InputAction::NO_VALUE, 50, InputCondition::INGAME, "firehomunculus|homunculusfire", - false} + false}, + {"keyWindowBank", + InputType::UNKNOWN, InputAction::NO_VALUE, + InputType::UNKNOWN, InputAction::NO_VALUE, + Input::GRP_DEFAULT | Input::GRP_GUI, + &Actions::bankWindowShow, + InputAction::NO_VALUE, 50, + InputCondition::SHORTCUT0, + "bank|openbank", + false}, }; #endif // INPUT_INPUTACTIONMAP_H diff --git a/src/input/pages/windows.cpp b/src/input/pages/windows.cpp index f16b1b34f..32fc18c49 100644 --- a/src/input/pages/windows.cpp +++ b/src/input/pages/windows.cpp @@ -51,6 +51,12 @@ SetupActionData setupActionDataWindows[] = }, { // TRANSLATORS: input action name + N_("Bank Window"), + InputAction::WINDOW_BANK, + "", + }, + { + // TRANSLATORS: input action name N_("Help Window"), InputAction::WINDOW_HELP, "", diff --git a/src/listeners/banklistener.cpp b/src/listeners/banklistener.cpp new file mode 100644 index 000000000..750cf01a6 --- /dev/null +++ b/src/listeners/banklistener.cpp @@ -0,0 +1,36 @@ +/* + * The ManaPlus Client + * Copyright (C) 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 "listeners/banklistener.h" + +#include "debug.h" + +defineListener(BankListener) + +void BankListener::distributeEvent(const int money) +{ + FOR_EACH (std::vector<BankListener*>::iterator, + it, mListeners) + { + BankListener *const listener = *it; + if (listener) + listener->bankMoneyChanged(money); + } +} diff --git a/src/listeners/banklistener.h b/src/listeners/banklistener.h new file mode 100644 index 000000000..b3bfc2bef --- /dev/null +++ b/src/listeners/banklistener.h @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 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 LISTENERS_BANKLISTENER_H +#define LISTENERS_BANKLISTENER_H + +#include "listeners/baselistener.hpp" + +#include "localconsts.h" + +class BankListener notfinal +{ + public: + virtual void bankMoneyChanged(const int money) = 0; + + static void distributeEvent(const int money); + + defineListenerHeader(BankListener) +}; + +#endif // LISTENERS_BANKLISTENER_H diff --git a/src/net/eathena/bankhandler.cpp b/src/net/eathena/bankhandler.cpp index 0df1734ba..99d5cf9e9 100644 --- a/src/net/eathena/bankhandler.cpp +++ b/src/net/eathena/bankhandler.cpp @@ -20,6 +20,8 @@ #include "net/eathena/bankhandler.h" +#include "listeners/banklistener.h" + #include "net/eathena/messageout.h" #include "net/eathena/protocol.h" @@ -87,22 +89,25 @@ void BankHandler::check() const void BankHandler::processBankStatus(Net::MessageIn &msg) { - msg.readInt64("money"); + const int money = static_cast<int>(msg.readInt64("money")); msg.readInt16("reason"); + BankListener::distributeEvent(money); } void BankHandler::processBankDeposit(Net::MessageIn &msg) { msg.readInt16("reason"); - msg.readInt64("money"); + const int money = static_cast<int>(msg.readInt64("money")); msg.readInt32("balance"); + BankListener::distributeEvent(money); } void BankHandler::processBankWithdraw(Net::MessageIn &msg) { msg.readInt16("reason"); - msg.readInt64("money"); + const int money = static_cast<int>(msg.readInt64("money")); msg.readInt32("balance"); + BankListener::distributeEvent(money); } } // namespace EAthena |