ManaPlus
statuspopup.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008 The Legend of Mazzeroth Development Team
4  * Copyright (C) 2009 The Mana World Development Team
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2009-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 
24 #include "gui/popups/statuspopup.h"
25 
26 #include "gamemodifiers.h"
27 
28 #include "gui/widgets/label.h"
29 
30 #include "input/inputmanager.h"
31 
32 #include "utils/stringutils.h"
33 
34 #include "gui/fonts/font.h"
35 
36 #include "debug.h"
37 
38 #define addLabel(num) \
39  { \
40  Label *const label = mLabels[num]; \
41  label->setPosition(0, y); \
42  label->setForegroundColorAll( \
43  getThemeColor(ThemeColorId::POPUP, 255U), \
44  getThemeColor(ThemeColorId::POPUP_OUTLINE, 255U)); \
45  add(label); \
46  y += fontHeight; \
47  }
48 
50  Popup("StatusPopup", "statuspopup.xml"),
51  mLabels()
52 {
53  for (int f = 0; f < STATUSPOPUP_NUM_LABELS; f ++)
54  mLabels[f] = new Label(this);
55 }
56 
58 {
60  const int fontHeight = getFont()->getHeight();
61  int y = 0;
62  addLabel(0)
63  addLabel(1)
64  addLabel(2)
65  addLabel(3)
66  y += 4;
67  addLabel(4)
68  addLabel(5)
69  addLabel(9)
70  addLabel(10)
71  y += 4;
72  addLabel(6)
73  addLabel(7)
74  y += 4;
75  addLabel(8)
76  y += 4;
77  addLabel(12)
78  addLabel(13)
79  addLabel(14)
80  addLabel(15)
81  y += 4;
82  addLabel(11)
83 }
84 
86 {
87 }
88 
90 {
91  updateLabels();
92 
93  int maxWidth = mLabels[0]->getWidth();
94 
95  for (int f = 0; f < STATUSPOPUP_NUM_LABELS; f ++)
96  {
97  const int width = mLabels[f]->getWidth();
98  if (width > maxWidth)
99  maxWidth = width;
100  }
101 
102  const int pad2 = 2 * mPadding;
103  maxWidth += pad2;
104  setWidth(maxWidth);
105  setHeight(mLabels[11]->getY()
106  + mLabels[11]->getHeight() + pad2);
107 }
108 
109 void StatusPopup::view(const int x, const int y)
110 {
111  const int distance = 20;
112 
113  int posX = std::max(0, x - getWidth() / 2);
114  int posY = y + distance;
115 
116  if (posX + getWidth() > mainGraphics->mWidth)
117  posX = mainGraphics->mWidth - getWidth();
118  if (posY + getHeight() > mainGraphics->mHeight)
119  posY = y - getHeight() - distance;
120 
121  update();
122 
123  setPosition(posX, posY);
126 }
127 
128 void StatusPopup::setLabelText(const int num,
129  const std::string &text,
130  const InputActionT key) const
131 {
132  Label *const label = mLabels[num];
133  label->setCaption(strprintf("%s %s", text.c_str(),
134  inputManager.getKeyValueString(key).c_str()));
135  label->adjustSize();
136 }
137 
139 {
172 }
int getHeight() const
Definition: font.cpp:362
static std::string getPickUpTypeString()
static std::string getMoveToTargetTypeString()
static std::string getQuickDropCounterString()
static std::string getAttackTypeString()
static std::string getMagicAttackTypeString()
static std::string getMoveTypeString()
static std::string getGameModifiersString()
static std::string getCrazyMoveTypeString()
static std::string getTargetingTypeString()
static std::string getAwayModeString()
static std::string getCameraModeString()
static std::string getFollowModeString()
static std::string getAttackWeaponTypeString()
static std::string getPvpAttackTypeString()
static std::string getMapDrawTypeString()
static std::string getImitationModeString()
int mWidth
Definition: graphics.h:484
int mHeight
Definition: graphics.h:485
std::string getKeyValueString(const InputActionT index) const
Definition: label.h:91
void adjustSize()
Definition: label.cpp:200
void setCaption(const std::string &caption)
Definition: label.cpp:264
Definition: popup.h:52
int mPadding
Definition: popup.h:181
void postInit()
Definition: popup.h:177
void setLabelText(const int num, const std::string &text, const InputActionT key) const
void view(const int x, const int y)
void update()
Definition: statuspopup.cpp:89
void updateLabels() const
Label * mLabels[STATUSPOPUP_NUM_LABELS]
Definition: statuspopup.h:69
void postInit()
Definition: statuspopup.cpp:57
void setVisible(Visible visible)
Definition: widget.cpp:225
void setWidth(const int width)
Definition: widget.cpp:133
virtual void requestMoveToTop()
Definition: widget.cpp:213
void setHeight(const int height)
Definition: widget.cpp:140
int getY() const
Definition: widget.h:288
Font * getFont() const
Definition: widget.cpp:331
void setPosition(const int x, const int y)
Definition: widget.cpp:161
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
Graphics * mainGraphics
Definition: graphics.cpp:109
InputAction ::T InputActionT
Definition: inputaction.h:717
InputManager inputManager
@ CHANGE_CRAZY_MOVES_TYPE
Definition: inputaction.h:278
@ CHANGE_MOVE_TO_TARGET
Definition: inputaction.h:52
@ CHANGE_IMITATION_MODE
Definition: inputaction.h:291
@ SWITCH_MAGIC_ATTACK
Definition: inputaction.h:285
@ CHANGE_ATTACK_WEAPON_TYPE
Definition: inputaction.h:288
@ CHANGE_FOLLOW_MODE
Definition: inputaction.h:290
@ CHANGE_TARGETING_TYPE
Definition: inputaction.h:606
@ CHANGE_ATTACK_TYPE
Definition: inputaction.h:289
@ CHANGE_PICKUP_TYPE
Definition: inputaction.h:63
@ DISABLE_GAME_MODIFIERS
Definition: inputaction.h:292
#define addLabel(num)
Definition: statuspopup.cpp:38
const int STATUSPOPUP_NUM_LABELS
Definition: statuspopup.h:33
std::string strprintf(const char *const format,...)
const bool Visible_true
Definition: visible.h:30