Project Alice
Loading...
Searching...
No Matches
gui_crisis_window.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace ui {
7
9public:
10 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
11 return state.world.nation_get_identity_from_identity_holder(state.primary_crisis_attacker);
12 }
13};
14
16public:
17 bool show = false;
18
19 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
20
21 auto first_wg = state.crisis_attacker_wargoals.at(0);
22 if(first_wg.cb == state.military_definitions.crisis_colony) {
23 auto colonizers = state.world.state_definition_get_colonization(first_wg.state);
24 if(colonizers.begin() != colonizers.end()) {
25 auto attacking_colonizer = (*colonizers.begin()).get_colonizer();
26 return state.world.nation_get_identity_from_identity_holder(attacking_colonizer);
27 }
28 } else if(first_wg.cb == state.military_definitions.liberate) {
29 return first_wg.wg_tag;
30 }
31 return dcon::national_identity_id{};
32 }
33 void on_update(sys::state& state) noexcept override {
35 auto first_wg = state.crisis_attacker_wargoals.at(0);
36 if(first_wg.cb == state.military_definitions.crisis_colony) {
37 auto colonizers = state.world.state_definition_get_colonization(first_wg.state);
38 if(colonizers.begin() != colonizers.end()) {
39 auto attacking_colonizer = (*colonizers.begin()).get_colonizer();
40 show = attacking_colonizer != state.primary_crisis_attacker;
41 } else {
42 show = false;
43 }
44 } else if(first_wg.cb == state.military_definitions.liberate) {
45 show = first_wg.wg_tag != state.world.nation_get_identity_from_identity_holder(state.primary_crisis_attacker);
46 }
47 }
48
49 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
50 if(show)
52 }
55 }
56 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
57 if(!show)
58 return mouse_probe{ nullptr, ui::xy_pair{} };
59 else
61 }
62 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
63 if(!show)
64 return;
65 flag_button::update_tooltip(state, x, y, contents);
66 }
67};
68
70 bool show = true;
71
72 void on_update(sys::state& state) noexcept override {
73 show = nations::is_involved_in_crisis(state, state.local_player_nation) && !nations::is_committed_in_crisis(state, state.local_player_nation);
74 disabled = !command::can_take_sides_in_crisis(state, state.local_player_nation, false);
75 }
76 void button_action(sys::state& state) noexcept override {
77 if(show)
78 command::take_sides_in_crisis(state, state.local_player_nation, false);
79 }
80
81 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
82 if(show)
84 }
85 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
87 }
88 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
89 if(!show)
90 return mouse_probe{ nullptr, ui::xy_pair{} };
91 else
93 }
94 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
95 if(!show)
96 return;
97
98 text::add_line_with_condition(state, contents, "crisis_back_explain_2", state.current_crisis_state == sys::crisis_state::heating_up);
99
100 for(auto& i : state.crisis_participants) {
101 if(i.id == state.local_player_nation) {
102 text::add_line_with_condition(state, contents, "crisis_back_explain_1", i.merely_interested == true);
103 return;
104 }
105 if(!i.id) {
106 text::add_line_with_condition(state, contents, "crisis_back_explain_1", false);
107 return;
108 }
109 }
110 }
111};
112
114 bool show = true;
115
116 void on_update(sys::state& state) noexcept override {
117 show = nations::is_involved_in_crisis(state, state.local_player_nation) && !nations::is_committed_in_crisis(state, state.local_player_nation);
118 disabled = !command::can_take_sides_in_crisis(state, state.local_player_nation, true);
119 }
120 void button_action(sys::state& state) noexcept override {
121 if(show)
122 command::take_sides_in_crisis(state, state.local_player_nation, true);
123 }
124
125 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
126 if(show)
128 }
129 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
131 }
132 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
133 if(!show)
134 return mouse_probe{ nullptr, ui::xy_pair{} };
135 else
137 }
138 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
139 if(!show)
140 return;
141
142 text::add_line_with_condition(state, contents, "crisis_back_explain_2", state.current_crisis_state == sys::crisis_state::heating_up);
143
144 for(auto& i : state.crisis_participants) {
145 if(i.id == state.local_player_nation) {
146 text::add_line_with_condition(state, contents, "crisis_back_explain_1", i.merely_interested == true);
147 return;
148 }
149 if(!i.id) {
150 text::add_line_with_condition(state, contents, "crisis_back_explain_1", false);
151 return;
152 }
153 }
154 }
155};
156
157
159 bool show = true;
160
161 void on_update(sys::state& state) noexcept override {
162 show = state.local_player_nation == state.primary_crisis_attacker;
163 }
164 void button_action(sys::state& state) noexcept override {
165 if(show)
167 }
168
169 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
170 if(show)
172 }
173 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
174 if(!show)
175 return mouse_probe{ nullptr, ui::xy_pair{} };
176 else
178 }
179};
180
182 bool show = true;
183
184 void on_update(sys::state& state) noexcept override {
185 show = state.local_player_nation == state.primary_crisis_defender;
186 }
187 void button_action(sys::state& state) noexcept override {
188 if(show)
190 }
191
192 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
193 if(show)
195 }
196 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
197 if(!show)
198 return mouse_probe{ nullptr, ui::xy_pair{} };
199 else
201 }
202};
203
205 bool show = true;
206
207 void on_update(sys::state& state) noexcept override {
208 show = state.local_player_nation == state.primary_crisis_attacker;
209 disabled = state.world.nation_get_diplomatic_points(state.local_player_nation) < 1.0f;
210 }
211 void button_action(sys::state& state) noexcept override {
212 if(show)
214 }
215
216 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
218 }
219
220 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
221 text::add_line_with_condition(state, contents, "crisis_offer_button_ex_3", state.world.nation_get_diplomatic_points(state.local_player_nation) >= 1.0f);
222 }
223
224 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
225 if(show)
227 }
228 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
229 if(!show)
230 return mouse_probe{ nullptr, ui::xy_pair{} };
231 else
233 }
234};
235
237 bool show = true;
238
239 void on_update(sys::state& state) noexcept override {
240 show = state.local_player_nation == state.primary_crisis_defender;
241 disabled = state.world.nation_get_diplomatic_points(state.local_player_nation) < 1.0f;
242 }
243 void button_action(sys::state& state) noexcept override {
244 if(show)
246 }
247
248 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
250 }
251
252 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
253 text::add_line_with_condition(state, contents, "crisis_offer_button_ex_3", state.world.nation_get_diplomatic_points(state.local_player_nation) >= 1.0f);
254 }
255
256 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
257 if(show)
259 }
260 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
261 if(!show)
262 return mouse_probe{ nullptr, ui::xy_pair{} };
263 else
265 }
266};
267
269public:
270 void on_update(sys::state& state) noexcept override {
271 auto wg_ready = retrieve<check_wg_completion>(state, parent).done;
272 if(!wg_ready) {
273 disabled = true;
274 return;
275 }
276 auto ni = retrieve<dcon::national_identity_id>(state, parent);
277 disabled = !command::crisis_can_add_wargoal(state, state.local_player_nation,
279 state.local_player_nation, // added_by;
280 retrieve<get_target>(state, parent).n, // target_nation;
281 state.world.national_identity_get_nation_from_identity_holder(ni), // secondary_nation;
282 ni, // wg_tag;
283 retrieve<dcon::state_definition_id>(state, parent), // state;
284 retrieve<dcon::cb_type_id>(state, parent) // cb
285 });
286 }
287
288 void button_action(sys::state& state) noexcept override {
289 auto ni = retrieve<dcon::national_identity_id>(state, parent);
291 state.local_player_nation, // added_by;
292 retrieve<get_target>(state, parent).n, // target_nation;
293 state.world.national_identity_get_nation_from_identity_holder(ni), // secondary_nation;
294 ni, // wg_tag;
295 retrieve<dcon::state_definition_id>(state, parent), // state;
296 retrieve<dcon::cb_type_id>(state, parent) // cb
297 });
298 parent->set_visible(state, false);
299 }
300
303 }
304
305 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
306 auto wg_ready = retrieve<check_wg_completion>(state, parent).done;
307 if(!wg_ready) {
308 text::add_line_with_condition(state, contents, "wg_not_ready", false);
309 return;
310 }
311 }
312};
313
315private:
316 wargoal_offer_setup_window* wargoal_setup_win = nullptr;
317 wargoal_offer_country_select_window* wargoal_country_win = nullptr;
318 wargoal_target_country_select_window* wargoal_target_win = nullptr;
319
320 dcon::nation_id offer_made_to;
321 dcon::nation_id wargoal_against;
322 dcon::cb_type_id cb_to_use;
323 dcon::state_definition_id target_state;
324 dcon::national_identity_id secondary_tag_identity;
325 dcon::national_identity_id wg_tag;
326
327 bool wargoal_decided_upon = false;
328
329 void select_mode(sys::state& state) {
331 seldata.single_state_select = true;
332 // Populate selectable states...
333 dcon::nation_id target = wargoal_against;
334 auto actor = state.local_player_nation;
335 dcon::cb_type_id cb = cb_to_use;
336 auto allowed_substate_regions = state.world.cb_type_get_allowed_substate_regions(cb);
337 if(allowed_substate_regions) {
338 for(auto v : state.world.nation_get_overlord_as_ruler(target)) {
339 if(v.get_subject().get_is_substate()) {
340 auto secondary_tag = state.world.national_identity_get_nation_from_identity_holder(secondary_tag_identity);
341 for(auto si : state.world.nation_get_state_ownership(target)) {
342 if(trigger::evaluate(state, allowed_substate_regions, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(actor)) &&
344 actor, // added_by;
345 target, // target_nation;
346 secondary_tag, // secondary_nation;
347 wg_tag, // wg_tag;
348 si.get_state().get_definition(), // state;
349 cb // cb
350 })) {
351 seldata.selectable_states.push_back(si.get_state().get_definition().id);
352 }
353 }
354 }
355 }
356 } else {
357 auto allowed_states = state.world.cb_type_get_allowed_states(cb);
358 if(auto allowed_countries = state.world.cb_type_get_allowed_countries(cb); allowed_countries) {
359 auto secondary_tag = state.world.national_identity_get_nation_from_identity_holder(secondary_tag_identity);
360 for(auto si : state.world.nation_get_state_ownership(target)) {
361 if(trigger::evaluate(state, allowed_states, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(secondary_tag)) &&
363 actor, // added_by;
364 target, // target_nation;
365 secondary_tag, // secondary_nation;
366 wg_tag, // wg_tag;
367 si.get_state().get_definition(), // state;
368 cb // cb
369 })) {
370 seldata.selectable_states.push_back(si.get_state().get_definition().id);
371 }
372 }
373 } else {
374 for(auto si : state.world.nation_get_state_ownership(target)) {
375 auto secondary_tag = state.world.national_identity_get_nation_from_identity_holder(secondary_tag_identity);
376
377 if(trigger::evaluate(state, allowed_states, trigger::to_generic(si.get_state().id), trigger::to_generic(actor), trigger::to_generic(actor)) &&
379 actor, // added_by;
380 target, // target_nation;
381 secondary_tag, // secondary_nation;
382 wg_tag, // wg_tag;
383 si.get_state().get_definition(), // state;
384 cb // cb
385 })) {
386 seldata.selectable_states.push_back(si.get_state().get_definition().id);
387 }
388 }
389 }
390 }
391 seldata.on_select = [&](sys::state& state, dcon::state_definition_id sdef) {
392 target_state = sdef;
393 wargoal_decided_upon = true;
394 wargoal_setup_win->set_visible(state, true);
395 wargoal_country_win->set_visible(state, false);
397 };
398 seldata.on_cancel = [&](sys::state& state) {
399 target_state = dcon::state_definition_id{};
401 wargoal_setup_win->set_visible(state, false);
402 //wargoal_state_win->set_visible(state, false);
403 wargoal_country_win->set_visible(state, true);
404 } else {
405 cb_to_use = dcon::cb_type_id{};
406 wargoal_decided_upon = false;
407 wargoal_setup_win->set_visible(state, true);
408 //wargoal_state_win->set_visible(state, false);
409 wargoal_country_win->set_visible(state, false);
410 }
412 };
413 state.start_state_selection(seldata);
414 }
415public:
417 wargoal_against = dcon::nation_id{};
418 offer_made_to = state.local_player_nation;
419 cb_to_use = dcon::cb_type_id{};
420 target_state = dcon::state_definition_id{};
421 secondary_tag_identity = dcon::national_identity_id{};
422 wargoal_decided_upon = false;
423
424 wargoal_setup_win->set_visible(state, false);
425 //wargoal_state_win->set_visible(state, false);
426 wargoal_country_win->set_visible(state, false);
427 wargoal_target_win->set_visible(state, true);
428 }
429
430 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
431 if(name == "background") {
432 auto ptr = make_element_by_type<draggable_target>(state, id);
433 ptr->base_data.size = base_data.size; // Nudge size for proper sizing
434 return ptr;
435 } else if(name == "leftshield") {
436 return make_element_by_type<nation_player_flag>(state, id);
437 } else if(name == "rightshield") {
438 return make_element_by_type<flag_button>(state, id);
439 } else if(name == "title") {
440 return make_element_by_type<wargoal_offer_title>(state, id);
441 } else if(name == "description") {
442 return make_element_by_type<wargoal_offer_description1>(state, id);
443 } else if(name == "wargoal_add_effect") {
444 return make_element_by_type<wargoal_offer_add_window>(state, id);
445 } else if(name == "wargoal_success_effect" || name == "wargoal_failure_effect") {
446 return make_element_by_type<invisible_element>(state, id);
447 } else if(name == "description2") {
448 return make_element_by_type<wargoal_offer_description2>(state, id);
449 } else if(name == "acceptance") {
450 return make_element_by_type<simple_text_element_base>(state, id);
451 } else if(name == "call_allies_checkbox") {
452 return make_element_by_type<invisible_element>(state, id);
453 } if(name == "call_allies_checkbox") {
454 return make_element_by_type<invisible_element>(state, id);
455 } else if(name == "run_conference_checkbox") {
456 return make_element_by_type<invisible_element>(state, id);
457 } else if(name == "agreebutton") {
458 return make_element_by_type<crisis_add_wargoal_confirm_button>(state, id);
459 } else if(name == "declinebutton") {
460 return make_element_by_type<cancel_pick_wg_button>(state, id);
461 } else if(name == "wargoal_setup") {
462 auto ptr = make_element_by_type<wargoal_target_country_select_window>(state, id);
463 wargoal_target_win = ptr.get();
464 ptr->set_visible(state, true);
465 return ptr;
466 } else if(name == "wargoal_state_select") {
467 return make_element_by_type<invisible_element>(state, id);
468 } else if(name == "wargoal_country_select") {
469 {
470 auto ptr = make_element_by_type<wargoal_offer_setup_window>(state, id);
471 wargoal_setup_win = ptr.get();
472 ptr->set_visible(state, false);
473 add_child_to_front(std::move(ptr));
474 }
475 {
476 auto ptr = make_element_by_type<wargoal_offer_country_select_window>(state, id);
477 wargoal_country_win = ptr.get();
478 ptr->set_visible(state, false);
479 return ptr;
480 }
481 } else {
482 return nullptr;
483 }
484 }
485
486 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
487 if(payload.holds_type<dcon::nation_id>()) {
488 payload.emplace<dcon::nation_id>(offer_made_to);
489 } else if(payload.holds_type<get_target>()) {
490 payload.emplace<get_target>(get_target{ wargoal_against });
491 } else if(payload.holds_type<get_offer_to>()) {
492 payload.emplace<get_offer_to>(get_offer_to{ offer_made_to });
493 } else if(payload.holds_type< check_wg_completion>()) {
494 payload.emplace<check_wg_completion>(check_wg_completion{ wargoal_decided_upon });
496 } else if(payload.holds_type<element_selection_wrapper<dcon::cb_type_id>>()) {
497 cb_to_use = any_cast<element_selection_wrapper<dcon::cb_type_id>>(payload).data;
498 if(!cb_to_use) {
499 wargoal_against = dcon::nation_id{};
500 cb_to_use = dcon::cb_type_id{};
501 target_state = dcon::state_definition_id{};
502 secondary_tag_identity = dcon::national_identity_id{};
503 wargoal_decided_upon = false;
504
505 wargoal_setup_win->set_visible(state, false);
506 //wargoal_state_win->set_visible(state, false);
507 wargoal_country_win->set_visible(state, false);
508 wargoal_target_win->set_visible(state, true);
510 wargoal_setup_win->set_visible(state, false);
511 //wargoal_state_win->set_visible(state, false);
512 wargoal_country_win->set_visible(state, true);
513 wargoal_target_win->set_visible(state, false);
515 wargoal_setup_win->set_visible(state, false);
516 //wargoal_state_win->set_visible(state, true);
517 wargoal_country_win->set_visible(state, false);
518 wargoal_target_win->set_visible(state, false);
519 select_mode(state);
520 } else {
521 wargoal_decided_upon = true;
522 wargoal_setup_win->set_visible(state, true);
523 //wargoal_state_win->set_visible(state, false);
524 wargoal_country_win->set_visible(state, false);
525 wargoal_target_win->set_visible(state, false);
526 }
529 } else if(payload.holds_type<element_selection_wrapper<dcon::national_identity_id>>()) {
530 secondary_tag_identity = any_cast<element_selection_wrapper<dcon::national_identity_id>>(payload).data;
531
532 if(secondary_tag_identity) { // goto next step
534 wargoal_setup_win->set_visible(state, true);
535 //wargoal_state_win->set_visible(state, true);
536 wargoal_country_win->set_visible(state, false);
537 wargoal_target_win->set_visible(state, true);
538 select_mode(state);
539 } else {
540 wargoal_setup_win->set_visible(state, true);
541 //wargoal_state_win->set_visible(state, false);
542 wargoal_country_win->set_visible(state, false);
543 wargoal_target_win->set_visible(state, false);
544 wargoal_decided_upon = true;
545 }
546 } else {
547 wargoal_decided_upon = false;
548 cb_to_use = dcon::cb_type_id{};
549 wargoal_setup_win->set_visible(state, true);
550 //wargoal_state_win->set_visible(state, false);
551 wargoal_country_win->set_visible(state, false);
552 wargoal_target_win->set_visible(state, false);
553 }
554
557 } else if(payload.holds_type<set_target>()) {
558 wargoal_against = any_cast<set_target>(payload).n;
559 if(wargoal_against) {
560 wargoal_decided_upon = false;
561 cb_to_use = dcon::cb_type_id{};
562 wargoal_setup_win->set_visible(state, true);
563 //wargoal_state_win->set_visible(state, false);
564 wargoal_country_win->set_visible(state, false);
565 wargoal_target_win->set_visible(state, false);
566 }
568 } else if(payload.holds_type<dcon::cb_type_id>()) {
569 payload.emplace<dcon::cb_type_id>(cb_to_use);
571 } else if(payload.holds_type<dcon::state_definition_id>()) {
572 payload.emplace<dcon::state_definition_id>(target_state);
574 } else if(payload.holds_type<dcon::national_identity_id>()) {
575 payload.emplace<dcon::national_identity_id>(secondary_tag_identity);
577 }
579 }
580};
581
583public:
584 void on_update(sys::state& state) noexcept override {
586 }
587};
588
590protected:
591 void populate_flags(sys::state& state) noexcept override {
592 row_contents.clear();
593 for(uint32_t i = 0; i < state.crisis_participants.size(); i++) {
594 if(!state.crisis_participants[i].id)
595 break;
596
597 if(state.crisis_participants[i].supports_attacker && !state.crisis_participants[i].merely_interested && state.crisis_participants[i].id != state.primary_crisis_attacker) {
598 auto content = dcon::fatten(state.world, state.crisis_participants[i].id);
599 row_contents.push_back(content.get_identity_from_identity_holder().id);
600 }
601 }
602 update(state);
603 }
604};
605
606class crisis_attacker_wargoals : public overlapping_listbox_element_base<overlapping_full_wg_icon, sys::full_wg> {
607protected:
608 std::string_view get_row_element_name() override {
609 return "wargoal";
610 }
611
612public:
613 void on_update(sys::state& state) noexcept override {
614 row_contents.clear();
615
616 for(auto wg : state.crisis_attacker_wargoals) {
617 if(wg.cb) {
618 row_contents.push_back(wg);
619 }
620 else {
621 break;
622 }
623 }
624
625 update(state);
626
627 }
628};
629
631public:
632 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
633 if(name == "country_flag") {
634 return make_element_by_type<diplomacy_crisis_attacker_flag>(state, id);
635 } else if(name == "sponsored_flag") {
636 return make_element_by_type<diplomacy_crisis_sponsored_attacker_flag>(state, id);
637 } else if(name == "country_name") {
638 return make_element_by_type<diplomacy_crisis_attacker_name>(state, id);
639 } else if(name == "wargoals") {
640 return make_element_by_type<crisis_attacker_wargoals>(state, id);
641 } else if(name == "backers") {
642 auto ptr = make_element_by_type<diplomacy_crisis_attacker_backers>(state, id);
643 ptr->base_data.position.y -= 6;
644 return ptr;
645 } else if(name == "support_side") {
646 return make_element_by_type<support_attacker_button>(state, id);
647 } else if(name == "back_down") {
648 return make_element_by_type<propose_defender_solution_button>(state, id);
649 } else if(name == "crisis_add_wg") {
650 return make_element_by_type<attacker_add_wg_button>(state, id);
651 } else {
652 return nullptr;
653 }
654 }
655};
656
658public:
659 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
660 return state.world.nation_get_identity_from_identity_holder(state.primary_crisis_defender);
661 }
662};
663
665public:
666 bool show = false;
667
668 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
669 auto first_wg = state.crisis_attacker_wargoals.at(0);
670
671 if(first_wg.cb == state.military_definitions.crisis_colony) {
672 auto colonizers = state.world.state_definition_get_colonization(first_wg.state);
673 if(colonizers.end() - colonizers.begin() >= 2) {
674 auto def_colonizer = (*(colonizers.begin() + 1)).get_colonizer();
675 return state.world.nation_get_identity_from_identity_holder(def_colonizer);
676 }
677 } else if(first_wg.cb == state.military_definitions.liberate) {
678 return first_wg.wg_tag;
679 }
680 return dcon::national_identity_id{};
681 }
682 void on_update(sys::state& state) noexcept override {
684
685 auto first_wg = state.crisis_attacker_wargoals.at(0);
686
687 if(first_wg.cb == state.military_definitions.crisis_colony) {
688 auto colonizers = state.world.state_definition_get_colonization(first_wg.state);
689 if(colonizers.end() - colonizers.begin() >= 2) {
690 auto def_colonizer = (*(colonizers.begin() + 1)).get_colonizer();
691 show = def_colonizer != state.primary_crisis_defender;
692 } else {
693 show = false;
694 }
695 } else if(first_wg.cb == state.military_definitions.liberate) {
696 show = first_wg.target_nation != state.primary_crisis_defender;
697 }
698 }
699
700 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
701 if(show)
703 }
706 }
707 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
708 if(!show)
709 return mouse_probe{ nullptr, ui::xy_pair{} };
710 else
712 }
713 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
714 if(!show)
715 return;
716 flag_button::update_tooltip(state, x, y, contents);
717 }
718};
719
721public:
722 void on_update(sys::state& state) noexcept override {
724 }
725};
726
728protected:
729 void populate_flags(sys::state& state) noexcept override {
730 row_contents.clear();
731 for(uint32_t i = 0; i < state.crisis_participants.size(); i++) {
732 if(!state.crisis_participants[i].id)
733 break;
734
735 if(!state.crisis_participants[i].supports_attacker && !state.crisis_participants[i].merely_interested && state.crisis_participants[i].id != state.primary_crisis_defender) {
736 auto content = dcon::fatten(state.world, state.crisis_participants[i].id);
737 row_contents.push_back(content.get_identity_from_identity_holder().id);
738 }
739 }
740 update(state);
741 }
742};
743
744
745class crisis_defender_wargoals : public overlapping_listbox_element_base<overlapping_full_wg_icon, sys::full_wg> {
746protected:
747 std::string_view get_row_element_name() override {
748 return "wargoal";
749 }
750
751public:
752 void on_update(sys::state& state) noexcept override {
753 row_contents.clear();
754
755 for(auto wg : state.crisis_defender_wargoals) {
756 if(wg.cb) {
757 row_contents.push_back(wg);
758 }
759 else {
760 break;
761 }
762 }
763
764 update(state);
765
766 }
767};
768
770public:
773 };
775 btn.disabled = (state.local_player_nation == state.primary_crisis_attacker);
776 };
777
778 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
779 if(name == "country_flag") {
780 return make_element_by_type<diplomacy_crisis_defender_flag>(state, id);
781 } else if(name == "sponsored_flag") {
782 return make_element_by_type<diplomacy_crisis_sponsored_defender_flag>(state, id);
783 } else if(name == "country_name") {
784 return make_element_by_type<diplomacy_crisis_defender_name>(state, id);
785 } else if(name == "wargoals") {
786 return make_element_by_type<crisis_defender_wargoals>(state, id);
787 } else if(name == "backers") {
788 auto ptr = make_element_by_type<diplomacy_crisis_defender_backers>(state, id);
789 ptr->base_data.position.y -= 6;
790 return ptr;
791 } else if(name == "support_side") {
792 return make_element_by_type<support_defender_button>(state, id);
793 } else if(name == "back_down") {
794 return make_element_by_type<propose_attacker_solution_button>(state, id);
795 } else if(name == "crisis_add_wg") {
796 return make_element_by_type<defender_add_wg_button>(state, id);
797 } else {
798 return nullptr;
799 }
800 }
801};
802
804public:
805 void on_update(sys::state& state) noexcept override {
806 auto first_wg = state.crisis_attacker_wargoals.at(0);
807 set_text(state, text::produce_simple_string(state, state.world.state_definition_get_name(first_wg.state)));
808 }
809};
810
812public:
813 void on_update(sys::state& state) noexcept override {
814 auto first_wg = state.crisis_attacker_wargoals.at(0);
815 if (first_wg.cb == state.military_definitions.liberate) {
818 if(state.world.nation_get_owned_province_count(state.world.national_identity_get_nation_from_identity_holder(first_wg.wg_tag)) > 0) {
819 set_text(state, text::resolve_string_substitution(state, "crisis_description_reclaim", m));
820 } else {
821 set_text(state, text::resolve_string_substitution(state, "crisis_description_liberation", m));
822 }
823 }
824 else if(first_wg.cb == state.military_definitions.crisis_colony) {
825 set_text(state, text::produce_simple_string(state, "crisis_description_colonize"));
826 }
827 }
828};
829
831public:
832 void on_update(sys::state& state) noexcept override {
833 progress = state.current_crisis_state == sys::crisis_state::heating_up ? state.crisis_temperature / 100.0f : 0.0f;
834 }
835
838 }
839 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
840 if(state.current_crisis_state != sys::crisis_state::heating_up)
841 return;
842 text::add_line(state, contents, "crisis_temperature_ex", text::variable_type::value, int64_t(state.crisis_temperature));
843 }
844};
845
847public:
848 void on_update(sys::state& state) noexcept override {
849 switch(state.current_crisis_state) {
851 set_text(state, text::produce_simple_string(state, "crisis_mode_no_crisis"));
852 break;
854 set_text(state, text::produce_simple_string(state, "crisis_mode_finding_attacker"));
855 break;
857 set_text(state, text::produce_simple_string(state, "crisis_mode_finding_defender"));
858 break;
860 set_text(state, text::produce_simple_string(state, "crisis_mode_heating_up"));
861 break;
862 default:
863 break;
864 }
865 }
866};
867
869public:
870 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
871 auto n = retrieve<dcon::nation_id>(state, parent);
872 return state.world.nation_get_identity_from_identity_holder(n);
873 }
874};
875
877 dcon::nation_id to;
878};
879
881public:
882
883 void on_update(sys::state& state) noexcept override {
884 disabled = state.world.nation_get_diplomatic_points(state.local_player_nation) < 1.0f || (state.local_player_nation != state.primary_crisis_attacker && state.local_player_nation != state.primary_crisis_defender) || (state.current_crisis_state != sys::crisis_state::heating_up);
885 }
888 }
889 void button_action(sys::state& state) noexcept override {
890 auto n = retrieve<dcon::nation_id>(state, parent);
891 if(n)
893 }
894 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
895 text::add_line(state, contents, "crisis_offer_button");
897 text::add_line_with_condition(state, contents, "crisis_offer_button_ex_1", state.local_player_nation == state.primary_crisis_attacker || state.local_player_nation == state.primary_crisis_defender);
898 text::add_line_with_condition(state, contents, "crisis_offer_button_ex_2", state.current_crisis_state == sys::crisis_state::heating_up);
899 text::add_line_with_condition(state, contents, "crisis_offer_button_ex_3", state.world.nation_get_diplomatic_points(state.local_player_nation) >= 1.0f);
900 }
901};
902
904public:
905 void button_action(sys::state& state) noexcept override {
907 }
908 void on_update(sys::state& state) noexcept override {
909 disabled = !(state.world.nation_get_is_great_power(state.local_player_nation) && state.current_crisis_state == sys::crisis_state::heating_up);
910 }
913 }
914 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
915 text::add_line(state, contents, "crisis_add_interest_button");
917 text::add_line_with_condition(state, contents, "crisis_add_interest_button_ex_1", state.world.nation_get_is_great_power(state.local_player_nation));
918 text::add_line_with_condition(state, contents, "crisis_add_interest_button_ex_2", state.current_crisis_state == sys::crisis_state::heating_up);
919 text::add_line_with_condition(state, contents, "crisis_add_interest_button_ex_3", state.world.nation_get_diplomatic_points(state.local_player_nation) >= 1.0f);
920 }
921};
922
924public:
925 bool show = true;
926 int32_t index = 0;
927
928 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
929 if(name == "country_flag") {
930 return make_element_by_type<interested_flag>(state, id);
931 } else if(name == "make_offer") {
932 return make_element_by_type<make_offer_button>(state, id);
933 } else {
934 return nullptr;
935 }
936 }
937
938 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
939 if(payload.holds_type<dcon::nation_id>()) {
940 dcon::nation_id n;
941 int32_t count = 0;
942 for(auto& par: state.crisis_participants) {
943 if(!par.id)
944 break;
945 if(par.merely_interested) {
946 if(count == index) {
947 n = par.id;
948 break;
949 }
950 ++count;
951 }
952 }
953 payload.emplace<dcon::nation_id>(n);
955 }
957 }
958
959 void on_update(sys::state& state) noexcept override {
960 show = false;
961 int32_t count = 0;
962 for(auto& par : state.crisis_participants) {
963 if(!par.id)
964 break;
965 if(par.merely_interested) {
966 if(count == index) {
967 show = true;
968 break;
969 }
970 ++count;
971 }
972 }
973 }
974 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
975 if(show)
977 }
978 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
979 if(!show)
980 return mouse_probe{ nullptr, ui::xy_pair{} };
981 else
983 }
984};
985
987public:
988 bool show = true;
989
990 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
991 if(name == "join_button") {
992 return make_element_by_type<join_crisis_button>(state, id);
993 } else {
994 return nullptr;
995 }
996 }
997
998 void on_update(sys::state& state) noexcept override {
999 show = false;
1000 if(!state.world.nation_get_is_great_power(state.local_player_nation))
1001 return;
1002 if(nations::is_involved_in_crisis(state, state.local_player_nation)) {
1003 return;
1004 }
1005 show = true;
1006 }
1007 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
1008 if(show)
1010 }
1011 mouse_probe impl_probe_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
1012 if(!show)
1013 return mouse_probe{ nullptr, ui::xy_pair{} };
1014 else
1016 }
1017};
1018
1020public:
1021 void on_create(sys::state& state) noexcept override {
1023
1024 {
1025 auto ptr = make_element_by_type<diplomacy_crisis_interested_container>(state, state.ui_state.defs_by_name.find(state.lookup_key("fence_sitter_entry"))->second.definition);
1026 ptr->base_data.position.x = int16_t(0);
1027 ptr->base_data.position.y = int16_t(0);
1028 ptr->index = 0;
1029 add_child_to_front(std::move(ptr));
1030 }
1031 {
1032 auto ptr = make_element_by_type<diplomacy_crisis_interested_container>(state, state.ui_state.defs_by_name.find(state.lookup_key("fence_sitter_entry"))->second.definition);
1033 ptr->base_data.position.x = int16_t(70 * 1);
1034 ptr->base_data.position.y = int16_t(0);
1035 ptr->index = 1;
1036 add_child_to_front(std::move(ptr));
1037 }
1038 {
1039 auto ptr = make_element_by_type<diplomacy_crisis_interested_container>(state, state.ui_state.defs_by_name.find(state.lookup_key("fence_sitter_entry"))->second.definition);
1040 ptr->base_data.position.x = int16_t(70 * 2);
1041 ptr->base_data.position.y = int16_t(0);
1042 ptr->index = 2;
1043 add_child_to_front(std::move(ptr));
1044 }
1045 {
1046 auto ptr = make_element_by_type<diplomacy_crisis_interested_container>(state, state.ui_state.defs_by_name.find(state.lookup_key("fence_sitter_entry"))->second.definition);
1047 ptr->base_data.position.x = int16_t(0);
1048 ptr->base_data.position.y = int16_t(75);
1049 ptr->index = 3;
1050 add_child_to_front(std::move(ptr));
1051 }
1052 {
1053 auto ptr = make_element_by_type<diplomacy_crisis_interested_container>(state, state.ui_state.defs_by_name.find(state.lookup_key("fence_sitter_entry"))->second.definition);
1054 ptr->base_data.position.x = int16_t(70 * 1);
1055 ptr->base_data.position.y = int16_t(75);
1056 ptr->index = 4;
1057 add_child_to_front(std::move(ptr));
1058 }
1059 {
1060 auto ptr = make_element_by_type<diplomacy_crisis_interested_container>(state, state.ui_state.defs_by_name.find(state.lookup_key("fence_sitter_entry"))->second.definition);
1061 ptr->base_data.position.x = int16_t(70 * 2);
1062 ptr->base_data.position.y = int16_t(75);
1063 ptr->index = 5;
1064 add_child_to_front(std::move(ptr));
1065 }
1066 {
1067 auto ptr = make_element_by_type<diplomacy_crisis_join_container>(state, state.ui_state.defs_by_name.find(state.lookup_key("join_fence_sitter_entry"))->second.definition);
1068 ptr->base_data.position.x = int16_t(70 * 2 - 3);
1069 ptr->base_data.position.y = int16_t(58);
1070 add_child_to_front(std::move(ptr));
1071 }
1072 }
1073};
1074
1076public:
1077
1078 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1079 if(name == "crisis_title") {
1080 return make_element_by_type<diplomacy_crisis_title_text>(state, id);
1081 } else if(name == "crisis_sub_title") {
1082 return make_element_by_type<diplomacy_crisis_subtitle_text>(state, id);
1083 } else if(name == "crisis_temperature") {
1084 return make_element_by_type<diplomacy_crisis_temperature_bar>(state, id);
1085 } else if(name == "crisis_status_label") {
1086 return make_element_by_type<diplomacy_crisis_status_text>(state, id);
1087 } else if(name == "attacker_win") {
1088 return make_element_by_type<diplomacy_crisis_attacker_window>(state, id);
1089 } else if(name == "defender_win") {
1090 return make_element_by_type<diplomacy_crisis_defender_window>(state, id);
1091 } else if(name == "fence_sitters_win") {
1092 return make_element_by_type< diplomacy_crisis_interested_window>(state, id);
1093 } else {
1094 return nullptr;
1095 }
1096 }
1097};
1098
1099} // namespace ui
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
void impl_on_update(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
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
void reset_window(sys::state &state)
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_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void populate_flags(sys::state &state) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void populate_flags(sys::state &state) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::function< void(generic_callback_button &, sys::state &)> on_add_wg_update
std::function< void(generic_callback_button &, sys::state &)> on_add_wg_action
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept override
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) 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
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) 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 render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
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
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
virtual void impl_render(sys::state &state, int32_t x, int32_t y) noexcept
element_data base_data
void set_visible(sys::state &state, bool vis)
virtual mouse_probe impl_probe_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
tooltip_behavior has_tooltip(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 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 set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
void queue_crisis_add_wargoal(sys::state &state, dcon::nation_id source, sys::full_wg wg)
Definition: commands.cpp:4595
bool can_take_sides_in_crisis(sys::state &state, dcon::nation_id source, bool join_attacker)
Definition: commands.cpp:1982
bool crisis_can_add_wargoal(sys::state &state, dcon::nation_id source, sys::full_wg wg)
Definition: commands.cpp:4625
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
bool cb_requires_selection_of_a_valid_nation(sys::state const &state, dcon::cb_type_id t)
Definition: military.cpp:2057
bool cb_requires_selection_of_a_liberatable_tag(sys::state const &state, dcon::cb_type_id t)
Definition: military.cpp:2061
bool cb_requires_selection_of_a_state(sys::state const &state, dcon::cb_type_id t)
Definition: military.cpp:2065
bool is_committed_in_crisis(sys::state const &state, dcon::nation_id n)
Definition: nations.cpp:1646
bool is_involved_in_crisis(sys::state const &state, dcon::nation_id n)
Definition: nations.cpp:1632
std::string resolve_string_substitution(sys::state &state, dcon::text_key source_text, substitution_map const &mp)
Definition: text.cpp:2137
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1923
void add_line_with_condition(sys::state &state, layout_base &dest, std::string_view key, bool condition_met, int32_t indent)
Definition: text.cpp:1979
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
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
dcon::text_key get_name(sys::state &state, dcon::nation_id id)
Definition: text.cpp:880
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:5895
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
@ count
Definition: gui_event.hpp:126
message_result
uint uint32_t
std::vector< dcon::state_definition_id > selectable_states
std::function< void(sys::state &, dcon::state_definition_id)> on_select
std::function< void(sys::state &)> on_cancel
Holds important data about the game world, state, and other data regarding windowing,...
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name