ManaPlus
statspage.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "gui/widgets/statspage.h"
23 
24 #include "gui/widgets/scrollarea.h"
26 
28 
29 #include "utils/foreach.h"
30 
31 #include "resources/db/statdb.h"
32 
33 #include "debug.h"
34 
35 StatsPage::StatsPage(const Widget2 *const widget,
36  const std::string &page) :
37  Container(widget),
40  StatListener(),
41  mAttrs(),
42  mAttrCont(new VertContainer(this, 32, true, 0)),
43  mAttrScroll(new ScrollArea(this, mAttrCont, Opaque_false, std::string()))
44 {
45  addWidgetListener(this);
46  setSelectable(false);
47 
50  mAttrScroll->setSelectable(false);
51  mAttrCont->setSelectable(false);
52 
54  const STD_VECTOR<BasicStat> &basicStats = StatDb::getStats(page);
55  FOR_EACH (STD_VECTOR<BasicStat>::const_iterator, it, basicStats)
56  {
57  const BasicStat &stat = *it;
58  AttrDisplay *disp = new DerDisplay(this,
59  stat.attr,
60  stat.name,
61  stat.tag);
62  disp->update();
63  mAttrCont->add2(disp, true, -1);
64  mAttrs[stat.attr] = disp;
65  }
66 }
67 
69 {
71 }
72 
74  const int64_t oldVal A_UNUSED,
75  const int64_t newVal A_UNUSED)
76 {
77  const Attrs::const_iterator it = mAttrs.find(id);
78  if (it != mAttrs.end() && (it->second != nullptr))
79  it->second->update();
80 }
81 
83  const int oldVal1 A_UNUSED,
84  const int oldVal2 A_UNUSED)
85 {
86  const Attrs::const_iterator it = mAttrs.find(id);
87  if (it != mAttrs.end() && (it->second != nullptr))
88  it->second->update();
89 }
Attributes ::T AttributesT
Definition: attributes.h:118
virtual std::string update()
Definition: attrdisplay.cpp:59
virtual void add(Widget *const widget)
Definition: event.h:79
void setVerticalScrollPolicy(const ScrollPolicy vPolicy)
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
void attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal)
Definition: statspage.cpp:73
StatsPage(const Widget2 *const widget, const std::string &page)
Definition: statspage.cpp:35
void widgetResized(const Event &event)
Definition: statspage.cpp:68
void statChanged(const AttributesT id, const int oldVal1, const int oldVal2)
Definition: statspage.cpp:82
Attrs mAttrs
Definition: statspage.h:57
ScrollArea * mAttrScroll
Definition: statspage.h:59
VertContainer * mAttrCont
Definition: statspage.h:58
void add2(Widget *const widget, const bool resizable, const int spacing)
void setSize(const int width, const int height)
Definition: widget.cpp:367
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302
void setSelectable(const bool selectable)
Definition: widget.h:948
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
#define new
Definition: debug_new.h:147
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
#define A_UNUSED
Definition: localconsts.h:160
const std::vector< BasicStat > & getStats(const std::string &page)
Definition: statdb.cpp:77
const bool Opaque_false
Definition: opaque.h:30
AttributesT attr
Definition: basicstat.h:47
std::string name
Definition: basicstat.h:46
std::string tag
Definition: basicstat.h:45