ManaPlus
clanwindowtabs.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2018 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 
23 #include "being/localclan.h"
24 
26 #include "gui/widgets/label.h"
28 
29 #include "utils/foreach.h"
30 #include "utils/gettext.h"
31 #include "utils/stringutils.h"
32 
33 #include "debug.h"
34 
35 InfoClanTab::InfoClanTab(const Widget2 *const widget) :
36  Container(widget),
37  mNameLabel(new Label(this, " ")),
38  mMasterLabel(new Label(this, " ")),
39  mMapLabel(new Label(this, " "))
40 {
41  setSelectable(false);
42 
43  LayoutHelper h(this);
45 
46  place(0, 0, mNameLabel, 2, 1);
47  place(0, 1, mMasterLabel, 2, 1);
48  place(0, 2, mMapLabel, 2, 1);
49 
50  place.getCell().matchColWidth(0, 0);
51  setDimension(Rect(0, 0, 600, 300));
52 }
53 
55 {
56  // TRANSLATORS: not in clan label
57  mNameLabel->setCaption(strprintf(_("Not in clan")));
58  mMasterLabel->setCaption(std::string());
59  mMapLabel->setCaption(std::string());
60 }
61 
63 {
65  // TRANSLATORS: clan name label
66  _("Clan name"),
67  localClan.name.c_str()));
69  // TRANSLATORS: clan master name label
70  _("Master name"),
71  localClan.masterName.c_str()));
72  mMapLabel->setCaption(strprintf("%s: %s",
73  // TRANSLATORS: clan map name label
74  _("Map name"),
75  localClan.mapName.c_str()));
76 }
77 
78 StatsClanTab::StatsClanTab(const Widget2 *const widget) :
79  Container(widget),
80  mLabels()
81 {
82  setSelectable(false);
83 }
84 
86 {
87  FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
88  {
89  remove(*it);
90  delete *it;
91  }
92  mLabels.clear();
93 }
94 
96 {
97  clearLabels();
98 }
99 
100 
102 {
103  clearLabels();
104 
105  LayoutHelper h(this);
106 
107  const int hPadding = h.getLayout().getHPadding();
108  const int vPadding = h.getLayout().getVPadding();
109  int y = vPadding;
110  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, localClan.stats)
111  {
112  Label *const label = new Label(this, *it);
113  add(label);
114  label->setPosition(hPadding, y);
115  label->adjustSize();
116  y += label->getHeight() + vPadding;
117  mLabels.push_back(label);
118  }
119 }
120 
122  Container(widget),
123  mLabels()
124 {
125  setSelectable(false);
126 }
127 
129 {
130  FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
131  {
132  remove(*it);
133  delete *it;
134  }
135  mLabels.clear();
136 }
137 
139 {
140  clearLabels();
141 }
142 
143 void RelationClanTab::updateClan(const STD_VECTOR<std::string> &restrict names)
144 {
145  clearLabels();
146 
147  LayoutHelper h(this);
148 
149  const int hPadding = h.getLayout().getHPadding();
150  const int vPadding = h.getLayout().getVPadding();
151  int y = vPadding;
152  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, names)
153  {
154  Label *const label = new Label(this, *it);
155  add(label);
156  label->setPosition(hPadding, y);
157  label->adjustSize();
158  y += label->getHeight() + vPadding;
159  mLabels.push_back(label);
160  }
161 }
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:117
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1383
#define _(s)
Definition: gettext.h:34
std::string masterName
Definition: localclan.h:63
StatsClanTab(const Widget2 *const widget)
std::string mapName
Definition: localclan.h:64
Definition: rect.h:72
std::vector< std::string > stats
Definition: localclan.h:65
Label * mMapLabel
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
InfoClanTab(const Widget2 *const widget)
LocalClan localClan
Definition: localclan.cpp:25
LayoutCell & getCell()
void setSelectable(const bool selectable)
Definition: widget.h:947
#define new
Definition: debug_new.h:147
int getVPadding() const
Definition: layoutcell.h:62
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 name
Definition: localclan.h:62
int getHPadding() const
Definition: layoutcell.h:65
const Layout & getLayout() const A_CONST
virtual void add(Widget *const widget)
Label * mNameLabel
void setPosition(const int x, const int y)
Definition: widget.cpp:160
void updateClan(const std::vector< std::string > &names)
Label * mMasterLabel
RelationClanTab(const Widget2 *const widget)
ContainerPlacer getPlacer(const int x, const int y)
std::vector< Label * > mLabels
int getHeight() const
Definition: widget.h:239
#define restrict
Definition: localconsts.h:164
void adjustSize()
Definition: label.cpp:197
std::vector< Label * > mLabels