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
153 text::add_to_substitution_map(sub, text::variable_type::crisistaker_adj, state.world.national_identity_get_adjective(state.crisis_liberation_tag));
154 text::add_to_substitution_map(sub, text::variable_type::crisistaker_capital, state.world.national_identity_get_capital(state.crisis_liberation_tag));
155 text::add_to_substitution_map(sub, text::variable_type::crisistaker_continent, state.world.national_identity_get_capital(state.crisis_liberation_tag).get_continent().get_name());
157 text::add_to_substitution_map(sub, text::variable_type::crisisattacker_capital, state.world.nation_get_capital(state.primary_crisis_attacker));
158 text::add_to_substitution_map(sub, text::variable_type::crisisattacker_continent, state.world.nation_get_capital(state.primary_crisis_attacker).get_continent().get_name());
160 text::add_to_substitution_map(sub, text::variable_type::crisisdefender_capital, state.world.nation_get_capital(state.primary_crisis_defender));
161 text::add_to_substitution_map(sub, text::variable_type::crisisdefender_continent, state.world.nation_get_capital(state.primary_crisis_defender).get_continent().get_name());
166 // Dates
167 text::add_to_substitution_map(sub, text::variable_type::year, int32_t(event_date.to_ymd(state.start_date).year));
168 //text::add_to_substitution_map(sub, text::variable_type::month, text::localize_month(state, event_date.to_ymd(state.start_date).month));
169 text::add_to_substitution_map(sub, text::variable_type::day, int32_t(event_date.to_ymd(state.start_date).day));
170
171 // Non-vanilla
172 text::add_to_substitution_map(sub, text::variable_type::government, state.world.nation_get_government_type(target_nation).get_name());
173 text::add_to_substitution_map(sub, text::variable_type::ideology, state.world.nation_get_ruling_party(target_nation).get_ideology().get_name());
174 text::add_to_substitution_map(sub, text::variable_type::party, state.world.nation_get_ruling_party(target_nation).get_name());
176 text::add_to_substitution_map(sub, text::variable_type::fromcontinent, state.world.province_get_continent(from_province).get_name());
177 text::add_to_substitution_map(sub, text::variable_type::fromcapital, state.world.province_get_name(from_capital));
178 text::add_to_substitution_map(sub, text::variable_type::religion, state.world.religion_get_name(state.world.nation_get_religion(target_nation)));
179 text::add_to_substitution_map(sub, text::variable_type::infamy, text::fp_two_places{ state.world.nation_get_infamy(target_nation) });
180 text::add_to_substitution_map(sub, text::variable_type::badboy, text::fp_two_places{ state.world.nation_get_infamy(target_nation) });
181 text::add_to_substitution_map(sub, text::variable_type::spheremaster, state.world.nation_get_in_sphere_of(target_nation));
182 text::add_to_substitution_map(sub, text::variable_type::overlord, state.world.overlord_get_ruler(state.world.nation_get_overlord_as_subject(target_nation)));
183 text::add_to_substitution_map(sub, text::variable_type::nationalvalue, state.world.nation_get_national_value(target_nation).get_name());
184 text::add_to_substitution_map(sub, text::variable_type::good, state.world.province_get_rgo(target_province).get_name());
185 text::add_to_substitution_map(sub, text::variable_type::resource, state.world.province_get_rgo(target_province).get_name());
186 text::add_to_substitution_map(sub, text::variable_type::terrain, state.world.province_get_terrain(target_province).get_name());
189 text::add_to_substitution_map(sub, text::variable_type::focus, state.world.state_instance_get_owner_focus(target_state).get_name());
190 text::add_to_substitution_map(sub, text::variable_type::nf, state.world.state_instance_get_owner_focus(target_state).get_name());
191 auto names_pair = rng::get_random_pair(state, uint32_t(target_nation.index()) << 6, uint32_t(event_date.value));
192 auto first_names = state.world.culture_get_first_names(state.world.nation_get_primary_culture(target_nation));
193 if(first_names.size() > 0) {
194 auto first_name = first_names.at(rng::reduce(uint32_t(names_pair.high), first_names.size()));
195 auto last_names = state.world.culture_get_last_names(state.world.nation_get_primary_culture(target_nation));
196 if(last_names.size() > 0) {
197 auto last_name = last_names.at(rng::reduce(uint32_t(names_pair.high), last_names.size()));
200 }
201 }
203 if(auto fl = state.world.province_get_factory_location_as_province(target_province); fl.begin() != fl.end()) {
204 text::add_to_substitution_map(sub, text::variable_type::factory, (*fl.begin()).get_factory().get_building_type().get_name());
205 }
206 text::add_to_substitution_map(sub, text::variable_type::tech, state.world.nation_get_current_research(target_nation).get_name());
207 //std::string list_provinces = "";
208 //for(const auto p : state.world.state_definition_get_abstract_state_membership(state.world.state_instance_get_definition(target_state))) {
209 // list_provinces += text::produce_simple_string(state, p.get_province().get_name()) + ", ";
210 //}
211 //text::add_to_substitution_map(sub, text::variable_type::provinces, list_provinces);
214 text::add_to_substitution_map(sub, text::variable_type::control, state.world.province_get_nation_from_province_control(target_province));
215 text::add_to_substitution_map(sub, text::variable_type::owner, state.world.province_get_nation_from_province_ownership(target_province));
216 if(auto plist = state.world.nation_get_province_ownership(target_nation); plist.begin() != plist.end()) {
217 auto plist_size = uint32_t(plist.end() - plist.begin());
218 uint32_t index = rng::reduce(uint32_t(names_pair.high), plist_size);
219 text::add_to_substitution_map(sub, text::variable_type::anyprovince, (*(plist.begin() + index)).get_province());
220 }
221}
222
224 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
225 auto index = retrieve<int32_t>(state, parent);
226
229 if(std::holds_alternative<event::pending_human_n_event>(content)) {
230 auto const& phe = std::get<event::pending_human_n_event>(content);
231 opt = state.world.national_event_get_options(std::get<event::pending_human_n_event>(content).e)[index];
232 populate_event_submap(state, sub, phe);
233 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
234 auto const& phe = std::get<event::pending_human_f_n_event>(content);
235 opt = state.world.free_national_event_get_options(std::get<event::pending_human_f_n_event>(content).e)[index];
236 populate_event_submap(state, sub, phe);
237 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
238 auto const& phe = std::get<event::pending_human_p_event>(content);
239 opt = state.world.provincial_event_get_options(std::get<event::pending_human_p_event>(content).e)[index];
240 populate_event_submap(state, sub, phe);
241 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
242 auto const& phe = std::get<event::pending_human_f_p_event>(content);
243 opt = state.world.free_provincial_event_get_options(std::get<event::pending_human_f_p_event>(content).e)[index];
244 populate_event_submap(state, sub, phe);
245 }
246
247 set_button_text(state, text::resolve_string_substitution(state, opt.name, sub));
248}
249
251 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
252 auto index = retrieve<int32_t>(state, parent);
253
254 if(std::holds_alternative<event::pending_human_n_event>(content)) {
255 auto const& phe = std::get<event::pending_human_n_event>(content);
256 state.world.national_event_set_auto_choice(phe.e, uint8_t(index + 1));
258 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
259 auto const& phe = std::get<event::pending_human_f_n_event>(content);
260 state.world.free_national_event_set_auto_choice(phe.e, uint8_t(index + 1));
262 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
263 auto const& phe = std::get<event::pending_human_p_event>(content);
264 state.world.provincial_event_set_auto_choice(phe.e, uint8_t(index + 1));
266 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
267 auto const& phe = std::get<event::pending_human_f_p_event>(content);
268 state.world.free_provincial_event_set_auto_choice(phe.e, uint8_t(index + 1));
270 }
272}
273
274void event_option_button::update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept {
275 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
276 auto index = retrieve<int32_t>(state, parent);
277
278 if(std::holds_alternative<event::pending_human_n_event>(content)) {
279 auto const& phe = std::get<event::pending_human_n_event>(content);
280 if(index == 0) {
281 text::add_line(state, contents, "event_taken_auto", text::variable_type::date, phe.date + 30);
282 }
283 effect_description(state, contents, state.world.national_event_get_options(phe.e)[index].effect, phe.primary_slot,
284 trigger::to_generic(phe.n), phe.from_slot, phe.r_lo, phe.r_hi);
285 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
286 auto const& phe = std::get<event::pending_human_f_n_event>(content);
287 if(index == 0) {
288 text::add_line(state, contents, "event_taken_auto", text::variable_type::date, phe.date + 30);
289 }
290 effect_description(state, contents, state.world.free_national_event_get_options(phe.e)[index].effect,
291 trigger::to_generic(phe.n), trigger::to_generic(phe.n), -1, phe.r_lo, phe.r_hi);
292 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
293 auto const& phe = std::get<event::pending_human_p_event>(content);
294 if(index == 0) {
295 text::add_line(state, contents, "event_taken_auto", text::variable_type::date, phe.date + 30);
296 }
297 effect_description(state, contents, state.world.provincial_event_get_options(phe.e)[index].effect,
298 trigger::to_generic(phe.p), trigger::to_generic(phe.p), phe.from_slot, phe.r_lo, phe.r_hi);
299 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
300 auto const& phe = std::get<event::pending_human_f_p_event>(content);
301 if(index == 0) {
302 text::add_line(state, contents, "event_taken_auto", text::variable_type::date, phe.date + 30);
303 }
304 effect_description(state, contents, state.world.free_provincial_event_get_options(phe.e)[index].effect,
305 trigger::to_generic(phe.p), trigger::to_generic(phe.p), -1, phe.r_lo, phe.r_hi);
306 }
307}
308
310 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
311 auto index = retrieve<int32_t>(state, parent);
312 if(std::holds_alternative<event::pending_human_n_event>(content)) {
313 auto phe = std::get<event::pending_human_n_event>(content);
315 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
316 auto phe = std::get<event::pending_human_f_n_event>(content);
318 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
319 auto phe = std::get<event::pending_human_p_event>(content);
321 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
322 auto phe = std::get<event::pending_human_f_p_event>(content);
324 }
326}
327
329 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
330 if(std::holds_alternative<event::pending_human_n_event>(content))
331 base_data.data.image.gfx_object = state.world.national_event_get_image(std::get<event::pending_human_n_event>(content).e);
332 else if(std::holds_alternative<event::pending_human_f_n_event>(content))
333 base_data.data.image.gfx_object = state.world.free_national_event_get_image(std::get<event::pending_human_f_n_event>(content).e);
334}
335
337 base_data.size.y = 200;
338 base_data.size.x -= 11;
340 delegate->base_data.data.text.font_handle = text::name_into_font_id(state, "ToolTip_Font");
341}
342
344 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
345
346 auto contents = text::create_endless_layout(state, delegate->internal_layout,
347 text::layout_parameters{0, 0, static_cast<int16_t>(base_data.size.x), static_cast<int16_t>(base_data.size.y),
348 delegate->base_data.data.text.font_handle, 0, text::alignment::left, delegate->black_text ? text::text_color::black : text::text_color::white, false});
349
351 dcon::text_key description{};
352 if(std::holds_alternative<event::pending_human_n_event>(content)) {
353 auto phe = std::get<event::pending_human_n_event>(content);
354 description = state.world.national_event_get_description(phe.e);
355 populate_event_submap(state, sub, phe);
356 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
357 auto phe = std::get<event::pending_human_f_n_event>(content);
358 description = state.world.free_national_event_get_description(phe.e);
359 populate_event_submap(state, sub, phe);
360 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
361 auto phe = std::get<event::pending_human_p_event>(content);
362 description = state.world.provincial_event_get_description(phe.e);
363 populate_event_submap(state, sub, phe);
364 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
365 auto phe = std::get<event::pending_human_f_p_event>(content);
366 description = state.world.free_provincial_event_get_description(phe.e);
367 populate_event_submap(state, sub, phe);
368 }
369
370 auto box = text::open_layout_box(contents);
371 text::add_to_layout_box(state, contents, box, description, sub);
372 text::close_layout_box(contents, box);
373
374 if(std::holds_alternative<event::pending_human_n_event>(content)) {
375 auto phe = std::get<event::pending_human_n_event>(content);
376 auto imm = state.world.national_event_get_immediate_effect(phe.e);
377 if(imm) {
378 effect_description(state, contents, imm, phe.primary_slot, trigger::to_generic(phe.n), phe.from_slot, phe.r_lo, phe.r_hi);
379 for(auto& l : delegate->internal_layout.contents) {
380 if(l.color == (delegate->black_text ? text::text_color::white : text::text_color::black)) //Invert colours
381 l.color = delegate->black_text ? text::text_color::black : text::text_color::white;
382 }
383 }
384 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
385 auto phe = std::get<event::pending_human_f_n_event>(content);
386 auto imm = state.world.free_national_event_get_immediate_effect(phe.e);
387 if(imm) {
388 effect_description(state, contents, imm, trigger::to_generic(phe.n), trigger::to_generic(phe.n), -1, phe.r_lo, phe.r_hi);
389 for(auto& l : delegate->internal_layout.contents) {
390 if(l.color == (delegate->black_text ? text::text_color::white : text::text_color::black)) //Invert colours
391 l.color = delegate->black_text ? text::text_color::black : text::text_color::white;
392 }
393 }
394 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
395 auto phe = std::get<event::pending_human_p_event>(content);
396 auto imm = state.world.provincial_event_get_immediate_effect(phe.e);
397 if(imm) {
398 effect_description(state, contents, imm, trigger::to_generic(phe.p), trigger::to_generic(phe.p), phe.from_slot, phe.r_lo, phe.r_hi);
399 for(auto& l : delegate->internal_layout.contents) {
400 if(l.color == (delegate->black_text ? text::text_color::white : text::text_color::black)) //Invert colours
401 l.color = delegate->black_text ? text::text_color::black : text::text_color::white;
402 }
403 }
404 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
405 auto phe = std::get<event::pending_human_f_p_event>(content);
406 auto imm = state.world.free_provincial_event_get_immediate_effect(phe.e);
407 if(imm) {
408 effect_description(state, contents, imm, trigger::to_generic(phe.p), trigger::to_generic(phe.p), -1, phe.r_lo, phe.r_hi);
409 for(auto& l : delegate->internal_layout.contents) {
410 if(l.color == (delegate->black_text ? text::text_color::white : text::text_color::black)) //Invert colours
411 l.color = delegate->black_text ? text::text_color::black : text::text_color::white;
412 }
413 }
414 }
415
416 calibrate_scrollbar(state);
417}
418
420 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
421
422 auto contents = text::create_endless_layout(state, internal_layout,
423 text::layout_parameters{0, 0, static_cast<int16_t>(base_data.size.x), static_cast<int16_t>(base_data.size.y),
424 base_data.data.text.font_handle, -15, text::alignment::center, black_text ? text::text_color::black : text::text_color::white, false});
425
426 auto box = text::open_layout_box(contents);
428 dcon::text_key name{};
429 if(std::holds_alternative<event::pending_human_n_event>(content)) {
430 auto phe = std::get<event::pending_human_n_event>(content);
431 name = state.world.national_event_get_name(phe.e);
432 populate_event_submap(state, sub, phe);
433 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
434 auto phe = std::get<event::pending_human_f_n_event>(content);
435 name = state.world.free_national_event_get_name(phe.e);
436 populate_event_submap(state, sub, phe);
437 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
438 auto phe = std::get<event::pending_human_p_event>(content);
439 name = state.world.provincial_event_get_name(phe.e);
440 populate_event_submap(state, sub, phe);
441 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
442 auto phe = std::get<event::pending_human_f_p_event>(content);
443 name = state.world.free_provincial_event_get_name(phe.e);
444 populate_event_submap(state, sub, phe);
445 }
446 text::add_to_layout_box(state, contents, box, name, sub);
447 text::close_layout_box(contents, box);
448}
449
450void event_requirements_icon::update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept {
451 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
452 {
453 auto box = text::open_layout_box(contents);
454 text::localised_format_box(state, contents, box, std::string_view("event_show_requirements"));
455 text::close_layout_box(contents, box);
456 }
457
458 if(state.cheat_data.show_province_id_tooltip) {
459 auto box = text::open_layout_box(contents);
460 if(std::holds_alternative<event::pending_human_p_event>(content)) {
461 auto phe = std::get<event::pending_human_p_event>(content);
462 text::add_to_layout_box(state, contents, box, std::string_view("Province Event ID:"));
463 text::add_space_to_layout_box(state, contents, box);
464 text::add_to_layout_box(state, contents, box, std::to_string(phe.e.value));
465 } else if(std::holds_alternative<event::pending_human_n_event>(content)) {
466 auto phe = std::get<event::pending_human_n_event>(content);
467 text::add_to_layout_box(state, contents, box, std::string_view("Nation Event ID:"));
468 text::add_space_to_layout_box(state, contents, box);
469 text::add_to_layout_box(state, contents, box, std::to_string(phe.e.value));
470 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
471 auto phe = std::get<event::pending_human_f_p_event>(content);
472 text::add_to_layout_box(state, contents, box, std::string_view("Free Province Event ID:"));
473 text::add_space_to_layout_box(state, contents, box);
474 text::add_to_layout_box(state, contents, box, std::to_string(phe.e.value));
475 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
476 auto phe = std::get<event::pending_human_f_n_event>(content);
477 text::add_to_layout_box(state, contents, box, std::string_view("Free Nation Event ID:"));
478 text::add_space_to_layout_box(state, contents, box);
479 text::add_to_layout_box(state, contents, box, std::to_string(phe.e.value));
480 text::add_space_to_layout_box(state, contents, box);
481 text::add_to_layout_box(state, contents, box, std::string_view("Legacy:"));
482 text::add_space_to_layout_box(state, contents, box);
483 text::add_to_layout_box(state, contents, box, std::to_string(state.world.free_national_event_get_legacy_id(phe.e)));
484 }
485 text::close_layout_box(contents, box);
486 }
487
488 if(std::holds_alternative<event::pending_human_p_event>(content) || std::holds_alternative<event::pending_human_n_event>(content)) {
489 auto box = text::open_layout_box(contents);
490 text::localised_format_box(state, contents, box, std::string_view("event_only_other_requirements"));
491 text::close_layout_box(contents, box);
492 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
493 auto phe = std::get<event::pending_human_f_p_event>(content);
494 trigger_description(state, contents, state.world.free_provincial_event_get_trigger(phe.e), trigger::to_generic(phe.p),
495 trigger::to_generic(phe.p), -1);
496 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
497 auto phe = std::get<event::pending_human_f_n_event>(content);
498 trigger_description(state, contents, state.world.free_national_event_get_trigger(phe.e), trigger::to_generic(phe.n),
499 trigger::to_generic(phe.n), -1);
500 }
501}
502
503void event_odds_icon::update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept {
504 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
505 {
506 auto box = text::open_layout_box(contents);
507 text::localised_format_box(state, contents, box, std::string_view("event_show_odds"));
508 text::close_layout_box(contents, box);
509 }
510 if(std::holds_alternative<event::pending_human_p_event>(content) || std::holds_alternative<event::pending_human_n_event>(content)) {
511 auto box = text::open_layout_box(contents);
512 text::localised_format_box(state, contents, box, std::string_view("event_only_other_requirements"));
513 text::close_layout_box(contents, box);
514 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
515 auto phe = std::get<event::pending_human_f_p_event>(content);
516 auto mod = state.world.free_provincial_event_get_mtth(phe.e);
517 if(mod)
519 else
520 text::add_line(state, contents, "always");
521 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
522 auto phe = std::get<event::pending_human_f_n_event>(content);
523 auto mod = state.world.free_national_event_get_mtth(phe.e);
524 if(mod)
526 else
527 text::add_line(state, contents, "always");
528 }
529}
530
532 auto iid = retrieve<dcon::issue_id>(state, parent);
533 set_text(state, text::produce_simple_string(state, state.world.issue_get_name(iid)));
534}
535
537 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
538 if(std::holds_alternative<event::pending_human_n_event>(content)) {
539 auto n = dcon::fatten(state.world, std::get<event::pending_human_n_event>(content).n);
541 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
542 auto n = dcon::fatten(state.world, std::get<event::pending_human_f_n_event>(content).n);
544 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
545 auto p = dcon::fatten(state.world, std::get<event::pending_human_p_event>(content).p);
546 auto n = p.get_nation_from_province_ownership();
548 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
549 auto p = dcon::fatten(state.world, std::get<event::pending_human_f_p_event>(content).p);
550 auto n = p.get_nation_from_province_ownership();
552 }
553}
554
556 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
557 if(std::holds_alternative<event::pending_human_n_event>(content)) {
558 auto n = dcon::fatten(state.world, std::get<event::pending_human_n_event>(content).n);
559 set_text(state, text::prettify(int64_t(n.get_demographics(demographics::total))));
560 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
561 auto n = dcon::fatten(state.world, std::get<event::pending_human_f_n_event>(content).n);
562 set_text(state, text::prettify(int64_t(n.get_demographics(demographics::total))));
563 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
564 auto p = dcon::fatten(state.world, std::get<event::pending_human_p_event>(content).p);
565 auto n = p.get_nation_from_province_ownership();
566 set_text(state, text::prettify(int64_t(n.get_demographics(demographics::total))));
567 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
568 auto p = dcon::fatten(state.world, std::get<event::pending_human_f_p_event>(content).p);
569 auto n = p.get_nation_from_province_ownership();
570 set_text(state, text::prettify(int64_t(n.get_demographics(demographics::total))));
571 }
572}
573
575 row_contents.clear();
576 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
577 if(std::holds_alternative<event::pending_human_n_event>(content)) {
578 auto e = std::get<event::pending_human_n_event>(content).e;
579 for(int32_t i = 0; i < sys::max_event_options; ++i) {
580 if(!event::is_valid_option(state.world.national_event_get_options(e)[i]))
581 break;
582 row_contents.push_back(i);
583 }
584 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
585 auto e = std::get<event::pending_human_f_n_event>(content).e;
586 for(int32_t i = 0; i < sys::max_event_options; ++i) {
587 if(!event::is_valid_option(state.world.free_national_event_get_options(e)[i]))
588 break;
589 row_contents.push_back(i);
590 }
591 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
592 auto e = std::get<event::pending_human_p_event>(content).e;
593 for(int32_t i = 0; i < sys::max_event_options; ++i) {
594 if(!event::is_valid_option(state.world.provincial_event_get_options(e)[i]))
595 break;
596 row_contents.push_back(i);
597 }
598 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
599 auto e = std::get<event::pending_human_f_p_event>(content).e;
600 for(int32_t i = 0; i < sys::max_event_options; ++i) {
601 if(!event::is_valid_option(state.world.free_provincial_event_get_options(e)[i]))
602 break;
603 row_contents.push_back(i);
604 }
605 }
606 update(state);
607}
608
611 if(image) {
612 move_child_to_front(image);
613 }
614 if(get_pool_slot() == event_pool_slot::province) {
615 image->set_visible(state, false);
616 {
617 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);
618 ptr->base_data.position.y = int16_t(355);
619 ptr->base_data.position.x += int16_t(ptr->base_data.size.x + 140);
620 add_child_to_front(std::move(ptr));
621 }
622 {
623 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);
624 ptr->base_data.position.y = int16_t(355);
625 ptr->base_data.position.x += int16_t(ptr->base_data.size.x * 2 + 140);
626 add_child_to_front(std::move(ptr));
627 }
628 {
629 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;
630 cur_offset.y += 22;
631 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);
632 ptr->base_data.position = cur_offset;
633 ptr->base_data.position.y -= 150; // Omega nudge??
634 add_child_to_front(std::move(ptr));
635 }
636 } else {
637 {
638 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);
639 ptr->base_data.position.y = 20;
640 ptr->base_data.position.x += ptr->base_data.size.x;
641 add_child_to_front(std::move(ptr));
642 }
643 {
644 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);
645 ptr->base_data.position.y = 20;
646 ptr->base_data.position.x += ptr->base_data.size.x * 2;
647 add_child_to_front(std::move(ptr));
648 }
649 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;
650 if(get_pool_slot() == event_pool_slot::country_election) {
651 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);
652 ptr->base_data.position = cur_offset;
653 ptr->base_data.position.y += 5;
654 add_child_to_front(std::move(ptr));
655 } else {
656 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);
657 ptr->base_data.position = cur_offset;
658 ptr->base_data.position.y += 5;
659 add_child_to_front(std::move(ptr));
660 }
661 }
662}
663
665public:
666 void on_update(sys::state& state) noexcept override {
667 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
668 if(std::holds_alternative<event::pending_human_n_event>(content)) {
669 set_text(state, text::date_to_string(state, std::get<event::pending_human_n_event>(content).date));
670 } else if(std::holds_alternative<event::pending_human_f_n_event>(content)) {
671 set_text(state, text::date_to_string(state, std::get<event::pending_human_f_n_event>(content).date));
672 } else if(std::holds_alternative<event::pending_human_p_event>(content)) {
673 set_text(state, text::date_to_string(state, std::get<event::pending_human_p_event>(content).date));
674 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
675 set_text(state, text::date_to_string(state, std::get<event::pending_human_f_p_event>(content).date));
676 }
677 }
678};
679
681public:
682 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
683 dcon::gfx_object_id gid;
688 }
689 if(gid && flag_texture_handle > 0) {
690 auto& gfx_def = state.ui_defs.gfx[gid];
691 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
692 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
694 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle, base_data.get_rotation(),
695 gfx_def.is_vertically_flipped(),
696 state.world.locale_get_native_rtl(state.font_collection.get_current_locale()));
697 }
699 }
700 void on_create(sys::state& state) noexcept override {
701 std::swap(base_data.size.x, base_data.size.y);
702 base_data.position.x += int16_t(24);
703 base_data.position.y -= int16_t(25);
705 }
706 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
707 auto n = retrieve<dcon::nation_id>(state, parent);
708 return state.world.nation_get_identity_from_identity_holder(n);
709 }
710 void button_action(sys::state& state) noexcept override {
711
712 }
713};
714
716public:
717 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
718 dcon::gfx_object_id gid;
723 }
724 if(gid && flag_texture_handle > 0) {
725 auto& gfx_def = state.ui_defs.gfx[gid];
726 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
727 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
728 //auto rotation = 0.f;
730 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle,
731 ui::rotation::r90_right, false, state.world.locale_get_native_rtl(state.font_collection.get_current_locale()));
733 float(x), float(y), float(base_data.size.x), float(base_data.size.y),
734 ogl::get_texture_handle(state, gfx_def.primary_texture_handle, gfx_def.is_partially_transparent()),
735 ui::rotation::r90_right, false, state.world.locale_get_native_rtl(state.font_collection.get_current_locale()));
736 }
737 }
738 void on_create(sys::state& state) noexcept override {
739 std::swap(base_data.size.x, base_data.size.y);
740 base_data.position.x += int16_t(21);
741 base_data.position.y -= int16_t(25);
743 }
744 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
745 auto n = retrieve<dcon::nation_id>(state, parent);
746 return state.world.nation_get_identity_from_identity_holder(n);
747 }
748 void button_action(sys::state& state) noexcept override {
749
750 }
751};
752
754public:
755 void on_update(sys::state& state) noexcept override {
757 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
758 if(std::holds_alternative<event::pending_human_p_event>(content)) {
759 set_text(state, text::produce_simple_string(state, state.world.province_get_name(std::get<event::pending_human_p_event>(content).p)));
760 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
761 set_text(state, text::produce_simple_string(state, state.world.province_get_name(std::get<event::pending_human_f_p_event>(content).p)));
762 }
763 }
764
765 message_result on_lbutton_down(sys::state& state, int32_t x, int32_t y, sys::key_modifiers mods) noexcept override {
766 event_data_wrapper content = retrieve<event_data_wrapper>(state, parent);
767 dcon::province_id prov{};
768 if(std::holds_alternative<event::pending_human_p_event>(content)) {
769 prov = std::get<event::pending_human_p_event>(content).p;
770 } else if(std::holds_alternative<event::pending_human_f_p_event>(content)) {
771 prov = std::get<event::pending_human_f_p_event>(content).p;
772 }
773 if(!prov || prov.value >= state.province_definitions.first_sea_province.value)
775
776 sound::play_interface_sound(state, sound::get_click_sound(state), state.user_settings.interface_volume * state.user_settings.master_volume);
777 state.map_state.set_selected_province(prov);
778 static_cast<ui::province_view_window*>(state.ui_state.province_window)->set_active_province(state, prov);
779 if(state.map_state.get_zoom() < map::zoom_very_close)
780 state.map_state.zoom = map::zoom_very_close;
781 state.map_state.center_map_on_province(state, prov);
783 }
784 message_result test_mouse(sys::state& state, int32_t x, int32_t y, mouse_probe_type type) noexcept override {
786 }
787};
788
789class election_voter_issue_entry : public listbox_row_element_base<dcon::issue_option_id> {
790private:
791 simple_text_element_base* issname = nullptr;
792 simple_text_element_base* issvalue = nullptr;
793public:
794 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
795 if(name == "issue_name") {
796 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
797 issname = ptr.get();
798 return ptr;
799 } else if(name == "voters_perc") {
800 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
801 issvalue = ptr.get();
802 return ptr;
803 } else {
804 return nullptr;
805 }
806 }
807 void on_update(sys::state& state) noexcept override {
808 auto n = retrieve<dcon::nation_id>(state, parent);
810 auto total = state.world.nation_get_demographics(n, demographics::total);
811 if(total > 0.f) {
812 auto value = state.world.nation_get_demographics(n, demographics::to_key(state, content)) / total;
813 issvalue->set_text(state, text::format_percentage(value));
814 }
815 }
816};
817
818class election_voter_issues_listbox : public listbox_element_base<election_voter_issue_entry, dcon::issue_option_id> {
819protected:
820 std::string_view get_row_element_name() override {
821 return "ew_issue_option_window";
822 }
823public:
824 void on_update(sys::state& state) noexcept override {
825 row_contents.clear();
826 auto content = retrieve<dcon::issue_id>(state, parent);
827 state.world.for_each_issue_option([&](dcon::issue_option_id id) {
828 if(content == dcon::fatten(state.world, id).get_parent_issue().id) {
829 row_contents.push_back(id);
830 }
831 });
832 update(state);
833 }
834};
835class election_party_entry : public listbox_row_element_base<dcon::political_party_id> {
836 simple_text_element_base* partyname = nullptr;
837 simple_text_element_base* partyvalue = nullptr;
838public:
839 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
840 if(name == "legend_color") {
841 return make_element_by_type<ideology_plupp>(state, id);
842 } else if(name == "legend_title") {
843 return make_element_by_type<generic_name_text<dcon::political_party_id>>(state, id);
844 } else if(name == "legend_desc") {
845 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
846 ptr->base_data.position.x += 4; // Nudge
847 partyvalue = ptr.get();
848 return ptr;
849 } else if(name == "legend_value") {
850 return make_element_by_type<invisible_element>(state, id);
851 } else {
852 return nullptr;
853 }
854 }
855
856 void on_update(sys::state& state) noexcept override {
857 auto issid = retrieve<dcon::issue_id>(state, parent);
858 partyvalue->set_text(state, text::produce_simple_string(state, dcon::fatten(state.world, content).get_party_issues(issid).get_name()));
859 }
860
861 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
862 if(payload.holds_type<dcon::ideology_id>()) {
863 payload.emplace<dcon::ideology_id>(state.world.political_party_get_ideology(content));
865 }
867 }
868};
869
870class election_parties_listbox : public listbox_element_base<election_party_entry, dcon::political_party_id> {
871protected:
872 std::string_view get_row_element_name() override {
873 return "eew_item";
874 }
875public:
876 void on_update(sys::state& state) noexcept override {
877 auto n = retrieve<dcon::nation_id>(state, parent);
878 row_contents.clear();
880 update(state);
881 }
882};
883class election_popularity_entry : public listbox_row_element_base<dcon::political_party_id> {
884public:
887public:
888 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
889 if(name == "legend_color") {
890 return make_element_by_type<ideology_plupp>(state, id);
891 } else if(name == "legend_title") {
892 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
893 partyname = ptr.get();
894 return ptr;
895 } else if(name == "legend_desc") {
896 return make_element_by_type<simple_text_element_base>(state, id);
897 } else if(name == "legend_value") {
898 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
899 ptr->base_data.position.x += 3; // Nudge
900 partyvalue = ptr.get();
901 return ptr;
902 } else {
903 return nullptr;
904 }
905 }
906 void on_update(sys::state& state) noexcept override {
907 auto n = retrieve<dcon::nation_id>(state, parent);
908 auto fat = dcon::fatten(state.world, content);
909 partyname->set_text(state, text::produce_simple_string(state, state.world.political_party_get_name(content)));
910 auto const total = state.world.nation_get_demographics(n, demographics::total);
911 if(total > 0.f) {
912 partyvalue->set_text(state, text::format_percentage(state.world.nation_get_demographics(n, demographics::to_key(state, fat.get_ideology().id)) / total, 0));
913 }
914 }
915 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
916 if(payload.holds_type<dcon::ideology_id>()) {
917 payload.emplace<dcon::ideology_id>(state.world.political_party_get_ideology(content));
919 }
921 }
922};
923
924class election_popularity_listbox : public listbox_element_base<election_popularity_entry, dcon::political_party_id> {
925protected:
926 std::string_view get_row_element_name() override {
927 return "eew_item";
928 }
929public:
930 void on_update(sys::state& state) noexcept override {
931 auto n = retrieve<dcon::nation_id>(state, parent);
932 row_contents.clear();
934 update(state);
935 }
936};
937
939public:
940 void on_create(sys::state& state) noexcept override {
941 base_data.position.x -= base_data.size.x / int16_t(2);
942 base_data.position.x += int16_t(8);
943 base_data.size.x *= 2;
944 base_data.size.y *= 2;
946 }
947};
948class election_party_popularity_piechart : public piechart<dcon::political_party_id> {
949public:
950 void on_update(sys::state& state) noexcept override {
951 auto n = retrieve<dcon::nation_id>(state, parent);
952 distribution.clear();
953 auto total = state.world.nation_get_demographics(n, demographics::total);
954 if(total > 0.f) {
955 std::vector<dcon::political_party_id> parties;
957 for(auto ppid : state.world.in_political_party) {
958 distribution.emplace_back(ppid.id, 0.0f);
959 }
960 for(auto ppid : parties) {
961 auto const dkey = demographics::to_key(state, state.world.political_party_get_ideology(ppid));
962 distribution[ppid.index()].value += state.world.nation_get_demographics(n, dkey) / total;
963 }
964 }
966 }
967 void on_create(sys::state& state) noexcept override {
969 piechart<dcon::political_party_id>::base_data.position.x += int16_t(8);
973 }
974};
975
976std::unique_ptr<element_base> election_issue_support_item::make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept {
977 if(name == "issue_name") {
978 return make_element_by_type<generic_name_text<dcon::issue_option_id>>(state, id);
979 } else if(name == "people_perc") {
980 return make_element_by_type<issue_option_popular_support>(state, id);
981 } else if(name == "voters_perc") {
982 return make_element_by_type<issue_option_voter_support>(state, id);
983 } else {
984 return nullptr;
985 }
986}
987
989 row_contents.clear();
990 auto iid = retrieve<dcon::issue_id>(state, parent);
991 for(const auto ioid : state.world.in_issue_option) {
992 if(ioid.get_parent_issue() == iid)
993 row_contents.push_back(ioid);
994 }
995 update(state);
996}
997
998std::unique_ptr<element_base> base_event_window::make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept {
999 if(name == "background") {
1000 return make_element_by_type<draggable_target>(state, id);
1001 } else if(name == "title") {
1002 return make_element_by_type<event_name_text>(state, id);
1003 } else if(name == "description") {
1004 return make_element_by_type<event_desc_text>(state, id);
1005 } else if(name == "event_images") {
1006 auto ptr = make_element_by_type<event_image>(state, id);
1007 image = ptr.get();
1008 return ptr;
1009 } else if(name == "event_separator_image") {
1010 auto ptr = make_element_by_type<image_element_base>(state, id);
1011 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;
1012 ptr->base_data.position.y = cur_offset.y;
1013 ptr->base_data.position.y -= 150; // Omega nudge??
1014 return ptr;
1015 } else if(name == "date") {
1016 return make_element_by_type<event_date_text>(state, id);
1017 } else if(name == "state_name") {
1018 return make_element_by_type<event_state_name_text>(state, id);
1019 } else if(name == "subtitle") {
1020 return make_element_by_type<event_subtitle_text>(state, id);
1021 } else if(name == "population_amount") {
1022 return make_element_by_type<event_population_amount_text>(state, id);
1023 } else if(name == "country_flag1") {
1024 return make_element_by_type<major_event_left_flag>(state, id);
1025 } else if(name == "country_flag2") {
1026 return make_element_by_type<major_event_right_flag>(state, id);
1027 } else if(name == "province") {
1028 return make_element_by_type<event_province_text>(state, id);
1029 } else if(name == "perc_of_parlament") {
1030 return make_element_by_type<nation_ruling_party_ideology_text>(state, id);
1031 } else if(name == "parties_listbox") {
1032 return make_element_by_type<election_parties_listbox>(state, id);
1033 } else if(name == "chart_ideology") {
1034 return make_element_by_type<election_voter_ideology_piechart>(state, id);
1035 } else if(name == "chart_popularity") {
1036 return make_element_by_type<election_party_popularity_piechart>(state, id);
1037 } else if(name == "popularity_listbox") {
1038 return make_element_by_type<election_popularity_listbox>(state, id);
1039 } else if(name == "sort_by_issue_name") {
1040 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
1042 return ptr;
1043 } else if(name == "sort_by_people") {
1044 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
1046 return ptr;
1047 } else if(name == "sort_by_voters") {
1048 auto ptr = make_element_by_type<politics_issue_sort_button>(state, id);
1050 return ptr;
1051 } else if(name == "issues_listbox") {
1052 auto ptr = make_element_by_type<elections_issue_option_listbox>(state, id);
1053 issues_listbox = ptr.get();
1054 return ptr;
1055 }
1056 return nullptr;
1057}
1058
1060 if(payload.holds_type<dcon::nation_id>()) {
1061 payload.emplace<dcon::nation_id>(state.local_player_nation);
1063 } else if(payload.holds_type<dcon::issue_id>()) {
1064 if(std::holds_alternative<event::pending_human_n_event>(event_data)) {
1065 auto e = std::get<event::pending_human_n_event>(event_data).e;
1067 payload.emplace<dcon::issue_id>(iid);
1068 }
1070 } else if(payload.holds_type<event_data_wrapper>()) {
1071 if(std::holds_alternative<event::pending_human_n_event>(event_data))
1072 payload.emplace<event_data_wrapper>(std::get<event::pending_human_n_event>(event_data));
1073 else if(std::holds_alternative<event::pending_human_f_n_event>(event_data))
1074 payload.emplace<event_data_wrapper>(std::get<event::pending_human_f_n_event>(event_data));
1075 else if(std::holds_alternative<event::pending_human_p_event>(event_data))
1076 payload.emplace<event_data_wrapper>(std::get<event::pending_human_p_event>(event_data));
1077 else if(std::holds_alternative<event::pending_human_f_p_event>(event_data))
1078 payload.emplace<event_data_wrapper>(std::get<event::pending_human_f_p_event>(event_data));
1080 } else if(payload.holds_type<option_taken_notification>()) {
1081 set_visible(state, false);
1082 auto uptr = state.ui_state.root->remove_child(this);
1083 if(uptr) {
1084 auto slot = uint8_t(get_pool_slot());
1085 std::unique_ptr<base_event_window> ptr(static_cast<base_event_window*>(uptr.release()));
1086 event_pool[slot].push_back(std::move(ptr));
1087 --pending_events[slot];
1088 }
1090 } else if(payload.holds_type<politics_issue_sort_order>()) {
1091 auto enum_val = any_cast<politics_issue_sort_order>(payload);
1092 switch(enum_val) {
1094 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
1095 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
1096 auto a_name = text::get_name_as_string(state, dcon::fatten(state.world, a));
1097 auto b_name = text::get_name_as_string(state, dcon::fatten(state.world, b));
1098 return a_name < b_name;
1099 });
1100 issues_listbox->update(state);
1101 break;
1103 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
1104 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
1105 auto a_support = politics::get_popular_support(state, state.local_player_nation, a);
1106 auto b_support = politics::get_popular_support(state, state.local_player_nation, b);
1107 return a_support > b_support;
1108 });
1109 issues_listbox->update(state);
1110 break;
1112 std::sort(issues_listbox->row_contents.begin(), issues_listbox->row_contents.end(),
1113 [&](dcon::issue_option_id a, dcon::issue_option_id b) {
1114 auto a_support = politics::get_voter_support(state, state.local_player_nation, a);
1115 auto b_support = politics::get_voter_support(state, state.local_player_nation, b);
1116 return a_support > b_support;
1117 });
1118 issues_listbox->update(state);
1119 break;
1120 }
1122 }
1124}
1125
1127 if(std::holds_alternative<event::pending_human_n_event>(event_data)) {
1128 if(std::get<event::pending_human_n_event>(event_data).date + event::expiration_in_days <= state.current_date) {
1129 pending_closure.push_back(this);
1130 }
1131 } else if(std::holds_alternative<event::pending_human_f_n_event>(event_data)) {
1132 if(std::get<event::pending_human_f_n_event>(event_data).date + event::expiration_in_days <= state.current_date) {
1133 pending_closure.push_back(this);
1134 }
1135 } else if(std::holds_alternative<event::pending_human_p_event>(event_data)) {
1136 if(std::get<event::pending_human_p_event>(event_data).date + event::expiration_in_days <= state.current_date) {
1137 pending_closure.push_back(this);
1138 }
1139 } else if(std::holds_alternative<event::pending_human_f_p_event>(event_data)) {
1140 if(std::get<event::pending_human_f_p_event>(event_data).date + event::expiration_in_days <= state.current_date) {
1141 pending_closure.push_back(this);
1142 }
1143 }
1144}
1145
1147 for(auto e : pending_closure)
1149 pending_closure.clear();
1150}
1151
1153 for(auto const& slot_pool : ui::event_pool) {
1154 for(auto const& win : slot_pool) {
1155 pending_closure.push_back(win.get());
1156 }
1157 }
1159}
1160
1162 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);
1163 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);
1164 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);
1165 return a || b || c;
1166}
1167
1168template<typename T>
1170 auto const slot = uint8_t(e_slot);
1171 if(event_pool[slot].empty()) {
1172 auto new_elm = ui::make_element_by_type<T>(state, T::window_element_name);
1173 auto ptr = new_elm.get();
1174 T* actual = static_cast<T*>(ptr);
1175 actual->event_data = dat;
1176 actual->impl_on_update(state);
1177 state.ui_state.root->add_child_to_front(std::move(new_elm));
1178 } else {
1179 std::unique_ptr<base_event_window> ptr = std::move(event_pool[slot].back());
1180 event_pool[slot].pop_back();
1181 ptr->event_data = dat;
1182 if(!ptr->is_visible())
1183 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;
1184 ptr->set_visible(state, true);
1185 state.ui_state.root->add_child_to_front(std::move(ptr));
1186 }
1187}
1188
1190 auto slot = event_pool_slot::country;
1191 if(std::holds_alternative<event::pending_human_n_event>(dat)) {
1193 auto e = std::get<event::pending_human_n_event>(dat).e;
1194 if(state.world.national_event_get_is_major(e)) {
1196 } else if(event::get_election_event_issue(state, e)) {
1198 }
1199 } else if(std::holds_alternative<event::pending_human_f_n_event>(dat)) {
1201 auto e = std::get<event::pending_human_f_n_event>(dat).e;
1202 if(state.world.free_national_event_get_is_major(e)) {
1204 }
1205 } else if(std::holds_alternative<event::pending_human_p_event>(dat)) {
1207 } else if(std::holds_alternative<event::pending_human_f_p_event>(dat)) {
1209 }
1210 switch(slot) {
1212 new_event_window_1<national_event_window>(state, dat, slot);
1213 break;
1215 new_event_window_1<national_major_event_window>(state, dat, slot);
1216 break;
1218 new_event_window_1<national_election_event_window>(state, dat, slot);
1219 break;
1221 new_event_window_1<provincial_event_window>(state, dat, slot);
1222 break;
1223 default:
1224 return;
1225 }
1226 ++pending_events[uint8_t(slot)];
1227}
1228
1229} // 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:574
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:1126
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:998
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
Definition: gui_event.cpp:1059
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:609
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:976
std::string_view get_row_element_name() override
Definition: gui_event.cpp:872
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:876
Definition: gui_event.cpp:835
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:856
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:839
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
Definition: gui_event.cpp:861
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:950
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:967
Definition: gui_event.cpp:883
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
Definition: gui_event.cpp:915
simple_text_element_base * partyname
Definition: gui_event.cpp:885
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:906
simple_text_element_base * partyvalue
Definition: gui_event.cpp:886
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:888
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:930
std::string_view get_row_element_name() override
Definition: gui_event.cpp:926
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:940
Definition: gui_event.cpp:789
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:807
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:794
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:824
std::string_view get_row_element_name() override
Definition: gui_event.cpp:820
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:988
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:250
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:666
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:336
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:343
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:328
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:419
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
Definition: gui_event.cpp:503
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:223
void button_action(sys::state &state) noexcept override
Definition: gui_event.cpp:309
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
Definition: gui_event.cpp:274
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:555
message_result on_lbutton_down(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mods) noexcept override
Definition: gui_event.cpp:765
message_result test_mouse(sys::state &state, int32_t x, int32_t y, mouse_probe_type type) noexcept override
Definition: gui_event.cpp:784
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:755
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
Definition: gui_event.cpp:450
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:536
void on_update(sys::state &state) noexcept override
Definition: gui_event.cpp:531
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:744
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:738
void button_action(sys::state &state) noexcept override
Definition: gui_event.cpp:748
void render(sys::state &state, int32_t x, int32_t y) noexcept override
Definition: gui_event.cpp:717
void button_action(sys::state &state) noexcept override
Definition: gui_event.cpp:710
void render(sys::state &state, int32_t x, int32_t y) noexcept override
Definition: gui_event.cpp:682
void on_create(sys::state &state) noexcept override
Definition: gui_event.cpp:700
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
Definition: gui_event.cpp:706
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:2058
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:4911
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:892
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:665
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
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:2113
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
std::string date_to_string(sys::state &state, sys::date date)
Definition: text.cpp:1082
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1880
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:1899
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:794
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:1788
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
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:1169
void send(sys::state &state, element_base *parent, T value)
void close_expired_event_windows(sys::state &state)
Definition: gui_event.cpp:1146
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:1152
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:1161
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:1189
uint uint32_t
uchar uint8_t
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