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-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
24 
25 #include "gui/gui.h"
26 
28 
29 #include "gui/popups/textpopup.h"
30 
32 #include "gui/widgets/label.h"
34 
35 #include "utils/gettext.h"
36 #include "utils/stringutils.h"
37 
38 #include "resources/db/unitsdb.h"
39 
40 #include "net/character.h"
41 
42 #include "debug.h"
43 
45  CharSelectDialog *const charSelectDialog) :
46  Container(widget),
47  MouseListener(),
49  mCharacter(nullptr),
50  mPlayerBox(new PlayerBox(nullptr, std::string(), std::string())),
51  mName(new Label(this, "wwwwwwwwwwwwwwwwwwwwwwww"))
52 {
53  mPlayerBox->setActionEventId("select");
54  mPlayerBox->addActionListener(charSelectDialog);
55  setActionEventId("use");
56  addActionListener(charSelectDialog);
57 
58  LayoutHelper h(this);
59  ContainerPlacer placer = h.getPlacer(0, 0);
60 
61  placer(0, 0, mPlayerBox, 3, 5);
62  placer(0, 5, mName, 3, 1);
63 
64  update();
65 
67  mName->adjustSize();
68 
69  if (mainGraphics->getWidth() > 800)
70  setWidth(120);
71  else
72  setWidth(80);
73  setHeight(120);
74  addMouseListener(this);
75  addWidgetListener(this);
76 }
77 
79 {
80 }
81 
83 {
84  if (mCharacter == character)
85  return;
86 
87  mCharacter = character;
88  mPlayerBox->setPlayer(character != nullptr ? character->dummy : nullptr);
89  update();
90 }
91 
93 {
94 }
95 
96 void CharacterDisplay::setActive(const bool active A_UNUSED)
97 {
98 }
99 
101 {
102  if (mCharacter != nullptr)
104  else
105  mName->setCaption("");
106  const int width = mPlayerBox->getWidth();
107  mName->resizeTo(width, width);
108 
110 }
111 
113 {
114  if (textPopup != nullptr)
116 }
117 
119 {
120  if (textPopup != nullptr)
122 }
123 
125 {
126  if (gui == nullptr ||
127  textPopup == nullptr ||
128  mCharacter == nullptr)
129  {
130  return;
131  }
132 
133  int mouseX = 0;
134  int mouseY = 0;
135  Gui::getMouseState(mouseX, mouseY);
136  const std::string &name = mName->getCaption();
137  if (!name.empty())
138  {
139  textPopup->show(mouseX, mouseY,
140  name,
141  // TRANSLATORS: character level
142  strprintf(_("Level: %u"),
143  CAST_U32(
145  // TRANSLATORS: character money
146  strprintf(_("Money: %s"), UnitsDb::formatCurrency64(
148  }
149  else
150  {
152  }
153 }
154 
156 {
157  event.consume();
158  if (event.getClickCount() == 2)
160 }
#define CAST_U32
Definition: cast.h:30
void setPlayer(Being *being)
Definition: playerbox.h:73
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:56
#define _(s)
Definition: gettext.h:34
int getWidth() const
Definition: widget.h:220
void setWidth(const int width)
Definition: widget.cpp:132
Gui * gui
Definition: gui.cpp:110
void widgetHidden(const Event &event)
void setActive(const bool active)
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void setVisible(Visible visible)
Definition: widget.cpp:224
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
void mouseMoved(MouseEvent &event)
Net::Character * mCharacter
int getWidth() const
Definition: graphics.cpp:642
std::string formatCurrency64(const int64_t value)
Definition: unitsdb.cpp:328
void distributeActionEvent()
Definition: widget.cpp:492
#define new
Definition: debug_new.h:147
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:261
const bool Visible_false
Definition: visible.h:29
Definition: label.h:87
PlayerBox * mPlayerBox
AtrIntMap mAttributes
Definition: playerinfo.h:72
#define nullptr
Definition: localconsts.h:44
Graphics * mainGraphics
Definition: graphics.cpp:108
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
static uint8_t getMouseState(int &x, int &y)
Definition: gui.cpp:1170
const std::string & getName() const
Definition: being.h:231
ContainerPlacer getPlacer(const int x, const int y)
void setHeight(const int height)
Definition: widget.cpp:139
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301
#define A_UNUSED
Definition: localconsts.h:159
CharacterDisplay(const Widget2 *const widget, CharSelectDialog *const charSelectDialog)
void setAlignment(Graphics::Alignment alignment)
Definition: label.h:152
Definition: event.h:77
void mouseExited(MouseEvent &event)
void distributeResizedEvent()
Definition: widget.cpp:465
void setCharacter(Net::Character *const character)
PlayerInfoBackend data
Definition: character.h:56
int getClickCount() const
Definition: mouseevent.h:146
void resizeTo(const int maxSize, const int minSize)
Definition: label.cpp:224
void mousePressed(MouseEvent &event)
void adjustSize()
Definition: label.cpp:197
LocalPlayer * dummy
Definition: character.h:55
TextPopup * textPopup
Definition: textpopup.cpp:32
const std::string & getCaption() const
Definition: label.h:132