Project Alice
Loading...
Searching...
No Matches
gui_map_legend.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "dcon_generated.hpp"
5#include "gui_graphics.hpp"
6#include "text.hpp"
7
8namespace ui {
9
11 std::string get_title_from_mode(map_mode::mode v) {
12 return "mapmode_" + std::to_string(uint32_t(v));
13 }
14public:
15 void on_update(sys::state& state) noexcept override {
16 set_text(state, text::produce_simple_string(state, get_title_from_mode(state.map_state.active_map_mode)));
17 }
18};
19
20enum class GRADIENT_ICON: int16_t {
21 GRAY = 0,
22 RED_TO_GREEN = 1,
24 GREEN_TO_RED = 3,
25 VIRIDIS = 4,
26 MAGMA = 5,
27};
28
30 int16_t get_frame_from_mode(map_mode::mode v) {
31 switch(v) {
39 return (int16_t)GRADIENT_ICON::VIRIDIS;
52 return (int16_t)GRADIENT_ICON::RED_TO_GREEN;
58 return (int16_t)GRADIENT_ICON::MAGMA;
59 default:
60 return (int16_t)GRADIENT_ICON::GRAY;
61 }
62 }
63public:
64 void on_update(sys::state& state) noexcept override {
65 frame = get_frame_from_mode(state.map_state.active_map_mode);
66 }
67};
69 std::string get_gradient_max_from_mode(map_mode::mode v) {
70 return "legend_max_mapmode_" + std::to_string(uint32_t(v));
71 }
72public:
73 void on_update(sys::state& state) noexcept override {
74 set_text(state, text::produce_simple_string(state, get_gradient_max_from_mode(state.map_state.active_map_mode)));
75 }
76};
78 std::string get_gradient_min_from_mode(map_mode::mode v) {
79 return "legend_min_mapmode_" + std::to_string(uint32_t(v));
80 }
81public:
82 void on_update(sys::state& state) noexcept override {
83 set_text(state, text::produce_simple_string(state, get_gradient_min_from_mode(state.map_state.active_map_mode)));
84 }
85};
86
88public:
89 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
90 if(name == "legend_title") {
91 return make_element_by_type<map_legend_title>(state, id);
92 } else if(name == "gradient_icon") {
93 return make_element_by_type<map_legend_gradient_image>(state, id);
94 } else if(name == "gradient_min") {
95 return make_element_by_type<map_legend_gradient_min>(state, id);
96 } else if(name == "gradient_max") {
97 return make_element_by_type<map_legend_gradient_max>(state, id);
98 } else {
99 return nullptr;
100 }
101 }
102
103 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
104 auto new_position = xy_pair{ int16_t((state.ui_state.root->base_data.size.x - base_data.size.x) / 2), int16_t((state.ui_state.root->base_data.size.y - base_data.size.y) - (state.ui_state.msg_log_window->is_visible() ? state.ui_state.msg_log_window->base_data.size.y + 54 : 12)) };
105 base_data.position = new_position;
106 window_element_base::impl_render(state, new_position.x, new_position.y);
107 }
108};
109
111public:
112 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
113 if(name == "s1_ico") {
114 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(53, 196, 53));
115 } else if(name == "s5_ico") {
116 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(53, 196, 53));
117 } else if(name == "s5_ico_b") {
118 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(53, 53, 250));
119 } else if(name == "s2_ico") {
120 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(250, 5, 5));
121 } else if(name == "s3_ico") {
122 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(250, 250, 5));
123 } else if(name == "s4_ico") {
124 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(64, 64, 64));
125 } else {
126 return nullptr;
127 }
128 }
129
130 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
131 auto new_position = xy_pair{ int16_t((state.ui_state.root->base_data.size.x - base_data.size.x) / 2), int16_t((state.ui_state.root->base_data.size.y - base_data.size.y) - (state.ui_state.msg_log_window->is_visible() ? state.ui_state.msg_log_window->base_data.size.y + 54 : 12)) };
132 base_data.position = new_position;
133 window_element_base::impl_render(state, new_position.x, new_position.y);
134 }
135};
136
138public:
139 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
140 if(name == "s1_ico") {
141 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(46, 247, 15));
142 } else if(name == "s2_ico") {
143 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(247, 15, 15));
144 } else if(name == "s3_ico") {
145 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(140, 247, 15));
146 } else if(name == "s4_ico") {
147 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(250, 250, 5));
148 } else {
149 return nullptr;
150 }
151 }
152
153 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
154 auto new_position = xy_pair{ int16_t((state.ui_state.root->base_data.size.x - base_data.size.x) / 2), int16_t((state.ui_state.root->base_data.size.y - base_data.size.y) - (state.ui_state.msg_log_window->is_visible() ? state.ui_state.msg_log_window->base_data.size.y + 54 : 12)) };
155 base_data.position = new_position;
156 window_element_base::impl_render(state, new_position.x, new_position.y);
157 }
158};
159
161public:
162 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
163 if(name == "s1_ico") { // Viewpoint
164 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x00FF00));
165 } else if(name == "s2_ico") { // Ally
166 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0xFFAA00));
167 } else if(name == "s3_ico") { // Enemy
168 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x0000FF));
169 } else if(name == "s4_ico") { // Puppet
170 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x009900));
171 } else if(name == "s5_ico") { // Sphere
172 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x55AA55));
173 } else if(name == "s6_ico") { // Other
174 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x222222));
175 } else if(name == "s7_ico") { // Core
176 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x222222));
177 } else if(name == "s8_ico") { // Non Core
178 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x00FF00));
179 } else if(name == "s9_ico") { // Union Core
180 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x222222));
181 } else if(name == "s7_ico_b") { // Core
182 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x00FF00));
183 } else if(name == "s8_ico_b") { // Non Core
184 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0xFFFFFF));
185 } else if(name == "s9_ico_b") { // Union Core
186 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x00FFFF));
187 } else {
188 return nullptr;
189 }
190 }
191
192 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
193 auto new_position = xy_pair{ int16_t((state.ui_state.root->base_data.size.x - base_data.size.x) / 2), int16_t((state.ui_state.root->base_data.size.y - base_data.size.y) - (state.ui_state.msg_log_window->is_visible() ? state.ui_state.msg_log_window->base_data.size.y + 54 : 12)) };
194 base_data.position = new_position;
195 window_element_base::impl_render(state, new_position.x, new_position.y);
196 }
197};
198
200public:
201 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
202 if(name == "s1_ico") { // Level 0
203 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(41, 5, 245));
204 } else if(name == "s2_ico") { // Level 5
205 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(14, 240, 44));
206 } else if(name == "s3_ico") { // Upgrading
207 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(222, 7, 46));
208 } else if(name == "s3_ico_b") { // Upgrading
209 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(232, 228, 111));
210 } else if(name == "s4_ico") { // Max level
211 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(232, 228, 111));
212 } else if(name == "s5_ico") { // Blocked
213 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(222, 7, 46));
214 } else {
215 return nullptr;
216 }
217 }
218
219 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
220 auto new_position = xy_pair{ int16_t((state.ui_state.root->base_data.size.x - base_data.size.x) / 2), int16_t((state.ui_state.root->base_data.size.y - base_data.size.y) - (state.ui_state.msg_log_window->is_visible() ? state.ui_state.msg_log_window->base_data.size.y + 54 : 12)) };
221 base_data.position = new_position;
222 window_element_base::impl_render(state, new_position.x, new_position.y);
223 }
224};
225
227public:
228 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
229 if(name == "s1_ico") { // No base
230 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x222222));
231 } else if(name == "s2_ico") { // Max level
232 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x005500));
233 } else if(name == "s3_ico") { // Upgrading
234 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x005500));
235 } else if(name == "s3_ico_b") { // Upgrading
236 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x00FF00));
237 } else if(name == "s4_ico") { // Upgradeable
238 return make_element_by_type<tinted_image_element_base>(state, id, uint32_t(0x00FF00));
239 } else if(name == "s5_ico") { // Constructible
240 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(50, 150, 200));
241 } else {
242 return nullptr;
243 }
244 }
245
246 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
247 auto new_position = xy_pair{ int16_t((state.ui_state.root->base_data.size.x - base_data.size.x) / 2), int16_t((state.ui_state.root->base_data.size.y - base_data.size.y) - (state.ui_state.msg_log_window->is_visible() ? state.ui_state.msg_log_window->base_data.size.y + 54 : 12)) };
248 base_data.position = new_position;
249 window_element_base::impl_render(state, new_position.x, new_position.y);
250 }
251};
252
254public:
255 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
256 if(name == "s1_ico") {
257 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(int32_t(48 * 0.65f), int32_t(242 * 0.65f), int32_t(51 * 0.65f)));
258 } else if(name == "s2_ico") {
259 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(int32_t(36 * 0.65f), int32_t(47 * 0.65f), int32_t(255 * 0.65f)));
260 } else if(name == "s3_ico") {
261 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(int32_t(238 * 0.65f), int32_t(252 * 0.65f), int32_t(38 * 0.65f)));
262 } else if(name == "s4_ico") {
263 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(int32_t(250 * 0.65f), int32_t(5 * 0.65f), int32_t(5 * 0.65f)));
264 } else {
265 return nullptr;
266 }
267 }
268
269 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
270 auto new_position = xy_pair{ int16_t((state.ui_state.root->base_data.size.x - base_data.size.x) / 2), int16_t((state.ui_state.root->base_data.size.y - base_data.size.y) - (state.ui_state.msg_log_window->is_visible() ? state.ui_state.msg_log_window->base_data.size.y + 54 : 12)) };
271 base_data.position = new_position;
272 window_element_base::impl_render(state, new_position.x, new_position.y);
273 }
274};
275
277public:
278 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
279 if(name == "s1_ico") {
280 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(53, 196, 53));
281 } else if(name == "s2_ico") {
282 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(212, 214, 62));
283 } else if(name == "s3_ico") {
284 return make_element_by_type<tinted_image_element_base>(state, id, sys::pack_color(155, 156, 149));
285 } else {
286 return nullptr;
287 }
288 }
289
290 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
291 auto new_position = xy_pair{ int16_t((state.ui_state.root->base_data.size.x - base_data.size.x) / 2), int16_t((state.ui_state.root->base_data.size.y - base_data.size.y) - (state.ui_state.msg_log_window->is_visible() ? state.ui_state.msg_log_window->base_data.size.y + 54 : 12)) };
292 base_data.position = new_position;
293 window_element_base::impl_render(state, new_position.x, new_position.y);
294 }
295};
296
297}
virtual void impl_render(sys::state &state, int32_t x, int32_t y) noexcept
bool is_visible() const
element_data base_data
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void on_update(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
uint32_t pack_color(float r, float g, float b)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
uint uint32_t
Holds important data about the game world, state, and other data regarding windowing,...
element_base * msg_log_window
std::unique_ptr< element_base > root