ManaPlus
bankwindow.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "gui/windows/bankwindow.h"
23 
24 #include "net/bankhandler.h"
25 
27 
28 #include "gui/widgets/button.h"
31 #include "gui/widgets/label.h"
32 
33 #include "utils/gettext.h"
34 #include "utils/stringutils.h"
35 
36 #include "resources/db/unitsdb.h"
37 
38 #include "debug.h"
39 
41 
43  // TRANSLATORS: bank window name
44  Window(_("Bank"), Modal_false, nullptr, "bank.xml"),
46  BankListener(),
47  mBankMoneyLabel(new Label(this, strprintf(
48  // TRANSLATORS: bank window money label
49  _("Money in bank: %s"), " "))),
50  mInputMoneyTextField(new IntTextField(this, 0, 0, 2147483647,
51  Enable_true, 0)),
52  // TRANSLATORS: bank window button
53  mWithdrawButton(new Button(this, _("Withdraw"), "withdraw",
54  BUTTON_SKIN, this)),
55  // TRANSLATORS: bank window button
56  mDepositButton(new Button(this, _("Deposit"), "deposit",
57  BUTTON_SKIN, this))
58 {
59  setWindowName("Bank");
60  setCloseButton(true);
61 
62  if (setupWindow != nullptr)
64 
66  ContainerPlacer placer = getPlacer(0, 0);
67  placer(0, 0, mBankMoneyLabel, 7, 1);
68  placer(0, 1, mInputMoneyTextField, 10, 1);
69  placer(0, 2, mDepositButton, 5, 1);
70  placer(5, 2, mWithdrawButton, 5, 1);
71 
72  setContentSize(300, 100);
73  setDefaultSize(300, 100, ImagePosition::CENTER, 0, 0);
74 
75  center();
78  reflowLayout(300, 0);
79  enableVisibleSound(true);
80 }
81 
83 {
84 }
85 
86 void BankWindow::widgetShown(const Event &event)
87 {
88  if (event.getSource() == this)
89  bankHandler->check();
90 }
91 
92 void BankWindow::bankMoneyChanged(const int money)
93 {
94  // TRANSLATORS: bank window money label
95  mBankMoneyLabel->setCaption(strprintf(_("Money in bank: %s"),
96  UnitsDb::formatCurrency(money).c_str()));
97 }
98 
99 void BankWindow::action(const ActionEvent &event)
100 {
101  const std::string &eventId = event.getId();
102  if (eventId == "deposit")
104  else if (eventId == "withdraw")
106 }
Net::BankHandler * bankHandler
Definition: net.cpp:105
BankWindow * bankWindow
Definition: bankwindow.cpp:40
const std::string BUTTON_SKIN
Definition: button.h:89
void action(const ActionEvent &event)
Definition: bankwindow.cpp:99
Button * mWithdrawButton
Definition: bankwindow.h:59
void widgetShown(const Event &event)
Definition: bankwindow.cpp:86
IntTextField * mInputMoneyTextField
Definition: bankwindow.h:58
Button * mDepositButton
Definition: bankwindow.h:60
void bankMoneyChanged(const int money)
Definition: bankwindow.cpp:92
Label * mBankMoneyLabel
Definition: bankwindow.h:57
Definition: button.h:102
Definition: event.h:79
Widget * getSource() const
Definition: event.h:104
int getValue() const
Definition: label.h:91
void adjustSize()
Definition: label.cpp:200
void setCaption(const std::string &caption)
Definition: label.cpp:264
virtual void deposit(const int money) const =0
virtual void check() const =0
virtual void withdraw(const int money) const =0
void registerWindowForReset(Window *const window)
Definition: window.h:102
void center()
Definition: window.cpp:1417
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1391
void setContentSize(int width, int height)
Definition: window.cpp:492
void reflowLayout(int w, int h)
Definition: window.cpp:1396
void setWindowName(const std::string &name)
Definition: window.h:355
void enableVisibleSound(bool b)
Definition: window.h:481
void setCloseButton(const bool flag)
Definition: window.cpp:749
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
#define new
Definition: debug_new.h:147
const bool Enable_true
Definition: enable.h:30
#define _(s)
Definition: gettext.h:35
#define nullptr
Definition: localconsts.h:45
const bool Modal_false
Definition: modal.h:30
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:324
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
std::string strprintf(const char *const format,...)