Project Alice
Loading...
Searching...
No Matches
gui_unit_panel_subwindow.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <vector>
5
6namespace ui {
7
8//======================================================================================================================================
9// REORGANISATION WINDOW
10//======================================================================================================================================
11
12template<class T>
14public:
15 void on_update(sys::state& state) noexcept override {
16 auto fat = dcon::fatten(state.world, retrieve<T>(state, parent));
17 progress = fat.get_org();
18 }
19
22 }
23
24 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
25 {
26 auto box = text::open_layout_box(contents, 0);
27 text::localised_format_box(state, contents, box, std::string_view("curr_comb_org"));
28 auto fat = dcon::fatten(state.world, retrieve<T>(state, parent));
29 auto color = fat.get_org() >= 0.9f ? text::text_color::green
30 : fat.get_org() < 0.5f ? text::text_color::red
32 text::add_to_layout_box(state, contents, box, text::fp_percentage{ fat.get_org() }, color);
33 text::close_layout_box(contents, box);
34 }
35 if constexpr(std::is_same_v<T, dcon::regiment_id>) {
36 ui::active_modifiers_description(state, contents, state.local_player_nation, 0, sys::national_mod_offsets::land_organisation, true);
37 } else {
38 ui::active_modifiers_description(state, contents, state.local_player_nation, 0, sys::national_mod_offsets::naval_organisation, true);
39 }
40 }
41};
42
43template<class T>
45public:
46 void on_update(sys::state& state) noexcept override {
47 auto fat = dcon::fatten(state.world, retrieve<T>(state, parent));
48 progress = fat.get_strength();
49 }
50
53 }
54
55 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
56 {
57 auto box = text::open_layout_box(contents, 0);
58 text::localised_format_box(state, contents, box, std::string_view("curr_comb_str"));
59 auto fat = dcon::fatten(state.world, retrieve<T>(state, parent));
60 auto color = fat.get_strength() >= 0.9f ? text::text_color::green
61 : fat.get_strength() < 0.5f ? text::text_color::red
63 text::add_to_layout_box(state, contents, box, text::fp_percentage{ fat.get_strength() }, color);
64 text::close_layout_box(contents, box);
65 }
66
67 auto fat_id = dcon::fatten(state.world, retrieve<T>(state, parent));
68 float total_cost = 0.f;
69
70 // Reinforcement cost as % of construction cost
71 // Shows how many goods will it take to fully reinforce the unit
72 auto& build_cost = state.military_definitions.unit_base_definitions[fat_id.get_type()].build_cost;
73 auto hadheader = false;
74 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
75 if(build_cost.commodity_type[i]) {
76 float cost = state.world.commodity_get_cost(build_cost.commodity_type[i]);
77 float curstr = military::unit_get_strength(state, fat_id);
78 if(curstr >= 1.0f) {
79 continue;
80 }
81 auto box = text::open_layout_box(contents, 0);
82
83 if(!hadheader) {
84 hadheader = true;
85
86 text::localised_format_box(state, contents, box, "unit_reinforcement_needs");
87 text::close_layout_box(contents, box);
88 box = text::open_layout_box(contents, 0);
89 }
90
91 float amount = build_cost.commodity_amounts[i] * (1.0f - curstr);
93 text::add_to_substitution_map(m, text::variable_type::name, state.world.commodity_get_name(build_cost.commodity_type[i]));
97
98 auto cid = build_cost.commodity_type[i];
99 std::string padding = cid.index() < 10 ? "0" : "";
100 std::string description = "@$" + padding + std::to_string(cid.index());
101 text::add_unparsed_text_to_layout_box(state, contents, box, description);
102
103 text::localised_format_box(state, contents, box, "alice_spending_commodity", m);
104 text::close_layout_box(contents, box);
105 total_cost += cost * amount;
106 } else {
107 break;
108 }
109 }
110 // Everyday supply costs
111 {
112 auto box = text::open_layout_box(contents, 0);
113 text::localised_format_box(state, contents, box, "unit_supply_needs");
114 text::close_layout_box(contents, box);
115 }
116 auto o_sc_mod = std::max(0.01f, state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::supply_consumption) + 1.0f);
117 auto& supply_cost = state.military_definitions.unit_base_definitions[fat_id.get_type()].supply_cost;
118 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
119 if(supply_cost.commodity_type[i]) {
120 float cost = state.world.commodity_get_cost(supply_cost.commodity_type[i]);
121 float curstr = military::unit_get_strength(state, fat_id);
122 float amount = supply_cost.commodity_amounts[i] * state.world.nation_get_unit_stats(state.local_player_nation, fat_id.get_type()).supply_consumption * o_sc_mod * curstr;
124 text::add_to_substitution_map(m, text::variable_type::name, state.world.commodity_get_name(supply_cost.commodity_type[i]));
128 auto box = text::open_layout_box(contents, 0);
129
130 auto cid = supply_cost.commodity_type[i];
131 std::string padding = cid.index() < 10 ? "0" : "";
132 std::string description = "@$" + padding + std::to_string(cid.index());
133 text::add_unparsed_text_to_layout_box(state, contents, box, description);
134
135 text::localised_format_box(state, contents, box, "alice_spending_commodity", m);
136 text::close_layout_box(contents, box);
137 total_cost += cost * amount;
138 } else {
139 break;
140 }
141 }
144 auto box = text::open_layout_box(contents, 0);
145 text::localised_format_box(state, contents, box, "alice_spending_unit_1", m);
146 text::close_layout_box(contents, box);
147 }
148};
149
151public:
152 void on_update(sys::state& state) noexcept override {
153 auto reg_id = retrieve<dcon::regiment_id>(state, parent);
154 auto base_pop = state.world.regiment_get_pop_from_regiment_source(reg_id);
155 if(!base_pop) {
156 frame = state.world.pop_type_get_sprite(state.culture_definitions.soldiers) - 1;
157 color = sys::pack_color(255, 75, 75);
158 } else {
159 frame = state.world.pop_type_get_sprite(state.world.pop_get_poptype(base_pop)) - 1;
160 if(state.world.pop_get_size(base_pop) < state.defines.pop_min_size_for_regiment) {
161 color = sys::pack_color(220, 75, 75);
162 } else if(state.world.pop_get_size(base_pop) < state.defines.pop_size_per_regiment) {
163 color = sys::pack_color(200, 200, 0);
164 } else {
165 color = sys::pack_color(255, 255, 255);
166 }
167 }
168 }
169
172 }
173
174 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
175 auto reg_id = retrieve<dcon::regiment_id>(state, parent);
176 auto base_pop = state.world.regiment_get_pop_from_regiment_source(reg_id);
177
178 if(!base_pop) {
179 text::add_line(state, contents, "reinforce_rate_none");
180 } else {
181 // Added culture name to the tooltip
182 text::add_line(state, contents, "x_from_y", text::variable_type::x, state.world.pop_get_poptype(base_pop).get_name(), text::variable_type::y, state.world.pop_get_province_from_pop_location(base_pop), text::variable_type::culture, state.world.pop_get_culture(base_pop).get_name());
184
185 auto reg_range = state.world.pop_get_regiment_source(base_pop);
186 text::add_line(state, contents, "pop_size_unitview",
187 text::variable_type::val, text::pretty_integer{ int64_t(state.world.pop_get_size(base_pop)) },
189 text::variable_type::current, int64_t(reg_range.end() - reg_range.begin())
190 );
191
192 auto a = state.world.regiment_get_army_from_army_membership(reg_id);
193 auto reinf = state.defines.pop_size_per_regiment * military::calculate_army_combined_reinforce(state, a);
194 if(reinf >= 2.0f) {
195 text::add_line(state, contents, "reinforce_rate", text::variable_type::x, int64_t(reinf));
196 } else {
197 text::add_line(state, contents, "reinforce_rate_none");
198 }
199 }
200 }
201};
202
203template<class T>
205public:
206 void on_update(sys::state& state) noexcept override {
207 if(parent) {
208 Cyto::Any payload = T{};
209 parent->impl_get(state, payload);
210 T content = any_cast<T>(payload);
211 dcon::unit_type_id utid = dcon::fatten(state.world, content).get_type();
212 if(utid)
213 frame = state.military_definitions.unit_base_definitions[utid].icon - 1;
214 }
215 }
216};
217
219 close = 0,
220 balance = 1,
221};
222
223template<class T>
225public:
226 void button_action(sys::state& state) noexcept override {
227 auto content = retrieve<T>(state, parent);
228 if(content)
230
231 }
232 void button_shift_action(sys::state& state) noexcept override {
233 auto content = retrieve<T>(state, parent);
234 if constexpr(std::is_same_v<T, dcon::regiment_id>) {
235 auto army = state.world.regiment_get_army_from_army_membership(content);
236 auto type = state.world.regiment_get_type(content);
237 for(auto r : state.world.army_get_army_membership(army)) {
238 if(r.get_regiment().get_type() == type) {
239 send(state, parent, element_selection_wrapper<T>{r.get_regiment().id});
240 }
241 }
242 } else {
243 auto n = state.world.ship_get_navy_from_navy_membership(content);
244 auto type = state.world.ship_get_type(content);
245 for(auto r : state.world.navy_get_navy_membership(n)) {
246 if(r.get_ship().get_type() == type) {
247 send(state, parent, element_selection_wrapper<T>{r.get_ship().id});
248 }
249 }
250 }
251 }
252};
253
254template<class T>
256public:
257 void on_update(sys::state& state) noexcept override {
258 if(parent) {
259 Cyto::Any payload = T{};
260 parent->impl_get(state, payload);
261 T content = any_cast<T>(payload);
262 dcon::unit_type_id utid = dcon::fatten(state.world, content).get_type();
263 if(utid)
264 set_text(state, text::produce_simple_string(state, state.military_definitions.unit_base_definitions[utid].name));
265 else
266 set_text(state, "");
267 }
268 }
269};
270
272public:
273 void on_update(sys::state& state) noexcept override {
274 if(parent) {
275 Cyto::Any payload = dcon::regiment_id{};
276 parent->impl_get(state, payload);
277 dcon::regiment_id content = any_cast<dcon::regiment_id>(payload);
278 if(content)
279 set_text(state, text::format_wholenum(int32_t(state.world.regiment_get_strength(content) * state.defines.pop_size_per_regiment)));
280 else
281 set_text(state, "");
282 }
283 }
284};
286public:
287 void on_update(sys::state& state) noexcept override {
288 if(parent) {
289 Cyto::Any payload = dcon::ship_id{};
290 parent->impl_get(state, payload);
291 dcon::ship_id content = any_cast<dcon::ship_id>(payload);
292 if(content)
293 set_text(state, text::format_percentage(state.world.ship_get_strength(content), 0));
294 else
295 set_text(state, "");
296 }
297 }
298};
299
300template<class T>
302public:
303 void on_update(sys::state& state) noexcept override {
304 if(parent) {
305 Cyto::Any payload = T{};
306 parent->impl_get(state, payload);
307 T content = any_cast<T>(payload);
308 std::string str{ state.to_string_view(dcon::fatten(state.world, content).get_name()) };
309 set_text(state, str);
310 }
311 }
312};
313
314template<class T>
317
318public:
319 void on_create(sys::state& state) noexcept override {
320 listrow::base_data.position.y += 128; // Nudge
323 }
324
325 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
326 if(name == "band_reorg_regiment") {
327 return make_element_by_type<reorg_unit_transfer_button<T>>(state, id);
328
329 } else if(name == "band_reorg_naval") {
330 return make_element_by_type<reorg_unit_transfer_button<T>>(state, id);
331
332 } else if(name == "unit_icon") {
333 return make_element_by_type<subunit_details_type_icon<T>>(state, id);
334 } else if(name == "subunit_name") {
335 return make_element_by_type<subunit_details_name<T>>(state, id);
336 } else if(name == "subunit_type") {
337 return make_element_by_type<subunit_details_type_text<T>>(state, id);
338 } else if(name == "subunit_strength") {
339 return make_element_by_type<subunit_details_regiment_amount>(state, id);
340 } else if(name == "subunit_strength_naval") {
341 return make_element_by_type<subunit_details_ship_amount>(state, id);
342 } else if(name == "connected_pop") {
343 if constexpr(std::is_same_v<T, dcon::regiment_id>) {
344 return make_element_by_type<regiment_pop_icon>(state, id);
345 } else {
346 return make_element_by_type<invisible_element>(state, id);
347 }
348 } else if(name == "rebel_faction") {
349 return make_element_by_type<invisible_element>(state, id);
350 } else if(name == "org_bar") {
351 return make_element_by_type<subunit_organisation_progress_bar<T>>(state, id);
352 } else if(name == "str_bar") {
353 return make_element_by_type<subunit_strength_progress_bar<T>>(state, id);
354 } else if(name == "transferbutton") {
355 return make_element_by_type<reorg_unit_transfer_button<T>>(state, id);
356 } else {
357 return nullptr;
358 }
359 }
360};
361
362template<class T, class T2>
363class reorg_unit_listbox_left : public listbox_element_base<reorg_unit_listbox_row<T2>, T2> {
365protected:
366 std::string_view get_row_element_name() override {
367 return "reorg_entry";
368 }
369
370public:
371 void on_update(sys::state& state) noexcept override {
373 auto content = retrieve<T>(state, listbox_left::parent);
374
375 Cyto::Any vpayload = std::vector<T2>{};
377 std::vector<T2> selectedunits = any_cast<std::vector<T2>>(vpayload);
378
379 auto fat = dcon::fatten(state.world, content);
380
382
383 if constexpr(std::is_same_v<T, dcon::army_id>) {
384 for(auto regi : fat.get_army_membership()) {
385 if(auto result = std::find(begin(selectedunits), end(selectedunits), regi.get_regiment().id); result == std::end(selectedunits)) {
386 listbox_left::row_contents.push_back(regi.get_regiment().id);
387 }
388 }
389 std::sort(listbox_left::row_contents.begin(), listbox_left::row_contents.end(), [&](dcon::regiment_id a, dcon::regiment_id b) {
390 auto av = state.world.regiment_get_type(a).index();
391 auto bv = state.world.regiment_get_type(b).index();
392 if(av != bv)
393 return av > bv;
394 else
395 return a.index() < b.index();
396 });
397 } else {
398 for(auto regi : fat.get_navy_membership()) {
399 if(auto result = std::find(begin(selectedunits), end(selectedunits), regi.get_ship().id); result == std::end(selectedunits)) {
400 listbox_left::row_contents.push_back(regi.get_ship().id);
401 }
402 }
403 std::sort(listbox_left::row_contents.begin(), listbox_left::row_contents.end(), [&](dcon::ship_id a, dcon::ship_id b) {
404 auto av = state.world.ship_get_type(a).index();
405 auto bv = state.world.ship_get_type(b).index();
406 if(av != bv)
407 return av > bv;
408 else
409 return a.index() < b.index();
410 });
411 }
412
414 }
415 }
416};
417
418template<class T, class T2>
419class reorg_unit_listbox_right : public listbox_element_base<reorg_unit_listbox_row<T2>, T2> {
421protected:
422 std::string_view get_row_element_name() override {
423 return "reorg_entry_right";
424 }
425
426public:
427 void on_update(sys::state& state) noexcept override {
429 auto content = retrieve<T>(state, listbox_right::parent);
430
431 Cyto::Any vpayload = std::vector<T2>{};
433 std::vector<T2> selectedunits = any_cast<std::vector<T2>>(vpayload);
434
435 auto fat = dcon::fatten(state.world, content);
436
438
439 if constexpr(std::is_same_v<T, dcon::army_id>) {
440 for(auto regi : fat.get_army_membership()) {
441 if(auto result = std::find(begin(selectedunits), end(selectedunits), regi.get_regiment().id); result != std::end(selectedunits)) {
442 listbox_right::row_contents.push_back(regi.get_regiment().id);
443 }
444 }
445 std::sort(listbox_right::row_contents.begin(), listbox_right::row_contents.end(), [&](dcon::regiment_id a, dcon::regiment_id b) {
446 auto av = state.world.regiment_get_type(a).index();
447 auto bv = state.world.regiment_get_type(b).index();
448 if(av != bv)
449 return av > bv;
450 else
451 return a.index() < b.index();
452 });
453 } else {
454 for(auto regi : fat.get_navy_membership()) {
455 if(auto result = std::find(begin(selectedunits), end(selectedunits), regi.get_ship().id); result != std::end(selectedunits)) {
456 listbox_right::row_contents.push_back(regi.get_ship().id);
457 }
458 }
459 std::sort(listbox_right::row_contents.begin(), listbox_right::row_contents.end(), [&](dcon::ship_id a, dcon::ship_id b) {
460 auto av = state.world.ship_get_type(a).index();
461 auto bv = state.world.ship_get_type(b).index();
462 if(av != bv)
463 return av > bv;
464 else
465 return a.index() < b.index();
466 });
467 }
468
470 }
471 }
472};
473
474
476public:
477 void button_action(sys::state& state) noexcept override {
478 if(parent) {
480 parent->impl_get(state, payload);
481 }
482 }
483};
484
486public:
487 void button_action(sys::state& state) noexcept override {
488 if(parent) {
490 parent->impl_get(state, payload);
491 }
492 }
493};
494
495template<class T, class T2>
497private:
498 std::vector<T2> selectedsubunits;
499 T unitToReorg{};
500 simple_text_element_base* orginialunit_text = nullptr;
501
502public:
503 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
504 if(name == "reorg_bg") {
505 return make_element_by_type<opaque_element_base>(state, id);
506
507 } else if(name == "reorg_label") {
508 return make_element_by_type<simple_text_element_base>(state, id);
509
510 } else if(name == "unitname_1") {
511 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
512 orginialunit_text = ptr.get();
513 return ptr;
514
515 } else if(name == "unitname_2") {
516 return make_element_by_type<simple_text_element_base>(state, id);
517
518 } else if(name == "cell_window_left" || name == "cell_window_right") {
519 return make_element_by_type<invisible_element>(state, id);
520
521 } else if(name == "balancebutton") {
522 return make_element_by_type<unit_reorg_balance_button>(state, id);
523
524 } else if(name == "closebutton") {
525 return make_element_by_type<reorg_win_close_button>(state, id);
526
527 } else if(name == "left_list") {
528 if constexpr(std::is_same_v<T, dcon::army_id>) {
529 auto ptr = make_element_by_type<reorg_unit_listbox_left<T, T2>>(state, id);
530 //ptr->base_data.position.x += 255; // Nudge
531 //ptr->list_scrollbar->base_data.position.x += 256;
532 ptr->base_data.size.x += 256;
533 return ptr;
534 } else {
535 auto ptr = make_element_by_type<reorg_unit_listbox_left<T, T2>>(state, id);
536 //ptr->base_data.position.x += 255; // Nudge
537 //ptr->list_scrollbar->base_data.position.x += 256;
538 ptr->base_data.size.x += 256;
539 return ptr;
540 }
541
542 } else if(name == "right_list") {
543 if constexpr(std::is_same_v<T, dcon::army_id>) {
544 auto ptr = make_element_by_type<reorg_unit_listbox_right<T, T2>>(state, id);
545 //ptr->base_data.position.x += 255; // Nudge
546 //ptr->list_scrollbar->base_data.position.x += 256;
547 ptr->base_data.size.x += 256;
548 return ptr;
549 } else {
550 auto ptr = make_element_by_type<reorg_unit_listbox_right<T, T2>>(state, id);
551 //ptr->base_data.position.x += 255; // Nudge
552 //ptr->list_scrollbar->base_data.position.x += 256;
553 ptr->base_data.size.x += 256;
554 return ptr;
555 }
556
557 } else if(name == "external_scroll_slider_left" || name == "external_scroll_slider_right") {
558 return make_element_by_type<invisible_element>(state, id);
559
560 } else {
561 return nullptr;
562 }
563 }
564
565 void on_update(sys::state& state) noexcept override {
566 unitToReorg = retrieve<T>(state, parent);
567 auto fat = dcon::fatten(state.world, unitToReorg);
568 orginialunit_text->set_text(state, std::string(state.to_string_view(fat.get_name())));
569 }
570
571 void on_visible(sys::state& state) noexcept override {
572 selectedsubunits.clear();
573 }
574 void on_hide(sys::state& state) noexcept override {
575 selectedsubunits.clear();
576 }
577
578 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
579 if(payload.holds_type<element_selection_wrapper<T>>()) {
580 unitToReorg = any_cast<element_selection_wrapper<T>>(payload).data;
582 } else if(payload.holds_type<T>()) {
583 payload.emplace<T>(unitToReorg);
585 } else if(payload.holds_type<element_selection_wrapper<T2>>()) {
586 auto content = any_cast<element_selection_wrapper<T2>>(payload).data;
587 if(!selectedsubunits.empty()) {
588 if(auto result = std::find(selectedsubunits.begin(), selectedsubunits.end(), content); result != selectedsubunits.end()) {
589 selectedsubunits.erase(result);
590 } else {
591 selectedsubunits.push_back(content);
592 }
593 } else {
594 selectedsubunits.push_back(content);
595 }
598 } else if(payload.holds_type<std::vector<T2>>()) {
599 payload.emplace<std::vector<T2>>(selectedsubunits);
601 } else if(payload.holds_type<element_selection_wrapper<reorg_win_action>>()) {
602 auto content = any_cast<element_selection_wrapper<reorg_win_action>>(payload).data;
603 switch(content) {
605 if(selectedsubunits.size() <= command::num_packed_units && !selectedsubunits.empty()) {
606 if constexpr(std::is_same_v<T2, dcon::regiment_id>) {
607 std::array<dcon::regiment_id, command::num_packed_units> tosplit{};
608 for(size_t i = 0; i < selectedsubunits.size(); i++) {
609 tosplit[i] = selectedsubunits[i];
610 }
611 command::mark_regiments_to_split(state, state.local_player_nation, tosplit);
612 command::split_army(state, state.local_player_nation, unitToReorg);
613 } else {
614 std::array<dcon::ship_id, command::num_packed_units> tosplit{};
615 for(size_t i = 0; i < selectedsubunits.size(); i++) {
616 tosplit[i] = selectedsubunits[i];
617 }
618 command::mark_ships_to_split( state, state.local_player_nation, tosplit);
619 command::split_navy(state, state.local_player_nation, unitToReorg);
620 }
621 } else if(selectedsubunits.size() > command::num_packed_units){
622 if constexpr(std::is_same_v<T2, dcon::regiment_id>) {
623 std::array<dcon::regiment_id, command::num_packed_units> tosplit{};
624 //while(selectedsubunits.size() > command::num_packed_units) {
625 while(selectedsubunits.size() > 0) {
626 tosplit.fill(dcon::regiment_id{});
627 for(size_t i = 0; i < command::num_packed_units && i < selectedsubunits.size(); i++) {
628 tosplit[i] = selectedsubunits[i];
629 }
630 command::mark_regiments_to_split(state, state.local_player_nation, tosplit);
631 (selectedsubunits.size() > command::num_packed_units) ? selectedsubunits.erase(selectedsubunits.begin(), selectedsubunits.begin() + command::num_packed_units)
632 : selectedsubunits.erase(selectedsubunits.begin(), selectedsubunits.end());
633 }
634 command::split_army(state, state.local_player_nation, unitToReorg);
635 } else {
636 std::array<dcon::ship_id, command::num_packed_units> tosplit{};
637 //while(selectedsubunits.size() > command::num_packed_units) {
638 while(selectedsubunits.size() > 0) {
639 tosplit.fill(dcon::ship_id{});
640 for(size_t i = 0; i < command::num_packed_units && i < selectedsubunits.size(); i++) {
641 tosplit[i] = selectedsubunits[i];
642 }
643 command::mark_ships_to_split(state, state.local_player_nation, tosplit);
644 (selectedsubunits.size() > command::num_packed_units) ? selectedsubunits.erase(selectedsubunits.begin(), selectedsubunits.begin() + command::num_packed_units)
645 : selectedsubunits.erase(selectedsubunits.begin(), selectedsubunits.end());
646 }
647 command::split_navy(state, state.local_player_nation, unitToReorg);
648 }
649 }
650 if(selectedsubunits.empty()) { selectedsubunits.erase(selectedsubunits.begin(), selectedsubunits.end()); }
651 set_visible(state, false);
652 break;
654 // Disregard any of the units the player already selected, because its our way or the hi(fi)-way
655 selectedsubunits.erase(selectedsubunits.begin(), selectedsubunits.end());
656 if constexpr(std::is_same_v<T, dcon::army_id>) {
657 for(auto reg : dcon::fatten(state.world, unitToReorg).get_army_membership()) {
658 selectedsubunits.push_back(reg.get_regiment().id);
659 }
660 } else {
661 for(auto reg : dcon::fatten(state.world, unitToReorg).get_navy_membership()) {
662 selectedsubunits.push_back(reg.get_ship().id);
663 }
664 }
665 std::sort(selectedsubunits.begin(), selectedsubunits.end(), [&](auto a, auto b){return dcon::fatten(state.world,a).get_type().value > dcon::fatten(state.world,b).get_type().value;});
666 //for(size_t i = selectedsubunits.size(); i > 0; i--) {
667 for(size_t i = selectedsubunits.size(); i-->0;) {
668 if((i % 2) == 0) {
669 selectedsubunits.erase(selectedsubunits.begin() + i);
670 }
671 }
673 break;
674 default:
675 break;
676 }
678 }
680 }
681};
682
683} // namespace ui
dcon::text_key get_name() noexcept
void impl_on_update(sys::state &state) noexcept override
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
virtual void on_create(sys::state &state) noexcept
element_data base_data
void set_visible(sys::state &state, bool vis)
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 on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_create(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 button_shift_action(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void on_update(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
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
void button_action(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_visible(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 on_update(sys::state &state) noexcept override
void on_hide(sys::state &state) noexcept override
void mark_ships_to_split(sys::state &state, dcon::nation_id source, std::array< dcon::ship_id, num_packed_units > const &list)
Definition: commands.cpp:4417
constexpr size_t num_packed_units
Definition: commands.hpp:414
void mark_regiments_to_split(sys::state &state, dcon::nation_id source, std::array< dcon::regiment_id, num_packed_units > const &list)
Definition: commands.cpp:4396
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
float calculate_army_combined_reinforce(sys::state &state, dcon::army_id a)
Definition: military.cpp:7343
int32_t regiments_possible_from_pop(sys::state &state, dcon::pop_id p)
Definition: military.cpp:851
float unit_get_strength(sys::state &state, dcon::regiment_id regiment_id)
Definition: military.cpp:7334
uint32_t pack_color(float r, float g, float b)
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_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1904
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1923
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
Definition: text.cpp:1152
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
Definition: text.cpp:1068
std::string format_wholenum(int32_t num)
Definition: text.cpp:1033
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
Definition: text.hpp:797
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
std::string format_percentage(float num, size_t digits)
Definition: text.cpp:977
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1831
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
message_result
void active_modifiers_description(sys::state &state, text::layout_base &layout, dcon::nation_id n, int32_t identation, dcon::national_modifier_value nmid, bool header)
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,...