ManaPlus
characterdisplay.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "gui/gui.h"
27 
29 
30 #include "gui/popups/textpopup.h"
31 
33 #include "gui/widgets/label.h"
35 
36 #include "utils/gettext.h"
37 #include "utils/stringutils.h"
38 
39 #include "resources/db/unitsdb.h"
40 
41 #include "net/character.h"
42 
43 #include "debug.h"
44 
46  CharSelectDialog *const charSelectDialog) :
47  Container(widget),
48  MouseListener(),
50  mCharacter(nullptr),
51  mPlayerBox(new PlayerBox(nullptr, std::string(), std::string())),
52  mName(new Label(this, "wwwwwwwwwwwwwwwwwwwwwwww"))
53 {
54  mPlayerBox->setActionEventId("select");
55  mPlayerBox->addActionListener(charSelectDialog);
56  setActionEventId("use");
57  addActionListener(charSelectDialog);
58 
59  LayoutHelper h(this);
60  ContainerPlacer placer = h.getPlacer(0, 0);
61 
62  placer(0, 0, mPlayerBox, 3, 5);
63  placer(0, 5, mName, 3, 1);
64 
65  update();
66 
68  mName->adjustSize();
69 
70  if (mainGraphics->getWidth() > 800)
71  setWidth(120);
72  else
73  setWidth(80);
74  setHeight(120);
75  addMouseListener(this);
76  addWidgetListener(this);
77 }
78 
80 {
81 }
82 
84 {
85  if (mCharacter == character)
86  return;
87 
88  mCharacter = character;
89  mPlayerBox->setPlayer(character != nullptr ? character->dummy : nullptr);
90  update();
91 }
92 
94 {
95 }
96 
97 void CharacterDisplay::setActive(const bool active A_UNUSED)
98 {
99 }
100 
102 {
103  if (mCharacter != nullptr)
105  else
106  mName->setCaption("");
107  const int width = mPlayerBox->getWidth();
108  mName->resizeTo(width, width);
109 
111 }
112 
114 {
115  if (textPopup != nullptr)
117 }
118 
120 {
121  if (textPopup != nullptr)
123 }
124 
126 {
127  if (gui == nullptr ||
128  textPopup == nullptr ||
129  mCharacter == nullptr)
130  {
131  return;
132  }
133 
134  int mouseX = 0;
135  int mouseY = 0;
136  Gui::getMouseState(mouseX, mouseY);
137  const std::string &name = mName->getCaption();
138  if (!name.empty())
139  {
140  textPopup->show(mouseX, mouseY,
141  name,
142  // TRANSLATORS: character level
143  strprintf(_("Level: %u"),
144  CAST_U32(
146  // TRANSLATORS: character money
147  strprintf(_("Money: %s"), UnitsDb::formatCurrency64(
149  }
150  else
151  {
153  }
154 }
155 
157 {
158  event.consume();
159  if (event.getClickCount() == 2)
161 }
#define CAST_U32
Definition: cast.h:31
const std::string & getName() const
Definition: being.h:232
CharacterDisplay(const Widget2 *const widget, CharSelectDialog *const charSelectDialog)
PlayerBox * mPlayerBox
void mouseMoved(MouseEvent &event)
void widgetHidden(const Event &event)
void setActive(const bool active)
void setCharacter(Net::Character *const character)
void mousePressed(MouseEvent &event)
void mouseExited(MouseEvent &event)
Net::Character * mCharacter
Definition: event.h:79
@ CENTER
Definition: graphics.h:132
int getWidth() const
Definition: graphics.cpp:643
static uint8_t getMouseState(int &x, int &y)
Definition: gui.cpp:1171
Definition: label.h:91
void resizeTo(const int maxSize, const int minSize)
Definition: label.cpp:227
void adjustSize()
Definition: label.cpp:200
void setAlignment(Graphics::Alignment alignment)
Definition: label.h:153
const std::string & getCaption() const
Definition: label.h:133
void setCaption(const std::string &caption)
Definition: label.cpp:264
ContainerPlacer getPlacer(const int x, const int y)
int getClickCount() const
Definition: mouseevent.h:147
void setPlayer(Being *being)
Definition: playerbox.h:74
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:57
void setVisible(Visible visible)
Definition: widget.cpp:225
void setWidth(const int width)
Definition: widget.cpp:133
void distributeActionEvent()
Definition: widget.cpp:493
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302
void setHeight(const int height)
Definition: widget.cpp:140
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void distributeResizedEvent()
Definition: widget.cpp:466
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
int getWidth() const
Definition: widget.h:221
#define new
Definition: debug_new.h:147
#define _(s)
Definition: gettext.h:35
Graphics * mainGraphics
Definition: graphics.cpp:109
Gui * gui
Definition: gui.cpp:111
#define nullptr
Definition: localconsts.h:45
#define A_UNUSED
Definition: localconsts.h:160
@ PLAYER_BASE_LEVEL
Definition: attributes.h:31
std::string formatCurrency64(const int64_t value)
Definition: unitsdb.cpp:329
std::string strprintf(const char *const format,...)
LocalPlayer * dummy
Definition: character.h:56
PlayerInfoBackend data
Definition: character.h:57
AtrIntMap mAttributes
Definition: playerinfo.h:73
TextPopup * textPopup
Definition: textpopup.cpp:33
const bool Visible_false
Definition: visible.h:30