ManaPlus
changedisplay.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 "configuration.h"
27 
28 #include "being/playerinfo.h"
29 
30 #include "gui/widgets/button.h"
33 
34 #include "net/net.h"
35 #include "net/playerhandler.h"
36 
37 #include "utils/gettext.h"
38 
39 #include "debug.h"
40 
42  const AttributesT id,
43  const std::string &restrict name,
44  const std::string &restrict shortName) :
45  AttrDisplay(widget, id, name, shortName),
47  mNeeded(1),
48  // TRANSLATORS: status window label
49  mPoints(new Label(this, _("Max"))),
50  // TRANSLATORS: status window label (plus sign)
51  mInc(new Button(this, _("+"), "inc", BUTTON_SKIN, this))
52 {
53  // Do the layout
54  ContainerPlacer place = mLayout->getPlacer(0, 0);
55 
56  place(0, 0, mLabel, 3, 1);
57  place(4, 0, mValue, 2, 1);
58  place(6, 0, mInc, 1, 1);
59  place(7, 0, mPoints, 1, 1);
60 }
61 
62 std::string ChangeDisplay::update()
63 {
64  if (mNeeded > 0)
65  {
67  }
68  else
69  {
70  // TRANSLATORS: status bar label
71  mPoints->setCaption(_("Max"));
72  }
73 
75  >= mNeeded && mNeeded > 0);
76 
77  return AttrDisplay::update();
78 }
79 
80 void ChangeDisplay::setPointsNeeded(const int needed)
81 {
82  mNeeded = needed;
83  update();
84 }
85 
87 {
88  if (event.getSource() == mInc)
89  {
90  int cnt = 1;
91  if (config.getBoolValue("quickStats"))
92  {
93  cnt = mInc->getClickCount();
94  if (cnt > 10)
95  cnt = 10;
96  }
97 
98  const int newpoints = PlayerInfo::getAttribute(
101  newpoints,
102  Notify_true);
103 
104  const int newbase = PlayerInfo::getStatBase(mId) + cnt;
106 
108  {
110  }
111  else
112  {
113  for (int f = 0; f < cnt; f ++)
114  {
116  if (cnt != 1)
117  SDL_Delay(100);
118  }
119  }
120  }
121 }
Attributes ::T AttributesT
Definition: attributes.h:118
const std::string BUTTON_SKIN
Definition: button.h:89
virtual std::string update()
Definition: attrdisplay.cpp:59
Label * mLabel
Definition: attrdisplay.h:77
LayoutHelper * mLayout
Definition: attrdisplay.h:76
Label * mValue
Definition: attrdisplay.h:78
const AttributesT mId
Definition: attrdisplay.h:72
Definition: button.h:102
int getClickCount() const
Definition: button.h:171
void action(const ActionEvent &event)
Label * mPoints
Definition: changedisplay.h:58
ChangeDisplay(const Widget2 *const widget, const AttributesT id, const std::string &name, const std::string &shortName)
Button * mInc
Definition: changedisplay.h:59
std::string update()
void setPointsNeeded(const int needed)
bool getBoolValue(const std::string &key) const
Widget * getSource() const
Definition: event.h:104
Definition: label.h:91
void setCaption(const std::string &caption)
Definition: label.cpp:264
ContainerPlacer getPlacer(const int x, const int y)
virtual void increaseAttribute(const AttributesT attr, const int amount) const =0
void setEnabled(const bool enabled)
Definition: widget.h:352
Configuration config
#define new
Definition: debug_new.h:147
#define _(s)
Definition: gettext.h:35
#define restrict
Definition: localconsts.h:165
@ PLAYER_CHAR_POINTS
Definition: attributes.h:49
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
ServerTypeT getNetworkType()
Definition: net.cpp:189
int getStatBase(const AttributesT id)
Definition: playerinfo.cpp:135
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102
void setAttribute(const AttributesT id, const int64_t value, const Notify notify)
Definition: playerinfo.cpp:110
void setStatBase(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:143
Net::PlayerHandler * playerHandler
Definition: net.cpp:96
const bool Notify_true
Definition: notify.h:30