ManaPlus
clanwindowtabs.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 
23 
24 #include "being/localclan.h"
25 
27 #include "gui/widgets/label.h"
29 
30 #include "utils/foreach.h"
31 #include "utils/gettext.h"
32 #include "utils/stringutils.h"
33 
34 #include "debug.h"
35 
36 InfoClanTab::InfoClanTab(const Widget2 *const widget) :
37  Container(widget),
38  mNameLabel(new Label(this, " ")),
39  mMasterLabel(new Label(this, " ")),
40  mMapLabel(new Label(this, " "))
41 {
42  setSelectable(false);
43 
44  LayoutHelper h(this);
45  ContainerPlacer place = h.getPlacer(0, 0);
46 
47  place(0, 0, mNameLabel, 2, 1);
48  place(0, 1, mMasterLabel, 2, 1);
49  place(0, 2, mMapLabel, 2, 1);
50 
51  place.getCell().matchColWidth(0, 0);
52  setDimension(Rect(0, 0, 600, 300));
53 }
54 
56 {
57  // TRANSLATORS: not in clan label
58  mNameLabel->setCaption(_("Not in clan"));
59  mMasterLabel->setCaption(std::string());
60  mMapLabel->setCaption(std::string());
61 }
62 
64 {
66  // TRANSLATORS: clan name label
67  _("Clan name"),
68  localClan.name.c_str()));
70  // TRANSLATORS: clan master name label
71  _("Master name"),
72  localClan.masterName.c_str()));
73  mMapLabel->setCaption(strprintf("%s: %s",
74  // TRANSLATORS: clan map name label
75  _("Map name"),
76  localClan.mapName.c_str()));
77 }
78 
79 StatsClanTab::StatsClanTab(const Widget2 *const widget) :
80  Container(widget),
81  mLabels()
82 {
83  setSelectable(false);
84 }
85 
87 {
88  FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
89  {
90  remove(*it);
91  delete *it;
92  }
93  mLabels.clear();
94 }
95 
97 {
98  clearLabels();
99 }
100 
101 
103 {
104  clearLabels();
105 
106  LayoutHelper h(this);
107 
108  const int hPadding = h.getLayout().getHPadding();
109  const int vPadding = h.getLayout().getVPadding();
110  int y = vPadding;
111  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, localClan.stats)
112  {
113  Label *const label = new Label(this, *it);
114  add(label);
115  label->setPosition(hPadding, y);
116  label->adjustSize();
117  y += label->getHeight() + vPadding;
118  mLabels.push_back(label);
119  }
120 }
121 
123  Container(widget),
124  mLabels()
125 {
126  setSelectable(false);
127 }
128 
130 {
131  FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
132  {
133  remove(*it);
134  delete *it;
135  }
136  mLabels.clear();
137 }
138 
140 {
141  clearLabels();
142 }
143 
144 void RelationClanTab::updateClan(const STD_VECTOR<std::string> &restrict names)
145 {
146  clearLabels();
147 
148  LayoutHelper h(this);
149 
150  const int hPadding = h.getLayout().getHPadding();
151  const int vPadding = h.getLayout().getVPadding();
152  int y = vPadding;
153  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, names)
154  {
155  Label *const label = new Label(this, *it);
156  add(label);
157  label->setPosition(hPadding, y);
158  label->adjustSize();
159  y += label->getHeight() + vPadding;
160  mLabels.push_back(label);
161  }
162 }
virtual void add(Widget *const widget)
virtual void remove(Widget *const widget)
LayoutCell & getCell()
Label * mNameLabel
InfoClanTab(const Widget2 *const widget)
Label * mMapLabel
Label * mMasterLabel
Definition: label.h:91
void adjustSize()
Definition: label.cpp:200
void setCaption(const std::string &caption)
Definition: label.cpp:264
int getHPadding() const
Definition: layoutcell.h:66
int getVPadding() const
Definition: layoutcell.h:63
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:118
ContainerPlacer getPlacer(const int x, const int y)
const Layout & getLayout() const A_CONST
Definition: rect.h:74
std::vector< Label * > mLabels
RelationClanTab(const Widget2 *const widget)
void updateClan(const std::vector< std::string > &names)
std::vector< Label * > mLabels
StatsClanTab(const Widget2 *const widget)
void setDimension(const Rect &dimension)
Definition: widget.cpp:169
void setSelectable(const bool selectable)
Definition: widget.h:948
void setPosition(const int x, const int y)
Definition: widget.cpp:161
int getHeight() const
Definition: widget.h:240
#define new
Definition: debug_new.h:147
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
#define _(s)
Definition: gettext.h:35
LocalClan localClan
Definition: localclan.cpp:26
#define restrict
Definition: localconsts.h:165
std::string strprintf(const char *const format,...)
std::string masterName
Definition: localclan.h:64
std::string mapName
Definition: localclan.h:65
std::string name
Definition: localclan.h:63
std::vector< std::string > stats
Definition: localclan.h:66