The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
label.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 - 2025
3 by David White <dave@whitevine.net>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#pragma once
17
18#include "color.hpp"
20#include "map/location.hpp"
21#include "sdl/rect.hpp"
22#include "tstring.hpp"
23
24#include <map>
25#include <string>
26
27class config;
28class display;
29class team;
30class terrain_label;
31
33{
34public:
35 typedef std::map<map_location, terrain_label> label_map;
36 typedef std::map<std::string, label_map> team_label_map;
37
38 map_labels(const map_labels&);
39 map_labels(const team*);
40
42
44
45 void write(config& res) const;
46 void read(const config& cfg);
47
48 const terrain_label* get_label(const map_location& loc, const std::string& team_name) const
49 {
50 return const_cast<map_labels*>(this)->get_label_private(loc, team_name);
51 }
52
53 // search a team-only label, if fails then try public labels
54 const terrain_label* get_label(const map_location& loc) const;
55
57 const t_string& text,
58 const int creator = -1,
59 const std::string& team = "",
60 const color_t color = font::NORMAL_COLOR,
61 const bool visible_in_fog = true,
62 const bool visible_in_shroud = false,
63 const bool immutable = false,
64 const std::string& category = "",
65 const t_string& tooltip = "");
66
67 bool enabled() const
68 {
69 return enabled_;
70 }
71 void enable(bool is_enabled);
72
73 void clear(const std::string&, bool force);
74
75 void recalculate_labels();
76 void recalculate_shroud();
77
78 bool visible_global_label(const map_location&) const;
79
80 const std::string& team_name() const;
81 const std::vector<std::string>& all_categories() const;
82
83 void set_team(const team*);
84
85 void clear_all();
86
87private:
88 template<typename... T>
89 terrain_label* add_label(T&&... args);
90
91 void clear_map(label_map&, bool);
92
93 terrain_label* get_label_private(const map_location& loc, const std::string& team_name);
94 // Note: this is not an overload of get_label() so that we do not block
95 // outsiders from calling get_label for a non-const map_labels object.
96
97 const team* team_;
98
101
102 mutable std::vector<std::string> categories;
103 mutable bool categories_dirty;
104};
105
106/**
107 * To store label data
108 * Class implements logic for rendering
109 */
111{
112public:
113 /** Delete copy ctor and assignment ops. */
114 terrain_label(const terrain_label&) = delete;
116
117 terrain_label(const map_labels& parent,
118 const t_string& text,
119 const int creator,
120 const std::string& team_name,
121 const map_location& loc,
123 const bool visible_in_fog = true,
124 const bool visible_in_shroud = false,
125 const bool immutable = false,
126 const std::string& category = "",
127 const t_string& tooltip = "");
128
129 terrain_label(const map_labels&, const config&);
130
131 /** Move ctor. */
132 terrain_label(terrain_label&&) noexcept;
133
134 ~terrain_label();
135
136 void write(config& res) const;
137 void read(const config& cfg);
138
139 const t_string& text() const
140 {
141 return text_;
142 }
143
144 const t_string& tooltip() const
145 {
146 return tooltip_;
147 }
148
149 int creator() const
150 {
151 return creator_;
152 }
153
154 const std::string& team_name() const
155 {
156 return team_name_;
157 }
158
159 const std::string& category() const
160 {
161 return category_;
162 }
163
164 bool visible_in_fog() const
165 {
166 return visible_in_fog_;
167 }
168
169 bool visible_in_shroud() const
170 {
171 return visible_in_shroud_;
172 }
173
174 bool immutable() const
175 {
176 return immutable_;
177 }
178
179 const map_location& location() const
180 {
181 return loc_;
182 }
183
184 const color_t& color() const
185 {
186 return color_;
187 }
188
189 void set_text(const t_string& text)
190 {
191 text_ = text;
192 }
193
194 void update_info(const t_string&, const int creator, const t_string&, const std::string&, const color_t);
195
196 void update_info(const t_string& text,
197 const int creator,
198 const t_string& tooltip,
199 const std::string& team_name,
200 const color_t color,
201 const bool visible_in_fog,
202 const bool visible_in_shroud,
203 const bool immutable,
204 const std::string& category);
205
206 void recalculate();
207 void calculate_shroud();
208
209private:
210 void clear();
211 bool hidden() const;
212 bool viewable(const display& disp) const;
213
216
219
220 std::string category_;
221 std::string team_name_;
222
227
229
232
233 rect get_rect() const;
234};
map_location loc
Definition move.cpp:172
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition display.hpp:88
void write(config &res) const
Definition label.cpp:81
void clear_map(label_map &, bool)
Definition label.cpp:227
const std::vector< std::string > & all_categories() const
Definition label.cpp:288
const team * team_
Definition label.hpp:97
bool enabled() const
Definition label.hpp:67
const std::string & team_name() const
Definition label.cpp:130
bool visible_global_label(const map_location &) const
Returns whether or not a global (non-team) label can be shown at a specified location.
Definition label.cpp:268
terrain_label * add_label(T &&... args)
Definition label.cpp:204
const terrain_label * set_label(const map_location &loc, const t_string &text, const int creator=-1, const std::string &team="", const color_t color=font::NORMAL_COLOR, const bool visible_in_fog=true, const bool visible_in_shroud=false, const bool immutable=false, const std::string &category="", const t_string &tooltip="")
Definition label.cpp:148
void recalculate_shroud()
Definition label.cpp:279
terrain_label * get_label_private(const map_location &loc, const std::string &team_name)
Definition label.cpp:104
void clear_all()
Definition label.cpp:241
map_labels & operator=(const map_labels &)
Definition label.cpp:71
void enable(bool is_enabled)
Definition label.cpp:255
void set_team(const team *)
Definition label.cpp:140
void clear(const std::string &, bool force)
Definition label.cpp:212
bool enabled_
Definition label.hpp:100
const terrain_label * get_label(const map_location &loc, const std::string &team_name) const
Definition label.hpp:48
team_label_map labels_
Definition label.hpp:99
std::vector< std::string > categories
Definition label.hpp:102
bool categories_dirty
Definition label.hpp:103
void recalculate_labels()
Definition label.cpp:246
~map_labels()
Definition label.cpp:66
std::map< std::string, label_map > team_label_map
Definition label.hpp:36
std::map< map_location, terrain_label > label_map
Definition label.hpp:35
void read(const config &cfg)
Definition label.cpp:93
This class stores all the data for a single 'side' (in game nomenclature).
Definition team.hpp:74
To store label data Class implements logic for rendering.
Definition label.hpp:111
terrain_label(const terrain_label &)=delete
Delete copy ctor and assignment ops.
rect get_rect() const
Definition label.cpp:502
bool visible_in_shroud() const
Definition label.hpp:169
const t_string & tooltip() const
Definition label.hpp:144
bool visible_in_fog_
Definition label.hpp:223
t_string tooltip_
Definition label.hpp:218
bool immutable() const
Definition label.hpp:174
terrain_label & operator=(const terrain_label &)=delete
int creator() const
Definition label.hpp:149
const std::string & team_name() const
Definition label.hpp:154
std::string category_
Definition label.hpp:220
const color_t & color() const
Definition label.hpp:184
color_t color_
Definition label.hpp:228
void update_info(const t_string &, const int creator, const t_string &, const std::string &, const color_t)
Definition label.cpp:448
bool visible_in_fog() const
Definition label.hpp:164
const t_string & text() const
Definition label.hpp:139
std::string team_name_
Definition label.hpp:221
int tooltip_handle_
Definition label.hpp:215
void set_text(const t_string &text)
Definition label.hpp:189
void write(config &res) const
Definition label.cpp:433
map_location loc_
Definition label.hpp:231
const map_labels * parent_
Definition label.hpp:230
const map_location & location() const
Definition label.hpp:179
bool immutable_
Definition label.hpp:225
bool hidden() const
This is a lightweight test used to see if labels are revealed as a result of unit actions (i....
Definition label.cpp:569
void clear()
Definition label.cpp:634
void recalculate()
Definition label.cpp:521
bool viewable(const display &disp) const
This is a test used to see if we should bother with the overhead of actually creating a label.
Definition label.cpp:611
bool visible_in_shroud_
Definition label.hpp:224
void calculate_shroud()
Definition label.cpp:481
void read(const config &cfg)
Definition label.cpp:386
const std::string & category() const
Definition label.hpp:159
t_string text_
Definition label.hpp:217
const config * cfg
const color_t NORMAL_COLOR
Contains the SDL_Rect helper code.
The basic class for representing 8-bit RGB or RGBA colour values.
Definition color.hpp:51
Encapsulates the map of the game.
Definition location.hpp:46
An abstract description of a rectangle with integer coordinates.
Definition rect.hpp:49