Project Alice
Loading...
Searching...
No Matches
gui_ledger_window.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace ui {
8
9
10
12public:
13 int8_t value;
14};
15
16enum class ledger_sort_type {
29 ships,
37 culture,
44 profit,
48 gdp,
50 sol
51};
52
54 std::variant<std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id> type = std::monostate{};
55 bool reversed = false;
56};
57
59 std::vector<bool> data;
60};
61
63 std::vector<bool> data;
64};
65
67public:
68 std::variant<std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id> type;
69
70 ledger_generic_sort_button(std::variant<std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id> type) : type(type) { }
71
72 void button_action(sys::state& state) noexcept override {
74 current_sort.data = retrieve< ledger_sort>(state, parent);
75 if(current_sort.data.type == type) {
76 current_sort.data.reversed = !current_sort.data.reversed;
77 } else {
78 current_sort.data.type = type;
79 current_sort.data.reversed = false;
80 }
81 send(state, parent, current_sort);
82 }
84 return std::holds_alternative<dcon::pop_type_id>(type) ? tooltip_behavior::tooltip : tooltip_behavior::no_tooltip;
85 }
86 void update_tooltip(sys::state& state, int32_t x, int32_t t, text::columnar_layout& contents) noexcept override {
87 if(std::holds_alternative<dcon::pop_type_id>(type))
88 text::add_line(state, contents, state.world.pop_type_get_name(std::get<dcon::pop_type_id>(type)));
89 }
90};
91
92class ledger_prev_button : public generic_settable_element<button_element_base, ledger_page_number> {
93public:
94 void button_action(sys::state& state) noexcept override {
95 if(parent) {
96 auto num = int8_t(content.value - 1);
97 if(num <= 0)
98 num = 12;
99 Cyto::Any new_payload = ledger_page_number{num};
100 parent->impl_set(state, new_payload);
101 }
102 }
103};
104
105class ledger_next_button : public generic_settable_element<button_element_base, ledger_page_number> {
106public:
107 void button_action(sys::state& state) noexcept override {
108 if(parent) {
109 auto num = int8_t(content.value + 1);
110 if(num > 12)
111 num = 1;
112 Cyto::Any new_payload = ledger_page_number{num};
113 parent->impl_set(state, new_payload);
114 }
115 }
116};
117
118//
119// Nation ranking
120//
121
123public:
124 void on_create(sys::state& state) noexcept override {
126
127 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
128
129 xy_pair cell_offset{ int16_t(24), 0 };
130 auto cell_width = (972 - cell_offset.x) / 9;
131 auto apply_offset = [&](auto& ptr) {
132 ptr->base_data.position = cell_offset;
133 ptr->base_data.size.x = int16_t(cell_width);
134 cell_offset.x += ptr->base_data.size.x;
135 };
136
137 {
138 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::country_name);
139 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_name"));
140 apply_offset(ptr);
141 add_child_to_front(std::move(ptr));
142 }
143 {
144 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::country_status);
145 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_status"));
146 apply_offset(ptr);
147 add_child_to_front(std::move(ptr));
148 }
149 {
150 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::military_score);
151 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_milscore"));
152 apply_offset(ptr);
153 add_child_to_front(std::move(ptr));
154 }
155 {
156 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::industrial_score);
157 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_indscore"));
158 apply_offset(ptr);
159 add_child_to_front(std::move(ptr));
160 }
161 {
162 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::prestige);
163 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_prestige"));
164 apply_offset(ptr);
165 add_child_to_front(std::move(ptr));
166 }
167 {
168 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::total_score);
169 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_totalscore"));
170 apply_offset(ptr);
171 add_child_to_front(std::move(ptr));
172 }
173 {
174 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::gdp);
175 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_ppp_gdp"));
176 apply_offset(ptr);
177 add_child_to_front(std::move(ptr));
178 }
179 {
180 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::gdp_capita);
181 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_ppp_gdp_per_capita"));
182 apply_offset(ptr);
183 add_child_to_front(std::move(ptr));
184 }
185 {
186 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::sol);
187 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_standard_of_living"));
188 apply_offset(ptr);
189 add_child_to_front(std::move(ptr));
190 }
191 }
192};
193
195 flag_button* country_flag = nullptr;
196
197public:
198 void on_create(sys::state& state) noexcept override {
200 // Country flag
201 {
202 auto ptr =
203 make_element_by_type<flag_button>(state, state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_flag"))->second.definition);
204 country_flag = ptr.get();
205 add_child_to_front(std::move(ptr));
206 }
207 xy_pair cell_offset{int16_t(country_flag->base_data.position.x + country_flag->base_data.size.x), 0};
208 auto cell_width = (972 - cell_offset.x) / 9;
209 auto apply_offset = [&](auto& ptr) {
210 ptr->base_data.position = cell_offset;
211 ptr->base_data.size.x = int16_t(cell_width);
212 cell_offset.x += ptr->base_data.size.x;
213 };
214 // Country name
215 {
216 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(state,
217 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
218 apply_offset(ptr);
219 add_child_to_front(std::move(ptr));
220 }
221 // Country status
222 {
223 auto ptr = make_element_by_type<nation_status_text>(state,
224 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
225 apply_offset(ptr);
226 add_child_to_front(std::move(ptr));
227 }
228 // Military score
229 {
230 auto ptr = make_element_by_type<nation_military_score_text>(state,
231 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
232 apply_offset(ptr);
233 add_child_to_front(std::move(ptr));
234 }
235 // Industrial score
236 {
237 auto ptr = make_element_by_type<nation_industry_score_text>(state,
238 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
239 apply_offset(ptr);
240 add_child_to_front(std::move(ptr));
241 }
242 // Prestige
243 {
244 auto ptr = make_element_by_type<nation_prestige_text>(state,
245 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
246 apply_offset(ptr);
247 add_child_to_front(std::move(ptr));
248 }
249 // Total score
250 {
251 auto ptr = make_element_by_type<nation_total_score_text>(state,
252 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
253 apply_offset(ptr);
254 add_child_to_front(std::move(ptr));
255 }
256 // GDP PPP
257 {
258 auto ptr = make_element_by_type<nation_ppp_gdp_text>(state,
259 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
260 apply_offset(ptr);
261 add_child_to_front(std::move(ptr));
262 }
263 // GDP PPP per capita
264 {
265 auto ptr = make_element_by_type<nation_ppp_gdp_per_capita_text>(state,
266 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
267 apply_offset(ptr);
268 add_child_to_front(std::move(ptr));
269 }
270 // Standard of living
271 {
272 auto ptr = make_element_by_type<nation_sol_text>(state,
273 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
274 apply_offset(ptr);
275 add_child_to_front(std::move(ptr));
276 }
277 }
278
279 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
280 if(payload.holds_type<dcon::nation_id>()) {
281 payload.emplace<dcon::nation_id>(content);
283 }
284 return listbox_row_element_base::get(state, payload);
285 }
286
287 void on_update(sys::state& state) noexcept override {
288 Cyto::Any payload = content;
289 impl_set(state, payload);
290 }
291};
292class ledger_nation_ranking_listbox : public listbox_element_base<ledger_nation_ranking_entry, dcon::nation_id> {
293protected:
294 std::string_view get_row_element_name() override {
295 return "default_listbox_entry";
296 }
297
298public:
299 void on_update(sys::state& state) noexcept override {
300 row_contents.clear();
301 state.world.for_each_nation([&](dcon::nation_id id) {
302 if(state.world.nation_get_owned_province_count(id) != 0)
303 row_contents.push_back(id);
304 });
305 auto lsort = retrieve<ledger_sort>(state, parent);
306 ledger_sort_type st = std::holds_alternative<ledger_sort_type>(lsort.type) ? std::get<ledger_sort_type>(lsort.type) : ledger_sort_type::country_name;
307 switch(st) {
309 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
310 if(lsort.reversed) {
311 return int32_t(nations::get_status(state, a)) > int32_t(nations::get_status(state, b));
312 } else {
313 return int32_t(nations::get_status(state, a)) < int32_t(nations::get_status(state, b));
314 }
315 });
316 break;
318 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
319 if(lsort.reversed) {
320 return state.world.nation_get_military_score(a) < state.world.nation_get_military_score(b);
321 } else {
322 return state.world.nation_get_military_score(a) > state.world.nation_get_military_score(b);
323 }
324 });
325 break;
327 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
328 if(lsort.reversed) {
329 return state.world.nation_get_industrial_score(a) < state.world.nation_get_industrial_score(b);
330 } else {
331 return state.world.nation_get_industrial_score(a) > state.world.nation_get_industrial_score(b);
332 }
333 });
334 break;
336 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
337 if(lsort.reversed) {
338 return nations::prestige_score(state, a) < nations::prestige_score(state, b);
339 } else {
340 return nations::prestige_score(state, a) > nations::prestige_score(state, b);
341 }
342 });
343 break;
344 case ledger_sort_type::total_score:
345 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
346 if(lsort.reversed) {
347 return state.world.nation_get_military_score(a) + state.world.nation_get_industrial_score(a) + nations::prestige_score(state, a) < state.world.nation_get_military_score(b) + state.world.nation_get_industrial_score(b) + nations::prestige_score(state, b);
348 } else {
349 return state.world.nation_get_military_score(a) + state.world.nation_get_industrial_score(a) + nations::prestige_score(state, a) > state.world.nation_get_military_score(b) + state.world.nation_get_industrial_score(b) + nations::prestige_score(state, b);
350 }
351 });
352 break;
353 case ledger_sort_type::gdp_capita:
354 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
355 float a_population = state.world.nation_get_demographics(a, demographics::total);
356 float b_population = state.world.nation_get_demographics(b, demographics::total);
357
358 if(lsort.reversed) {
359 return economy::gdp_adjusted(state, a) / a_population < economy::gdp_adjusted(state, b) / b_population;
360 } else {
361 return economy::gdp_adjusted(state, a) / a_population > economy::gdp_adjusted(state, b) / b_population;
362 }
363 });
364 break;
365 case ledger_sort_type::gdp:
366 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
367 if(lsort.reversed) {
368 return economy::gdp_adjusted(state, a) < economy::gdp_adjusted(state, b);
369 } else {
370 return economy::gdp_adjusted(state, a) > economy::gdp_adjusted(state, b);
371 }
372 });
373 break;
374 case ledger_sort_type::sol:
375 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
376 if(lsort.reversed) {
377 return demographics::calculate_nation_sol(state, a) < demographics::calculate_nation_sol(state, b);
378 } else {
379 return demographics::calculate_nation_sol(state, a) > demographics::calculate_nation_sol(state, b);
380 }
381 });
382 break;
383
384 default:
385 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
386 if(lsort.reversed) {
387 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
388 } else {
389 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
390 }
391 });
392 break;
393 }
394 update(state);
395 }
396};
397
398//
399// Nation comparison
400//
401
403public:
404 void on_create(sys::state& state) noexcept override {
405 window_element_base::on_create(state);
406
407 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
408
409 xy_pair cell_offset{ int16_t(24), 0 };
410 auto cell_width = (972 - cell_offset.x) / 8;
411 auto apply_offset = [&](auto& ptr) {
412 ptr->base_data.position = cell_offset;
413 ptr->base_data.size.x = int16_t(cell_width);
414 cell_offset.x += ptr->base_data.size.x;
415 };
416
417 {
418 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::country_name);
419 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_name"));
420 apply_offset(ptr);
421 add_child_to_front(std::move(ptr));
422 }
423 {
424 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::total_pop);
425 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_total_pop"));
426 apply_offset(ptr);
427 add_child_to_front(std::move(ptr));
428 }
429 {
430 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::provinces);
431 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_provcount"));
432 apply_offset(ptr);
433 add_child_to_front(std::move(ptr));
434 }
435 {
436 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::factories);
437 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_factorycount"));
438 apply_offset(ptr);
439 add_child_to_front(std::move(ptr));
440 }
441 {
442 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::literacy);
443 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_literacy"));
444 apply_offset(ptr);
445 add_child_to_front(std::move(ptr));
446 }
447 {
448 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::leadership);
449 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_leadership"));
450 apply_offset(ptr);
451 add_child_to_front(std::move(ptr));
452 }
453 {
454 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::brigades);
455 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_divisions"));
456 apply_offset(ptr);
457 add_child_to_front(std::move(ptr));
458 }
459 {
460 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::ships);
461 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_ships"));
462 apply_offset(ptr);
463 add_child_to_front(std::move(ptr));
464 }
465 }
466};
467
469 flag_button* country_flag = nullptr;
470
471public:
472 void on_create(sys::state& state) noexcept override {
473 listbox_row_element_base::on_create(state);
474 // Country flag
475 {
476 auto ptr =
477 make_element_by_type<flag_button>(state, state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_flag"))->second.definition);
478 country_flag = ptr.get();
479 add_child_to_front(std::move(ptr));
480 }
481 xy_pair cell_offset{int16_t(country_flag->base_data.position.x + country_flag->base_data.size.x), 0};
482 auto cell_width = (972 - cell_offset.x) / 8;
483 auto apply_offset = [&](auto& ptr) {
484 ptr->base_data.position = cell_offset;
485 ptr->base_data.size.x = int16_t(cell_width);
486 cell_offset.x += ptr->base_data.size.x;
487 };
488 // Country name
489 {
490 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(state,
491 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
492 apply_offset(ptr);
493 add_child_to_front(std::move(ptr));
494 }
495 // Total population
496 {
497 auto ptr = make_element_by_type<nation_population_text>(state,
498 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
499 apply_offset(ptr);
500 add_child_to_front(std::move(ptr));
501 }
502 // Provinces count
503 {
504 auto ptr = make_element_by_type<nation_provinces_text>(state,
505 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
506 apply_offset(ptr);
507 add_child_to_front(std::move(ptr));
508 }
509 // Factories count
510 {
511 auto ptr = make_element_by_type<nation_industries_text>(state,
512 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
513 apply_offset(ptr);
514 add_child_to_front(std::move(ptr));
515 }
516 // Literacy
517 {
518 auto ptr = make_element_by_type<nation_literacy_text>(state,
519 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
520 apply_offset(ptr);
521 add_child_to_front(std::move(ptr));
522 }
523 // Leadership
524 {
525 auto ptr = make_element_by_type<nation_leadership_points_text>(state,
526 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
527 apply_offset(ptr);
528 add_child_to_front(std::move(ptr));
529 }
530 // Brigades
531 {
532 auto ptr = make_element_by_type<nation_num_regiments>(state,
533 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
534 apply_offset(ptr);
535 add_child_to_front(std::move(ptr));
536 }
537 // Ships
538 {
539 auto ptr = make_element_by_type<nation_num_ships>(state,
540 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
541 apply_offset(ptr);
542 add_child_to_front(std::move(ptr));
543 }
544 }
545
546 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
547 if(payload.holds_type<dcon::nation_id>()) {
548 payload.emplace<dcon::nation_id>(content);
549 return message_result::consumed;
550 }
551 return listbox_row_element_base::get(state, payload);
552 }
553};
554class ledger_nation_comparison_listbox : public listbox_element_base<ledger_nation_comparison_entry, dcon::nation_id> {
555protected:
556 std::string_view get_row_element_name() override {
557 return "default_listbox_entry";
558 }
559
560public:
561 void on_update(sys::state& state) noexcept override {
562 row_contents.clear();
563 state.world.for_each_nation([&](dcon::nation_id id) {
564 if(state.world.nation_get_owned_province_count(id) != 0)
565 row_contents.push_back(id);
566 });
567
568 auto lsort = retrieve<ledger_sort>(state, parent);
569 ledger_sort_type st = std::holds_alternative<ledger_sort_type>(lsort.type) ? std::get<ledger_sort_type>(lsort.type) : ledger_sort_type::country_name;
570 switch(st) {
571 case ledger_sort_type::total_pop:
572 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
573 if(lsort.reversed) {
574 return state.world.nation_get_demographics(a, demographics::total) < state.world.nation_get_demographics(b, demographics::total);
575 } else {
576 return state.world.nation_get_demographics(a, demographics::total) > state.world.nation_get_demographics(b, demographics::total);
577 }
578 });
579 break;
580 case ledger_sort_type::provinces:
581 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
582 if(lsort.reversed) {
583 return state.world.nation_get_owned_province_count(a) < state.world.nation_get_owned_province_count(b);
584 } else {
585 return state.world.nation_get_owned_province_count(a) > state.world.nation_get_owned_province_count(b);
586 }
587 });
588 break;
589 case ledger_sort_type::factories:
590 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
591 uint32_t anum_factories = 0;
592 for(auto si : state.world.nation_get_state_ownership(a)) {
593 province::for_each_province_in_state_instance(state, si.get_state(), [&](dcon::province_id p) {
594 anum_factories += uint32_t(state.world.province_get_factory_location(p).end() - state.world.province_get_factory_location(p).begin());
595 });
596 }
597 uint32_t bnum_factories = 0;
598 for(auto si : state.world.nation_get_state_ownership(b)) {
599 province::for_each_province_in_state_instance(state, si.get_state(), [&](dcon::province_id p) {
600 bnum_factories += uint32_t(state.world.province_get_factory_location(p).end() - state.world.province_get_factory_location(p).begin());
601 });
602 }
603 if(lsort.reversed) {
604 return anum_factories < bnum_factories;
605 } else {
606 return anum_factories > bnum_factories;
607 }
608 });
609 break;
610 case ledger_sort_type::literacy:
611 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
612 auto aliteracy = state.world.nation_get_demographics(a, demographics::literacy) / std::max(1.0f, state.world.nation_get_demographics(a, demographics::total));
613 auto bliteracy = state.world.nation_get_demographics(b, demographics::literacy) / std::max(1.0f, state.world.nation_get_demographics(b, demographics::total));
614 if(lsort.reversed) {
615 return aliteracy < bliteracy;
616 } else {
617 return aliteracy > bliteracy;
618 }
619 });
620 break;
621 case ledger_sort_type::leadership:
622 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
623 if(lsort.reversed) {
624 return state.world.nation_get_leadership_points(a) < state.world.nation_get_leadership_points(b);
625 } else {
626 return state.world.nation_get_leadership_points(a) > state.world.nation_get_leadership_points(b);
627 }
628 });
629 break;
630 case ledger_sort_type::brigades:
631 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
632 if(lsort.reversed) {
633 return state.world.nation_get_active_regiments(a) < state.world.nation_get_active_regiments(b);
634 } else {
635 return state.world.nation_get_active_regiments(a) > state.world.nation_get_active_regiments(b);
636 }
637 });
638 break;
639 case ledger_sort_type::ships:
640 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
641 if(lsort.reversed) {
642 return military::total_ships(state, a) < military::total_ships(state, b);
643 } else {
644 return military::total_ships(state, a) > military::total_ships(state, b);
645 }
646 });
647 break;
648 default:
649 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
650 if(lsort.reversed) {
651 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
652 } else {
653 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
654 }
655 });
656 break;
657 }
658
659 update(state);
660 }
661};
662
663//
664// Nation political systems
665//
666
668public:
669 void on_create(sys::state& state) noexcept override {
670 window_element_base::on_create(state);
671
672 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
673
674 xy_pair cell_offset{ int16_t(24), 0 };
675 auto cell_width = (972 - cell_offset.x) / 5;
676 auto apply_offset = [&](auto& ptr) {
677 ptr->base_data.position = cell_offset;
678 ptr->base_data.size.x = int16_t(cell_width);
679 cell_offset.x += ptr->base_data.size.x;
680 };
681
682 {
683 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::country_name);
684 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_name"));
685 apply_offset(ptr);
686 add_child_to_front(std::move(ptr));
687 }
688 {
689 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::government_type);
690 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_government"));
691 apply_offset(ptr);
692 add_child_to_front(std::move(ptr));
693 }
694 {
695 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::national_value);
696 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_nationalvalue"));
697 apply_offset(ptr);
698 add_child_to_front(std::move(ptr));
699 }
700 {
701 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::ruling_party);
702 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_rulingparty"));
703 apply_offset(ptr);
704 add_child_to_front(std::move(ptr));
705 }
706 {
707 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::ruling_ideology);
708 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_rulingideology"));
709 apply_offset(ptr);
710 add_child_to_front(std::move(ptr));
711 }
712 }
713};
714
716 flag_button* country_flag = nullptr;
717
718public:
719 void on_create(sys::state& state) noexcept override {
720 listbox_row_element_base::on_create(state);
721 // Country flag
722 {
723 auto ptr =
724 make_element_by_type<flag_button>(state, state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_flag"))->second.definition);
725 country_flag = ptr.get();
726 add_child_to_front(std::move(ptr));
727 }
728 xy_pair cell_offset{int16_t(country_flag->base_data.position.x + country_flag->base_data.size.x), 0};
729 auto cell_width = (972 - cell_offset.x) / 5;
730 auto apply_offset = [&](auto& ptr) {
731 ptr->base_data.position = cell_offset;
732 ptr->base_data.size.x = int16_t(cell_width);
733 cell_offset.x += ptr->base_data.size.x;
734 };
735 // Country name
736 {
737 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(state,
738 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
739 apply_offset(ptr);
740 add_child_to_front(std::move(ptr));
741 }
742 // Government
743 {
744 auto ptr = make_element_by_type<nation_government_type_text>(state,
745 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
746 apply_offset(ptr);
747 add_child_to_front(std::move(ptr));
748 }
749 // National value
750 {
751 auto ptr = make_element_by_type<nation_national_value_text>(state,
752 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
753 apply_offset(ptr);
754 add_child_to_front(std::move(ptr));
755 }
756 // Ruling party
757 {
758 auto ptr = make_element_by_type<nation_ruling_party_text>(state,
759 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
760 apply_offset(ptr);
761 add_child_to_front(std::move(ptr));
762 }
763 // Party ideology
764 {
765 auto ptr = make_element_by_type<nation_ruling_party_ideology_text>(state,
766 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
767 apply_offset(ptr);
768 add_child_to_front(std::move(ptr));
769 }
770 }
771
772 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
773 if(payload.holds_type<dcon::nation_id>()) {
774 payload.emplace<dcon::nation_id>(content);
775 return message_result::consumed;
776 }
777 return listbox_row_element_base::get(state, payload);
778 }
779};
781 : public listbox_element_base<ledger_nation_political_systems_entry, dcon::nation_id> {
782protected:
783 std::string_view get_row_element_name() override {
784 return "default_listbox_entry";
785 }
786
787public:
788 void on_update(sys::state& state) noexcept override {
789 row_contents.clear();
790 state.world.for_each_nation([&](dcon::nation_id id) {
791 if(state.world.nation_get_owned_province_count(id) != 0)
792 row_contents.push_back(id);
793 });
794
795 auto lsort = retrieve<ledger_sort>(state, parent);
796 ledger_sort_type st = std::holds_alternative<ledger_sort_type>(lsort.type) ? std::get<ledger_sort_type>(lsort.type) : ledger_sort_type::country_name;
797 switch(st) {
798 case ledger_sort_type::government_type:
799 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
800 if(lsort.reversed) {
801 return state.world.nation_get_government_type(a).id.index() < state.world.nation_get_government_type(b).id.index();
802 } else {
803 return state.world.nation_get_government_type(a).id.index() > state.world.nation_get_government_type(b).id.index();
804 }
805 });
806 break;
807 case ledger_sort_type::ruling_party:
808 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
809 if(lsort.reversed) {
810 return text::produce_simple_string(state, state.world.nation_get_ruling_party(a).get_name()) < text::produce_simple_string(state, state.world.nation_get_ruling_party(b).get_name());
811 } else {
812 return text::produce_simple_string(state, state.world.nation_get_ruling_party(a).get_name()) > text::produce_simple_string(state, state.world.nation_get_ruling_party(b).get_name());
813 }
814 });
815 break;
816 case ledger_sort_type::national_value:
817 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
818 if(lsort.reversed) {
819 return state.world.nation_get_national_value(a).id.index() < state.world.nation_get_national_value(b).id.index();
820 } else {
821 return state.world.nation_get_national_value(a).id.index() > state.world.nation_get_national_value(b).id.index();
822 }
823 });
824 break;
825 case ledger_sort_type::ruling_ideology:
826 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
827 if(lsort.reversed) {
828 return state.world.nation_get_ruling_party(a).get_ideology().id.index() < state.world.nation_get_ruling_party(b).get_ideology().id.index();
829 } else {
830 return state.world.nation_get_ruling_party(a).get_ideology().id.index() > state.world.nation_get_ruling_party(b).get_ideology().id.index();
831 }
832 });
833 break;
834 default:
835 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
836 if(lsort.reversed) {
837 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
838 } else {
839 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
840 }
841 });
842 break;
843 }
844
845 update(state);
846 }
847};
848
849//
850// Social & Political reforms
851//
853public:
854 dcon::issue_id issue_id{};
855 std::string get_text(sys::state& state, dcon::nation_id nation_id) noexcept override {
856 // Obtain the active issue option for this issue id
857 auto active_issue_option = state.world.nation_get_issues(nation_id, issue_id);
858 return text::produce_simple_string(state, active_issue_option.get_name());
859 }
860};
861
862template<bool IsPolitical>
864public:
865 void on_create(sys::state& state) noexcept override {
866 window_element_base::on_create(state);
867
868 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
869
870 xy_pair cell_offset{ int16_t(24), 0 };
871
872 auto num_issues = 0;
873 state.world.for_each_issue([&](dcon::issue_id id) {
874 if(state.world.issue_get_issue_type(id) == uint8_t(culture::issue_type::party) || (state.world.issue_get_issue_type(id) == uint8_t(culture::issue_type::political)) != IsPolitical)
875 return;
876 ++num_issues;
877 });
878
879 // 1 for the country name
880 auto cell_width = (972 - cell_offset.x) / (1 + num_issues);
881 auto apply_offset = [&](auto& ptr) {
882 ptr->base_data.position = cell_offset;
883 ptr->base_data.size.x = int16_t(cell_width);
884 cell_offset.x += ptr->base_data.size.x;
885 };
886
887 {
888 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::country_name);
889 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_name"));
890 apply_offset(ptr);
891 add_child_to_front(std::move(ptr));
892 }
893
894 state.world.for_each_issue([&](dcon::issue_id id) {
895 if(state.world.issue_get_issue_type(id) == uint8_t(culture::issue_type::party) || (state.world.issue_get_issue_type(id) == uint8_t(culture::issue_type::political)) != IsPolitical)
896 return;
897
898
899 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, id);
900 ptr->set_button_text(state, text::produce_simple_string(state, state.world.issue_get_name(id)));
901 apply_offset(ptr);
902 add_child_to_front(std::move(ptr));
903 });
904 }
905};
906
907template<bool IsPolitical>
909 flag_button* country_flag = nullptr;
910
911public:
912 void on_create(sys::state& state) noexcept override {
913 listbox_row_element_base::on_create(state);
914 // Country flag
915 {
916 auto ptr =
917 make_element_by_type<flag_button>(state, state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_flag"))->second.definition);
918 country_flag = ptr.get();
919 add_child_to_front(std::move(ptr));
920 }
921 xy_pair cell_offset{int16_t(country_flag->base_data.position.x + country_flag->base_data.size.x), 0};
922
923 auto num_issues = 0;
924 state.world.for_each_issue([&](dcon::issue_id id) {
925 if(state.world.issue_get_issue_type(id) == uint8_t(culture::issue_type::party) || (state.world.issue_get_issue_type(id) == uint8_t(culture::issue_type::political)) != IsPolitical)
926 return;
927 ++num_issues;
928 });
929
930 // 1 for the country name
931 auto cell_width = (972 - cell_offset.x) / (1 + num_issues);
932 auto apply_offset = [&](auto& ptr) {
933 ptr->base_data.position = cell_offset;
934 ptr->base_data.size.x = int16_t(cell_width);
935 cell_offset.x += ptr->base_data.size.x;
936 };
937 // Country name
938 {
939 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(state,
940 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
941 apply_offset(ptr);
942 add_child_to_front(std::move(ptr));
943 }
944 // For each (political) issue generate
945 state.world.for_each_issue([&](dcon::issue_id id) {
946 if(state.world.issue_get_issue_type(id) == uint8_t(culture::issue_type::party) || (state.world.issue_get_issue_type(id) == uint8_t(culture::issue_type::political)) != IsPolitical)
947 return;
948
949 auto ptr = make_element_by_type<nation_selected_issue_text>(state,
950 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
951 ptr->issue_id = id;
952 apply_offset(ptr);
953 add_child_to_front(std::move(ptr));
954 });
955 }
956
957 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
958 if(payload.holds_type<dcon::nation_id>()) {
959 payload.emplace<dcon::nation_id>(content);
960 return message_result::consumed;
961 }
962 return listbox_row_element_base::get(state, payload);
963 }
964};
965class ledger_nation_political_reforms_listbox : public listbox_element_base<ledger_nation_reforms_entry<true>, dcon::nation_id> {
966protected:
967 std::string_view get_row_element_name() override {
968 return "default_listbox_entry";
969 }
970
971public:
972 void on_update(sys::state& state) noexcept override {
973 row_contents.clear();
974 state.world.for_each_nation([&](dcon::nation_id id) {
975 if(state.world.nation_get_owned_province_count(id) != 0)
976 row_contents.push_back(id);
977 });
978
979 auto lsort = retrieve<ledger_sort>(state, parent);
980 if(std::holds_alternative<dcon::issue_id>(lsort.type)) {
981 auto iss = std::get<dcon::issue_id>(lsort.type);
982 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
983 if(lsort.reversed) {
984 return state.world.nation_get_issues(a, iss).id.index() < state.world.nation_get_issues(b, iss).id.index();
985 } else {
986 return state.world.nation_get_issues(a, iss).id.index() > state.world.nation_get_issues(b, iss).id.index();
987 }
988 });
989 } else {
990 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
991 if(lsort.reversed) {
992 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
993 } else {
994 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
995 }
996 });
997 }
998
999 update(state);
1000 }
1001};
1002class ledger_nation_social_reforms_listbox : public listbox_element_base<ledger_nation_reforms_entry<false>, dcon::nation_id> {
1003protected:
1004 std::string_view get_row_element_name() override {
1005 return "default_listbox_entry";
1006 }
1007
1008public:
1009 void on_update(sys::state& state) noexcept override {
1010 row_contents.clear();
1011 state.world.for_each_nation([&](dcon::nation_id id) {
1012 if(state.world.nation_get_owned_province_count(id) != 0)
1013 row_contents.push_back(id);
1014 });
1015
1016 auto lsort = retrieve<ledger_sort>(state, parent);
1017 if(std::holds_alternative<dcon::issue_id>(lsort.type)) {
1018 auto iss = std::get<dcon::issue_id>(lsort.type);
1019 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
1020 if(lsort.reversed) {
1021 return state.world.nation_get_issues(a, iss).id.index() < state.world.nation_get_issues(b, iss).id.index();
1022 } else {
1023 return state.world.nation_get_issues(a, iss).id.index() > state.world.nation_get_issues(b, iss).id.index();
1024 }
1025 });
1026 } else {
1027 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
1028 if(lsort.reversed) {
1029 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
1030 } else {
1031 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
1032 }
1033 });
1034 }
1035
1036 update(state);
1037 }
1038};
1039
1040//
1041// Nation population per strata
1042//
1044public:
1045 dcon::pop_type_id pop_type_id{};
1046 std::string get_text(sys::state& state, dcon::nation_id nation_id) noexcept override {
1047 auto total_pop = state.world.nation_get_demographics(nation_id, demographics::to_key(state, pop_type_id));
1048 return text::prettify(int32_t(total_pop));
1049 }
1050};
1051
1053public:
1054 void on_create(sys::state& state) noexcept override {
1055 window_element_base::on_create(state);
1056
1057 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
1058 auto ibutton_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_pop_icon"))->second.definition;
1059
1060 xy_pair cell_offset{ int16_t(24), 0 };
1061
1062 auto num_pop_types = 0;
1063 state.world.for_each_pop_type([&](dcon::pop_type_id id) { ++num_pop_types; });
1064
1065 // 1 for the country name
1066 auto cell_width = (972 - cell_offset.x) / (1 + num_pop_types);
1067 auto apply_offset = [&](auto& ptr) {
1068 ptr->base_data.position = cell_offset;
1069 cell_offset.x += int16_t(cell_width);
1070 };
1071
1072 {
1073 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::country_name);
1074 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_country_name"));
1075 apply_offset(ptr);
1076 ptr->base_data.size.x = int16_t(cell_width);
1077 add_child_to_front(std::move(ptr));
1078 }
1079
1080
1081 state.world.for_each_pop_type([&](dcon::pop_type_id id) {
1082 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, ibutton_def, id);
1083 ptr->frame = int32_t(state.world.pop_type_get_sprite(id) - 1);
1084 apply_offset(ptr);
1085 add_child_to_front(std::move(ptr));
1086 });
1087 }
1088};
1089
1091 flag_button* country_flag = nullptr;
1092
1093public:
1094 void on_create(sys::state& state) noexcept override {
1095 listbox_row_element_base::on_create(state);
1096 // Country flag
1097 {
1098 auto ptr =
1099 make_element_by_type<flag_button>(state, state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_flag"))->second.definition);
1100 country_flag = ptr.get();
1101 add_child_to_front(std::move(ptr));
1102 }
1103 xy_pair cell_offset{int16_t(country_flag->base_data.position.x + country_flag->base_data.size.x), 0};
1104
1105 auto num_pop_types = 0;
1106 state.world.for_each_pop_type([&](dcon::pop_type_id id) { ++num_pop_types; });
1107
1108 // 1 for the country name
1109 auto cell_width = (972 - cell_offset.x) / (1 + num_pop_types);
1110 auto apply_offset = [&](auto& ptr) {
1111 ptr->base_data.position = cell_offset;
1112 ptr->base_data.size.x = int16_t(cell_width);
1113 cell_offset.x += ptr->base_data.size.x;
1114 };
1115 // Country name
1116 {
1117 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(state,
1118 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1119 apply_offset(ptr);
1120 add_child_to_front(std::move(ptr));
1121 }
1122 // For each pop type generate
1123 state.world.for_each_pop_type([&](dcon::pop_type_id id) {
1124 auto ptr = make_element_by_type<nation_population_per_pop_type_text>(state,
1125 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1126 ptr->pop_type_id = id;
1127 apply_offset(ptr);
1128 add_child_to_front(std::move(ptr));
1129 });
1130 }
1131
1132 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1133 if(payload.holds_type<dcon::nation_id>()) {
1134 payload.emplace<dcon::nation_id>(content);
1135 return message_result::consumed;
1136 }
1137 return listbox_row_element_base::get(state, payload);
1138 }
1139};
1140class ledger_nation_population_listbox : public listbox_element_base<ledger_nation_population_entry, dcon::nation_id> {
1141protected:
1142 std::string_view get_row_element_name() override {
1143 return "default_listbox_entry";
1144 }
1145
1146public:
1147 void on_update(sys::state& state) noexcept override {
1148 row_contents.clear();
1149 state.world.for_each_nation([&](dcon::nation_id id) {
1150 if(state.world.nation_get_owned_province_count(id) != 0)
1151 row_contents.push_back(id);
1152 });
1153
1154 auto lsort = retrieve<ledger_sort>(state, parent);
1155 if(std::holds_alternative<dcon::pop_type_id>(lsort.type)) {
1156 auto pt = std::get<dcon::pop_type_id>(lsort.type);
1157 auto dkey = demographics::to_key(state, pt);
1158 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
1159 if(lsort.reversed) {
1160 return state.world.nation_get_demographics(a, dkey) < state.world.nation_get_demographics(b, dkey);
1161 } else {
1162 return state.world.nation_get_demographics(a, dkey) > state.world.nation_get_demographics(b, dkey);
1163 }
1164 });
1165 } else {
1166 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
1167 if(lsort.reversed) {
1168 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
1169 } else {
1170 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
1171 }
1172 });
1173 }
1174
1175 update(state);
1176 }
1177};
1178
1179//
1180// Provinces
1181//
1182
1184public:
1185 void on_create(sys::state& state) noexcept override {
1186 window_element_base::on_create(state);
1187
1188 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
1189
1190 xy_pair cell_offset{ 0, 0 };
1191
1192 auto cell_width = (972 - cell_offset.x) / 9;
1193 auto apply_offset = [&](auto& ptr) {
1194 ptr->base_data.position = cell_offset;
1195 ptr->base_data.size.x = int16_t(cell_width);
1196 cell_offset.x += ptr->base_data.size.x;
1197 };
1198
1199 {
1200 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::province_name);
1201 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_name"));
1202 apply_offset(ptr);
1203 add_child_to_front(std::move(ptr));
1204 }
1205 {
1206 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::total_pop);
1207 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_totalpop"));
1208 apply_offset(ptr);
1209 add_child_to_front(std::move(ptr));
1210 }
1211 {
1212 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::militancy);
1213 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_avgmil"));
1214 apply_offset(ptr);
1215 add_child_to_front(std::move(ptr));
1216 }
1217 {
1218 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::conciousness);
1219 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_avgcon"));
1220 apply_offset(ptr);
1221 add_child_to_front(std::move(ptr));
1222 }
1223 {
1224 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::literacy);
1225 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_avglit"));
1226 apply_offset(ptr);
1227 add_child_to_front(std::move(ptr));
1228 }
1229 {
1230 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::religion);
1231 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_religion"));
1232 apply_offset(ptr);
1233 add_child_to_front(std::move(ptr));
1234 }
1235 {
1236 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::culture);
1237 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_culture"));
1238 apply_offset(ptr);
1239 add_child_to_front(std::move(ptr));
1240 }
1241 {
1242 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::dom_issue);
1243 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_issue"));
1244 apply_offset(ptr);
1245 add_child_to_front(std::move(ptr));
1246 }
1247 {
1248 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::dom_ideology);
1249 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_ideology"));
1250 apply_offset(ptr);
1251 add_child_to_front(std::move(ptr));
1252 }
1253 }
1254};
1255
1256class ledger_province_entry : public listbox_row_element_base<dcon::province_id> {
1257public:
1258 void on_create(sys::state& state) noexcept override {
1259 listbox_row_element_base::on_create(state);
1260
1261 xy_pair cell_offset{0, 0};
1262
1263 auto cell_width = (972 - cell_offset.x) / 9;
1264 auto apply_offset = [&](auto& ptr) {
1265 ptr->base_data.position = cell_offset;
1266 ptr->base_data.size.x = int16_t(cell_width);
1267 cell_offset.x += ptr->base_data.size.x;
1268 };
1269 // Province name
1270 {
1271 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(state,
1272 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1273 apply_offset(ptr);
1274 add_child_to_front(std::move(ptr));
1275 }
1276 // Total population
1277 {
1278 auto ptr = make_element_by_type<province_population_text>(state,
1279 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1280 apply_offset(ptr);
1281 add_child_to_front(std::move(ptr));
1282 }
1283 // Average militancy
1284 {
1285 auto ptr = make_element_by_type<province_militancy_text>(state,
1286 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1287 apply_offset(ptr);
1288 add_child_to_front(std::move(ptr));
1289 }
1290 // Average consciousness
1291 {
1292 auto ptr = make_element_by_type<province_consciousness_text>(state,
1293 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1294 apply_offset(ptr);
1295 add_child_to_front(std::move(ptr));
1296 }
1297 // Average literacy
1298 {
1299 auto ptr = make_element_by_type<province_literacy_text>(state,
1300 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1301 apply_offset(ptr);
1302 add_child_to_front(std::move(ptr));
1303 }
1304 // Religion
1305 {
1306 auto ptr = make_element_by_type<province_dominant_religion_text>(state,
1307 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1308 apply_offset(ptr);
1309 add_child_to_front(std::move(ptr));
1310 }
1311 // Culture
1312 {
1313 auto ptr = make_element_by_type<province_dominant_culture_text>(state,
1314 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1315 apply_offset(ptr);
1316 add_child_to_front(std::move(ptr));
1317 }
1318 // Issues
1319 {
1320 auto ptr = make_element_by_type<province_dominant_issue_text>(state,
1321 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1322 apply_offset(ptr);
1323 add_child_to_front(std::move(ptr));
1324 }
1325 // Ideology
1326 {
1327 auto ptr = make_element_by_type<province_dominant_ideology_text>(state,
1328 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1329 apply_offset(ptr);
1330 add_child_to_front(std::move(ptr));
1331 }
1332 }
1333
1334 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1335 if(payload.holds_type<dcon::province_id>()) {
1336 payload.emplace<dcon::province_id>(content);
1337 return message_result::consumed;
1338 }
1339 return listbox_row_element_base::get(state, payload);
1340 }
1341};
1342class ledger_province_listbox : public listbox_element_base<ledger_province_entry, dcon::province_id> {
1343protected:
1344 std::string_view get_row_element_name() override {
1345 return "default_listbox_entry";
1346 }
1347
1348public:
1349 void on_update(sys::state& state) noexcept override {
1350 row_contents.clear();
1351 for(auto si : state.world.nation_get_state_ownership(state.local_player_nation))
1353 [&](dcon::province_id p) { row_contents.push_back(p); });
1354
1355 auto lsort = retrieve<ledger_sort>(state, parent);
1356 ledger_sort_type st = std::holds_alternative<ledger_sort_type>(lsort.type) ? std::get<ledger_sort_type>(lsort.type) : ledger_sort_type::country_name;
1357 switch(st) {
1358 case ledger_sort_type::total_pop:
1359 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1360 if(lsort.reversed) {
1361 return state.world.province_get_demographics(a, demographics::total) < state.world.province_get_demographics(b, demographics::total);
1362 } else {
1363 return state.world.province_get_demographics(a, demographics::total) > state.world.province_get_demographics(b, demographics::total);
1364 }
1365 });
1366 break;
1367 case ledger_sort_type::militancy:
1368 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1369 if(lsort.reversed) {
1370 return state.world.province_get_demographics(a, demographics::militancy) / std::max(1.0f, state.world.province_get_demographics(a, demographics::total)) < state.world.province_get_demographics(b, demographics::militancy) / std::max(1.0f, state.world.province_get_demographics(b, demographics::total));
1371 } else {
1372 return state.world.province_get_demographics(a, demographics::militancy) / std::max(1.0f, state.world.province_get_demographics(a, demographics::total)) > state.world.province_get_demographics(b, demographics::militancy) / std::max(1.0f, state.world.province_get_demographics(b, demographics::total));
1373 }
1374 });
1375 break;
1376 case ledger_sort_type::conciousness:
1377 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1378 if(lsort.reversed) {
1379 return state.world.province_get_demographics(a, demographics::consciousness) / std::max(1.0f, state.world.province_get_demographics(a, demographics::total)) < state.world.province_get_demographics(b, demographics::consciousness) / std::max(1.0f, state.world.province_get_demographics(b, demographics::total));
1380 } else {
1381 return state.world.province_get_demographics(a, demographics::consciousness) / std::max(1.0f, state.world.province_get_demographics(a, demographics::total)) > state.world.province_get_demographics(b, demographics::consciousness) / std::max(1.0f, state.world.province_get_demographics(b, demographics::total));
1382 }
1383 });
1384 break;
1385 case ledger_sort_type::literacy:
1386 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1387 if(lsort.reversed) {
1388 return state.world.province_get_demographics(a, demographics::literacy) / std::max(1.0f, state.world.province_get_demographics(a, demographics::total)) < state.world.province_get_demographics(b, demographics::literacy) / std::max(1.0f, state.world.province_get_demographics(b, demographics::total));
1389 } else {
1390 return state.world.province_get_demographics(a, demographics::literacy) / std::max(1.0f, state.world.province_get_demographics(a, demographics::total)) > state.world.province_get_demographics(b, demographics::literacy) / std::max(1.0f, state.world.province_get_demographics(b, demographics::total));
1391 }
1392 });
1393 break;
1394 case ledger_sort_type::culture:
1395 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1396 if(lsort.reversed) {
1397 return text::produce_simple_string(state, state.world.culture_get_name(state.world.province_get_dominant_culture(a))) > text::produce_simple_string(state, state.world.culture_get_name(state.world.province_get_dominant_culture(b)));
1398 } else {
1399 return text::produce_simple_string(state, state.world.culture_get_name(state.world.province_get_dominant_culture(a))) < text::produce_simple_string(state, state.world.culture_get_name(state.world.province_get_dominant_culture(b)));
1400 }
1401 });
1402 break;
1403 case ledger_sort_type::religion:
1404 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1405 if(lsort.reversed) {
1406 return state.world.province_get_dominant_religion(a).id.index() > state.world.province_get_dominant_religion(b).id.index();
1407 } else {
1408 return state.world.province_get_dominant_religion(a).id.index() < state.world.province_get_dominant_religion(b).id.index();
1409 }
1410 });
1411 break;
1412 case ledger_sort_type::dom_ideology:
1413 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1414 if(lsort.reversed) {
1415 return state.world.province_get_dominant_ideology(a).id.index() > state.world.province_get_dominant_ideology(b).id.index();
1416 } else {
1417 return state.world.province_get_dominant_ideology(a).id.index() < state.world.province_get_dominant_ideology(b).id.index();
1418 }
1419 });
1420 break;
1421 case ledger_sort_type::dom_issue:
1422 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1423 if(lsort.reversed) {
1424 return state.world.province_get_dominant_issue_option(a).id.index() > state.world.province_get_dominant_issue_option(b).id.index();
1425 } else {
1426 return state.world.province_get_dominant_issue_option(a).id.index() < state.world.province_get_dominant_issue_option(b).id.index();
1427 }
1428 });
1429 break;
1430 default:
1431 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1432 if(lsort.reversed) {
1433 return text::produce_simple_string(state, state.world.province_get_name(a)) > text::produce_simple_string(state, state.world.province_get_name(b));
1434 } else {
1435 return text::produce_simple_string(state, state.world.province_get_name(a)) < text::produce_simple_string(state, state.world.province_get_name(b));
1436 }
1437 });
1438 break;
1439 }
1440
1441 update(state);
1442 }
1443};
1444
1445//
1446// Province population per strata
1447//
1449public:
1450 dcon::pop_type_id pop_type_id;
1451
1452 province_population_per_pop_type_text(dcon::pop_type_id pop_type_id) : pop_type_id(pop_type_id) { }
1453
1454 void on_update(sys::state& state) noexcept override {
1455 auto province_id = retrieve<dcon::province_id>(state, parent);
1456 auto total_pop = state.world.province_get_demographics(province_id, demographics::to_key(state, pop_type_id));
1457 set_text(state, text::prettify(int32_t(total_pop)));
1458 }
1459};
1460
1462public:
1463 void on_create(sys::state& state) noexcept override {
1464 window_element_base::on_create(state);
1465
1466 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
1467 auto ibutton_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_pop_icon"))->second.definition;
1468
1469 xy_pair cell_offset{ 0, 0 };
1470
1471 auto num_pop_types = 0;
1472 state.world.for_each_pop_type([&](dcon::pop_type_id id) { ++num_pop_types; });
1473
1474 // 1 for the country name
1475 auto cell_width = (972 - cell_offset.x) / (1 + num_pop_types);
1476 auto apply_offset = [&](auto& ptr) {
1477 ptr->base_data.position = cell_offset;
1478 cell_offset.x += int16_t(cell_width);
1479 };
1480
1481 {
1482 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::province_name);
1483 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_name"));
1484 ptr->base_data.size.x = int16_t(cell_width);
1485 apply_offset(ptr);
1486 add_child_to_front(std::move(ptr));
1487 }
1488
1489
1490 state.world.for_each_pop_type([&](dcon::pop_type_id id) {
1491 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, ibutton_def, id);
1492 ptr->frame = int32_t(state.world.pop_type_get_sprite(id) - 1);
1493 apply_offset(ptr);
1494 add_child_to_front(std::move(ptr));
1495 });
1496 }
1497};
1498
1500public:
1501 void on_create(sys::state& state) noexcept override {
1502 listbox_row_element_base::on_create(state);
1503
1504 xy_pair cell_offset{0, 0};
1505
1506 auto num_pop_types = 0;
1507 state.world.for_each_pop_type([&](dcon::pop_type_id id) { ++num_pop_types; });
1508
1509 auto cell_width = (972 - cell_offset.x) / (1 + num_pop_types);
1510 auto apply_offset = [&](auto& ptr) {
1511 ptr->base_data.position = cell_offset;
1512 ptr->base_data.size.x = int16_t(cell_width);
1513 cell_offset.x += ptr->base_data.size.x;
1514 };
1515 // Province name
1516 {
1517 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(state,
1518 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1519 apply_offset(ptr);
1520 add_child_to_front(std::move(ptr));
1521 }
1522 // For each pop type generate
1523 state.world.for_each_pop_type([&](dcon::pop_type_id id) {
1524 auto ptr = make_element_by_type<province_population_per_pop_type_text>(state, state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition, id);
1525 apply_offset(ptr);
1526 add_child_to_front(std::move(ptr));
1527 });
1528 }
1529
1530 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1531 if(payload.holds_type<dcon::province_id>()) {
1532 payload.emplace<dcon::province_id>(content);
1533 return message_result::consumed;
1534 }
1535 return listbox_row_element_base::get(state, payload);
1536 }
1537};
1538class ledger_province_population_listbox : public listbox_element_base<ledger_province_population_entry, dcon::province_id> {
1539protected:
1540 std::string_view get_row_element_name() override {
1541 return "default_listbox_entry";
1542 }
1543
1544public:
1545 void on_update(sys::state& state) noexcept override {
1546 row_contents.clear();
1547 for(auto si : state.world.nation_get_state_ownership(state.local_player_nation))
1549 [&](dcon::province_id p) { row_contents.push_back(p); });
1550
1551 auto lsort = retrieve<ledger_sort>(state, parent);
1552 if(std::holds_alternative<dcon::pop_type_id>(lsort.type)) {
1553 auto pt = std::get<dcon::pop_type_id>(lsort.type);
1554 auto dkey = demographics::to_key(state, pt);
1555 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1556 if(lsort.reversed) {
1557 return state.world.province_get_demographics(a, dkey) < state.world.province_get_demographics(b, dkey);
1558 } else {
1559 return state.world.province_get_demographics(a, dkey) > state.world.province_get_demographics(b, dkey);
1560 }
1561 });
1562 } else {
1563 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1564 if(lsort.reversed) {
1565 return text::produce_simple_string(state, state.world.province_get_name(a)) > text::produce_simple_string(state, state.world.province_get_name(b));
1566 } else {
1567 return text::produce_simple_string(state, state.world.province_get_name(a)) < text::produce_simple_string(state, state.world.province_get_name(b));
1568 }
1569 });
1570 }
1571
1572 update(state);
1573 }
1574};
1575
1576//
1577// Provinces production
1578//
1579
1581public:
1582 void on_create(sys::state& state) noexcept override {
1583 window_element_base::on_create(state);
1584
1585 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
1586
1587 xy_pair cell_offset{ 0, 0 };
1588
1589 auto cell_width = (972 - cell_offset.x) / 7;
1590 auto apply_offset = [&](auto& ptr) {
1591 ptr->base_data.position = cell_offset;
1592 ptr->base_data.size.x = int16_t(cell_width);
1593 cell_offset.x += ptr->base_data.size.x;
1594 };
1595
1596 {
1597 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::province_name);
1598 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_province_name"));
1599 apply_offset(ptr);
1600 add_child_to_front(std::move(ptr));
1601 }
1602 {
1603 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::state_name);
1604 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_state_name"));
1605 apply_offset(ptr);
1606 add_child_to_front(std::move(ptr));
1607 }
1608 {
1609 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::commodity_type);
1610 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_goods"));
1611 apply_offset(ptr);
1612 add_child_to_front(std::move(ptr));
1613 }
1614 {
1615 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::output_amount);
1616 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_output"));
1617 apply_offset(ptr);
1618 add_child_to_front(std::move(ptr));
1619 }
1620 {
1621 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::profit);
1622 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_income"));
1623 apply_offset(ptr);
1624 add_child_to_front(std::move(ptr));
1625 }
1626 {
1627 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::employment);
1628 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_employed"));
1629 apply_offset(ptr);
1630 add_child_to_front(std::move(ptr));
1631 }
1632 {
1633 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::rgo_size);
1634 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_level"));
1635 apply_offset(ptr);
1636 add_child_to_front(std::move(ptr));
1637 }
1638 }
1639};
1640
1642public:
1643 void on_create(sys::state& state) noexcept override {
1644 listbox_row_element_base::on_create(state);
1645
1646 xy_pair cell_offset{0, 0};
1647
1648 auto cell_width = (972 - cell_offset.x) / 7;
1649 auto apply_offset = [&](auto& ptr) {
1650 ptr->base_data.position = cell_offset;
1651 ptr->base_data.size.x = int16_t(cell_width);
1652 cell_offset.x += ptr->base_data.size.x;
1653 };
1654 // Province name
1655 {
1656 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(state,
1657 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1658 apply_offset(ptr);
1659 add_child_to_front(std::move(ptr));
1660 }
1661 // State name
1662 {
1663 auto ptr = make_element_by_type<province_state_name_text>(state,
1664 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1665 apply_offset(ptr);
1666 add_child_to_front(std::move(ptr));
1667 }
1668 // Goods
1669 {
1670 auto ptr = make_element_by_type<province_rgo_name_text>(state,
1671 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1672 apply_offset(ptr);
1673 add_child_to_front(std::move(ptr));
1674 }
1675 // Output
1676 {
1677 auto ptr = make_element_by_type<province_goods_produced_text>(state,
1678 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1679 apply_offset(ptr);
1680 add_child_to_front(std::move(ptr));
1681 }
1682 // Income
1683 {
1684 auto ptr = make_element_by_type<province_income_text>(state,
1685 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1686 apply_offset(ptr);
1687 add_child_to_front(std::move(ptr));
1688 }
1689 // Employed
1690 {
1691 auto ptr = make_element_by_type<province_rgo_workers_text>(state,
1692 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1693 apply_offset(ptr);
1694 add_child_to_front(std::move(ptr));
1695 }
1696 // Level
1697 {
1698 auto ptr = make_element_by_type<province_rgo_size_text>(state,
1699 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1700 apply_offset(ptr);
1701 add_child_to_front(std::move(ptr));
1702 }
1703 }
1704
1705 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1706 if(payload.holds_type<dcon::province_id>()) {
1707 payload.emplace<dcon::province_id>(content);
1708 return message_result::consumed;
1709 }
1710 return listbox_row_element_base::get(state, payload);
1711 }
1712};
1713class ledger_provinces_production_listbox : public listbox_element_base<ledger_provinces_production_entry, dcon::province_id> {
1714protected:
1715 std::string_view get_row_element_name() override {
1716 return "default_listbox_entry";
1717 }
1718
1719public:
1720 void on_update(sys::state& state) noexcept override {
1721 row_contents.clear();
1722 for(auto si : state.world.nation_get_state_ownership(state.local_player_nation))
1724 [&](dcon::province_id p) { row_contents.push_back(p); });
1725
1726 auto lsort = retrieve<ledger_sort>(state, parent);
1727 ledger_sort_type st = std::holds_alternative<ledger_sort_type>(lsort.type) ? std::get<ledger_sort_type>(lsort.type) : ledger_sort_type::country_name;
1728 switch(st) {
1729 case ledger_sort_type::state_name:
1730 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1731 if(lsort.reversed) {
1732 return text::get_province_state_name(state, a) > text::get_province_state_name(state, b);
1733 } else {
1734 return text::get_province_state_name(state, a) < text::get_province_state_name(state, b);
1735 }
1736 });
1737 break;
1738 case ledger_sort_type::commodity_type:
1739 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1740 if(lsort.reversed) {
1741 return state.world.province_get_rgo(a).id.index() < state.world.province_get_rgo(b).id.index();
1742 } else {
1743 return state.world.province_get_rgo(a).id.index() > state.world.province_get_rgo(b).id.index();
1744 }
1745 });
1746 break;
1747 /*
1748 case ledger_sort_type::output_amount:
1749 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1750 if(lsort.reversed) {
1751 return province::rgo_production_quantity(state, a) < province::rgo_production_quantity(state, b);
1752 } else {
1753 return province::rgo_production_quantity(state, a) > province::rgo_production_quantity(state, b);
1754 }
1755 });
1756 break;
1757 */
1758 case ledger_sort_type::profit:
1759 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1760 if(lsort.reversed) {
1761 return province::rgo_income(state, a) < province::rgo_income(state, b);
1762 } else {
1763 return province::rgo_income(state, a) > province::rgo_income(state, b);
1764 }
1765 });
1766 break;
1767 case ledger_sort_type::employment:
1768 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1769 if(lsort.reversed) {
1770 return province::rgo_employment(state, a) < province::rgo_employment(state, b);
1771 } else {
1772 return province::rgo_employment(state, a) > province::rgo_employment(state, b);
1773 }
1774 });
1775 break;
1776 /*
1777 case ledger_sort_type::rgo_size:
1778 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1779 if(lsort.reversed) {
1780 return economy::rgo_effective_size(state, state.world.province_get_nation_from_province_ownership(a), a) < economy::rgo_effective_size(state, state.world.province_get_nation_from_province_ownership(b), b);
1781 } else {
1782 return economy::rgo_effective_size(state, state.world.province_get_nation_from_province_ownership(a), a) > economy::rgo_effective_size(state, state.world.province_get_nation_from_province_ownership(b), b);
1783 }
1784 });
1785 break;
1786 */
1787 default:
1788 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::province_id a, dcon::province_id b) {
1789 if(lsort.reversed) {
1790 return text::produce_simple_string(state, state.world.province_get_name(a)) > text::produce_simple_string(state, state.world.province_get_name(b));
1791 } else {
1792 return text::produce_simple_string(state, state.world.province_get_name(a)) < text::produce_simple_string(state, state.world.province_get_name(b));
1793 }
1794 });
1795 break;
1796 }
1797
1798 update(state);
1799 }
1800};
1801
1802//
1803// Factory production
1804//
1805
1807public:
1808 void on_create(sys::state& state) noexcept override {
1809 window_element_base::on_create(state);
1810
1811 auto button_def = state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_button"))->second.definition;
1812
1813 xy_pair cell_offset{ 0, 0 };
1814
1815 auto cell_width = (972 - cell_offset.x) / 6;
1816 auto apply_offset = [&](auto& ptr) {
1817 ptr->base_data.position = cell_offset;
1818 ptr->base_data.size.x = int16_t(cell_width);
1819 cell_offset.x += ptr->base_data.size.x;
1820 };
1821
1822 {
1823 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::state_name);
1824 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_state_name"));
1825 apply_offset(ptr);
1826 add_child_to_front(std::move(ptr));
1827 }
1828 {
1829 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::commodity_type);
1830 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_goods"));
1831 apply_offset(ptr);
1832 add_child_to_front(std::move(ptr));
1833 }
1834 {
1835 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::output_amount);
1836 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_output"));
1837 apply_offset(ptr);
1838 add_child_to_front(std::move(ptr));
1839 }
1840 {
1841 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::profit);
1842 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_income"));
1843 apply_offset(ptr);
1844 add_child_to_front(std::move(ptr));
1845 }
1846 {
1847 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::employment);
1848 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_employed"));
1849 apply_offset(ptr);
1850 add_child_to_front(std::move(ptr));
1851 }
1852 {
1853 auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::factory_level);
1854 ptr->set_button_text(state, text::produce_simple_string(state, "ledger_level"));
1855 apply_offset(ptr);
1856 add_child_to_front(std::move(ptr));
1857 }
1858 }
1859};
1860
1862public:
1863 void on_create(sys::state& state) noexcept override {
1864 listbox_row_element_base::on_create(state);
1865
1866 xy_pair cell_offset{0, 0};
1867
1868 auto cell_width = (972 - cell_offset.x) / 6;
1869 auto apply_offset = [&](auto& ptr) {
1870 ptr->base_data.position = cell_offset;
1871 ptr->base_data.size.x = int16_t(cell_width);
1872 cell_offset.x += ptr->base_data.size.x;
1873 };
1874 // State name
1875 {
1876 auto ptr = make_element_by_type<factory_state_name_text>(state,
1877 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1878 apply_offset(ptr);
1879 add_child_to_front(std::move(ptr));
1880 }
1881 // Goods
1882 {
1883 auto ptr = make_element_by_type<factory_output_name_text>(state,
1884 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1885 apply_offset(ptr);
1886 add_child_to_front(std::move(ptr));
1887 }
1888 // Output
1889 {
1890 auto ptr = make_element_by_type<factory_produced_text>(state,
1891 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1892 apply_offset(ptr);
1893 add_child_to_front(std::move(ptr));
1894 }
1895 // Income
1896 {
1897 auto ptr = make_element_by_type<factory_income_text>(state,
1898 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1899 apply_offset(ptr);
1900 add_child_to_front(std::move(ptr));
1901 }
1902 // Employed
1903 {
1904 auto ptr = make_element_by_type<factory_workers_text>(state,
1905 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1906 apply_offset(ptr);
1907 add_child_to_front(std::move(ptr));
1908 }
1909 // Level
1910 {
1911 auto ptr = make_element_by_type<factory_level_text>(state,
1912 state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
1913 apply_offset(ptr);
1914 add_child_to_front(std::move(ptr));
1915 }
1916 }
1917};
1918class ledger_factories_production_listbox : public listbox_element_base<ledger_factories_production_entry, dcon::factory_id> {
1919protected:
1920 std::string_view get_row_element_name() override {
1921 return "default_listbox_entry";
1922 }
1923
1924public:
1925 void on_update(sys::state& state) noexcept override {
1926 row_contents.clear();
1927 for(auto const fat_smemb_id : state.world.nation_get_state_ownership(state.local_player_nation))
1928 province::for_each_province_in_state_instance(state, fat_smemb_id.get_state(), [&](dcon::province_id pid) {
1929 auto fat_id = dcon::fatten(state.world, pid);
1930 fat_id.for_each_factory_location_as_province(
1931 [&](dcon::factory_location_id flid) { row_contents.push_back(state.world.factory_location_get_factory(flid)); });
1932 });
1933
1934 auto lsort = retrieve<ledger_sort>(state, parent);
1935 ledger_sort_type st = std::holds_alternative<ledger_sort_type>(lsort.type) ? std::get<ledger_sort_type>(lsort.type) : ledger_sort_type::country_name;
1936 switch(st) {
1937 case ledger_sort_type::commodity_type:
1938 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::factory_id a, dcon::factory_id b) {
1939 if(lsort.reversed) {
1940 return state.world.factory_get_building_type(a).get_output().id.index() < state.world.factory_get_building_type(b).get_output().id.index();
1941 } else {
1942 return state.world.factory_get_building_type(a).get_output().id.index() > state.world.factory_get_building_type(b).get_output().id.index();
1943 }
1944 });
1945 break;
1946 case ledger_sort_type::output_amount:
1947 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::factory_id a, dcon::factory_id b) {
1948 if(lsort.reversed) {
1949 return state.world.factory_get_actual_production(a) < state.world.factory_get_actual_production(b);
1950 } else {
1951 return state.world.factory_get_actual_production(a) > state.world.factory_get_actual_production(b);
1952 }
1953 });
1954 break;
1955 case ledger_sort_type::profit:
1956 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::factory_id a, dcon::factory_id b) {
1957 if(lsort.reversed) {
1958 return state.world.factory_get_full_profit(a) < state.world.factory_get_full_profit(b);
1959 } else {
1960 return state.world.factory_get_full_profit(a) > state.world.factory_get_full_profit(b);
1961 }
1962 });
1963 break;
1964 case ledger_sort_type::employment:
1965 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::factory_id a, dcon::factory_id b) {
1966 if(lsort.reversed) {
1967 return economy::factory_total_employment(state, a) < economy::factory_total_employment(state, b);
1968 } else {
1969 return economy::factory_total_employment(state, a) > economy::factory_total_employment(state, b);
1970 }
1971 });
1972 break;
1973 case ledger_sort_type::factory_level:
1974 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::factory_id a, dcon::factory_id b) {
1975 if(lsort.reversed) {
1976 return state.world.factory_get_level(a) < state.world.factory_get_level(b);
1977 } else {
1978 return state.world.factory_get_level(a) > state.world.factory_get_level(b);
1979 }
1980 });
1981 break;
1982 default:
1983 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::factory_id a, dcon::factory_id b) {
1984 if(lsort.reversed) {
1985 return text::get_province_state_name(state, state.world.factory_get_province_from_factory_location(a)) > text::get_province_state_name(state, state.world.factory_get_province_from_factory_location(b));
1986 } else {
1987 return text::get_province_state_name(state, state.world.factory_get_province_from_factory_location(a)) < text::get_province_state_name(state, state.world.factory_get_province_from_factory_location(b));
1988 }
1989 });
1990 break;
1991 }
1992
1993 update(state);
1994 }
1995};
1996
1998public:
1999 void on_update(sys::state& state) noexcept override {
2000 auto content = retrieve<dcon::commodity_id>(state, parent);
2001 color = state.world.commodity_get_color(content);
2002 }
2003};
2004
2006public:
2007 void on_update(sys::state& state) noexcept override {
2008 auto content = retrieve<dcon::nation_id>(state, parent);
2009 color = state.world.nation_get_color(content);
2010 }
2011};
2012
2013//
2014// GDP graph
2015//
2016
2018 std::vector<line_graph*> graph_per_nation;
2019 const uint32_t graph_length = economy::gdp_history_length;
2020public:
2021 void on_create(sys::state& state) noexcept override {
2022 window_element_base::on_create(state);
2023 uint32_t total_nations = state.world.nation_size();
2024
2025 state.world.for_each_nation([&](dcon::nation_id nation) {
2026 auto ptr = make_element_by_type<line_graph>(state, "ledger_linechart", graph_length);
2027 auto graph = reinterpret_cast<line_graph*>(ptr.get());
2028 auto color = state.world.nation_get_color(nation);
2029 graph->is_coloured = true;
2030 graph->r = sys::red_from_int(color);
2031 graph->g = sys::green_from_int(color);
2032 graph->b = sys::blue_from_int(color);
2033
2034 graph_per_nation.push_back(graph);
2035 add_child_to_front(std::move(ptr));
2036 });
2037 }
2038 void on_update(sys::state& state) noexcept override {
2039 float min = 0.f;
2040 float max = 0.f;
2041
2042 auto ptr = retrieve< nation_toggle_list*>(state, parent);
2043 if(!ptr)
2044 return;
2045
2046 state.world.for_each_nation([&](dcon::nation_id nation) {
2047 auto newest_index = economy::most_recent_gdp_record_index(state);
2048 if((*ptr).data[nation.index()]) {
2049 for(uint32_t i = 0; i < graph_length; ++i) {
2050 auto record = state.world.nation_get_gdp_record(nation, (newest_index + economy::gdp_history_length - graph_length + i + 1) % economy::gdp_history_length);
2051 if(record > max) {
2052 max = record;
2053 }
2054 }
2055 }
2056 });
2057
2058 state.world.for_each_nation([&](dcon::nation_id nation) {
2059 if(!((*ptr).data[nation.index()])) {
2060 graph_per_nation[nation.index()]->set_visible(state, false);
2061 } else {
2062 graph_per_nation[nation.index()]->set_visible(state, true);
2063 std::vector<float> datapoints(graph_length);
2064 auto newest_index = economy::most_recent_gdp_record_index(state);
2065
2066 for(uint32_t i = 0; i < graph_length; ++i) {
2067 datapoints[i] = state.world.nation_get_gdp_record(nation, (newest_index + economy::gdp_history_length - graph_length + i + 1) % economy::gdp_history_length);
2068 }
2069 graph_per_nation[nation.index()]->set_data_points(state, datapoints, min, max);
2070 }
2071 });
2072 }
2073};
2074
2076public:
2077 int32_t index;
2078 nation_toggle_checkbox(dcon::nation_id nation_id) {
2079 index = nation_id.index();
2080 };
2081 void button_action(sys::state& state) noexcept override {
2082 if(index < 0) return;
2083 auto ptr = retrieve< nation_toggle_list*>(state, parent);
2084 if(!ptr)
2085 return;
2086 (*ptr).data[index] = !(*ptr).data[index];
2087 state.game_state_updated.store(true, std::memory_order_release);
2088 }
2089 bool is_active(sys::state& state) noexcept override {
2090 if(index < 0) return false;
2091 auto ptr = retrieve< nation_toggle_list*>(state, parent);
2092 if(!ptr)
2093 return false;
2094 return (*ptr).data[index];
2095 }
2096};
2097
2098class ledger_nation_entry : public listbox_row_element_base<dcon::nation_id> {
2099public:
2100 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
2101 if(name == "nation_ledger_default_textbox") {
2102 return make_element_by_type<generic_name_text<dcon::nation_id>>(state, id);
2103 } else if(name == "nation_ledger_legend_plupp") {
2104 return make_element_by_type<ledger_nation_plupp>(state, id);
2105 } else if(name == "nation_ledger_legend_checkbox") {
2106 return make_element_by_type<nation_toggle_checkbox>(state, id, content);
2107 } else {
2108 return nullptr;
2109 }
2110 }
2111
2112 void on_update(sys::state& state) noexcept override {
2113 (reinterpret_cast<nation_toggle_checkbox*>(get_child_by_name(state, "nation_ledger_legend_checkbox")))->index = content.index();
2114 }
2115};
2116
2117
2118//
2119// Commodity price
2120//
2121
2122
2124 std::vector<line_graph*> graph_per_price;
2125 const uint32_t graph_length = 256;
2126public:
2127 void on_create(sys::state& state) noexcept override {
2128 window_element_base::on_create(state);
2129
2130 assert(graph_length <= economy::price_history_length);
2131
2132 uint32_t total_commodities = state.world.commodity_size();
2133
2134 state.world.for_each_commodity([&](dcon::commodity_id commodity) {
2135 auto ptr = make_element_by_type<line_graph>(state, "ledger_linechart", graph_length);
2136 auto graph = reinterpret_cast<line_graph*>(ptr.get());
2137 auto color = state.world.commodity_get_color(commodity);
2138 graph->is_coloured = true;
2139 graph->r = sys::red_from_int(color);
2140 graph->g = sys::green_from_int(color);
2141 graph->b = sys::blue_from_int(color);
2142
2143 graph_per_price.push_back(graph);
2144 add_child_to_front(std::move(ptr));
2145 });
2146 }
2147 void on_update(sys::state& state) noexcept override {
2148 float min = 0.f;
2149 float max = 0.f;
2150
2151 auto ptr = retrieve< price_toggle_list*>(state, parent);
2152 if(!ptr)
2153 return;
2154
2155 state.world.for_each_commodity([&](dcon::commodity_id commodity) {
2157 if((*ptr).data[commodity.index()]) {
2158 for(uint32_t i = 0; i < graph_length; ++i) {
2159 auto price = state.world.commodity_get_price_record(commodity, (newest_index + economy::price_history_length - graph_length + i + 1) % economy::price_history_length);
2160 if(price > max) {
2161 max = price;
2162 }
2163 }
2164 }
2165 });
2166
2167 state.world.for_each_commodity([&](dcon::commodity_id commodity) {
2168 if(!((*ptr).data[commodity.index()])) {
2169 graph_per_price[commodity.index()]->set_visible(state, false);
2170 } else {
2171 graph_per_price[commodity.index()]->set_visible(state, true);
2172 std::vector<float> datapoints(graph_length);
2174
2175 for(uint32_t i = 0; i < graph_length; ++i) {
2176 datapoints[i] = state.world.commodity_get_price_record(commodity, (newest_index + economy::price_history_length - graph_length + i + 1) % economy::price_history_length);
2177 }
2178 graph_per_price[commodity.index()]->set_data_points(state, datapoints, min, max);
2179 }
2180 });
2181 }
2182};
2183
2185public:
2186 int32_t index;
2187 price_toggle_checkbox(dcon::commodity_id good_id) {
2188 index = good_id.index();
2189 };
2190 void button_action(sys::state& state) noexcept override {
2191 if(index < 0) return;
2192 auto ptr = retrieve< price_toggle_list*>(state, parent);
2193 if(!ptr)
2194 return;
2195 (*ptr).data[index] = !(*ptr).data[index];
2196 state.game_state_updated.store(true, std::memory_order_release);
2197 }
2198 bool is_active(sys::state& state) noexcept override {
2199 if(index < 0) return false;
2200 auto ptr = retrieve< price_toggle_list*>(state, parent);
2201 if(!ptr)
2202 return false;
2203 return (*ptr).data[index];
2204 }
2205};
2206
2207class ledger_commodity_price_entry : public listbox_row_element_base<dcon::commodity_id> {
2208public:
2209 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
2210 if(name == "ledger_default_textbox") {
2211 return make_element_by_type<generic_name_text<dcon::commodity_id>>(state, id);
2212 } else if(name == "ledger_legend_plupp") {
2213 return make_element_by_type<ledger_commodity_plupp>(state, id);
2214 } else if(name == "ledger_legend_checkbox") {
2215 return make_element_by_type<price_toggle_checkbox>(state, id, content);
2216 } else {
2217 return nullptr;
2218 }
2219 }
2220
2221 void on_update(sys::state& state) noexcept override {
2222 (reinterpret_cast<price_toggle_checkbox*>(get_child_by_name(state, "ledger_legend_checkbox")))->index = content.index();
2223 }
2224};
2225
2226class ledger_commodity_price_listbox : public listbox_element_base<ledger_commodity_price_entry, dcon::commodity_id> {
2227protected:
2228 std::string_view get_row_element_name() override {
2229 return "ledger_legend_entry";
2230 }
2231public:
2232 void on_update(sys::state& state) noexcept override {
2233 row_contents.clear();
2234 state.world.for_each_commodity([&](dcon::commodity_id id) {
2235 row_contents.push_back(id);
2236 });
2237 update(state);
2238 }
2239};
2240
2241class ledger_nations_listbox : public listbox_element_base<ledger_nation_entry, dcon::nation_id> {
2242protected:
2243 std::string_view get_row_element_name() override {
2244 return "ledger_nations_legend_entry";
2245 }
2246public:
2247 void on_update(sys::state& state) noexcept override {
2248 row_contents.clear();
2249 state.world.for_each_nation([&](dcon::nation_id id) {
2250 row_contents.push_back(id);
2251 });
2252 update(state);
2253 }
2254};
2255
2257public:
2258 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
2259 if(name == "legend_list") {
2260 return make_element_by_type<ledger_commodity_price_listbox>(state, id);
2261 } else {
2262 return nullptr;
2263 }
2264 }
2265};
2266
2268public:
2269 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
2270 if(name == "legend_nations_list") {
2271 return make_element_by_type<ledger_nations_listbox>(state, id);
2272 } else {
2273 return nullptr;
2274 }
2275 }
2276};
2277
2279 dcon::gui_def_id listbox_def_id{};
2280 dcon::gui_def_id sort_buttons_window_id{};
2281
2282 all_prices_graph* commodity_linegraph = nullptr;
2283 gdp_graph* gdp_linegraph = nullptr;
2284
2285 commodity_linegraph_legend_window* commodity_linegraph_legend = nullptr;
2286 nations_linegraph_legend_window* gdp_linegraph_legend = nullptr;
2287
2288 image_element_base* commodity_linegraph_image = nullptr;
2289 image_element_base* gdp_linegraph_image = nullptr;
2290
2291 simple_text_element_base* page_number_text = nullptr;
2292 simple_text_element_base* ledger_header_text = nullptr;
2293 ledger_page_number page_num{int8_t(1)};
2294
2295 ledger_nation_ranking_listbox* nation_ranking_listbox = nullptr;
2296 ledger_nation_comparison_listbox* nation_compare_listbox = nullptr;
2297 ledger_nation_political_systems_listbox* nation_party_listbox = nullptr;
2298 ledger_nation_political_reforms_listbox* nation_political_reforms_listbox = nullptr;
2299 ledger_nation_social_reforms_listbox* nation_social_reforms_listbox = nullptr;
2300 ledger_nation_population_listbox* nation_pops_listbox = nullptr;
2301 ledger_province_listbox* provinces_listbox = nullptr;
2302 ledger_province_population_listbox* provinces_pops_listbox = nullptr;
2303 ledger_provinces_production_listbox* provinces_production_listbox = nullptr;
2304 ledger_factories_production_listbox* factory_production_listbox = nullptr;
2305
2306 ledger_sort current_sorting;
2307
2308 void hide_sub_windows(sys::state& state) noexcept {
2309 nation_ranking_listbox->set_visible(state, false);
2310 nation_compare_listbox->set_visible(state, false);
2311 nation_party_listbox->set_visible(state, false);
2312 nation_political_reforms_listbox->set_visible(state, false);
2313 nation_social_reforms_listbox->set_visible(state, false);
2314 nation_pops_listbox->set_visible(state, false);
2315 provinces_listbox->set_visible(state, false);
2316 provinces_pops_listbox->set_visible(state, false);
2317 provinces_production_listbox->set_visible(state, false);
2318 factory_production_listbox->set_visible(state, false);
2319
2320 // Linegraphs
2321 commodity_linegraph->set_visible(state, false);
2322 commodity_linegraph_legend->set_visible(state, false);
2323 commodity_linegraph_image->set_visible(state, false);
2324
2325
2326 gdp_linegraph->set_visible(state, false);
2327 gdp_linegraph_legend->set_visible(state, false);
2328 gdp_linegraph_image->set_visible(state, false);
2329 }
2330
2331 price_toggle_list price_toggle_status;
2332 nation_toggle_list nation_toggle_status;
2333
2334public:
2335 void on_create(sys::state& state) noexcept override {
2336 window_element_base::on_create(state);
2337
2338 uint32_t total_commodities = state.world.commodity_size();
2339 for(uint32_t k = 0; k < total_commodities; ++k) {
2340 price_toggle_status.data.push_back(true);
2341 }
2342
2343 uint32_t total_nations = state.world.nation_size();
2344 for(uint32_t k = 0; k < total_nations; ++k) {
2345 nation_toggle_status.data.push_back(true);
2346 }
2347
2348 {
2349 auto ptr = make_element_by_type<ledger_nation_ranking_listbox>(state, listbox_def_id);
2350 nation_ranking_listbox = ptr.get();
2351
2352 auto ptrb = make_element_by_type<ledger_nation_ranking_buttons>(state, sort_buttons_window_id);
2353 ptrb->base_data.position.x -= ptr->base_data.position.x;
2354 ptrb->base_data.position.y -= ptr->base_data.position.y;
2355 ptr->add_child_to_back(std::move(ptrb));
2356
2357 add_child_to_front(std::move(ptr));
2358 }
2359 {
2360 auto ptr = make_element_by_type<ledger_nation_comparison_listbox>(state, listbox_def_id);
2361 nation_compare_listbox = ptr.get();
2362
2363 auto ptrb = make_element_by_type<ledger_nation_comparison_buttons>(state, sort_buttons_window_id);
2364 ptrb->base_data.position.x -= ptr->base_data.position.x;
2365 ptrb->base_data.position.y -= ptr->base_data.position.y;
2366 ptr->add_child_to_back(std::move(ptrb));
2367
2368 add_child_to_front(std::move(ptr));
2369 }
2370 {
2371 auto ptr = make_element_by_type<ledger_nation_political_systems_listbox>(state, listbox_def_id);
2372 nation_party_listbox = ptr.get();
2373
2374 auto ptrb = make_element_by_type<ledger_nation_political_systems_buttons>(state, sort_buttons_window_id);
2375 ptrb->base_data.position.x -= ptr->base_data.position.x;
2376 ptrb->base_data.position.y -= ptr->base_data.position.y;
2377 ptr->add_child_to_back(std::move(ptrb));
2378
2379 add_child_to_front(std::move(ptr));
2380 }
2381 {
2382 auto ptr = make_element_by_type<ledger_nation_political_reforms_listbox>(state, listbox_def_id);
2383 nation_political_reforms_listbox = ptr.get();
2384
2385 auto ptrb = make_element_by_type<ledger_nation_reforms_buttons<true>>(state, sort_buttons_window_id);
2386 ptrb->base_data.position.x -= ptr->base_data.position.x;
2387 ptrb->base_data.position.y -= ptr->base_data.position.y;
2388 ptr->add_child_to_back(std::move(ptrb));
2389
2390 add_child_to_front(std::move(ptr));
2391 }
2392 {
2393 auto ptr = make_element_by_type<ledger_nation_social_reforms_listbox>(state, listbox_def_id);
2394 nation_social_reforms_listbox = ptr.get();
2395
2396 auto ptrb = make_element_by_type<ledger_nation_reforms_buttons<false>>(state, sort_buttons_window_id);
2397 ptrb->base_data.position.x -= ptr->base_data.position.x;
2398 ptrb->base_data.position.y -= ptr->base_data.position.y;
2399 ptr->add_child_to_back(std::move(ptrb));
2400
2401 add_child_to_front(std::move(ptr));
2402 }
2403 {
2404 auto ptr = make_element_by_type<ledger_nation_population_listbox>(state, listbox_def_id);
2405 nation_pops_listbox = ptr.get();
2406
2407 auto ptrb = make_element_by_type<ledger_nation_population_buttons>(state, sort_buttons_window_id);
2408 ptrb->base_data.position.x -= ptr->base_data.position.x;
2409 ptrb->base_data.position.y -= ptr->base_data.position.y;
2410 ptr->add_child_to_back(std::move(ptrb));
2411
2412 add_child_to_front(std::move(ptr));
2413 }
2414 {
2415 auto ptr = make_element_by_type<ledger_province_listbox>(state, listbox_def_id);
2416 provinces_listbox = ptr.get();
2417
2418 auto ptrb = make_element_by_type<ledger_province_buttons>(state, sort_buttons_window_id);
2419 ptrb->base_data.position.x -= ptr->base_data.position.x;
2420 ptrb->base_data.position.y -= ptr->base_data.position.y;
2421 ptr->add_child_to_back(std::move(ptrb));
2422
2423 add_child_to_front(std::move(ptr));
2424 }
2425 {
2426 auto ptr = make_element_by_type<ledger_province_population_listbox>(state, listbox_def_id);
2427 provinces_pops_listbox = ptr.get();
2428
2429 auto ptrb = make_element_by_type<ledger_province_population_buttons>(state, sort_buttons_window_id);
2430 ptrb->base_data.position.x -= ptr->base_data.position.x;
2431 ptrb->base_data.position.y -= ptr->base_data.position.y;
2432 ptr->add_child_to_back(std::move(ptrb));
2433
2434 add_child_to_front(std::move(ptr));
2435 }
2436 {
2437 auto ptr = make_element_by_type<ledger_provinces_production_listbox>(state, listbox_def_id);
2438 provinces_production_listbox = ptr.get();
2439
2440 auto ptrb = make_element_by_type<ledger_province_production_buttons>(state, sort_buttons_window_id);
2441 ptrb->base_data.position.x -= ptr->base_data.position.x;
2442 ptrb->base_data.position.y -= ptr->base_data.position.y;
2443 ptr->add_child_to_back(std::move(ptrb));
2444
2445 add_child_to_front(std::move(ptr));
2446 }
2447 {
2448 auto ptr = make_element_by_type<ledger_factories_production_listbox>(state, listbox_def_id);
2449 factory_production_listbox = ptr.get();
2450
2451 auto ptrb = make_element_by_type<ledger_factories_production_buttons>(state, sort_buttons_window_id);
2452 ptrb->base_data.position.x -= ptr->base_data.position.x;
2453 ptrb->base_data.position.y -= ptr->base_data.position.y;
2454 ptr->add_child_to_back(std::move(ptrb));
2455
2456 add_child_to_front(std::move(ptr));
2457 }
2458
2459 //gdp block
2460
2461 {
2462 auto def = state.ui_state.defs_by_name.find(state.lookup_key("gdp_ledger_linegraph_bg"))->second.definition;
2463 auto ptr = make_element_by_type<image_element_base>(state, def);
2464 gdp_linegraph_image = ptr.get();
2465 add_child_to_front(std::move(ptr));
2466 }
2467
2468 {
2469 auto def = state.ui_state.defs_by_name.find(state.lookup_key("gdp_ledger_linegraphs"))->second.definition;
2470 auto ptr = make_element_by_type<gdp_graph>(state, def);
2471 gdp_linegraph = ptr.get();
2472 add_child_to_front(std::move(ptr));
2473 }
2474
2475 {
2476 auto def = state.ui_state.defs_by_name.find(state.lookup_key("gdp_ledger_linegraph_legend"))->second.definition;
2477 auto ptr = make_element_by_type<nations_linegraph_legend_window>(state, def);
2478 gdp_linegraph_legend = ptr.get();
2479 add_child_to_front(std::move(ptr));
2480 }
2481
2482 Cyto::Any payload = page_num;
2483 impl_set(state, payload);
2484 }
2485
2486 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
2487 if(name == "close") {
2488 auto ptr = make_element_by_type<generic_close_button>(state, id);
2489 ptr->set_button_text(state, "");
2490 return ptr;
2491 } else if(name == "ledger_bg") {
2492 return make_element_by_type<draggable_target>(state, id);
2493 } else if(name == "ledger_linegraphs") { // prices block
2494 auto ptr = make_element_by_type<all_prices_graph>(state, id);
2495 commodity_linegraph = ptr.get();
2496 return ptr;
2497 } else if(name == "ledger_linegraph_legend") {
2498 auto ptr = make_element_by_type<commodity_linegraph_legend_window>(state, id);
2499 commodity_linegraph_legend = ptr.get();
2500 return ptr;
2501 } else if(name == "ledger_linegraph_bg") {
2502 auto ptr = make_element_by_type<image_element_base>(state, id);
2503 commodity_linegraph_image = ptr.get();
2504 return ptr;
2505 } else if(name == "page_number") {
2506 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
2507 page_number_text = ptr.get();
2508 return ptr;
2509 } else if(name == "ledger_header") {
2510 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
2511 ledger_header_text = ptr.get();
2512 return ptr;
2513 } else if(name == "prev") {
2514 return make_element_by_type<ledger_prev_button>(state, id);
2515 } else if(name == "next") {
2516 return make_element_by_type<ledger_next_button>(state, id);
2517 } else if(name == "ledger_sort_buttons") {
2518 sort_buttons_window_id = id;
2519 return make_element_by_type<invisible_element>(state, id);
2520 } else if(name == "default_listbox") {
2521 listbox_def_id = id;
2522 return make_element_by_type<invisible_element>(state, id);
2523 } else {
2524 return nullptr;
2525 }
2526 }
2527
2528 void on_update(sys::state& state) noexcept override {
2529 page_number_text->set_text(state, std::to_string(page_num.value));
2530
2531 hide_sub_windows(state);
2532 switch(page_num.value) {
2533 case 1:
2534 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_rank"));
2535 nation_ranking_listbox->set_visible(state, true);
2536 break;
2537 case 2:
2538 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_countrycompare"));
2539 nation_compare_listbox->set_visible(state, true);
2540 break;
2541 case 3:
2542 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_countryparty"));
2543 nation_party_listbox->set_visible(state, true);
2544 break;
2545 case 4:
2546 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_countrypoliticalreforms"));
2547 nation_political_reforms_listbox->set_visible(state, true);
2548 break;
2549 case 5:
2550 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_countrysocialreforms"));
2551 nation_social_reforms_listbox->set_visible(state, true);
2552 break;
2553 case 6:
2554 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_country_pops"));
2555 nation_pops_listbox->set_visible(state, true);
2556 break;
2557 case 7:
2558 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_provinces"));
2559 provinces_listbox->set_visible(state, true);
2560 break;
2561 case 8:
2562 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_province_pops"));
2563 provinces_pops_listbox->set_visible(state, true);
2564 break;
2565 case 9:
2566 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_provinceproduction"));
2567 provinces_production_listbox->set_visible(state, true);
2568 break;
2569 case 10:
2570 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_factoryproduction"));
2571 factory_production_listbox->set_visible(state, true);
2572 break;
2573 case 11:
2574 ledger_header_text->set_text(state, text::produce_simple_string(state, "ledger_header_goods_pricehistory"));
2575 commodity_linegraph->set_visible(state, true);
2576 commodity_linegraph_legend->set_visible(state, true);
2577 commodity_linegraph_image->set_visible(state, true);
2578 break;
2579 case 12:
2580 ledger_header_text->set_text(state, text::produce_simple_string(state, "alice_ledger_header_gdp_history"));
2581 gdp_linegraph->set_visible(state, true);
2582 gdp_linegraph_legend->set_visible(state, true);
2583 gdp_linegraph_image->set_visible(state, true);
2584 break;
2585 default:
2586 break;
2587 }
2588 }
2589 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
2590 if(payload.holds_type<ledger_sort>()) {
2591 payload.emplace<ledger_sort>(current_sorting);
2592 return message_result::consumed;
2593 } else if(payload.holds_type<element_selection_wrapper<ledger_sort>>()) {
2594 current_sorting = any_cast<element_selection_wrapper<ledger_sort>>(payload).data;
2595 impl_on_update(state);
2596 return message_result::consumed;
2597 } else if(payload.holds_type< price_toggle_list*>()) {
2598 payload.emplace<price_toggle_list*>(&price_toggle_status);
2599 return message_result::consumed;
2600 } else if(payload.holds_type< nation_toggle_list*>()) {
2601 payload.emplace<nation_toggle_list*>(&nation_toggle_status);
2602 return message_result::consumed;
2603 }
2604 return message_result::unseen;
2605 }
2606 message_result set(sys::state& state, Cyto::Any& payload) noexcept override {
2607 if(payload.holds_type<ledger_page_number>()) {
2608 page_num = any_cast<ledger_page_number>(payload);
2609 for(auto& child : children)
2610 child->impl_set(state, payload);
2611 impl_on_update(state);
2612 return message_result::consumed;
2613 }
2614 return message_result::unseen;
2615 }
2616};
2617} // namespace ui
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
message_result impl_set(sys::state &state, Cyto::Any &payload) noexcept final
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
virtual message_result impl_set(sys::state &state, Cyto::Any &payload) noexcept
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 set_visible(sys::state &state, bool vis)
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
ledger_generic_sort_button(std::variant< std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id > type)
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t t, text::columnar_layout &contents) noexcept override
std::variant< std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id > type
void button_action(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void button_action(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_create(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
message_result set(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::string get_text(sys::state &state, dcon::nation_id nation_id) noexcept override
std::string get_text(sys::state &state, dcon::nation_id nation_id) noexcept override
bool is_active(sys::state &state) noexcept override
nation_toggle_checkbox(dcon::nation_id nation_id)
void button_action(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void button_action(sys::state &state) noexcept override
bool is_active(sys::state &state) noexcept override
price_toggle_checkbox(dcon::commodity_id good_id)
province_population_per_pop_type_text(dcon::pop_type_id pop_type_id)
void on_update(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
#define assert(condition)
Definition: debug.h:74
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
constexpr uint32_t gdp_history_length
Definition: economy.hpp:123
constexpr uint32_t price_history_length
Definition: economy.hpp:122
int32_t most_recent_price_record_index(sys::state &state)
Definition: economy.cpp:82
int32_t most_recent_gdp_record_index(sys::state &state)
Definition: economy.cpp:89
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
float blue_from_int(uint32_t v)
float green_from_int(uint32_t v)
float red_from_int(uint32_t v)
std::string prettify(int64_t num)
Definition: text.cpp:762
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
message_result
uint uint32_t
uchar uint8_t
std::variant< std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id > type
std::vector< bool > data
std::vector< bool > data
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name