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) 2009-2010 Andrei Karas
6  * Copyright (C) 2011-2018 The ManaPlus Developers
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 }
Font * getFont() const
Definition: widget.cpp:330
#define addLabel(num)
Definition: statuspopup.cpp:38
int getWidth() const
Definition: widget.h:220
void setWidth(const int width)
Definition: widget.cpp:132
const bool Visible_true
Definition: visible.h:29
int getY() const
Definition: widget.h:287
void setVisible(Visible visible)
Definition: widget.cpp:224
virtual void requestMoveToTop()
Definition: widget.cpp:212
void postInit()
Definition: popup.h:176
int mWidth
Definition: graphics.h:483
void view(const int x, const int y)
int mPadding
Definition: popup.h:180
static std::string getMapDrawTypeString()
static std::string getMoveTypeString()
void updateLabels() const
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:261
Definition: label.h:87
std::string getKeyValueString(const InputActionT index) const
static std::string getQuickDropCounterString()
void setLabelText(const int num, const std::string &text, const InputActionT key) const
static std::string getMoveToTargetTypeString()
InputAction ::T InputActionT
Definition: inputaction.h:715
Graphics * mainGraphics
Definition: graphics.cpp:108
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int mHeight
Definition: graphics.h:484
static std::string getPickUpTypeString()
static std::string getAwayModeString()
static std::string getFollowModeString()
void setHeight(const int height)
Definition: widget.cpp:139
static std::string getTargetingTypeString()
static std::string getImitationModeString()
Label * mLabels[STATUSPOPUP_NUM_LABELS]
Definition: statuspopup.h:69
static std::string getCrazyMoveTypeString()
void update()
Definition: statuspopup.cpp:89
int getHeight() const
Definition: widget.h:239
Definition: popup.h:48
static std::string getGameModifiersString()
const int STATUSPOPUP_NUM_LABELS
Definition: statuspopup.h:33
InputManager inputManager
int getHeight() const
Definition: font.cpp:360
static std::string getMagicAttackTypeString()
void adjustSize()
Definition: label.cpp:197
void postInit()
Definition: statuspopup.cpp:57
static std::string getAttackWeaponTypeString()
static std::string getAttackTypeString()
static std::string getPvpAttackTypeString()
static std::string getCameraModeString()