Project Alice
Loading...
Searching...
No Matches
gui_politics_window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "commands.hpp"
4#include "culture.hpp"
5#include "cyto_any.hpp"
6#include "dcon_generated.hpp"
9#include "gui_graphics.hpp"
15#include "nations.hpp"
16#include "politics.hpp"
17#include "system_state.hpp"
18#include "text.hpp"
19#include <cstdint>
20#include <string_view>
21#include <vector>
22
23namespace ui {
24
26public:
27 int32_t get_icon_frame(sys::state& state, dcon::nation_id nation_id) noexcept override {
28 auto nat_val = state.world.nation_get_national_value(nation_id);
29 return nat_val.get_icon();
30 }
31
34 }
35
36 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
37 auto nation_id = retrieve<dcon::nation_id>(state, parent);
38 auto fat_id = dcon::fatten(state.world, nation_id);
39 if(auto name = fat_id.get_national_value().get_name(); state.key_is_localized(name)) {
40 auto box = text::open_layout_box(contents, 0);
41 text::localised_single_sub_box(state, contents, box, "politics_nationalvalue_tooltip", text::variable_type::nationalvalue, name);
42 text::close_layout_box(contents, box);
43 }
44 auto mod_id = fat_id.get_national_value().id;
45 if(bool(mod_id)) {
46 modifier_description(state, contents, mod_id);
47 }
48 }
49};
50
51
52enum class politics_window_tab : uint8_t { reforms = 0x0, movements = 0x1, decisions = 0x2, releasables = 0x3 };
53
55
57public:
58 std::string get_text(sys::state& state, dcon::nation_id nation_id) noexcept override {
59 auto plurality = state.world.nation_get_plurality(nation_id);
60 return std::to_string(int32_t(plurality)) + '%';
61 }
62
65 }
66
67 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
68 auto box = text::open_layout_box(contents);
69 text::localised_format_box(state, contents, box, "plurality");
71 text::localised_format_box(state, contents, box, "plurality_explanation");
73 text::localised_format_box(state, contents, box, "plurality_change");
75 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
76 text::add_to_layout_box(state, contents, box,
77 text::fp_two_places{state.world.nation_get_demographics(state.local_player_nation, demographics::consciousness) * 0.0222f / std::max(state.world.nation_get_demographics(state.local_player_nation, demographics::total), 1.0f)},
79 text::close_layout_box(contents, box);
80 text::add_line(state, contents, "plurality_change_reason");
81 }
82};
83
85public:
86 std::string get_text(sys::state& state, dcon::nation_id nation_id) noexcept override {
87 auto revanchism = state.world.nation_get_revanchism(nation_id);
88 return std::to_string(int32_t(revanchism * 100.0f)) + '%';
89 }
92 }
93
94 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
95 text::add_line(state, contents, "revanchism");
96 text::add_line(state, contents, "revanchism_explanation");
97 text::add_line(state, contents, "revanchism_reason");
98 }
99};
100
102public:
103 int32_t get_icon_frame(sys::state& state, dcon::nation_id nation_id) noexcept override {
104 set_visible(state, !state.world.nation_get_is_civilized(nation_id));
105 return 0;
106 }
107};
108
109class politics_upper_house_entry : public listbox_row_element_base<dcon::ideology_id> {
110public:
111 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
112 if(name == "ideology_icon") {
113 return make_element_by_type<ideology_plupp>(state, id);
114 } else if(name == "ideology_name") {
115 return make_element_by_type<generic_name_text<dcon::ideology_id>>(state, id);
116 } else if(name == "ideology_perc") {
117 return make_element_by_type<nation_ideology_percentage_text>(state, id);
118 } else {
119 return nullptr;
120 }
121 }
122};
123
125public:
126 void button_action(sys::state& state) noexcept override {
127 command::start_election(state, state.local_player_nation);
128 }
129
130 void on_update(sys::state& state) noexcept override {
131 disabled = !command::can_start_election(state, state.local_player_nation);
132 }
133};
134
135class politics_upper_house_listbox : public listbox_element_base<politics_upper_house_entry, dcon::ideology_id> {
136protected:
137 std::string_view get_row_element_name() override {
138 return "ideology_option_window";
139 }
140
141public:
142 void on_update(sys::state& state) noexcept override {
143 row_contents.clear();
144 state.world.for_each_ideology([&](dcon::ideology_id ideology_id) {
145 if(state.world.nation_get_upper_house(state.local_player_nation, ideology_id) > 0.f)
146 row_contents.push_back(ideology_id);
147 });
148 update(state);
149 }
150};
151
153 void on_update(sys::state& state) noexcept override {
154 auto option = retrieve<dcon::issue_option_id>(state, parent);
155 set_text(state, text::produce_simple_string(state, state.world.issue_option_get_name(option)));
156 }
157 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
159 }
160 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
161 auto option = retrieve<dcon::issue_option_id>(state, parent);
162 reform_description(state, contents, option);
163 }
164};
165
166class politics_party_issue_entry : public listbox_row_element_base<dcon::issue_option_id> {
167public:
168 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
169 if(name == "issue_group") {
170 return make_element_by_type<generic_name_text<dcon::issue_id>>(state, id);
171 } else if(name == "issue_name") {
172 return make_element_by_type<issue_option_text>(state, id);
173 } else {
174 return nullptr;
175 }
176 }
177
178 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
179 if(payload.holds_type<dcon::issue_id>()) {
180 payload.emplace<dcon::issue_id>(state.world.issue_option_get_parent_issue(content).id);
182 }
184 }
185};
186
187class politics_party_issues_listbox : public listbox_element_base<politics_party_issue_entry, dcon::issue_option_id> {
188protected:
189 std::string_view get_row_element_name() override {
190 return "party_issue_option_window";
191 }
192
193public:
194 void on_update(sys::state& state) noexcept override {
195 auto party = retrieve<dcon::political_party_id>(state, parent);
196 row_contents.clear();
197 for(auto& issue : state.culture_definitions.party_issues) {
198 auto issue_option = state.world.political_party_get_party_issues(party, issue);
199 if(issue_option) {
200 row_contents.push_back(issue_option.id);
201 }
202 }
203 update(state);
204 }
205};
206
208public:
209 void on_update(sys::state& state) noexcept override {
210 if(parent) {
211 auto political_party_id = retrieve<dcon::political_party_id>(state, parent);
212 set_button_text(state, text::produce_simple_string(state, state.world.political_party_get_name(political_party_id)));
213
214 disabled = !command::can_appoint_ruling_party(state, state.local_player_nation, political_party_id);
215 }
216 }
217
218 void button_action(sys::state& state) noexcept override {
219 if(parent) {
220 auto political_party_id = retrieve<dcon::political_party_id>(state, parent);
221
222 command::appoint_ruling_party(state, state.local_player_nation, political_party_id);
223
224 auto lb = parent->parent;
225 if(!lb)
226 return;
227 auto window = lb->parent;
228 if(!window)
229 return;
230 window->set_visible(state, false);
231 }
232 }
233
236 }
237
238 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
239 auto party = retrieve<dcon::political_party_id>(state, parent);
240 {
241 auto box = text::open_layout_box(contents);
242 text::add_to_layout_box(state, contents, box, state.world.political_party_get_name(party));
243 text::add_space_to_layout_box(state, contents, box);
244 text::add_to_layout_box(state, contents, box, std::string_view{ "(" });
245 text::add_to_layout_box(state, contents, box, state.world.ideology_get_name(state.world.political_party_get_ideology(party)));
246 text::add_to_layout_box(state, contents, box, std::string_view{ ")" });
247 text::close_layout_box(contents, box);
248 }
249
250 for(auto pi : state.culture_definitions.party_issues) {
251 reform_description(state, contents, state.world.political_party_get_party_issues(party, pi));
253 }
254
255 if(state.world.political_party_get_trigger(party)) {
256 text::add_line(state, contents, "alice_political_party_trigger", text::variable_type::date_long_0, state.world.political_party_get_start_date(party),
257 text::variable_type::date_long_1, state.world.political_party_get_end_date(party));
258 ui::trigger_description(state, contents, state.world.political_party_get_trigger(party), trigger::to_generic(state.local_player_nation), trigger::to_generic(state.local_player_nation), -1);
259 } else {
260 text::add_line(state, contents, "alice_political_party_no_trigger", text::variable_type::date_long_0, state.world.political_party_get_start_date(party),
261 text::variable_type::date_long_1, state.world.political_party_get_end_date(party));
262 }
263 }
264};
265
266class politics_all_party_entry : public listbox_row_element_base<dcon::political_party_id> {
267public:
268 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
269 if(name == "party_name") {
270 return make_element_by_type<politics_choose_party_button>(state, id);
271 } else if(name == "party_icon") {
272 return make_element_by_type<ideology_plupp>(state, id);
273 } else if(name == "issue_listbox") {
274 return make_element_by_type<politics_party_issues_listbox>(state, id);
275 } else {
276 return nullptr;
277 }
278 }
279
280 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
281 if(payload.holds_type<dcon::ideology_id>()) {
282 payload.emplace<dcon::ideology_id>(state.world.political_party_get_ideology(content));
284 }
286 }
287};
288
289class politics_all_party_listbox : public listbox_element_base<politics_all_party_entry, dcon::political_party_id> {
290protected:
291 std::string_view get_row_element_name() override {
292 return "party_window";
293 }
294
295 void on_update(sys::state& state) noexcept override {
296 row_contents.clear();
298 update(state);
299 }
300};
301
303public:
304 void on_create(sys::state& state) noexcept override {
306 base_data.position.y -= 66;
307 }
308
309 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
310 if(name == "all_party_window_close") {
311 return make_element_by_type<generic_close_button>(state, id);
312 } else if(name == "party_listbox") {
313 return make_element_by_type<politics_all_party_listbox>(state, id);
314 } else {
315 return nullptr;
316 }
317 }
318};
319
321private:
322 politics_all_party_window* all_party_window = nullptr;
323
324public:
325 void on_update(sys::state& state) noexcept override {
326 auto party = state.world.nation_get_ruling_party(state.local_player_nation);
327 set_button_text(state, text::produce_simple_string(state, state.world.political_party_get_name(party)));
328 }
329
330 void button_action(sys::state& state) noexcept override {
331 if(all_party_window == nullptr) {
332 auto ptr = make_element_by_type<politics_all_party_window>(state, "all_party_window");
333 all_party_window = static_cast<politics_all_party_window*>(ptr.get());
334 parent->parent->add_child_to_front(std::move(ptr));
335 } else {
336 all_party_window->set_visible(state, !all_party_window->is_visible());
337 }
338 if(all_party_window && all_party_window->is_visible()) {
339 all_party_window->impl_on_update(state);
340 }
341 }
342
345 }
346
347 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
348 auto ruling_party = state.world.nation_get_ruling_party(state.local_player_nation);
349 {
350 auto box = text::open_layout_box(contents);
351 text::add_to_layout_box(state, contents, box, state.world.political_party_get_name(ruling_party));
352 text::add_space_to_layout_box(state, contents, box);
353 text::add_to_layout_box(state, contents, box, std::string_view{ "(" });
354 text::add_to_layout_box(state, contents, box, state.world.ideology_get_name(state.world.political_party_get_ideology(ruling_party)));
355 text::add_to_layout_box(state, contents, box, std::string_view{ ")" });
356 text::close_layout_box(contents, box);
357 }
358 for(auto pi : state.culture_definitions.party_issues) {
359 reform_description(state, contents, ruling_party.get_party_issues(pi));
361 }
362 }
363};
364
366public:
367 void on_create(sys::state& state) noexcept override {
369 base_data.position = state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key("ruling_party_pos"))->second.definition].position;
370 }
371
372 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
373 if(name == "politics_selectparty_entrybg") {
374 return make_element_by_type<invisible_element>(state, id);
375 } else if(name == "party_name") {
376 return make_element_by_type<politics_change_party_button>(state, id);
377 } else if(name == "party_icon") {
378 return make_element_by_type<nation_ruling_party_ideology_plupp>(state, id);
379 } else if(name == "issue_listbox") {
380 return make_element_by_type<politics_party_issues_listbox>(state, id);
381 } else {
382 return nullptr;
383 }
384 }
385
386 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
387 if(payload.holds_type<dcon::political_party_id>()) {
388 payload.emplace<dcon::political_party_id>(state.world.nation_get_ruling_party(state.local_player_nation));
390 }
391 return window_element_base::get(state, payload);
392 }
393};
394
396public:
397 void populate_layout(sys::state& state, text::endless_layout& contents, dcon::nation_id nation_id) noexcept override {
399 auto box = text::open_layout_box(contents);
400 text::localised_format_box(state, contents, box, std::string_view("can_appoint_ruling_party"));
401 text::close_layout_box(contents, box);
402 }
403 if(!politics::has_elections(state, nation_id)) {
404 auto box = text::open_layout_box(contents);
405 text::localised_format_box(state, contents, box, std::string_view("term_for_life"));
406 text::close_layout_box(contents, box);
407 } else if(politics::is_election_ongoing(state, nation_id)) {
408 auto box = text::open_layout_box(contents);
409 text::localised_format_box(state, contents, box, std::string_view("election_info_in_gov"));
410 text::close_layout_box(contents, box);
411 } else {
412 auto box = text::open_layout_box(contents);
413 auto election_start_date = politics::next_election_date(state, nation_id);
414 text::localised_format_box(state, contents, box, std::string_view("next_election"));
415 text::add_to_layout_box(state, contents, box, std::string(":"), text::text_color::black);
416 text::add_space_to_layout_box(state, contents, box);
418 text::close_layout_box(contents, box);
419 }
420 }
421};
422
424public:
425 virtual std::string get_text(sys::state& state, dcon::issue_option_id issue_option_id) noexcept {
426 return "";
427 }
428
429 void on_update(sys::state& state) noexcept override {
430 auto content = retrieve<dcon::issue_option_id>(state, parent);
431 set_text(state, get_text(state, content));
432 }
433};
434
436public:
437 std::string get_text(sys::state& state, dcon::issue_option_id issue_option_id) noexcept override {
438 return text::format_percentage(politics::get_popular_support(state, state.local_player_nation, issue_option_id), 1);
439 }
440};
441
443public:
444 std::string get_text(sys::state& state, dcon::issue_option_id issue_option_id) noexcept override {
445 return text::format_percentage(politics::get_voter_support(state, state.local_player_nation, issue_option_id), 1);
446 }
447};
448
449class politics_issue_support_item : public listbox_row_element_base<dcon::issue_option_id> {
450public:
451 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
452 if(name == "issue_name") {
453 return make_element_by_type<generic_name_text<dcon::issue_option_id>>(state, id);
454 } else if(name == "people_perc") {
455 return make_element_by_type<issue_option_popular_support>(state, id);
456 } else if(name == "voters_perc") {
457 return make_element_by_type<issue_option_voter_support>(state, id);
458 } else {
459 return nullptr;
460 }
461 }
462};
463
464class politics_issue_support_listbox : public listbox_element_base<politics_issue_support_item, dcon::issue_option_id> {
465protected:
466 std::string_view get_row_element_name() override {
467 return "issue_option_window";
468 }
469public:
470 void on_create(sys::state& state) noexcept override {
472 state.world.for_each_issue_option([&](dcon::issue_option_id io_id) { row_contents.push_back(io_id); });
473 update(state);
474 }
475};
476
478 void on_update(sys::state& state) noexcept override {
479 disabled = !command::can_start_election(state, state.local_player_nation);
480 }
481
482 void button_action(sys::state& state) noexcept override {
483 command::start_election(state, state.local_player_nation);
484 }
485};
486
487
489public:
490 bool get_horizontal_flip(sys::state& state) noexcept override {
491 return false; //never flip
492 }
493
494 void on_update(sys::state& state) noexcept override {
495 sys::dated_modifier mod = retrieve< sys::dated_modifier>(state, parent);
496 if(mod.mod_id) {
497 frame = int8_t(state.world.modifier_get_icon(mod.mod_id)) + 1;
498 }
499 }
500
503 }
504
505 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
506 sys::dated_modifier mod = retrieve< sys::dated_modifier>(state, parent);
507 if(mod.mod_id) {
508 text::add_line(state, contents, state.world.modifier_get_name(mod.mod_id));
509 modifier_description(state, contents, mod.mod_id, 15);
510 }
511 if(mod.expiration) {
512 text::add_line(state, contents, "expires_on", text::variable_type::date, mod.expiration);
513 }
514 }
515};
516
518public:
520
521 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
522 if(name == "country_modifier_icon") {
523 return make_element_by_type<national_modifier_icon>(state, id);
524 } else {
525 return nullptr;
526 }
527 }
528
529 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
530 if(payload.holds_type<sys::dated_modifier>()) {
531 payload.emplace<sys::dated_modifier>(mod);
533 }
535 }
536
537};
538
539class national_modifiers : public overlapping_listbox_element_base<national_modifier_win, sys::dated_modifier> {
540public:
541 std::string_view get_row_element_name() override {
542 return "country_modifier_item";
543 }
545 subwindow.mod = content;
546 }
547 void on_update(sys::state& state) noexcept override {
548 row_contents.clear();
549
550 for(auto mods : state.world.nation_get_current_modifiers(state.local_player_nation)) {
551 row_contents.push_back(mods);
552 }
553
554 for(auto tm : state.national_definitions.triggered_modifiers) {
555 if(tm.trigger_condition && tm.linked_modifier) {
556 auto trigger_condition_satisfied =
557 trigger::evaluate(state, tm.trigger_condition, trigger::to_generic(state.local_player_nation), trigger::to_generic(state.local_player_nation), 0);
558 if(trigger_condition_satisfied)
559 row_contents.push_back(sys::dated_modifier{ sys::date{}, tm.linked_modifier });
560 }
561 }
562
563 update(state);
564 }
565};
566
567
569public:
571 void button_action(sys::state& state) noexcept override {
573 }
574};
575
576class politics_window : public generic_tabbed_window<politics_window_tab> {
577private:
578 reforms_window* reforms_win = nullptr;
579 unciv_reforms_window* unciv_reforms_win = nullptr;
580 movements_window* movements_win = nullptr;
581 decision_window* decision_win = nullptr;
582 release_nation_window* release_nation_win = nullptr;
583 politics_issue_support_listbox* issues_listbox = nullptr;
584 element_base* release_win = nullptr;
585 dcon::nation_id release_nation_id{};
586
587public:
588 void on_create(sys::state& state) noexcept override {
590 {
591 auto ptr = make_element_by_type<politics_ruling_party_window>(state, "party_window");
592 add_child_to_front(std::move(ptr));
593 }
594 {
595 auto ptr = make_element_by_type<politics_release_nation_window>(state, "releaseconfirm");
596 release_win = ptr.get();
597 add_child_to_front(std::move(ptr));
598 }
599 set_visible(state, false);
600 }
601 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
602 if(name == "main_bg") {
603 return make_element_by_type<image_element_base>(state, id);
604 } else if(name == "bg_politics") {
605 return make_element_by_type<opaque_element_base>(state, id);
606 } else if(name == "close_button") {
607 return make_element_by_type<generic_close_button>(state, id);
608 } else if(name == "reforms_tab") {
609 auto ptr = make_element_by_type<generic_tab_button<politics_window_tab>>(state, id);
610 ptr->target = politics_window_tab::reforms;
611 return ptr;
612 } else if(name == "movements_tab") {
613 auto ptr = make_element_by_type<generic_tab_button<politics_window_tab>>(state, id);
614 ptr->target = politics_window_tab::movements;
615 return ptr;
616 } else if(name == "decisions_tab") {
617 auto ptr = make_element_by_type<generic_tab_button<politics_window_tab>>(state, id);
618 ptr->target = politics_window_tab::decisions;
619 return ptr;
620 } else if(name == "release_nations_tab") {
621 auto ptr = make_element_by_type<generic_tab_button<politics_window_tab>>(state, id);
623 return ptr;
624 } else if(name == "reforms_window") {
625 auto ptr = make_element_by_type<reforms_window>(state, id);
626 reforms_win = ptr.get();
627 ptr->set_visible(state, true);
628 return ptr;
629 } else if(name == "movements_window") {
630 auto ptr = make_element_by_type<movements_window>(state, id);
631 movements_win = ptr.get();
632 ptr->set_visible(state, false);
633 return ptr;
634 } else if(name == "decision_window") {
635 auto ptr = make_element_by_type<decision_window>(state, id);
636 decision_win = ptr.get();
637 ptr->set_visible(state, false);
638 return ptr;
639 } else if(name == "release_nation") {
640 auto ptr = make_element_by_type<release_nation_window>(state, id);
641 release_nation_win = ptr.get();
642 ptr->set_visible(state, false);
643 return ptr;
644 } else if(name == "unciv_reforms_window") {
645 auto ptr = make_element_by_type<unciv_reforms_window>(state, id);
646 unciv_reforms_win = ptr.get();
647 ptr->set_visible(state, false);
648 return ptr;
649 } else if(name == "country_modifier_overlappingbox") {
650 return make_element_by_type<national_modifiers>(state, id);
651 } else if(name == "government_name") {
652 return make_element_by_type<nation_government_type_text>(state, id);
653 } else if(name == "government_desc") {
654 return make_element_by_type<nation_government_description_text>(state, id);
655 } else if(name == "national_value") {
656 return make_element_by_type<nation_national_value_icon>(state, id);
657 } else if(name == "plurality_value") {
658 return make_element_by_type<nation_plurality_text>(state, id);
659 } else if(name == "revanchism_value") {
660 return make_element_by_type<nation_revanchism_text>(state, id);
661 } else if(name == "can_do_social_reforms") {
662 return make_element_by_type<nation_can_do_social_reform_text>(state, id);
663 } else if(name == "social_reforms_bock") {
664 return make_element_by_type<nation_can_do_social_reform_icon>(state, id);
665 } else if(name == "can_do_political_reforms") {
666 return make_element_by_type<nation_can_do_political_reform_text>(state, id);
667 } else if(name == "political_reforms_bock") {
668 return make_element_by_type<nation_can_do_political_reform_icon>(state, id);
669 } else if(name == "chart_upper_house") {
670 return make_element_by_type<upper_house_piechart>(state, id);
671 } else if(name == "chart_voters_ideologies") {
672 return make_element_by_type<voter_ideology_piechart>(state, id);
673 } else if(name == "chart_people_ideologies") {
674 return make_element_by_type<ideology_piechart<dcon::nation_id>>(state, id);
675 } else if(name == "upperhouse_ideology_listbox") {
676 return make_element_by_type<politics_upper_house_listbox>(state, id);
677 } else if(name == "unciv_overlay") {
678 return make_element_by_type<politics_unciv_overlay>(state, id);
679 } else if(name == "hold_election") {
680 return make_element_by_type<politics_hold_election_button>(state, id);
681 } else if(name == "issue_listbox") {
682 auto ptr = make_element_by_type<politics_issue_support_listbox>(state, id);
683 issues_listbox = ptr.get();
684 return ptr;
685 } else if(name == "sort_by_issue_name") {
686 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
688 return ptr;
689 } else if(name == "sort_by_people") {
690 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
692 return ptr;
693 } else if(name == "sort_by_voters") {
694 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
696 return ptr;
697 } else {
698 return nullptr;
699 }
700 }
701 void on_update(sys::state& state) noexcept override {
702 if(state.world.nation_get_is_civilized(state.local_player_nation) && unciv_reforms_win->is_visible()) {
703 unciv_reforms_win->set_visible(state, false);
704 reforms_win->set_visible(state, true);
705 } else if(!state.world.nation_get_is_civilized(state.local_player_nation) && reforms_win->is_visible()) {
706 reforms_win->set_visible(state, false);
707 unciv_reforms_win->set_visible(state, true);
708 }
709 }
710
712 reforms_win->set_visible(state, false);
713 unciv_reforms_win->set_visible(state, false);
714 decision_win->set_visible(state, false);
715 movements_win->set_visible(state, false);
716 release_nation_win->set_visible(state, false);
717 }
718
719 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
720 if(payload.holds_type<politics_window_tab>()) {
721 auto enum_val = any_cast<politics_window_tab>(payload);
723 switch(enum_val) {
725 if(state.world.nation_get_is_civilized(state.local_player_nation)) {
726 reforms_win->set_visible(state, true);
727 } else {
728 unciv_reforms_win->set_visible(state, true);
729 }
730 break;
732 movements_win->set_visible(state, true);
733 break;
735 decision_win->set_visible(state, true);
736 break;
738 release_nation_win->set_visible(state, true);
739 break;
740 default:
741 break;
742 }
743 active_tab = enum_val;
745 } else if(payload.holds_type<dcon::nation_id>()) {
746 payload.emplace<dcon::nation_id>(state.local_player_nation);
748 } else if(payload.holds_type<release_query_wrapper>()) {
749 payload.emplace<dcon::nation_id>(release_nation_id);
751 } else if(payload.holds_type<release_emplace_wrapper>()) {
752 release_nation_id = any_cast<release_emplace_wrapper>(payload).content;
753 release_win->set_visible(state, true);
754 move_child_to_front(release_win);
756 } else if(payload.holds_type<politics_issue_sort_order>()) {
757 auto enum_val = any_cast<politics_issue_sort_order>(payload);
758 switch(enum_val) {
760 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
761 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
762 auto a_name = text::get_name_as_string(state, dcon::fatten(state.world, a));
763 auto b_name = text::get_name_as_string(state, dcon::fatten(state.world, b));
764 return a_name < b_name;
765 });
766 issues_listbox->update(state);
767 break;
769 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
770 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
771 auto a_support = politics::get_popular_support(state, state.local_player_nation, a);
772 auto b_support = politics::get_popular_support(state, state.local_player_nation, b);
773 return a_support > b_support;
774 });
775 issues_listbox->update(state);
776 break;
778 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
779 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
780 auto a_support = politics::get_voter_support(state, state.local_player_nation, a);
781 auto b_support = politics::get_voter_support(state, state.local_player_nation, b);
782 return a_support > b_support;
783 });
784 issues_listbox->update(state);
785 break;
786 default:
787 break;
788 }
790 }
792 }
793};
794
795} // namespace ui
void set_button_text(sys::state &state, std::string const &new_text)
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
void move_child_to_front(element_base *child) noexcept final
void impl_on_update(sys::state &state) noexcept override
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
bool is_visible() const
virtual void add_child_to_front(std::unique_ptr< element_base > child) noexcept
virtual void on_create(sys::state &state) noexcept
element_data base_data
void set_visible(sys::state &state, bool vis)
std::string get_text(sys::state &state, dcon::issue_option_id issue_option_id) noexcept override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void populate_layout(sys::state &state, text::endless_layout &contents, dcon::nation_id nation_id) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
int32_t get_icon_frame(sys::state &state, dcon::nation_id nation_id) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
std::string get_text(sys::state &state, dcon::nation_id nation_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
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 get_text(sys::state &state, dcon::nation_id nation_id) 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
bool get_horizontal_flip(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
std::string_view get_row_element_name() override
void update_subwindow(sys::state &state, national_modifier_win &subwindow, sys::dated_modifier content) 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 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 on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_action(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
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 button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
politics_issue_sort_order order
void button_action(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_create(sys::state &state) noexcept override
std::string_view get_row_element_name() override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::string_view get_row_element_name() 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 on_create(sys::state &state) noexcept override
int32_t get_icon_frame(sys::state &state, dcon::nation_id nation_id) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void hide_sub_windows(sys::state &state)
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 on_update(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
virtual std::string get_text(sys::state &state, dcon::issue_option_id issue_option_id) noexcept
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
bool can_appoint_ruling_party(sys::state &state, dcon::nation_id source, dcon::political_party_id p)
Definition: commands.cpp:1822
bool can_start_election(sys::state &state, dcon::nation_id source)
Definition: commands.cpp:1003
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr dcon::demographics_key total(0)
constexpr dcon::demographics_key consciousness(3)
void get_active_political_parties(sys::state &state, dcon::nation_id n, std::vector< dcon::political_party_id > &parties)
Definition: nations.cpp:892
float get_voter_support(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
Definition: politics.cpp:33
sys::date next_election_date(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:64
bool can_appoint_ruling_party(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:51
float get_popular_support(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
Definition: politics.cpp:24
bool has_elections(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:60
bool is_election_ongoing(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:55
void add_line_break_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1147
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
std::string date_to_string(sys::state &state, sys::date date)
Definition: text.cpp:1082
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
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
Definition: text.cpp:1152
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 add_space_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1788
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
bool evaluate(sys::state &state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:5865
void modifier_description(sys::state &state, text::layout_base &layout, dcon::modifier_id mid, int32_t indentation=0)
void reform_description(sys::state &state, text::columnar_layout &contents, dcon::issue_option_id ref)
politics_issue_sort_order
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
void trigger_description(sys::state &state, text::layout_base &layout, dcon::trigger_key k, int32_t primary_slot=-1, int32_t this_slot=-1, int32_t from_slot=-1)
message_result
uchar uint8_t
sys::date expiration
Definition: modifiers.hpp:321
dcon::modifier_id mod_id
Definition: modifiers.hpp:322
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name