Project Alice
Loading...
Searching...
No Matches
gui_event.cpp
Go to the documentation of this file.
1#include "gui_event.hpp"
4#include "triggers.hpp"
5
6namespace ui {
7
8static std::vector<std::unique_ptr<base_event_window>> event_pool[uint32_t(event_pool_slot::count)];
9static int32_t pending_events[uint32_t(event_pool_slot::count)];
10static std::vector<base_event_window*> pending_closure;
11
12void populate_event_submap(sys::state& state, text::substitution_map& sub, std::variant<event::pending_human_n_event, event::pending_human_f_n_event, event::pending_human_p_event, event::pending_human_f_p_event> const& phe) noexcept {
13 dcon::nation_id target_nation{};
14 dcon::nation_id from_nation{};
15 dcon::province_id target_province{};
16 dcon::province_id from_province{};
17 dcon::state_instance_id target_state{};
18 dcon::state_instance_id from_state{};
19 dcon::province_id target_capital{};
20 dcon::province_id from_capital{};
21 int32_t target_pop = 0;
22
24 int32_t from_slot = -1;
25
27 int32_t primary_slot = -1;
28 sys::date event_date;
29
30 if(std::holds_alternative<event::pending_human_n_event>(phe)) {
31 auto const& e = std::get<event::pending_human_n_event>(phe);
32 target_nation = e.n;
33 target_pop = int32_t(state.world.nation_get_demographics(target_nation, demographics::total));
34 target_capital = state.world.nation_get_capital(target_nation);
35 target_province = target_capital;
36 if(e.pt != event::slot_type::state)
37 target_state = state.world.province_get_state_membership(target_province);
38 else
39 target_state = trigger::to_state(e.primary_slot);
40
41 from_slot = e.from_slot;
42 ft = e.ft;
43 primary_slot = e.primary_slot;
44 pt = e.pt;
45 event_date = e.date;
46 } else if(std::holds_alternative<event::pending_human_f_n_event>(phe)) {
47 auto const& e = std::get<event::pending_human_f_n_event>(phe);
48 target_nation = e.n;
49 target_pop = int32_t(state.world.nation_get_demographics(target_nation, demographics::total));
50 target_capital = state.world.nation_get_capital(target_nation);
51 target_province = target_capital;
52 target_state = state.world.province_get_state_membership(target_province);
53
54 event_date = e.date;
55 } else if(std::holds_alternative<event::pending_human_p_event>(phe)) {
56 auto const& e = std::get<event::pending_human_p_event>(phe);
57 target_nation = state.world.province_get_nation_from_province_ownership(e.p);
58 target_state = state.world.province_get_state_membership(e.p);
59 target_capital = state.world.state_instance_get_capital(target_state);
60 target_province = e.p;
61 target_pop = int32_t(state.world.province_get_demographics(target_province, demographics::total));
62
63 from_slot = e.from_slot;
64 ft = e.ft;
65 event_date = e.date;
66 } else if(std::holds_alternative<event::pending_human_f_p_event>(phe)) {
67 auto const& e = std::get<event::pending_human_f_p_event>(phe);
68 target_nation = state.world.province_get_nation_from_province_ownership(e.p);
69 target_state = state.world.province_get_state_membership(e.p);
70 target_capital = state.world.state_instance_get_capital(target_state);
71 target_province = e.p;
72 target_pop = int32_t(state.world.province_get_demographics(target_province, demographics::total));
73 event_date = e.date;
74 }
75
76 switch(ft) {
78 from_nation = trigger::to_nation(from_slot);
79 from_capital = state.world.nation_get_capital(from_nation);
80 switch(pt) {
82 from_state = trigger::to_state(primary_slot);
83 from_province = state.world.state_instance_get_capital(from_state);
84 break;
86 from_province = trigger::to_prov(primary_slot);
87 from_state = state.world.province_get_state_membership(from_province);
88 break;
89 default:
90 from_province = state.world.nation_get_capital(from_nation);
91 from_state = state.world.province_get_state_membership(from_province);
92 break;
93 }
94 break;
96 from_state = trigger::to_state(from_slot);
97 from_nation = state.world.state_instance_get_nation_from_state_ownership(from_state);
98 from_capital = state.world.state_instance_get_capital(from_state);
99 switch(pt) {
101 from_province = trigger::to_prov(primary_slot);
102 break;
103 default:
104 from_province = state.world.state_instance_get_capital(from_state);
105 break;
106 }
107 break;
109 from_province = trigger::to_prov(from_slot);
110 from_capital = from_province;
111 from_state = state.world.province_get_state_membership(from_province);
112 from_nation = state.world.province_get_nation_from_province_ownership(from_province);
113 break;
114 default:
115 // TODO: Handle rest
116 break;
117 }
118
119 // Target
120 text::add_to_substitution_map(sub, text::variable_type::continentname, state.world.province_get_continent(target_province).get_name());
122 text::add_to_substitution_map(sub, text::variable_type::provinceculture, state.world.culture_get_name(state.world.province_get_dominant_culture(target_province)));
123 text::add_to_substitution_map(sub, text::variable_type::provincereligion, state.world.religion_get_name(state.world.province_get_dominant_religion(target_province)));
130 text::add_to_substitution_map(sub, text::variable_type::cb_target_name, state.world.nation_get_constructing_cb_target(target_nation));
131 text::add_to_substitution_map(sub, text::variable_type::cb_target_name_adj, text::get_adjective(state, state.world.nation_get_constructing_cb_target(target_nation)));
134 // TODO: Is this correct? I remember in vanilla it could vary
135 auto pc = state.world.nation_get_primary_culture(target_nation);
136 text::add_to_substitution_map(sub, text::variable_type::culture, state.world.culture_get_name(pc));
137 text::add_to_substitution_map(sub, text::variable_type::culture_group_union, pc.get_group_from_culture_group_membership().get_identity_from_cultural_union_of().get_nation_from_identity_holder());
138 text::add_to_substitution_map(sub, text::variable_type::union_adj, pc.get_group_from_culture_group_membership().get_identity_from_cultural_union_of().get_adjective());
140 auto sm = state.world.nation_get_in_sphere_of(target_nation);
143 auto smpc = state.world.nation_get_primary_culture(sm);
144 text::add_to_substitution_map(sub, text::variable_type::spheremaster_union_adj, smpc.get_group_from_culture_group_membership().get_identity_from_cultural_union_of().get_adjective());
145
146 // From
150
151 // Global crisis stuff
152
153 auto first_wg = state.crisis_attacker_wargoals.at(0);
155 text::add_to_substitution_map(sub, text::variable_type::crisistaker_adj, state.world.national_identity_get_adjective(first_wg.wg_tag));
156 text::add_to_substitution_map(sub, text::variable_type::crisistaker_capital, state.world.national_identity_get_capital(first_wg.wg_tag));
157 text::add_to_substitution_map(sub, text::variable_type::crisistaker_continent, state.world.national_identity_get_capital(first_wg.wg_tag).get_continent().get_name());
159 text::add_to_substitution_map(sub, text::variable_type::crisisattacker_capital, state.world.nation_get_capital(state.primary_crisis_attacker));
160 text::add_to_substitution_map(sub, text::variable_type::crisisattacker_continent, state.world.nation_get_capital(state.primary_crisis_attacker).get_continent().get_name());
162 text::add_to_substitution_map(sub, text::variable_type::crisisdefender_capital, state.world.nation_get_capital(state.primary_crisis_defender));
163 text::add_to_substitution_map(sub, text::variable_type::crisisdefender_continent, state.world.nation_get_capital(state.primary_crisis_defender).get_continent().get_name());
168 // Dates
169 text::add_to_substitution_map(sub, text::variable_type::year, int32_t(event_date.to_ymd(state.start_date).year));
170 //text::add_to_substitution_map(sub, text::variable_type::month, text::localize_month(state, event_date.to_ymd(state.start_date).month));
171 text::add_to_substitution_map(sub, text::variable_type::day, int32_t(event_date.to_ymd(state.start_date).day));
172
173 // Non-vanilla
174 text::add_to_substitution_map(sub, text::variable_type::government, state.world.nation_get_government_type(target_nation).get_name());
175 text::add_to_substitution_map(sub, text::variable_type::ideology, state.world.nation_get_ruling_party(target_nation).get_ideology().get_name());
176 text::add_to_substitution_map(sub, text::variable_type::party, state.world.nation_get_ruling_party(target_nation).get_name());
178 text::add_to_substitution_map(sub, text::variable_type::fromcontinent, state.world.province_get_continent(from_province).get_name());
179 text::add_to_substitution_map(sub, text::variable_type::fromcapital, state.world.province_get_name(from_capital));
180 text::add_to_substitution_map(sub, text::variable_type::religion, state.world.religion_get_name(state.world.nation_get_religion(target_nation)));
181 text::add_to_substitution_map(sub, text::variable_type::infamy, text::fp_two_places{ state.world.nation_get_infamy(target_nation) });
182 text::add_to_substitution_map(sub, text::variable_type::badboy, text::fp_two_places{ state.world.nation_get_infamy(target_nation) });
183 text::add_to_substitution_map(sub, text::variable_type::spheremaster, state.world.nation_get_in_sphere_of(target_nation));
184 text::add_to_substitution_map(sub, text::variable_type::overlord, state.world.overlord_get_ruler(state.world.nation_get_overlord_as_subject(target_nation)));
185 text::add_to_substitution_map(sub, text::variable_type::nationalvalue, state.world.nation_get_national_value(target_nation).get_name());
186 text::add_to_substitution_map(sub, text::variable_type::good, state.world.province_get_rgo(target_province).get_name());
187 text::add_to_substitution_map(sub, text::variable_type::resource, state.world.province_get_rgo(target_province).get_name());
188 text::add_to_substitution_map(sub, text::variable_type::terrain, state.world.province_get_terrain(target_province).get_name());
191 text::add_to_substitution_map(sub, text::variable_type::focus, state.world.state_instance_get_owner_focus(target_state).get_name());
192 text::add_to_substitution_map(sub, text::variable_type::nf, state.world.state_instance_get_owner_focus(target_state).get_name());
193 auto names_pair = rng::get_random_pair(state, uint32_t(target_nation.index()) << 6, uint32_t(event_date.value));
194 auto first_names = state.world.culture_get_first_names(state.world.nation_get_primary_culture(target_nation));
195 if(first_names.size() > 0) {
196 auto first_name = first_names.at(rng::reduce(uint32_t(names_pair.high), first_names.size()));
197 auto last_names = state.world.culture_get_last_names(state.world.nation_get_primary_culture(target_nation));
198 if(last_names.size() > 0) {
199 auto last_name = last_names.at(rng::reduce(uint32_t(names_pair.high), last_names.size()));
202 }
203 }
205 if(auto fl = state.world.province_get_factory_location_as_province(target_province); fl.begin() != fl.end()) {
206 text::add_to_substitution_map(sub, text::variable_type::factory, (*fl.begin()).get_factory().get_building_type().get_name());
207 }
208 text::add_to_substitution_map(sub, text::variable_type::tech, state.world.nation_get_current_research(target_nation).get_name());
209 //std::string list_provinces = "";
210 //for(const auto p : state.world.state_definition_get_abstract_state_membership(state.world.state_instance_get_definition(target_state))) {
211 // list_provinces += text::produce_simple_string(state, p.get_province().get_name()) + ", ";
212 //}
213 //text::add_to_substitution_map(sub, text::variable_type::provinces, list_provinces);
216 text::add_to_substitution_map(sub, text::variable_type::control, state.world.province_get_nation_from_province_control(target_province));
217 text::add_to_substitution_map(sub, text::variable_type::owner, state.world.province_get_nation_from_province_ownership(target_province));
218 if(auto plist = state.world.nation_get_province_ownership(target_nation); plist.begin() != plist.end()) {
219 auto plist_size = uint32_t(plist.end() - plist.begin());
220 uint32_t index = rng::reduce(uint32_t(names_pair.high), plist_size);
221 text::add_to_substitution_map(sub, text::variable_type::anyprovince, (*(plist.begin() + index)).get_province());
222 }
223}
224
226 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
227 auto index = retrieve<int32_t>(state, parent);
228
231 if(std::holds_alternative<event::pending_human_n_event>(content)) {
232 auto const& phe = std::get<event::pending_human_n_event>(content);
233 opt = state.world.national_event_get_options(std::get<event::pending_human_n_event>(content).e)[index];
234 populate_event_submap(state, sub, phe);
235 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
236 auto const& phe = std::get<event::pending_human_f_n_event>(content);
237 opt = state.world.free_national_event_get_options(std::get<event::pending_human_f_n_event>(content).e)[index];
238 populate_event_submap(state, sub, phe);
239 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
240 auto const& phe = std::get<event::pending_human_p_event>(content);
241 opt = state.world.provincial_event_get_options(std::get<event::pending_human_p_event>(content).e)[index];
242 populate_event_submap(state, sub, phe);
243 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
244 auto const& phe = std::get<event::pending_human_f_p_event>(content);
245 opt = state.world.free_provincial_event_get_options(std::get<event::pending_human_f_p_event>(content).e)[index];
246 populate_event_submap(state, sub, phe);
247 }
248
249 set_button_text(state, text::resolve_string_substitution(state, opt.name, sub));
250}
251
253 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
254 auto index = retrieve<int32_t>(state, parent);
255
256 if(std::holds_alternative<event::pending_human_n_event>(content)) {
257 auto const& phe = std::get<event::pending_human_n_event>(content);
258 state.world.national_event_set_auto_choice(phe.e, uint8_t(index + 1));
260 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
261 auto const& phe = std::get<event::pending_human_f_n_event>(content);
262 state.world.free_national_event_set_auto_choice(phe.e, uint8_t(index + 1));
264 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
265 auto const& phe = std::get<event::pending_human_p_event>(content);
266 state.world.provincial_event_set_auto_choice(phe.e, uint8_t(index + 1));
268 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
269 auto const& phe = std::get<event::pending_human_f_p_event>(content);
270 state.world.free_provincial_event_set_auto_choice(phe.e, uint8_t(index + 1));
272 }
274}
275
276void event_option_button::update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept {
277 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
278 auto index = retrieve<int32_t>(state, parent);
279
280 if(std::holds_alternative<event::pending_human_n_event>(content)) {
281 auto const& phe = std::get<event::pending_human_n_event>(content);
282 if(index == 0) {
283 text::add_line(state, contents, "event_taken_auto", text::variable_type::date, phe.date + 30);
284 }
285 effect_description(state, contents, state.world.national_event_get_options(phe.e)[index].effect, phe.primary_slot,
286 trigger::to_generic(phe.n), phe.from_slot, phe.r_lo, phe.r_hi);
287 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
288 auto const& phe = std::get<event::pending_human_f_n_event>(content);
289 if(index == 0) {
290 text::add_line(state, contents, "event_taken_auto", text::variable_type::date, phe.date + 30);
291 }
292 effect_description(state, contents, state.world.free_national_event_get_options(phe.e)[index].effect,
293 trigger::to_generic(phe.n), trigger::to_generic(phe.n), -1, phe.r_lo, phe.r_hi);
294 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
295 auto const& phe = std::get<event::pending_human_p_event>(content);
296 if(index == 0) {
297 text::add_line(state, contents, "event_taken_auto", text::variable_type::date, phe.date + 30);
298 }
299 effect_description(state, contents, state.world.provincial_event_get_options(phe.e)[index].effect,
300 trigger::to_generic(phe.p), trigger::to_generic(phe.p), phe.from_slot, phe.r_lo, phe.r_hi);
301 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
302 auto const& phe = std::get<event::pending_human_f_p_event>(content);
303 if(index == 0) {
304 text::add_line(state, contents, "event_taken_auto", text::variable_type::date, phe.date + 30);
305 }
306 effect_description(state, contents, state.world.free_provincial_event_get_options(phe.e)[index].effect,
307 trigger::to_generic(phe.p), trigger::to_generic(phe.p), -1, phe.r_lo, phe.r_hi);
308 }
309}
310
312 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
313 auto index = retrieve<int32_t>(state, parent);
314 if(std::holds_alternative<event::pending_human_n_event>(content)) {
315 auto phe = std::get<event::pending_human_n_event>(content);
317 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
318 auto phe = std::get<event::pending_human_f_n_event>(content);
320 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
321 auto phe = std::get<event::pending_human_p_event>(content);
323 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
324 auto phe = std::get<event::pending_human_f_p_event>(content);
326 }
328}
329
331 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
332 if(std::holds_alternative<event::pending_human_n_event>(content))
333 base_data.data.image.gfx_object = state.world.national_event_get_image(std::get<event::pending_human_n_event>(content).e);
334 else if(std::holds_alternative<event::pending_human_f_n_event>(content))
335 base_data.data.image.gfx_object = state.world.free_national_event_get_image(std::get<event::pending_human_f_n_event>(content).e);
336}
337
339 base_data.size.y = 200;
340 base_data.size.x -= 11;
342 delegate->base_data.data.text.font_handle = text::name_into_font_id(state, "ToolTip_Font");
343}
344
346 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
347
348 auto contents = text::create_endless_layout(state, delegate->internal_layout,
349 text::layout_parameters{0, 0, static_cast<int16_t>(base_data.size.x), static_cast<int16_t>(base_data.size.y),
350 delegate->base_data.data.text.font_handle, 0, text::alignment::left, delegate->black_text ? text::text_color::black : text::text_color::white, false});
351
353 dcon::text_key description{};
354 if(std::holds_alternative<event::pending_human_n_event>(content)) {
355 auto phe = std::get<event::pending_human_n_event>(content);
356 description = state.world.national_event_get_description(phe.e);
357 populate_event_submap(state, sub, phe);
358 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
359 auto phe = std::get<event::pending_human_f_n_event>(content);
360 description = state.world.free_national_event_get_description(phe.e);
361 populate_event_submap(state, sub, phe);
362 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
363 auto phe = std::get<event::pending_human_p_event>(content);
364 description = state.world.provincial_event_get_description(phe.e);
365 populate_event_submap(state, sub, phe);
366 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
367 auto phe = std::get<event::pending_human_f_p_event>(content);
368 description = state.world.free_provincial_event_get_description(phe.e);
369 populate_event_submap(state, sub, phe);
370 }
371
372 auto box = text::open_layout_box(contents);
373 text::add_to_layout_box(state, contents, box, description, sub);
374 text::close_layout_box(contents, box);
375
376 if(std::holds_alternative<event::pending_human_n_event>(content)) {
377 auto phe = std::get<event::pending_human_n_event>(content);
378 auto imm = state.world.national_event_get_immediate_effect(phe.e);
379 if(imm) {
380 effect_description(state, contents, imm, phe.primary_slot, trigger::to_generic(phe.n), phe.from_slot, phe.r_lo, phe.r_hi);
381 for(auto& l : delegate->internal_layout.contents) {
382 if(l.color == (delegate->black_text ? text::text_color::white : text::text_color::black)) //Invert colours
383 l.color = delegate->black_text ? text::text_color::black : text::text_color::white;
384 }
385 }
386 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
387 auto phe = std::get<event::pending_human_f_n_event>(content);
388 auto imm = state.world.free_national_event_get_immediate_effect(phe.e);
389 if(imm) {
390 effect_description(state, contents, imm, trigger::to_generic(phe.n), trigger::to_generic(phe.n), -1, phe.r_lo, phe.r_hi);
391 for(auto& l : delegate->internal_layout.contents) {
392 if(l.color == (delegate->black_text ? text::text_color::white : text::text_color::black)) //Invert colours
393 l.color = delegate->black_text ? text::text_color::black : text::text_color::white;
394 }
395 }
396 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
397 auto phe = std::get<event::pending_human_p_event>(content);
398 auto imm = state.world.provincial_event_get_immediate_effect(phe.e);
399 if(imm) {
400 effect_description(state, contents, imm, trigger::to_generic(phe.p), trigger::to_generic(phe.p), phe.from_slot, phe.r_lo, phe.r_hi);
401 for(auto& l : delegate->internal_layout.contents) {
402 if(l.color == (delegate->black_text ? text::text_color::white : text::text_color::black)) //Invert colours
403 l.color = delegate->black_text ? text::text_color::black : text::text_color::white;
404 }
405 }
406 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
407 auto phe = std::get<event::pending_human_f_p_event>(content);
408 auto imm = state.world.free_provincial_event_get_immediate_effect(phe.e);
409 if(imm) {
410 effect_description(state, contents, imm, trigger::to_generic(phe.p), trigger::to_generic(phe.p), -1, phe.r_lo, phe.r_hi);
411 for(auto& l : delegate->internal_layout.contents) {
412 if(l.color == (delegate->black_text ? text::text_color::white : text::text_color::black)) //Invert colours
413 l.color = delegate->black_text ? text::text_color::black : text::text_color::white;
414 }
415 }
416 }
417
418 calibrate_scrollbar(state);
419}
420
422 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
423
424 auto contents = text::create_endless_layout(state, internal_layout,
425 text::layout_parameters{0, 0, static_cast<int16_t>(base_data.size.x), static_cast<int16_t>(base_data.size.y),
426 base_data.data.text.font_handle, -15, text::alignment::center, black_text ? text::text_color::black : text::text_color::white, false});
427
428 auto box = text::open_layout_box(contents);
430 dcon::text_key name{};
431 if(std::holds_alternative<event::pending_human_n_event>(content)) {
432 auto phe = std::get<event::pending_human_n_event>(content);
433 name = state.world.national_event_get_name(phe.e);
434 populate_event_submap(state, sub, phe);
435 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
436 auto phe = std::get<event::pending_human_f_n_event>(content);
437 name = state.world.free_national_event_get_name(phe.e);
438 populate_event_submap(state, sub, phe);
439 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
440 auto phe = std::get<event::pending_human_p_event>(content);
441 name = state.world.provincial_event_get_name(phe.e);
442 populate_event_submap(state, sub, phe);
443 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
444 auto phe = std::get<event::pending_human_f_p_event>(content);
445 name = state.world.free_provincial_event_get_name(phe.e);
446 populate_event_submap(state, sub, phe);
447 }
448 text::add_to_layout_box(state, contents, box, name, sub);
449 text::close_layout_box(contents, box);
450}
451
452void event_requirements_icon::update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept {
453 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
454 {
455 auto box = text::open_layout_box(contents);
456 text::localised_format_box(state, contents, box, std::string_view("event_show_requirements"));
457 text::close_layout_box(contents, box);
458 }
459
460 if(state.cheat_data.show_province_id_tooltip) {
461 auto box = text::open_layout_box(contents);
462 if(std::holds_alternative<event::pending_human_p_event>(content)) {
463 auto phe = std::get<event::pending_human_p_event>(content);
464 text::add_to_layout_box(state, contents, box, std::string_view("Province Event ID:"));
465 text::add_space_to_layout_box(state, contents, box);
466 text::add_to_layout_box(state, contents, box, std::to_string(phe.e.value));
467 } else if(std::holds_alternative<event::pending_human_n_event>(content)) {
468 auto phe = std::get<event::pending_human_n_event>(content);
469 text::add_to_layout_box(state, contents, box, std::string_view("Nation Event ID:"));
470 text::add_space_to_layout_box(state, contents, box);
471 text::add_to_layout_box(state, contents, box, std::to_string(phe.e.value));
472 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
473 auto phe = std::get<event::pending_human_f_p_event>(content);
474 text::add_to_layout_box(state, contents, box, std::string_view("Free Province Event ID:"));
475 text::add_space_to_layout_box(state, contents, box);
476 text::add_to_layout_box(state, contents, box, std::to_string(phe.e.value));
477 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
478 auto phe = std::get<event::pending_human_f_n_event>(content);
479 text::add_to_layout_box(state, contents, box, std::string_view("Free Nation Event ID:"));
480 text::add_space_to_layout_box(state, contents, box);
481 text::add_to_layout_box(state, contents, box, std::to_string(phe.e.value));
482 text::add_space_to_layout_box(state, contents, box);
483 text::add_to_layout_box(state, contents, box, std::string_view("Legacy:"));
484 text::add_space_to_layout_box(state, contents, box);
485 text::add_to_layout_box(state, contents, box, std::to_string(state.world.free_national_event_get_legacy_id(phe.e)));
486 }
487 text::close_layout_box(contents, box);
488 }
489
490 if(std::holds_alternative<event::pending_human_p_event>(content) || std::holds_alternative<event::pending_human_n_event>(content)) {
491 auto box = text::open_layout_box(contents);
492 text::localised_format_box(state, contents, box, std::string_view("event_only_other_requirements"));
493 text::close_layout_box(contents, box);
494 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
495 auto phe = std::get<event::pending_human_f_p_event>(content);
496 trigger_description(state, contents, state.world.free_provincial_event_get_trigger(phe.e), trigger::to_generic(phe.p),
497 trigger::to_generic(phe.p), -1);
498 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
499 auto phe = std::get<event::pending_human_f_n_event>(content);
500 trigger_description(state, contents, state.world.free_national_event_get_trigger(phe.e), trigger::to_generic(phe.n),
501 trigger::to_generic(phe.n), -1);
502 }
503}
504
505void event_odds_icon::update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept {
506 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
507 {
508 auto box = text::open_layout_box(contents);
509 text::localised_format_box(state, contents, box, std::string_view("event_show_odds"));
510 text::close_layout_box(contents, box);
511 }
512 if(std::holds_alternative<event::pending_human_p_event>(content) || std::holds_alternative<event::pending_human_n_event>(content)) {
513 auto box = text::open_layout_box(contents);
514 text::localised_format_box(state, contents, box, std::string_view("event_only_other_requirements"));
515 text::close_layout_box(contents, box);
516 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
517 auto phe = std::get<event::pending_human_f_p_event>(content);
518 auto mod = state.world.free_provincial_event_get_mtth(phe.e);
519 if(mod)
521 else
522 text::add_line(state, contents, "always");
523 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
524 auto phe = std::get<event::pending_human_f_n_event>(content);
525 auto mod = state.world.free_national_event_get_mtth(phe.e);
526 if(mod)
528 else
529 text::add_line(state, contents, "always");
530 }
531}
532
534 auto iid = retrieve<dcon::issue_id>(state, parent);
535 set_text(state, text::produce_simple_string(state, state.world.issue_get_name(iid)));
536}
537
539 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
540 if(std::holds_alternative<event::pending_human_n_event>(content)) {
541 auto n = dcon::fatten(state.world, std::get<event::pending_human_n_event>(content).n);
543 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
544 auto n = dcon::fatten(state.world, std::get<event::pending_human_f_n_event>(content).n);
546 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
547 auto p = dcon::fatten(state.world, std::get<event::pending_human_p_event>(content).p);
548 auto n = p.get_nation_from_province_ownership();
550 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
551 auto p = dcon::fatten(state.world, std::get<event::pending_human_f_p_event>(content).p);
552 auto n = p.get_nation_from_province_ownership();
554 }
555}
556
558 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
559 if(std::holds_alternative<event::pending_human_n_event>(content)) {
560 auto n = dcon::fatten(state.world, std::get<event::pending_human_n_event>(content).n);
561 set_text(state, text::prettify(int64_t(n.get_demographics(demographics::total))));
562 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
563 auto n = dcon::fatten(state.world, std::get<event::pending_human_f_n_event>(content).n);
564 set_text(state, text::prettify(int64_t(n.get_demographics(demographics::total))));
565 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
566 auto p = dcon::fatten(state.world, std::get<event::pending_human_p_event>(content).p);
567 auto n = p.get_nation_from_province_ownership();
568 set_text(state, text::prettify(int64_t(n.get_demographics(demographics::total))));
569 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
570 auto p = dcon::fatten(state.world, std::get<event::pending_human_f_p_event>(content).p);
571 auto n = p.get_nation_from_province_ownership();
572 set_text(state, text::prettify(int64_t(n.get_demographics(demographics::total))));
573 }
574}
575
577 row_contents.clear();
578 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
579 if(std::holds_alternative<event::pending_human_n_event>(content)) {
580 auto e = std::get<event::pending_human_n_event>(content).e;
581 for(int32_t i = 0; i < sys::max_event_options; ++i) {
582 if(!event::is_valid_option(state.world.national_event_get_options(e)[i]))
583 break;
584 row_contents.push_back(i);
585 }
586 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
587 auto e = std::get<event::pending_human_f_n_event>(content).e;
588 for(int32_t i = 0; i < sys::max_event_options; ++i) {
589 if(!event::is_valid_option(state.world.free_national_event_get_options(e)[i]))
590 break;
591 row_contents.push_back(i);
592 }
593 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
594 auto e = std::get<event::pending_human_p_event>(content).e;
595 for(int32_t i = 0; i < sys::max_event_options; ++i) {
596 if(!event::is_valid_option(state.world.provincial_event_get_options(e)[i]))
597 break;
598 row_contents.push_back(i);
599 }
600 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
601 auto e = std::get<event::pending_human_f_p_event>(content).e;
602 for(int32_t i = 0; i < sys::max_event_options; ++i) {
603 if(!event::is_valid_option(state.world.free_provincial_event_get_options(e)[i]))
604 break;
605 row_contents.push_back(i);
606 }
607 }
608 update(state);
609}
610
613 if(image) {
614 move_child_to_front(image);
615 }
616 if(get_pool_slot() == event_pool_slot::province) {
617 image->set_visible(state, false);
618 {
619 auto ptr = make_element_by_type<event_requirements_icon>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_event_requirements"))->second.definition);
620 ptr->base_data.position.y = int16_t(355);
621 ptr->base_data.position.x += int16_t(ptr->base_data.size.x + 140);
622 add_child_to_front(std::move(ptr));
623 }
624 {
625 auto ptr = make_element_by_type<event_odds_icon>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_event_odds"))->second.definition);
626 ptr->base_data.position.y = int16_t(355);
627 ptr->base_data.position.x += int16_t(ptr->base_data.size.x * 2 + 140);
628 add_child_to_front(std::move(ptr));
629 }
630 {
631 xy_pair cur_offset = state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key(get_option_start_element_name()))->second.definition].position;
632 cur_offset.y += 22;
633 auto ptr = make_element_by_type<provincial_event_listbox>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_povince_event_opts_list"))->second.definition);
634 ptr->base_data.position = cur_offset;
635 ptr->base_data.position.y -= 150; // Omega nudge??
636 add_child_to_front(std::move(ptr));
637 }
638 } else {
639 {
640 auto ptr = make_element_by_type<event_requirements_icon>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_event_requirements"))->second.definition);
641 ptr->base_data.position.y = 20;
642 ptr->base_data.position.x += ptr->base_data.size.x;
643 add_child_to_front(std::move(ptr));
644 }
645 {
646 auto ptr = make_element_by_type<event_odds_icon>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_event_odds"))->second.definition);
647 ptr->base_data.position.y = 20;
648 ptr->base_data.position.x += ptr->base_data.size.x * 2;
649 add_child_to_front(std::move(ptr));
650 }
651 xy_pair cur_offset = state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key(get_option_start_element_name()))->second.definition].position;
652 if(get_pool_slot() == event_pool_slot::country_election) {
653 auto ptr = make_element_by_type<national_election_event_listbox>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_election_event_opts_list"))->second.definition);
654 ptr->base_data.position = cur_offset;
655 ptr->base_data.position.y += 5;
656 add_child_to_front(std::move(ptr));
657 } else {
658 auto ptr = make_element_by_type<national_event_listbox>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_nation_event_opts_list"))->second.definition);
659 ptr->base_data.position = cur_offset;
660 ptr->base_data.position.y += 5;
661 add_child_to_front(std::move(ptr));
662 }
663 }
664}
665
667public:
668 void on_update(sys::state& state) noexcept override {
669 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
670 if(std::holds_alternative<event::pending_human_n_event>(content)) {
671 set_text(state, text::date_to_string(state, std::get<event::pending_human_n_event>(content).date));
672 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
673 set_text(state, text::date_to_string(state, std::get<event::pending_human_f_n_event>(content).date));
674 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
675 set_text(state, text::date_to_string(state, std::get<event::pending_human_p_event>(content).date));
676 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
677 set_text(state, text::date_to_string(state, std::get<event::pending_human_f_p_event>(content).date));
678 }
679 }
680};
681
683public:
684 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
685 dcon::gfx_object_id gid;
690 }
691 if(gid && flag_texture_handle > 0) {
692 auto& gfx_def = state.ui_defs.gfx[gid];
693 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
694 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
696 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle, base_data.get_rotation(),
697 gfx_def.is_vertically_flipped(),
698 state.world.locale_get_native_rtl(state.font_collection.get_current_locale()));
699 }
701 }
702 void on_create(sys::state& state) noexcept override {
704 base_data.position.x += int16_t(24);
705 base_data.position.y -= int16_t(25);
707 }
708 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
709 auto n = retrieve<dcon::nation_id>(state, parent);
710 return state.world.nation_get_identity_from_identity_holder(n);
711 }
712 void button_action(sys::state& state) noexcept override {
713
714 }
715};
716
718public:
719 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
720 dcon::gfx_object_id gid;
725 }
726 if(gid && flag_texture_handle > 0) {
727 auto& gfx_def = state.ui_defs.gfx[gid];
728 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
729 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
730 //auto rotation = 0.f;
732 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle,
733 ui::rotation::r90_right, false, state.world.locale_get_native_rtl(state.font_collection.get_current_locale()));
735 float(x), float(y), float(base_data.size.x), float(base_data.size.y),
736 ogl::get_texture_handle(state, gfx_def.primary_texture_handle, gfx_def.is_partially_transparent()),
737 ui::rotation::r90_right, false, state.world.locale_get_native_rtl(state.font_collection.get_current_locale()));
738 }
739 }
740 void on_create(sys::state& state) noexcept override {
742 base_data.position.x += int16_t(21);
743 base_data.position.y -= int16_t(25);
745 }
746 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
747 auto n = retrieve<dcon::nation_id>(state, parent);
748 return state.world.nation_get_identity_from_identity_holder(n);
749 }
750 void button_action(sys::state& state) noexcept override {
751
752 }
753};
754
756public:
757 void on_update(sys::state& state) noexcept override {
759 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
760 if(std::holds_alternative<event::pending_human_p_event>(content)) {
761 set_text(state, text::produce_simple_string(state, state.world.province_get_name(std::get<event::pending_human_p_event>(content).p)));
762 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
763 set_text(state, text::produce_simple_string(state, state.world.province_get_name(std::get<event::pending_human_f_p_event>(content).p)));
764 }
765 }
766
767 message_result on_lbutton_down(sys::state& state, int32_t x, int32_t y, sys::key_modifiers mods) noexcept override {
768 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
769 dcon::province_id prov{};
770 if(std::holds_alternative<event::pending_human_p_event>(content)) {
771 prov = std::get<event::pending_human_p_event>(content).p;
772 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
773 prov = std::get<event::pending_human_f_p_event>(content).p;
774 }
775 if(!prov || prov.value >= state.province_definitions.first_sea_province.value)
777
778 sound::play_interface_sound(state, sound::get_click_sound(state), state.user_settings.interface_volume * state.user_settings.master_volume);
779 state.map_state.set_selected_province(prov);
780 static_cast<ui::province_view_window*>(state.ui_state.province_window)->set_active_province(state, prov);
781 if(state.map_state.get_zoom() < map::zoom_very_close)
782 state.map_state.zoom = map::zoom_very_close;
783 state.map_state.center_map_on_province(state, prov);
785 }
786 message_result test_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
788 }
789};
790
791class election_voter_issue_entry : public listbox_row_element_base<dcon::issue_option_id> {
792private:
793 simple_text_element_base* issname = nullptr;
794 simple_text_element_base* issvalue = nullptr;
795public:
796 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
797 if(name == "issue_name") {
798 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
799 issname = ptr.get();
800 return ptr;
801 } else if(name == "voters_perc") {
802 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
803 issvalue = ptr.get();
804 return ptr;
805 } else {
806 return nullptr;
807 }
808 }
809 void on_update(sys::state& state) noexcept override {
810 auto n = retrieve<dcon::nation_id>(state, parent);
812 auto total = state.world.nation_get_demographics(n, demographics::total);
813 if(total > 0.f) {
814 auto value = state.world.nation_get_demographics(n, demographics::to_key(state, content)) / total;
815 issvalue->set_text(state, text::format_percentage(value));
816 }
817 }
818};
819
820class election_voter_issues_listbox : public listbox_element_base<election_voter_issue_entry, dcon::issue_option_id> {
821protected:
822 std::string_view get_row_element_name() override {
823 return "ew_issue_option_window";
824 }
825public:
826 void on_update(sys::state& state) noexcept override {
827 row_contents.clear();
828 auto content = retrieve<dcon::issue_id>(state, parent);
829 state.world.for_each_issue_option([&](dcon::issue_option_id id) {
830 if(content == dcon::fatten(state.world, id).get_parent_issue().id) {
831 row_contents.push_back(id);
832 }
833 });
834 update(state);
835 }
836};
837class election_party_entry : public listbox_row_element_base<dcon::political_party_id> {
838 simple_text_element_base* partyname = nullptr;
839 simple_text_element_base* partyvalue = nullptr;
840public:
841 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
842 if(name == "legend_color") {
843 return make_element_by_type<ideology_plupp>(state, id);
844 } else if(name == "legend_title") {
845 return make_element_by_type<generic_name_text<dcon::political_party_id>>(state, id);
846 } else if(name == "legend_desc") {
847 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
848 ptr->base_data.position.x += 4; // Nudge
849 partyvalue = ptr.get();
850 return ptr;
851 } else if(name == "legend_value") {
852 return make_element_by_type<invisible_element>(state, id);
853 } else {
854 return nullptr;
855 }
856 }
857
858 void on_update(sys::state& state) noexcept override {
859 auto issid = retrieve<dcon::issue_id>(state, parent);
860 partyvalue->set_text(state, text::produce_simple_string(state, dcon::fatten(state.world, content).get_party_issues(issid).get_name()));
861 }
862
863 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
864 if(payload.holds_type<dcon::ideology_id>()) {
865 payload.emplace<dcon::ideology_id>(state.world.political_party_get_ideology(content));
867 }
869 }
870};
871
872class election_parties_listbox : public listbox_element_base<election_party_entry, dcon::political_party_id> {
873protected:
874 std::string_view get_row_element_name() override {
875 return "eew_item";
876 }
877public:
878 void on_update(sys::state& state) noexcept override {
879 auto n = retrieve<dcon::nation_id>(state, parent);
880 row_contents.clear();
882 update(state);
883 }
884};
885class election_popularity_entry : public listbox_row_element_base<dcon::political_party_id> {
886public:
889public:
890 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
891 if(name == "legend_color") {
892 return make_element_by_type<ideology_plupp>(state, id);
893 } else if(name == "legend_title") {
894 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
895 partyname = ptr.get();
896 return ptr;
897 } else if(name == "legend_desc") {
898 return make_element_by_type<simple_text_element_base>(state, id);
899 } else if(name == "legend_value") {
900 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
901 ptr->base_data.position.x += 3; // Nudge
902 partyvalue = ptr.get();
903 return ptr;
904 } else {
905 return nullptr;
906 }
907 }
908 void on_update(sys::state& state) noexcept override {
909 auto n = retrieve<dcon::nation_id>(state, parent);
910 auto fat = dcon::fatten(state.world, content);
911 partyname->set_text(state, text::produce_simple_string(state, state.world.political_party_get_name(content)));
912 auto const total = state.world.nation_get_demographics(n, demographics::total);
913 if(total > 0.f) {
914 partyvalue->set_text(state, text::format_percentage(state.world.nation_get_demographics(n, demographics::to_key(state, fat.get_ideology().id)) / total, 0));
915 }
916 }
917 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
918 if(payload.holds_type<dcon::ideology_id>()) {
919 payload.emplace<dcon::ideology_id>(state.world.political_party_get_ideology(content));
921 }
923 }
924};
925
926class election_popularity_listbox : public listbox_element_base<election_popularity_entry, dcon::political_party_id> {
927protected:
928 std::string_view get_row_element_name() override {
929 return "eew_item";
930 }
931public:
932 void on_update(sys::state& state) noexcept override {
933 auto n = retrieve<dcon::nation_id>(state, parent);
934 row_contents.clear();
936 update(state);
937 }
938};
939
941public:
942 void on_create(sys::state& state) noexcept override {
943 base_data.position.x -= base_data.size.x / int16_t(2);
944 base_data.position.x += int16_t(8);
945 base_data.size.x *= 2;
946 base_data.size.y *= 2;
948 }
949};
950class election_party_popularity_piechart : public piechart<dcon::political_party_id> {
951public:
952 void on_update(sys::state& state) noexcept override {
953 auto n = retrieve<dcon::nation_id>(state, parent);
954 distribution.clear();
955 auto total = state.world.nation_get_demographics(n, demographics::total);
956 if(total > 0.f) {
957 std::vector<dcon::political_party_id> parties;
959 for(auto ppid : state.world.in_political_party) {
960 distribution.emplace_back(ppid.id, 0.0f);
961 }
962 for(auto ppid : parties) {
963 auto const dkey = demographics::to_key(state, state.world.political_party_get_ideology(ppid));
964 distribution[ppid.index()].value += state.world.nation_get_demographics(n, dkey) / total;
965 }
966 }
968 }
969 void on_create(sys::state& state) noexcept override {
971 piechart<dcon::political_party_id>::base_data.position.x += int16_t(8);
975 }
976};
977
978std::unique_ptr<element_base> election_issue_support_item::make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept {
979 if(name == "issue_name") {
980 return make_element_by_type<generic_name_text<dcon::issue_option_id>>(state, id);
981 } else if(name == "people_perc") {
982 return make_element_by_type<issue_option_popular_support>(state, id);
983 } else if(name == "voters_perc") {
984 return make_element_by_type<issue_option_voter_support>(state, id);
985 } else {
986 return nullptr;
987 }
988}
989
991 row_contents.clear();
992 auto iid = retrieve<dcon::issue_id>(state, parent);
993 for(const auto ioid : state.world.in_issue_option) {
994 if(ioid.get_parent_issue() == iid)
995 row_contents.push_back(ioid);
996 }
997 update(state);
998}
999
1000std::unique_ptr<element_base> base_event_window::make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept {
1001 if(name == "background") {
1002 return make_element_by_type<draggable_target>(state, id);
1003 } else if(name == "title") {
1004 return make_element_by_type<event_name_text>(state, id);
1005 } else if(name == "description") {
1006 return make_element_by_type<event_desc_text>(state, id);
1007 } else if(name == "event_images") {
1008 auto ptr = make_element_by_type<event_image>(state, id);
1009 image = ptr.get();
1010 return ptr;
1011 } else if(name == "event_separator_image") {
1012 auto ptr = make_element_by_type<image_element_base>(state, id);
1013 xy_pair cur_offset = state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key("event_province_option_start"))->second.definition].position;
1014 ptr->base_data.position.y = cur_offset.y;
1015 ptr->base_data.position.y -= 150; // Omega nudge??
1016 return ptr;
1017 } else if(name == "date") {
1018 return make_element_by_type<event_date_text>(state, id);
1019 } else if(name == "state_name") {
1020 return make_element_by_type<event_state_name_text>(state, id);
1021 } else if(name == "subtitle") {
1022 return make_element_by_type<event_subtitle_text>(state, id);
1023 } else if(name == "population_amount") {
1024 return make_element_by_type<event_population_amount_text>(state, id);
1025 } else if(name == "country_flag1") {
1026 return make_element_by_type<major_event_left_flag>(state, id);
1027 } else if(name == "country_flag2") {
1028 return make_element_by_type<major_event_right_flag>(state, id);
1029 } else if(name == "province") {
1030 return make_element_by_type<event_province_text>(state, id);
1031 } else if(name == "perc_of_parlament") {
1032 return make_element_by_type<nation_ruling_party_ideology_text>(state, id);
1033 } else if(name == "parties_listbox") {
1034 return make_element_by_type<election_parties_listbox>(state, id);
1035 } else if(name == "chart_ideology") {
1036 return make_element_by_type<election_voter_ideology_piechart>(state, id);
1037 } else if(name == "chart_popularity") {
1038 return make_element_by_type<election_party_popularity_piechart>(state, id);
1039 } else if(name == "popularity_listbox") {
1040 return make_element_by_type<election_popularity_listbox>(state, id);
1041 } else if(name == "sort_by_issue_name") {
1042 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
1044 return ptr;
1045 } else if(name == "sort_by_people") {
1046 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
1048 return ptr;
1049 } else if(name == "sort_by_voters") {
1050 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
1052 return ptr;
1053 } else if(name == "issues_listbox") {
1054 auto ptr = make_element_by_type<elections_issue_option_listbox>(state, id);
1055 issues_listbox = ptr.get();
1056 return ptr;
1057 }
1058 return nullptr;
1059}
1060
1062 if(payload.holds_type<dcon::nation_id>()) {
1063 payload.emplace<dcon::nation_id>(state.local_player_nation);
1065 } else if(payload.holds_type<dcon::issue_id>()) {
1066 if(std::holds_alternative<event::pending_human_n_event>(event_data)) {
1067 auto e = std::get<event::pending_human_n_event>(event_data).e;
1069 payload.emplace<dcon::issue_id>(iid);
1070 }
1072 } else if(payload.holds_type<event_data_wrapper>()) {
1073 if(std::holds_alternative<event::pending_human_n_event>(event_data))
1074 payload.emplace<event_data_wrapper>(std::get<event::pending_human_n_event>(event_data));
1075 else if(std::holds_alternative<event::pending_human_f_n_event>(event_data))
1076 payload.emplace<event_data_wrapper>(std::get<event::pending_human_f_n_event>(event_data));
1077 else if(std::holds_alternative<event::pending_human_p_event>(event_data))
1078 payload.emplace<event_data_wrapper>(std::get<event::pending_human_p_event>(event_data));
1079 else if(std::holds_alternative<event::pending_human_f_p_event>(event_data))
1080 payload.emplace<event_data_wrapper>(std::get<event::pending_human_f_p_event>(event_data));
1082 } else if(payload.holds_type<option_taken_notification>()) {
1083 set_visible(state, false);
1084 auto uptr = state.ui_state.root->remove_child(this);
1085 if(uptr) {
1086 auto slot = uint8_t(get_pool_slot());
1087 std::unique_ptr<base_event_window> ptr(static_cast<base_event_window*>(uptr.release()));
1088 event_pool[slot].push_back(std::move(ptr));
1089 --pending_events[slot];
1090 }
1092 } else if(payload.holds_type<politics_issue_sort_order>()) {
1093 auto enum_val = any_cast<politics_issue_sort_order>(payload);
1094 switch(enum_val) {
1096 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
1097 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
1098 auto a_name = text::get_name_as_string(state, dcon::fatten(state.world, a));
1099 auto b_name = text::get_name_as_string(state, dcon::fatten(state.world, b));
1100 return a_name < b_name;
1101 });
1102 issues_listbox->update(state);
1103 break;
1105 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
1106 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
1107 auto a_support = politics::get_popular_support(state, state.local_player_nation, a);
1108 auto b_support = politics::get_popular_support(state, state.local_player_nation, b);
1109 return a_support > b_support;
1110 });
1111 issues_listbox->update(state);
1112 break;
1114 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
1115 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
1116 auto a_support = politics::get_voter_support(state, state.local_player_nation, a);
1117 auto b_support = politics::get_voter_support(state, state.local_player_nation, b);
1118 return a_support > b_support;
1119 });
1120 issues_listbox->update(state);
1121 break;
1122 }
1124 }
1126}
1127
1129 if(std::holds_alternative<event::pending_human_n_event>(event_data)) {
1130 if(std::get<event::pending_human_n_event>(event_data).date + event::expiration_in_days <= state.current_date) {
1131 pending_closure.push_back(this);
1132 }
1133 } else if(std::holds_alternative<event::pending_human_f_n_event>(event_data)) {
1134 if(std::get<event::pending_human_f_n_event>(event_data).date + event::expiration_in_days <= state.current_date) {
1135 pending_closure.push_back(this);
1136 }
1137 } else if(std::holds_alternative<event::pending_human_p_event>(event_data)) {
1138 if(std::get<event::pending_human_p_event>(event_data).date + event::expiration_in_days <= state.current_date) {
1139 pending_closure.push_back(this);
1140 }
1141 } else if(std::holds_alternative<event::pending_human_f_p_event>(event_data)) {
1142 if(std::get<event::pending_human_f_p_event>(event_data).date + event::expiration_in_days <= state.current_date) {
1143 pending_closure.push_back(this);
1144 }
1145 }
1146}
1147
1149 for(auto e : pending_closure)
1151 pending_closure.clear();
1152}
1153
1155 for(auto const& slot_pool : ui::event_pool) {
1156 for(auto const& win : slot_pool) {
1157 pending_closure.push_back(win.get());
1158 }
1159 }
1161}
1162
1164 bool a = ((state.user_settings.self_message_settings[int32_t(sys::message_setting_type::province_event)] & sys::message_response::pause) != 0 && ui::pending_events[uint8_t(ui::event_pool_slot::province)] > 0);
1165 bool b = ((state.user_settings.self_message_settings[int32_t(sys::message_setting_type::national_event)] & sys::message_response::pause) != 0 && ui::pending_events[uint8_t(ui::event_pool_slot::country)] > 0);
1166 bool c = ((state.user_settings.self_message_settings[int32_t(sys::message_setting_type::major_event)] & sys::message_response::pause) != 0 && ui::pending_events[uint8_t(ui::event_pool_slot::country_major)] > 0);
1167 return a || b || c;
1168}
1169
1170template<typename T>
1172 auto const slot = uint8_t(e_slot);
1173 if(event_pool[slot].empty()) {
1174 auto new_elm = ui::make_element_by_type<T>(state, T::window_element_name);
1175 auto ptr = new_elm.get();
1176 T* actual = static_cast<T*>(ptr);
1177 actual->event_data = dat;
1178 actual->impl_on_update(state);
1179 state.ui_state.root->add_child_to_front(std::move(new_elm));
1180 } else {
1181 std::unique_ptr<base_event_window> ptr = std::move(event_pool[slot].back());
1182 event_pool[slot].pop_back();
1183 ptr->event_data = dat;
1184 if(!ptr->is_visible())
1185 ptr->base_data.position = state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key(T::window_element_name))->second.definition].position;
1186 ptr->set_visible(state, true);
1187 state.ui_state.root->add_child_to_front(std::move(ptr));
1188 }
1189}
1190
1192 auto slot = event_pool_slot::country;
1193 if(std::holds_alternative<event::pending_human_n_event>(dat)) {
1195 auto e = std::get<event::pending_human_n_event>(dat).e;
1196 if(state.world.national_event_get_is_major(e)) {
1198 } else if(event::get_election_event_issue(state, e)) {
1200 }
1201 } else if(std::holds_alternative<event::pending_human_f_n_event>(dat)) {
1203 auto e = std::get<event::pending_human_f_n_event>(dat).e;
1204 if(state.world.free_national_event_get_is_major(e)) {
1206 }
1207 } else if(std::holds_alternative<event::pending_human_p_event>(dat)) {
1209 } else if(std::holds_alternative<event::pending_human_f_p_event>(dat)) {
1211 }
1212 switch(slot) {
1214 new_event_window_1<national_event_window>(state, dat, slot);
1215 break;
1217 new_event_window_1<national_major_event_window>(state, dat, slot);
1218 break;
1220 new_event_window_1<national_election_event_window>(state, dat, slot);
1221 break;
1223 new_event_window_1<provincial_event_window>(state, dat, slot);
1224 break;
1225 default:
1226 return;
1227 }
1228 ++pending_events[uint8_t(slot)];
1229}
1230
1231} // namespace ui
dcon::text_key get_name() noexcept
year_month_day to_ymd(absolute_time_point base) const noexcept
constexpr date() noexcept=default
value_base_t value
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:576
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:1128
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
Definition: gui_event.cpp:1000
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
Definition: gui_event.cpp:1061
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:611
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
Definition: gui_event.cpp:978
std::string_view get_row_element_name() override
Definition: gui_event.cpp:874
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:878
Definition: gui_event.cpp:837
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:858
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
Definition: gui_event.cpp:841
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
Definition: gui_event.cpp:863
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:952
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:969
Definition: gui_event.cpp:885
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
Definition: gui_event.cpp:917
simple_text_element_base * partyname
Definition: gui_event.cpp:887
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:908
simple_text_element_base * partyvalue
Definition: gui_event.cpp:888
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
Definition: gui_event.cpp:890
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:932
std::string_view get_row_element_name() override
Definition: gui_event.cpp:928
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:942
Definition: gui_event.cpp:791
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:809
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
Definition: gui_event.cpp:796
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:826
std::string_view get_row_element_name() override
Definition: gui_event.cpp:822
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:990
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
virtual void on_create(sys::state &state) noexcept
element_data base_data
void button_action(sys::state &state) noexcept override
Definition: gui_event.cpp:252
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:668
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:338
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:345
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:330
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:421
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
Definition: gui_event.cpp:505
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:225
void button_action(sys::state &state) noexcept override
Definition: gui_event.cpp:311
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
Definition: gui_event.cpp:276
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:557
message_result on_lbutton_down(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mods) noexcept override
Definition: gui_event.cpp:767
message_result test_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept override
Definition: gui_event.cpp:786
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:757
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
Definition: gui_event.cpp:452
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:538
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:533
void on_create(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
Definition: gui_event.cpp:746
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:740
void button_action(sys::state &state) noexcept override
Definition: gui_event.cpp:750
void render(sys::state &state, int32_t x, int32_t y) noexcept override
Definition: gui_event.cpp:719
void button_action(sys::state &state) noexcept override
Definition: gui_event.cpp:712
void render(sys::state &state, int32_t x, int32_t y) noexcept override
Definition: gui_event.cpp:684
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:702
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
Definition: gui_event.cpp:708
void on_create(sys::state &state) noexcept override
void on_create(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 make_event_choice(sys::state &state, event::pending_human_n_event const &e, uint8_t option_id)
Definition: commands.cpp:2087
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr dcon::demographics_key total(0)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
int32_t state_factory_count(sys::state &state, dcon::state_instance_id sid, dcon::nation_id n)
Definition: economy.cpp:8347
constexpr int32_t expiration_in_days
Definition: events.hpp:9
slot_type
Definition: events.hpp:11
dcon::issue_id get_election_event_issue(sys::state &state, dcon::national_event_id e)
Definition: events.cpp:787
bool is_valid_option(sys::event_option const &opt)
Definition: events.cpp:10
constexpr float zoom_very_close
Definition: constants.hpp:606
void get_active_political_parties(sys::state &state, dcon::nation_id n, std::vector< dcon::political_party_id > &parties)
Definition: nations.cpp:1457
void render_masked_rect(sys::state const &state, color_modification enabled, float x, float y, float width, float height, GLuint texture_handle, GLuint mask_texture_handle, ui::rotation r, bool flipped, bool rtl)
void render_textured_rect(sys::state const &state, color_modification enabled, float x, float y, float width, float height, GLuint texture_handle, ui::rotation r, bool flipped, bool rtl)
GLuint get_texture_handle(sys::state &state, dcon::texture_id id, bool keep_data)
Definition: texture.cpp:1066
random_pair get_random_pair(sys::state const &state, uint32_t value_in)
Definition: prng.cpp:26
uint32_t reduce(uint32_t value_in, uint32_t upper_bound)
Definition: prng.cpp:46
void play_interface_sound(sys::state &state, audio_instance &s, float volume)
Definition: sound_nix.cpp:203
audio_instance & get_click_sound(sys::state &state)
Definition: sound_nix.cpp:263
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.hpp:24635
constexpr uint8_t pause
Definition: constants.hpp:538
key_modifiers
Definition: constants.hpp:156
constexpr int32_t max_event_options
Definition: constants.hpp:562
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
std::string resolve_string_substitution(sys::state &state, dcon::text_key source_text, substitution_map const &mp)
Definition: text.cpp:2137
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1823
std::string date_to_string(sys::state &state, sys::date date)
Definition: text.cpp:1082
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1904
std::string prettify(int64_t num)
Definition: text.cpp:762
endless_layout create_endless_layout(sys::state &state, layout &dest, layout_parameters const &params)
Definition: text.cpp:1100
dcon::text_key get_ruler_title(sys::state &state, dcon::nation_id n)
Definition: text.cpp:899
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1923
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
Definition: text.cpp:1068
dcon::text_key get_adjective(sys::state &state, dcon::nation_id id)
Definition: text.cpp:890
uint16_t name_into_font_id(sys::state &state, std::string_view txt)
Definition: fonts.cpp:93
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
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:1812
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1831
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
dcon::state_instance_id to_state(int32_t v)
Definition: triggers.hpp:136
dcon::province_id to_prov(int32_t v)
Definition: triggers.hpp:88
dcon::nation_id to_nation(int32_t v)
Definition: triggers.hpp:104
void multiplicative_value_modifier_description(sys::state &state, text::layout_base &layout, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
void effect_description(sys::state &state, text::layout_base &layout, dcon::effect_key k, int32_t primary_slot, int32_t this_slot, int32_t from_slot, uint32_t r_lo, uint32_t r_hi)
politics_issue_sort_order
void new_event_window_1(sys::state &state, event_data_wrapper &dat, event_pool_slot e_slot)
Definition: gui_event.cpp:1171
void send(sys::state &state, element_base *parent, T value)
void close_expired_event_windows(sys::state &state)
Definition: gui_event.cpp:1148
void populate_event_submap(sys::state &state, text::substitution_map &sub, std::variant< event::pending_human_n_event, event::pending_human_f_n_event, event::pending_human_p_event, event::pending_human_f_p_event > const &phe) noexcept
Definition: gui_event.cpp:12
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)
event_pool_slot
Definition: gui_event.hpp:121
@ country_major
Definition: gui_event.hpp:124
@ country
Definition: gui_event.hpp:122
@ country_election
Definition: gui_event.hpp:123
@ province
Definition: gui_event.hpp:125
@ count
Definition: gui_event.hpp:126
message_result
void clear_event_windows(sys::state &state)
Definition: gui_event.cpp:1154
ogl::color_modification get_color_modification(bool is_under_mouse, bool is_disabled, bool is_interactable)
bool events_pause_test(sys::state &state)
Definition: gui_event.cpp:1163
std::variant< event::pending_human_n_event, event::pending_human_f_n_event, event::pending_human_p_event, event::pending_human_f_p_event > event_data_wrapper
Definition: gui_event.hpp:12
void new_event_window(sys::state &state, event_data_wrapper dat)
Definition: gui_event.cpp:1191
uint uint32_t
uchar uint8_t
Holds important data about the game world, state, and other data regarding windowing,...
dcon::gfx_object_id button_image
element_type get_element_type() const
rotation get_rotation() const
union ui::element_data::internal_data data
dcon::gfx_object_id gfx_object
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name
std::unique_ptr< element_base > root
element_base * province_window
element_base * under_mouse