Project Alice
Loading...
Searching...
No Matches
gui_units_window.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace ui {
6
7template<typename T>
8struct military_unit_info : public std::variant<T, dcon::province_land_construction_id, dcon::province_naval_construction_id> { };
9
10template<typename T>
12public:
13 void on_update(sys::state& state) noexcept override {
14 auto content = retrieve<military_unit_info<T>>(state, parent);
15
16 if(std::holds_alternative<dcon::province_land_construction_id>(content)) {
17 auto c = std::get<dcon::province_land_construction_id>(content);
18 auto utid = state.world.province_land_construction_get_type(c);
19 auto unitname = utid ? state.military_definitions.unit_base_definitions[utid].name : dcon::text_key{};
20 std::string res = text::produce_simple_string(state, unitname);
21
22 set_text(state, res);
23 }
24 else if(std::holds_alternative<dcon::province_naval_construction_id>(content)) {
25 auto c = std::get<dcon::province_naval_construction_id>(content);
26 auto utid = state.world.province_naval_construction_get_type(c);
27 auto unitname = utid ? state.military_definitions.unit_base_definitions[utid].name : dcon::text_key{};
28 std::string res = text::produce_simple_string(state, unitname);
29
30 set_text(state, res);
31 }
32 else if(std::holds_alternative<T>(content)) {
33 auto fat_id = dcon::fatten(state.world, std::get<T>(content));
34 auto unit_name = std::string{ state.to_string_view(fat_id.get_name()) };
35 set_text(state, std::string{ state.to_string_view(fat_id.get_name()) });
36 }
37 }
38};
39
40template<typename T>
42public:
45 }
46
47 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
48 auto container = retrieve<military_unit_info<T>>(state, parent);
49 float admin_eff = state.world.nation_get_administrative_efficiency(state.local_player_nation);
50 float admin_cost_factor = 2.0f - admin_eff;
51
52 if(std::holds_alternative<dcon::province_land_construction_id>(container)) {
53 auto c = std::get<dcon::province_land_construction_id>(container);
54
55 auto& goods = state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(c)].build_cost;
56 auto& cgoods = state.world.province_land_construction_get_purchased_goods(c);
57
58 float total = 0.0f;
59 float purchased = 0.0f;
60
61 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
62 if(goods.commodity_type[i]) {
63 auto box = text::open_layout_box(contents, 0);
64 text::add_to_layout_box(state, contents, box, state.world.commodity_get_name(goods.commodity_type[i]));
65 text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
66 text::add_to_layout_box(state, contents, box, text::fp_one_place{ cgoods.commodity_amounts[i] });
67 text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
68 text::add_to_layout_box(state, contents, box, text::fp_one_place{ goods.commodity_amounts[i] * admin_cost_factor });
69 text::close_layout_box(contents, box);
70 }
71 }
72 } else if(std::holds_alternative<dcon::province_naval_construction_id>(container)) {
73 auto c = std::get<dcon::province_naval_construction_id>(container);
74
75 auto& goods = state.military_definitions.unit_base_definitions[state.world.province_naval_construction_get_type(c)].build_cost;
76 auto& cgoods = state.world.province_naval_construction_get_purchased_goods(c);
77
78 float total = 0.0f;
79 float purchased = 0.0f;
80
81 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
82 if(goods.commodity_type[i]) {
83 auto box = text::open_layout_box(contents, 0);
84 text::add_to_layout_box(state, contents, box, state.world.commodity_get_name(goods.commodity_type[i]));
85 text::add_to_layout_box(state, contents, box, std::string_view{ ": " });
86 text::add_to_layout_box(state, contents, box, text::fp_one_place{ cgoods.commodity_amounts[i] });
87 text::add_to_layout_box(state, contents, box, std::string_view{ " / " });
88 text::add_to_layout_box(state, contents, box, text::fp_one_place{ goods.commodity_amounts[i] * admin_cost_factor });
89 text::close_layout_box(contents, box);
90 }
91 }
92 }
93
94 }
95};
96
98public:
101 }
102
103 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
104 auto box = text::open_layout_box(contents, 0);
105 text::localised_single_sub_box(state, contents, box, std::string_view("military_morale_tooltip"), text::variable_type::value,
106 uint8_t(progress * 100));
107 text::close_layout_box(contents, box);
108 }
109};
110
112public:
115 }
116
117 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
118 auto box = text::open_layout_box(contents, 0);
119 // This should change to use "military_shipstrength_tooltip" instead for naval units
120 text::localised_single_sub_box(state, contents, box, std::string_view("military_strength_tooltip2"),
122 text::close_layout_box(contents, box);
123 }
124};
125
126template<typename T>
128 bool visible = true;
129 dcon::gfx_object_id default_img;
130
131 void on_update(sys::state& state) noexcept override {
132 if(!default_img)
133 default_img = base_data.data.image.gfx_object;
134
135 auto container = retrieve<military_unit_info<T>>(state, parent);
136 if(!std::holds_alternative<T>(container)) {
137 visible = false;
138 return;
139 }
140
141 auto unit = std::get<T>(container);
142 dcon::leader_id lid;
143 if constexpr(std::is_same_v<T, dcon::army_id>) {
144 lid = state.world.army_get_general_from_army_leadership(unit);
145 } else {
146 lid = state.world.navy_get_admiral_from_navy_leadership(unit);
147 }
148
149 auto pculture = state.world.nation_get_primary_culture(state.local_player_nation);
150 auto ltype = pculture.get_group_from_culture_group_membership().get_leader();
151
152 if(ltype && lid) {
153 auto admiral = state.world.leader_get_is_admiral(lid);
154 if(admiral) {
155 auto arange = ltype.get_admirals();
156 if(arange.size() > 0) {
157 auto rval = rng::get_random(state, uint32_t(state.world.leader_get_since(lid).value), uint32_t(lid.value));
158 auto in_range = rng::reduce(uint32_t(rval), arange.size());
159 base_data.data.image.gfx_object = arange[in_range];
160 }
161 } else {
162 auto grange = ltype.get_generals();
163 if(grange.size() > 0) {
164 auto rval = rng::get_random(state, uint32_t(state.world.leader_get_since(lid).value), uint32_t(lid.value));
165 auto in_range = rng::reduce(uint32_t(rval), grange.size());
166 base_data.data.image.gfx_object = grange[in_range];
167 }
168 }
169 } else {
170 base_data.data.image.gfx_object = default_img;
171 }
172
173 }
174
175 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
176 if(visible)
178 }
179
180 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
182 }
183
184 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
185 auto container = retrieve<military_unit_info<T>>(state, parent);
186 if(!std::holds_alternative<T>(container)) {
187 return;
188 }
189
190 auto unit = std::get<T>(container);
191 dcon::leader_id lid;
192 if constexpr(std::is_same_v<T, dcon::army_id>) {
193 lid = state.world.army_get_general_from_army_leadership(unit);
194 } else {
195 lid = state.world.navy_get_admiral_from_navy_leadership(unit);
196 }
197 if(lid)
198 display_leader_full(state, lid, contents, 0);
199 }
200};
201
202template<typename T>
204
205template<>
207public:
208 void on_update(sys::state& state) noexcept override {
209 auto info = retrieve<military_unit_info<dcon::army_id>>(state, parent);
210 if(std::holds_alternative<dcon::province_land_construction_id>(info)) {
211 auto pc = std::get<dcon::province_land_construction_id>(info);
212 auto pop = state.world.province_land_construction_get_pop(pc);
213 disabled = !command::can_cancel_land_unit_construction(state, state.local_player_nation, state.world.pop_get_province_from_pop_location(pop), state.world.pop_get_culture(pop), state.world.province_land_construction_get_type(pc));
214 }
215 }
216 void button_action(sys::state& state) noexcept override {
217 auto info = retrieve<military_unit_info<dcon::army_id>>(state, parent);
218 if(std::holds_alternative<dcon::province_land_construction_id>(info)) {
219 auto pc = std::get<dcon::province_land_construction_id>(info);
220 auto pop = state.world.province_land_construction_get_pop(pc);
221 command::cancel_land_unit_construction(state, state.local_player_nation, state.world.pop_get_province_from_pop_location(pop), state.world.pop_get_culture(pop), state.world.province_land_construction_get_type(pc));
222 }
223 }
224};
225
226template<>
228public:
229 void on_update(sys::state& state) noexcept override {
230 auto info = retrieve<military_unit_info<dcon::navy_id>>(state, parent);
231 if(std::holds_alternative<dcon::province_naval_construction_id>(info)) {
232 auto pc = std::get<dcon::province_naval_construction_id>(info);
233 auto loc = state.world.province_naval_construction_get_province(pc);
234 auto type = state.world.province_naval_construction_get_type(pc);
235 disabled = !command::can_cancel_naval_unit_construction(state, state.local_player_nation, loc, type);
236 }
237 }
238 void button_action(sys::state& state) noexcept override {
239 auto info = retrieve<military_unit_info<dcon::navy_id>>(state, parent);
240 if(std::holds_alternative<dcon::province_naval_construction_id>(info)) {
241 auto pc = std::get<dcon::province_naval_construction_id>(info);
242 auto loc = state.world.province_naval_construction_get_province(pc);
243 auto type = state.world.province_naval_construction_get_type(pc);
244 command::cancel_naval_unit_construction(state, state.local_player_nation, loc, type);
245 }
246 }
247};
248
249template<typename T>
251public:
252 void on_update(sys::state& state) noexcept override {
253 auto container = retrieve<military_unit_info<T>>(state, parent);
254 interactable = std::holds_alternative<T>(container);
255 }
256 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
258 }
259 void button_action(sys::state& state) noexcept override {
260 auto container = retrieve<military_unit_info<T>>(state, parent);
261 if(std::holds_alternative<T>(container)) {
262 T id = std::get<T>(container);
263 state.selected_armies.clear();
264 state.selected_navies.clear();
265
266 if constexpr(std::is_same_v<T, dcon::army_id>) {
267 state.map_state.center_map_on_province(state, state.world.army_get_location_from_army_location(id));
268 } else {
269 state.map_state.center_map_on_province(state, state.world.navy_get_location_from_navy_location(id));
270 }
271 state.ui_state.military_subwindow->set_visible(state, false);
272 state.select(id);
273 }
274 }
275};
276
277template<typename T>
278class military_unit_entry : public listbox_row_element_base<military_unit_info<T>> {
279 simple_text_element_base* unit_name = nullptr;
280 image_element_base* unit_icon = nullptr;
281 image_element_base* leader_icon = nullptr;
282 button_element_base* cancel_button = nullptr;
283 simple_text_element_base* eta_date_text = nullptr;
284 simple_text_element_base* location_text = nullptr;
285 military_unit_building_progress_bar<T>* unit_building_progress = nullptr;
286 simple_text_element_base* unit_regiments_text = nullptr;
287 simple_text_element_base* unit_men_text = nullptr;
288 military_unit_morale_progress_bar* unit_morale_progress = nullptr;
289 military_unit_strength_progress_bar* unit_strength_progress = nullptr;
290 image_element_base* unit_moving_icon = nullptr;
291 image_element_base* unit_digin_icon = nullptr;
292 image_element_base* unit_combat_icon = nullptr;
293public:
294 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
295 auto name2 = name;
296 if(name == "military_unit_entry_bg") {
297 return make_element_by_type<mil_goto_background_button<T>>(state, id);
298 } else if(name == "unit_progress") {
299 auto ptr = make_element_by_type<military_unit_building_progress_bar<T>>(state, id);
300 unit_building_progress = ptr.get();
301 return ptr;
302 } else if(name == "leader") {
303 auto ptr = make_element_by_type<leader_in_army_img<T>>(state, id);
304 leader_icon = ptr.get();
305 return ptr;
306 } else if(name == "unit_strip") {
307 auto ptr = make_element_by_type<image_element_base>(state, id);
308 unit_icon = ptr.get();
309 return ptr;
310 } else if(name == "name") {
311 auto ptr = make_element_by_type<military_unit_name_text<T>>(state, id);
312 unit_name = ptr.get();
313 return ptr;
314 } else if(name == "location") {
315 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(state, id);
316 location_text = ptr.get();
317 return ptr;
318 }
319 else if(name == "unit_eta") {
320 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
321 eta_date_text = ptr.get();
322 return ptr;
323 } else if(name == "military_cancel_unit") {
324 auto ptr = make_element_by_type<cancel_unit_construction_button<T>>(state, id);
325 cancel_button = ptr.get();
326 return ptr;
327 } else if(name == "regiments") {
328 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
329 unit_regiments_text = ptr.get();
330 return ptr;
331 } else if(name == "men") {
332 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
333 unit_men_text = ptr.get();
334 return ptr;
335 } else if(name == "morale_progress") {
336 auto ptr = make_element_by_type<military_unit_morale_progress_bar>(state, id);
337 unit_morale_progress = ptr.get();
338 return ptr;
339 } else if(name == "strength_progress") {
340 auto ptr = make_element_by_type<military_unit_strength_progress_bar>(state, id);
341 unit_strength_progress = ptr.get();
342 return ptr;
343 } else if(name == "moving") {
344 auto ptr = make_element_by_type<image_element_base>(state, id);
345 unit_moving_icon = ptr.get();
346 return ptr;
347 } else if(name == "digin") {
348 auto ptr = make_element_by_type<image_element_base>(state, id);
349 unit_digin_icon = ptr.get();
350 return ptr;
351 } else if(name == "combat") {
352 auto ptr = make_element_by_type<image_element_base>(state, id);
353 unit_combat_icon = ptr.get();
354 return ptr;
355 } else {
356 return nullptr;
357 }
358 }
359
360 void on_update(sys::state& state) noexcept override {
362
363 bool is_building = !std::holds_alternative<T>(content);
364 bool is_moving = false;
365 bool is_digin = false;
366 bool is_combat = false;
367
368 if(is_building) {
369 if(std::holds_alternative<dcon::province_land_construction_id>(content)) {
370 auto c = std::get<dcon::province_land_construction_id>(content);
371 if(unit_icon) unit_icon->frame = state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(c)].icon - 1;
372 if(unit_building_progress) unit_building_progress->progress = economy::unit_construction_progress(state, c);
373 } else if(std::holds_alternative<dcon::province_naval_construction_id>(content)) {
374 auto c = std::get<dcon::province_naval_construction_id>(content);
375 if(unit_icon) unit_icon->frame = state.military_definitions.unit_base_definitions[state.world.province_naval_construction_get_type(c)].icon - 1;
376 if(unit_building_progress) unit_building_progress->progress = economy::unit_construction_progress(state, c);
377 }
378 } else {
379 auto regiments = 0;
380 auto strength = 0.f;
381 auto full_strength = 0.f;
382 // Armies
383 if constexpr(std::is_same_v<T, dcon::army_id>) {
384 state.world.army_for_each_army_membership_as_army(std::get<dcon::army_id>(content), [&](dcon::army_membership_id amid) {
385 auto rid = state.world.army_membership_get_regiment(amid);
386 full_strength += 1.f * state.defines.pop_size_per_regiment;
387 strength += state.world.regiment_get_strength(rid) * state.defines.pop_size_per_regiment;
388 ++regiments;
389 });
390 }
391 // Navies
392 if constexpr(std::is_same_v<T, dcon::navy_id>) {
393 state.world.navy_for_each_navy_membership_as_navy(std::get<dcon::navy_id>(content), [&](dcon::navy_membership_id nmid) {
394 auto sid = state.world.navy_membership_get_ship(nmid);
395 full_strength += 1.f;
396 strength += state.world.ship_get_strength(sid);
397 ++regiments;
398 });
399 }
400 if(unit_strength_progress) unit_strength_progress->progress = (full_strength != 0.0f) ? strength / full_strength : 0.f;
401 if(unit_men_text) unit_men_text->set_text(state, text::prettify(int32_t(strength)));
402 if(unit_regiments_text) unit_regiments_text->set_text(state, std::to_string(regiments));
403 }
404
405 if(unit_icon) unit_icon->set_visible(state, is_building);
406 if(cancel_button) cancel_button->set_visible(state, is_building);
407 if(eta_date_text) eta_date_text->set_visible(state, is_building);
408 if(location_text) location_text->set_visible(state, is_building);
409
410 if(unit_building_progress) unit_building_progress->set_visible(state, is_building);
411
412 if(unit_name) unit_name->set_visible(state, true);
413 if(leader_icon) leader_icon->set_visible(state, !is_building);
414 if(unit_regiments_text) unit_regiments_text->set_visible(state, !is_building);
415 if(unit_men_text) unit_men_text->set_visible(state, !is_building);
416 if(unit_morale_progress) unit_morale_progress->set_visible(state, !is_building);
417 if(unit_strength_progress) unit_strength_progress->set_visible(state, !is_building);
418 if(unit_moving_icon) unit_moving_icon->set_visible(state, !is_building && is_moving);
419 if(unit_digin_icon) unit_digin_icon->set_visible(state, !is_building && is_digin);
420 if(unit_combat_icon) unit_combat_icon->set_visible(state, !is_building && is_combat);
421 }
422
423
424 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
426 if(payload.holds_type<dcon::province_id>()) {
427 dcon::province_id p{};
428 if(std::holds_alternative<dcon::province_land_construction_id>(content)) {
429 auto c = std::get<dcon::province_land_construction_id>(content);
430 p = state.world.pop_location_get_province(
431 state.world.pop_get_pop_location_as_pop(state.world.province_land_construction_get_pop(c)));
432 } else if(std::holds_alternative<dcon::province_naval_construction_id>(content)) {
433 auto c = std::get<dcon::province_naval_construction_id>(content);
434 p = state.world.province_naval_construction_get_province(c);
435 }
436 payload.emplace<dcon::province_id>(p);
438 }
440 }
441};
442
443template<typename T>
444class military_units_listbox : public listbox_element_base<military_unit_entry<T>, military_unit_info<T>> {
445protected:
446 std::string_view get_row_element_name() override {
447 return "unit_entry";
448 }
449
450public:
451 void on_update(sys::state& state) noexcept override {
453 row_contents.clear();
455 Cyto::Any payload = dcon::nation_id{};
457 dcon::nation_id n = Cyto::any_cast<dcon::nation_id>(payload);
458 // Armies
459 if constexpr(std::is_same_v<T, dcon::army_id>) {
460 state.world.nation_for_each_army_control_as_controller(n, [&](dcon::army_control_id acid) {
461 auto aid = state.world.army_control_get_army(acid);
462 row_contents.push_back(military_unit_info<T>{aid});
463 });
464 state.world.nation_for_each_province_land_construction_as_nation(n,
465 [&](dcon::province_land_construction_id p) { row_contents.push_back(military_unit_info<T>{p}); });
466 }
467 // Navies
468 if constexpr(std::is_same_v<T, dcon::navy_id>) {
469 state.world.nation_for_each_navy_control_as_controller(n, [&](dcon::navy_control_id ncid) {
470 auto nid = state.world.navy_control_get_navy(ncid);
471 row_contents.push_back(military_unit_info<T>{nid});
472 });
473 state.world.nation_for_each_province_naval_construction_as_nation(n,
474 [&](dcon::province_naval_construction_id p) { row_contents.push_back(military_unit_info<T>{p}); });
475 }
476 }
478 }
479};
480
481template<class T>
483public:
484 bool disarmed = false;
485 bool no_possible_units = false;
486 void button_action(sys::state& state) noexcept override {
487 state.ui_state.unit_window_army->set_visible(state, false);
488 state.ui_state.unit_window_navy->set_visible(state, false);
489 state.ui_state.root->move_child_to_front(state.ui_state.build_unit_window);
490 Cyto::Any payload = T{};
491 state.ui_state.build_unit_window->impl_set(state, payload);
492 state.ui_state.build_unit_window->set_visible(state, true);
493 }
496 }
497 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
498 auto box = text::open_layout_box(contents, 0);
499 if(disarmed) {
500 text::localised_format_box(state, contents, box, std::string_view("cantbuild_forcedisarm"));
501 } else if(no_possible_units) {
502 text::localised_format_box(state, contents, box, std::string_view("alice_no_possible_units"));
503 } else {
504 if constexpr(std::is_same_v<T, dcon::army_id>) {
505 text::localised_format_box(state, contents, box, std::string_view("military_build_army_tooltip"));
506 } else if constexpr(std::is_same_v<T, dcon::navy_id>) {
507 text::localised_format_box(state, contents, box, std::string_view("military_build_navy_tooltip"));
508 }
509 }
510 text::close_layout_box(contents, box);
511 }
512 void on_update(sys::state& state) noexcept override {
513 if(state.world.nation_get_disarmed_until(state.local_player_nation) && state.current_date < state.world.nation_get_disarmed_until(state.local_player_nation)) {
514 disabled = true;
515 disarmed = true;
516 } else {
517 dcon::unit_type_id utid = dcon::unit_type_id{ 0 };
518 disarmed = false;
519 uint32_t count = 0;
520 uint8_t unit_def_count = 0;
521 for(auto const& ubd : state.military_definitions.unit_base_definitions) {
522 if(state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].is_land) {
523 if(!state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].primary_culture) {
524 if(state.world.nation_get_active_unit(state.local_player_nation, dcon::unit_type_id{ unit_def_count }) || state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].active) {
525 break;
526 }
527 }
528 }
529 unit_def_count++;
530 }
531 utid = dcon::unit_type_id{ unit_def_count };
532 if constexpr(std::is_same_v<T, dcon::army_id>) {
533 for(auto ucon : state.world.nation_get_province_land_construction(state.local_player_nation)) {
534 count++;
535 if(count) {
536 disabled = false;
537 no_possible_units = false;
538 return;
539 }
540 }
541 for(auto po : state.world.nation_get_province_ownership_as_nation(state.local_player_nation)) {
542 auto p = po.get_province();
543 state.world.for_each_culture([&](dcon::culture_id c) {
544 if(command::can_start_land_unit_construction(state, state.local_player_nation, p, c, utid)) {
545 count++;
546 }
547 });
548 if(count) {
549 disabled = false;
550 no_possible_units = false;
551 return;
552 }
553 }
554 disabled = true;
555 no_possible_units = true;
556 } else {
557 disarmed = false;
558 utid = dcon::unit_type_id{ 0 };
559 count = 0;
560 unit_def_count = 0;
561 for(auto const& ubd : state.military_definitions.unit_base_definitions) {
562 if(!state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].is_land) {
563 if(state.world.nation_get_active_unit(state.local_player_nation, dcon::unit_type_id{ unit_def_count }) || state.military_definitions.unit_base_definitions[dcon::unit_type_id{ unit_def_count }].active) {
564 utid = dcon::unit_type_id{ unit_def_count };
565 for(auto po : state.world.nation_get_province_ownership_as_nation(state.local_player_nation)) {
566 auto p = po.get_province();
567 if(command::can_start_naval_unit_construction(state, state.local_player_nation, p, utid)) {
568 disabled = false;
569 no_possible_units = false;
570 return;
571 }
572 }
573 }
574 }
575 unit_def_count++;
576 }
577 disabled = true;
578 no_possible_units = true;
579 }
580 }
581 }
582};
583
585public:
587 return tooltip_behavior::variable_tooltip;
588 }
589 void on_update(sys::state& state) noexcept override {
590 auto rng = state.world.nation_get_army_control(state.local_player_nation);
591 set_text(state, text::prettify(int64_t(rng.end() - rng.begin())));
592 }
593
594 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
595 auto box = text::open_layout_box(contents, 0);
596 auto rng = state.world.nation_get_army_control(state.local_player_nation);
597 text::localised_single_sub_box(state, contents, box, std::string_view("military_army_count_tooltip"),
598 text::variable_type::value, int64_t(rng.end() - rng.begin()));
599 text::close_layout_box(contents, box);
600 }
601};
602
604public:
606 return tooltip_behavior::variable_tooltip;
607 }
608 void on_update(sys::state& state) noexcept override {
609 auto rng = state.world.nation_get_navy_control(state.local_player_nation);
610 set_text(state, text::prettify(int64_t(rng.end() - rng.begin())));
611 }
612 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
613 auto box = text::open_layout_box(contents, 0);
614 auto rng = state.world.nation_get_navy_control(state.local_player_nation);
615 text::localised_single_sub_box(state, contents, box, std::string_view("military_navy_count_tooltip"),
616 text::variable_type::value, int64_t(rng.end() - rng.begin()));
617 text::close_layout_box(contents, box);
618 }
619};
620
622public:
623 void on_update(sys::state& state) noexcept override {
624 auto cstr_range = state.world.nation_get_province_land_construction(state.local_player_nation);
625 set_text(state, std::to_string(cstr_range.end() - cstr_range.begin()));
626 }
627};
628
630public:
631 void on_update(sys::state& state) noexcept override {
632 auto cstr_range = state.world.nation_get_province_naval_construction(state.local_player_nation);
633 set_text(state, std::to_string(cstr_range.end() - cstr_range.begin()));
634 }
635};
636
638public:
640 return tooltip_behavior::variable_tooltip;
641 }
642
643 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
644 auto box = text::open_layout_box(contents, 0);
645 text::localised_format_box(state, contents, box, std::string_view("military_sort_by_name_tooltip"));
646 text::close_layout_box(contents, box);
647 }
648};
649
651public:
653 return tooltip_behavior::variable_tooltip;
654 }
655
656 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
657 auto box = text::open_layout_box(contents, 0);
658 text::localised_format_box(state, contents, box, std::string_view("military_sort_by_strength_tooltip"));
659 text::close_layout_box(contents, box);
660 }
661};
662
663template<class T>
665private:
666 image_element_base* cdts_icon = nullptr;
667public:
668 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
669 if(name == "current_count") {
670 if constexpr(std::is_same_v<T, dcon::army_id>) {
671 return make_element_by_type<military_armies_text>(state, id);
672 } else {
673 return make_element_by_type<military_navies_text>(state, id);
674 }
675 } else if(name == "under_construction") {
676 if constexpr(std::is_same_v<T, dcon::army_id>) {
677 return make_element_by_type<military_armies_construction_text>(state, id);
678 } else {
679 return make_element_by_type<military_navies_construction_text>(state, id);
680 }
681 } else if(name == "cut_down_to_size") {
682 auto ptr = make_element_by_type<image_element_base>(state, id);
683 ptr->set_visible(state, false);
684 cdts_icon = ptr.get();
685 return ptr;
686 } else if(name == "sort_name") {
687 return make_element_by_type<military_units_sortby_name>(state, id);
688 } else if(name == "sort_strength") {
689 return make_element_by_type<military_units_sortby_strength>(state, id);
690 } else if(name == "build_new") {
691 auto ptr = make_element_by_type<build_unit_button<T>>(state, id);
692 if constexpr(std::is_same_v<T, dcon::army_id>) {
693 ptr->set_button_text(state, text::produce_simple_string(state, "military_build_army_label"));
694 } else {
695 ptr->set_button_text(state, text::produce_simple_string(state, "military_build_navy_label"));
696 }
697 return ptr;
698 } else if(name == "unit_listbox") {
699 return make_element_by_type<military_units_listbox<T>>(state, id);
700 } else {
701 return nullptr;
702 }
703 }
704};
705
706} // namespace ui
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
virtual message_result impl_set(sys::state &state, Cyto::Any &payload) noexcept
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
element_data base_data
void set_visible(sys::state &state, bool vis)
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void button_action(sys::state &state) noexcept override
void 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 update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) 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
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void set_text(sys::state &state, std::string const &new_text)
bool can_start_land_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province)
Definition: commands.cpp:679
bool can_cancel_land_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type)
Definition: commands.cpp:752
bool can_cancel_naval_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type)
Definition: commands.cpp:728
bool can_start_naval_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province)
Definition: commands.cpp:620
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
float unit_construction_progress(sys::state &state, dcon::province_land_construction_id c)
Definition: economy.cpp:4907
Definition: prng.cpp:6
uint32_t reduce(uint32_t value_in, uint32_t upper_bound)
Definition: prng.cpp:46
uint64_t get_random(sys::state const &state, uint32_t value_in)
Definition: prng.cpp:8
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
void localised_single_sub_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, variable_type subkey, substitution value)
Definition: text.cpp:1888
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1880
std::string prettify(int64_t num)
Definition: text.cpp:762
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
tooltip_behavior
@ count
Definition: gui_event.hpp:126
message_result
void display_leader_full(sys::state &state, dcon::leader_id lid, text::layout_base &contents, int32_t indent)
uint uint32_t
uchar uint8_t
static constexpr uint32_t set_size
union ui::element_data::internal_data data
dcon::gfx_object_id gfx_object
element_base * military_subwindow
element_base * unit_window_army
element_base * unit_window_navy
std::unique_ptr< element_base > root
element_base * build_unit_window