Mana
Loading...
Searching...
No Matches
buyselldialog.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana 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 "buyselldialog.h"
23
24#include "playerinfo.h"
25
26#include "gui/widgets/button.h"
27
28#include "net/net.h"
29#include "net/npchandler.h"
30
31#include "utils/gettext.h"
32
34
36 Window(_("Shop")),
37 mNpcId(npcId),
38 mBuyButton(nullptr)
39{
40 setWindowName("BuySell");
41 //setupWindow->registerWindowForReset(this);
42 setCloseButton(true);
43
44 static const char *buttonNames[] = {
45 N_("Buy"), N_("Sell"), N_("Cancel"), nullptr
46 };
47 int x = 10, y = 10;
48
49 for (const char **curBtn = buttonNames; *curBtn; curBtn++)
50 {
51 auto *btn = new Button(gettext(*curBtn), *curBtn, this);
52 if (!mBuyButton)
53 mBuyButton = btn; // For focus request
54 btn->setPosition(x, y);
55 add(btn);
56 x += btn->getWidth() + 10;
57 }
58 mBuyButton->requestFocus();
59
60 setContentSize(x, 2 * y + mBuyButton->getHeight());
61
62 center();
65
66 instances.push_back(this);
67 setVisible(true);
68
70}
71
79
80void BuySellDialog::setVisible(bool visible)
81{
82 Window::setVisible(visible);
83
84 if (visible)
85 {
86 mBuyButton->requestFocus();
87 }
88 else
89 {
91 }
92}
93
94void BuySellDialog::action(const gcn::ActionEvent &event)
95{
96 if (event.getId() == "Buy")
97 {
99 }
100 else if (event.getId() == "Sell")
101 {
103 }
104
105 close();
106}
107
109{
110 for (auto &instance : instances)
111 instance->close();
112}
Button widget.
Definition button.h:38
static void closeAll()
Closes all instances.
std::list< BuySellDialog * > DialogList
~BuySellDialog() override
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
static DialogList instances
BuySellDialog(int npcId)
Constructor.
gcn::Button * mBuyButton
void setVisible(bool visible) override
Overloads window setVisible by Guichan to allow sticky window handling.
virtual void sell(int beingId)=0
virtual void buy(int beingId)=0
A window.
Definition window.h:59
void center()
Positions the window in the center of it's parent.
Definition window.cpp:768
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
Definition window.cpp:282
virtual void close()
Overrideable functionality for when the window is to close.
Definition window.cpp:327
void setContentSize(int width, int height)
Sets the size of this window.
Definition window.cpp:151
void setWindowName(const std::string &name)
Sets the name of the window.
Definition window.h:272
void scheduleDelete()
Schedule this window for deletion.
Definition window.cpp:299
void setCloseButton(bool flag)
Sets whether or not the window has a close button.
Definition window.cpp:262
void setDefaultSize()
Set the default win pos and size to the current ones.
Definition window.cpp:545
void loadWindowState()
Reads the position (and the size for resizable windows) in the configuration based on the given strin...
Definition window.cpp:467
#define gettext(s)
Definition gettext.h:37
#define N_(s)
Definition gettext.h:39
#define _(s)
Definition gettext.h:38
NpcHandler * getNpcHandler()
Definition net.cpp:100
void setBuySellState(BuySellState buySellState)
Sets which buy, sell, or related interaction the player is currently involved in.
BuySellState getBuySellState()
Returns the current buy, sell, or related interaction the player is involved in.
@ BUYSELL_NONE
Definition playerinfo.h:66
@ BUYSELL_CHOOSING
Definition playerinfo.h:67