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