54 std::variant<std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id>
type = std::monostate{};
68 std::variant<std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id>
type;
76 current_sort.
data.reversed = !current_sort.
data.reversed;
79 current_sort.
data.reversed =
false;
87 if(std::holds_alternative<dcon::pop_type_id>(
type))
127 auto button_def =
state.ui_state.
defs_by_name.find(
state.lookup_key(
"ledger_default_button"))->second.definition;
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;
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();
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;
216 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(
state,
223 auto ptr = make_element_by_type<nation_status_text>(
state,
230 auto ptr = make_element_by_type<nation_military_score_text>(
state,
237 auto ptr = make_element_by_type<nation_industry_score_text>(
state,
244 auto ptr = make_element_by_type<nation_prestige_text>(
state,
251 auto ptr = make_element_by_type<nation_total_score_text>(
state,
258 auto ptr = make_element_by_type<nation_ppp_gdp_text>(
state,
265 auto ptr = make_element_by_type<nation_ppp_gdp_per_capita_text>(
state,
272 auto ptr = make_element_by_type<nation_sol_text>(
state,
280 if(payload.holds_type<dcon::nation_id>()) {
281 payload.emplace<dcon::nation_id>(
content);
295 return "default_listbox_entry";
301 state.world.for_each_nation([&](dcon::nation_id
id) {
302 if(
state.world.nation_get_owned_province_count(
id) != 0)
311 return int32_t(nations::get_status(state, a)) > int32_t(nations::get_status(state, b));
313 return int32_t(nations::get_status(state, a)) < int32_t(nations::get_status(state, b));
320 return state.world.nation_get_military_score(a) < state.world.nation_get_military_score(b);
322 return state.world.nation_get_military_score(a) > state.world.nation_get_military_score(b);
329 return state.world.nation_get_industrial_score(a) < state.world.nation_get_industrial_score(b);
331 return state.world.nation_get_industrial_score(a) > state.world.nation_get_industrial_score(b);
336 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
338 return nations::prestige_score(state, a) < nations::prestige_score(state, b);
340 return nations::prestige_score(state, a) > nations::prestige_score(state, b);
344 case ledger_sort_type::total_score:
345 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
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);
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);
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);
359 return economy::gdp_adjusted(state, a) / a_population < economy::gdp_adjusted(state, b) / b_population;
361 return economy::gdp_adjusted(state, a) / a_population > economy::gdp_adjusted(state, b) / b_population;
365 case ledger_sort_type::gdp:
366 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
368 return economy::gdp_adjusted(state, a) < economy::gdp_adjusted(state, b);
370 return economy::gdp_adjusted(state, a) > economy::gdp_adjusted(state, b);
374 case ledger_sort_type::sol:
375 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
377 return demographics::calculate_nation_sol(state, a) < demographics::calculate_nation_sol(state, b);
379 return demographics::calculate_nation_sol(state, a) > demographics::calculate_nation_sol(state, b);
385 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
387 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
389 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
405 window_element_base::on_create(
state);
407 auto button_def =
state.ui_state.
defs_by_name.find(
state.lookup_key(
"ledger_default_button"))->second.definition;
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;
418 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::country_name);
421 add_child_to_front(std::move(ptr));
424 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::total_pop);
427 add_child_to_front(std::move(ptr));
430 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::provinces);
433 add_child_to_front(std::move(ptr));
436 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::factories);
439 add_child_to_front(std::move(ptr));
442 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::literacy);
445 add_child_to_front(std::move(ptr));
448 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::leadership);
451 add_child_to_front(std::move(ptr));
454 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::brigades);
457 add_child_to_front(std::move(ptr));
460 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::ships);
463 add_child_to_front(std::move(ptr));
473 listbox_row_element_base::on_create(
state);
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));
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;
490 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(
state,
493 add_child_to_front(std::move(ptr));
497 auto ptr = make_element_by_type<nation_population_text>(
state,
500 add_child_to_front(std::move(ptr));
504 auto ptr = make_element_by_type<nation_provinces_text>(
state,
507 add_child_to_front(std::move(ptr));
511 auto ptr = make_element_by_type<nation_industries_text>(
state,
514 add_child_to_front(std::move(ptr));
518 auto ptr = make_element_by_type<nation_literacy_text>(
state,
521 add_child_to_front(std::move(ptr));
525 auto ptr = make_element_by_type<nation_leadership_points_text>(
state,
528 add_child_to_front(std::move(ptr));
532 auto ptr = make_element_by_type<nation_num_regiments>(
state,
535 add_child_to_front(std::move(ptr));
539 auto ptr = make_element_by_type<nation_num_ships>(
state,
542 add_child_to_front(std::move(ptr));
547 if(payload.holds_type<dcon::nation_id>()) {
548 payload.emplace<dcon::nation_id>(content);
549 return message_result::consumed;
551 return listbox_row_element_base::get(
state, payload);
557 return "default_listbox_entry";
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);
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;
571 case ledger_sort_type::total_pop:
572 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
574 return state.world.nation_get_demographics(a, demographics::total) < state.world.nation_get_demographics(b, demographics::total);
576 return state.world.nation_get_demographics(a, demographics::total) > state.world.nation_get_demographics(b, demographics::total);
580 case ledger_sort_type::provinces:
581 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
583 return state.world.nation_get_owned_province_count(a) < state.world.nation_get_owned_province_count(b);
585 return state.world.nation_get_owned_province_count(a) > state.world.nation_get_owned_province_count(b);
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());
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());
604 return anum_factories < bnum_factories;
606 return anum_factories > bnum_factories;
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));
615 return aliteracy < bliteracy;
617 return aliteracy > bliteracy;
621 case ledger_sort_type::leadership:
622 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
624 return state.world.nation_get_leadership_points(a) < state.world.nation_get_leadership_points(b);
626 return state.world.nation_get_leadership_points(a) > state.world.nation_get_leadership_points(b);
630 case ledger_sort_type::brigades:
631 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
633 return state.world.nation_get_active_regiments(a) < state.world.nation_get_active_regiments(b);
635 return state.world.nation_get_active_regiments(a) > state.world.nation_get_active_regiments(b);
639 case ledger_sort_type::ships:
640 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
642 return military::total_ships(state, a) < military::total_ships(state, b);
644 return military::total_ships(state, a) > military::total_ships(state, b);
649 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
651 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
653 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
670 window_element_base::on_create(
state);
672 auto button_def =
state.ui_state.
defs_by_name.find(
state.lookup_key(
"ledger_default_button"))->second.definition;
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;
683 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::country_name);
686 add_child_to_front(std::move(ptr));
689 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::government_type);
692 add_child_to_front(std::move(ptr));
695 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::national_value);
698 add_child_to_front(std::move(ptr));
701 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::ruling_party);
704 add_child_to_front(std::move(ptr));
707 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::ruling_ideology);
710 add_child_to_front(std::move(ptr));
720 listbox_row_element_base::on_create(
state);
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));
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;
737 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(
state,
740 add_child_to_front(std::move(ptr));
744 auto ptr = make_element_by_type<nation_government_type_text>(
state,
747 add_child_to_front(std::move(ptr));
751 auto ptr = make_element_by_type<nation_national_value_text>(
state,
754 add_child_to_front(std::move(ptr));
758 auto ptr = make_element_by_type<nation_ruling_party_text>(
state,
761 add_child_to_front(std::move(ptr));
765 auto ptr = make_element_by_type<nation_ruling_party_ideology_text>(
state,
768 add_child_to_front(std::move(ptr));
773 if(payload.holds_type<dcon::nation_id>()) {
774 payload.emplace<dcon::nation_id>(content);
775 return message_result::consumed;
777 return listbox_row_element_base::get(
state, payload);
784 return "default_listbox_entry";
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);
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;
798 case ledger_sort_type::government_type:
799 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
801 return state.world.nation_get_government_type(a).id.index() < state.world.nation_get_government_type(b).id.index();
803 return state.world.nation_get_government_type(a).id.index() > state.world.nation_get_government_type(b).id.index();
807 case ledger_sort_type::ruling_party:
808 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
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());
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());
816 case ledger_sort_type::national_value:
817 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
819 return state.world.nation_get_national_value(a).id.index() < state.world.nation_get_national_value(b).id.index();
821 return state.world.nation_get_national_value(a).id.index() > state.world.nation_get_national_value(b).id.index();
825 case ledger_sort_type::ruling_ideology:
826 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
828 return state.world.nation_get_ruling_party(a).get_ideology().id.index() < state.world.nation_get_ruling_party(b).get_ideology().id.index();
830 return state.world.nation_get_ruling_party(a).get_ideology().id.index() > state.world.nation_get_ruling_party(b).get_ideology().id.index();
835 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
837 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
839 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
854 dcon::issue_id issue_id{};
857 auto active_issue_option =
state.world.nation_get_issues(nation_id, issue_id);
862template<
bool IsPolitical>
866 window_element_base::on_create(
state);
868 auto button_def =
state.ui_state.
defs_by_name.find(
state.lookup_key(
"ledger_default_button"))->second.definition;
870 xy_pair cell_offset{ int16_t(24), 0 };
873 state.world.for_each_issue([&](dcon::issue_id
id) {
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;
888 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::country_name);
891 add_child_to_front(std::move(ptr));
894 state.world.for_each_issue([&](dcon::issue_id
id) {
899 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def,
id);
902 add_child_to_front(std::move(ptr));
907template<
bool IsPolitical>
913 listbox_row_element_base::on_create(
state);
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));
924 state.world.for_each_issue([&](dcon::issue_id
id) {
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;
939 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(
state,
942 add_child_to_front(std::move(ptr));
945 state.world.for_each_issue([&](dcon::issue_id
id) {
949 auto ptr = make_element_by_type<nation_selected_issue_text>(
state,
953 add_child_to_front(std::move(ptr));
958 if(payload.holds_type<dcon::nation_id>()) {
959 payload.emplace<dcon::nation_id>(content);
960 return message_result::consumed;
962 return listbox_row_element_base::get(
state, payload);
968 return "default_listbox_entry";
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);
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) {
984 return state.world.nation_get_issues(a, iss).id.index() < state.world.nation_get_issues(b, iss).id.index();
986 return state.world.nation_get_issues(a, iss).id.index() > state.world.nation_get_issues(b, iss).id.index();
990 std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
992 return text::produce_simple_string(state, text::get_name(state, a)) > text::produce_simple_string(state, text::get_name(state, b));
994 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
1005 return "default_listbox_entry";
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);
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();
1023 return state.world.nation_get_issues(a, iss).id.index() > state.world.nation_get_issues(b, iss).id.index();
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));
1031 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
1045 dcon::pop_type_id pop_type_id{};
1055 window_element_base::on_create(
state);
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;
1060 xy_pair cell_offset{ int16_t(24), 0 };
1062 auto num_pop_types = 0;
1063 state.world.for_each_pop_type([&](dcon::pop_type_id
id) { ++num_pop_types; });
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);
1073 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::country_name);
1076 ptr->base_data.size.x = int16_t(cell_width);
1077 add_child_to_front(std::move(ptr));
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);
1085 add_child_to_front(std::move(ptr));
1095 listbox_row_element_base::on_create(
state);
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));
1105 auto num_pop_types = 0;
1106 state.world.for_each_pop_type([&](dcon::pop_type_id
id) { ++num_pop_types; });
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;
1117 auto ptr = make_element_by_type<generic_name_text<dcon::nation_id>>(
state,
1120 add_child_to_front(std::move(ptr));
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,
1126 ptr->pop_type_id = id;
1128 add_child_to_front(std::move(ptr));
1133 if(payload.holds_type<dcon::nation_id>()) {
1134 payload.emplace<dcon::nation_id>(content);
1135 return message_result::consumed;
1137 return listbox_row_element_base::get(
state, payload);
1143 return "default_listbox_entry";
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);
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);
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);
1162 return state.world.nation_get_demographics(a, dkey) > state.world.nation_get_demographics(b, dkey);
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));
1170 return text::produce_simple_string(state, text::get_name(state, a)) < text::produce_simple_string(state, text::get_name(state, b));
1186 window_element_base::on_create(
state);
1188 auto button_def =
state.ui_state.
defs_by_name.find(
state.lookup_key(
"ledger_default_button"))->second.definition;
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;
1200 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::province_name);
1203 add_child_to_front(std::move(ptr));
1206 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::total_pop);
1209 add_child_to_front(std::move(ptr));
1212 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::militancy);
1215 add_child_to_front(std::move(ptr));
1218 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::conciousness);
1221 add_child_to_front(std::move(ptr));
1224 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::literacy);
1227 add_child_to_front(std::move(ptr));
1230 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::religion);
1233 add_child_to_front(std::move(ptr));
1236 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::culture);
1239 add_child_to_front(std::move(ptr));
1242 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::dom_issue);
1245 add_child_to_front(std::move(ptr));
1248 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::dom_ideology);
1251 add_child_to_front(std::move(ptr));
1259 listbox_row_element_base::on_create(
state);
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;
1271 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(
state,
1274 add_child_to_front(std::move(ptr));
1278 auto ptr = make_element_by_type<province_population_text>(
state,
1281 add_child_to_front(std::move(ptr));
1285 auto ptr = make_element_by_type<province_militancy_text>(
state,
1288 add_child_to_front(std::move(ptr));
1292 auto ptr = make_element_by_type<province_consciousness_text>(
state,
1295 add_child_to_front(std::move(ptr));
1299 auto ptr = make_element_by_type<province_literacy_text>(
state,
1302 add_child_to_front(std::move(ptr));
1306 auto ptr = make_element_by_type<province_dominant_religion_text>(
state,
1309 add_child_to_front(std::move(ptr));
1313 auto ptr = make_element_by_type<province_dominant_culture_text>(
state,
1316 add_child_to_front(std::move(ptr));
1320 auto ptr = make_element_by_type<province_dominant_issue_text>(
state,
1323 add_child_to_front(std::move(ptr));
1327 auto ptr = make_element_by_type<province_dominant_ideology_text>(
state,
1330 add_child_to_front(std::move(ptr));
1335 if(payload.holds_type<dcon::province_id>()) {
1336 payload.emplace<dcon::province_id>(content);
1337 return message_result::consumed;
1339 return listbox_row_element_base::get(
state, payload);
1345 return "default_listbox_entry";
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); });
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;
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);
1363 return state.world.province_get_demographics(a, demographics::total) > state.world.province_get_demographics(b, demographics::total);
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));
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));
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));
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));
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));
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));
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)));
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)));
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();
1408 return state.world.province_get_dominant_religion(a).id.index() < state.world.province_get_dominant_religion(b).id.index();
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();
1417 return state.world.province_get_dominant_ideology(a).id.index() < state.world.province_get_dominant_ideology(b).id.index();
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();
1426 return state.world.province_get_dominant_issue_option(a).id.index() < state.world.province_get_dominant_issue_option(b).id.index();
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));
1435 return text::produce_simple_string(state, state.world.province_get_name(a)) < text::produce_simple_string(state, state.world.province_get_name(b));
1455 auto province_id = retrieve<dcon::province_id>(
state, parent);
1464 window_element_base::on_create(
state);
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;
1471 auto num_pop_types = 0;
1472 state.world.for_each_pop_type([&](dcon::pop_type_id
id) { ++num_pop_types; });
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);
1482 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::province_name);
1484 ptr->base_data.size.x = int16_t(cell_width);
1486 add_child_to_front(std::move(ptr));
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);
1494 add_child_to_front(std::move(ptr));
1502 listbox_row_element_base::on_create(
state);
1506 auto num_pop_types = 0;
1507 state.world.for_each_pop_type([&](dcon::pop_type_id
id) { ++num_pop_types; });
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;
1517 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(
state,
1520 add_child_to_front(std::move(ptr));
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);
1526 add_child_to_front(std::move(ptr));
1531 if(payload.holds_type<dcon::province_id>()) {
1532 payload.emplace<dcon::province_id>(content);
1533 return message_result::consumed;
1535 return listbox_row_element_base::get(
state, payload);
1541 return "default_listbox_entry";
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); });
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);
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);
1559 return state.world.province_get_demographics(a, dkey) > state.world.province_get_demographics(b, dkey);
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));
1567 return text::produce_simple_string(state, state.world.province_get_name(a)) < text::produce_simple_string(state, state.world.province_get_name(b));
1583 window_element_base::on_create(
state);
1585 auto button_def =
state.ui_state.
defs_by_name.find(
state.lookup_key(
"ledger_default_button"))->second.definition;
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;
1597 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::province_name);
1600 add_child_to_front(std::move(ptr));
1603 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::state_name);
1606 add_child_to_front(std::move(ptr));
1609 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::commodity_type);
1612 add_child_to_front(std::move(ptr));
1615 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::output_amount);
1618 add_child_to_front(std::move(ptr));
1621 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::profit);
1624 add_child_to_front(std::move(ptr));
1627 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::employment);
1630 add_child_to_front(std::move(ptr));
1633 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::rgo_size);
1636 add_child_to_front(std::move(ptr));
1644 listbox_row_element_base::on_create(
state);
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;
1656 auto ptr = make_element_by_type<generic_name_text<dcon::province_id>>(
state,
1659 add_child_to_front(std::move(ptr));
1663 auto ptr = make_element_by_type<province_state_name_text>(
state,
1666 add_child_to_front(std::move(ptr));
1670 auto ptr = make_element_by_type<province_rgo_name_text>(
state,
1673 add_child_to_front(std::move(ptr));
1677 auto ptr = make_element_by_type<province_goods_produced_text>(
state,
1680 add_child_to_front(std::move(ptr));
1684 auto ptr = make_element_by_type<province_income_text>(
state,
1687 add_child_to_front(std::move(ptr));
1691 auto ptr = make_element_by_type<province_rgo_workers_text>(
state,
1694 add_child_to_front(std::move(ptr));
1698 auto ptr = make_element_by_type<province_rgo_size_text>(
state,
1701 add_child_to_front(std::move(ptr));
1706 if(payload.holds_type<dcon::province_id>()) {
1707 payload.emplace<dcon::province_id>(content);
1708 return message_result::consumed;
1710 return listbox_row_element_base::get(
state, payload);
1716 return "default_listbox_entry";
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); });
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;
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);
1734 return text::get_province_state_name(state, a) < text::get_province_state_name(state, b);
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();
1743 return state.world.province_get_rgo(a).id.index() > state.world.province_get_rgo(b).id.index();
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);
1763 return province::rgo_income(state, a) > province::rgo_income(state, b);
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);
1772 return province::rgo_employment(state, a) > province::rgo_employment(state, b);
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));
1792 return text::produce_simple_string(state, state.world.province_get_name(a)) < text::produce_simple_string(state, state.world.province_get_name(b));
1809 window_element_base::on_create(
state);
1811 auto button_def =
state.ui_state.
defs_by_name.find(
state.lookup_key(
"ledger_default_button"))->second.definition;
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;
1823 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::state_name);
1826 add_child_to_front(std::move(ptr));
1829 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::commodity_type);
1832 add_child_to_front(std::move(ptr));
1835 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::output_amount);
1838 add_child_to_front(std::move(ptr));
1841 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::profit);
1844 add_child_to_front(std::move(ptr));
1847 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::employment);
1850 add_child_to_front(std::move(ptr));
1853 auto ptr = make_element_by_type<ledger_generic_sort_button>(
state, button_def, ledger_sort_type::factory_level);
1856 add_child_to_front(std::move(ptr));
1864 listbox_row_element_base::on_create(
state);
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;
1876 auto ptr = make_element_by_type<factory_state_name_text>(
state,
1879 add_child_to_front(std::move(ptr));
1883 auto ptr = make_element_by_type<factory_output_name_text>(
state,
1886 add_child_to_front(std::move(ptr));
1890 auto ptr = make_element_by_type<factory_produced_text>(
state,
1893 add_child_to_front(std::move(ptr));
1897 auto ptr = make_element_by_type<factory_income_text>(
state,
1900 add_child_to_front(std::move(ptr));
1904 auto ptr = make_element_by_type<factory_workers_text>(
state,
1907 add_child_to_front(std::move(ptr));
1911 auto ptr = make_element_by_type<factory_level_text>(
state,
1914 add_child_to_front(std::move(ptr));
1921 return "default_listbox_entry";
1926 row_contents.clear();
1927 for(
auto const fat_smemb_id :
state.world.nation_get_state_ownership(
state.local_player_nation))
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)); });
1934 auto lsort = retrieve<ledger_sort>(
state, parent);
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();
1942 return state.world.factory_get_building_type(a).get_output().id.index() > state.world.factory_get_building_type(b).get_output().id.index();
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);
1951 return state.world.factory_get_actual_production(a) > state.world.factory_get_actual_production(b);
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);
1960 return state.world.factory_get_full_profit(a) > state.world.factory_get_full_profit(b);
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);
1969 return economy::factory_total_employment(state, a) > economy::factory_total_employment(state, b);
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);
1978 return state.world.factory_get_level(a) > state.world.factory_get_level(b);
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));
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));
2000 auto content = retrieve<dcon::commodity_id>(
state, parent);
2001 color =
state.world.commodity_get_color(content);
2008 auto content = retrieve<dcon::nation_id>(
state, parent);
2009 color =
state.world.nation_get_color(content);
2018 std::vector<line_graph*> graph_per_nation;
2022 window_element_base::on_create(
state);
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;
2034 graph_per_nation.push_back(graph);
2035 add_child_to_front(std::move(ptr));
2042 auto ptr = retrieve< nation_toggle_list*>(
state, parent);
2046 state.world.for_each_nation([&](dcon::nation_id nation) {
2048 if((*ptr).data[nation.index()]) {
2049 for(
uint32_t i = 0; i < graph_length; ++i) {
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);
2062 graph_per_nation[nation.index()]->set_visible(
state,
true);
2063 std::vector<float> datapoints(graph_length);
2066 for(
uint32_t i = 0; i < graph_length; ++i) {
2069 graph_per_nation[nation.index()]->set_data_points(
state, datapoints, min, max);
2079 index = nation_id.index();
2082 if(index < 0)
return;
2083 auto ptr = retrieve< nation_toggle_list*>(
state, parent);
2086 (*ptr).data[index] = !(*ptr).data[index];
2087 state.game_state_updated.store(
true, std::memory_order_release);
2090 if(index < 0)
return false;
2091 auto ptr = retrieve< nation_toggle_list*>(
state, parent);
2094 return (*ptr).data[index];
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);
2124 std::vector<line_graph*> graph_per_price;
2128 window_element_base::on_create(
state);
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());
2138 graph->is_coloured =
true;
2143 graph_per_price.push_back(graph);
2144 add_child_to_front(std::move(ptr));
2151 auto ptr = retrieve< price_toggle_list*>(
state, parent);
2155 state.world.for_each_commodity([&](dcon::commodity_id
commodity) {
2158 for(
uint32_t i = 0; i < graph_length; ++i) {
2167 state.world.for_each_commodity([&](dcon::commodity_id
commodity) {
2172 std::vector<float> datapoints(graph_length);
2175 for(
uint32_t i = 0; i < graph_length; ++i) {
2178 graph_per_price[
commodity.index()]->set_data_points(
state, datapoints, min, max);
2188 index = good_id.index();
2191 if(index < 0)
return;
2192 auto ptr = retrieve< price_toggle_list*>(
state, parent);
2195 (*ptr).data[index] = !(*ptr).data[index];
2196 state.game_state_updated.store(
true, std::memory_order_release);
2199 if(index < 0)
return false;
2200 auto ptr = retrieve< price_toggle_list*>(
state, parent);
2203 return (*ptr).data[index];
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);
2229 return "ledger_legend_entry";
2233 row_contents.clear();
2234 state.world.for_each_commodity([&](dcon::commodity_id
id) {
2235 row_contents.push_back(
id);
2244 return "ledger_nations_legend_entry";
2248 row_contents.clear();
2249 state.world.for_each_nation([&](dcon::nation_id
id) {
2250 row_contents.push_back(
id);
2259 if(
name ==
"legend_list") {
2260 return make_element_by_type<ledger_commodity_price_listbox>(
state,
id);
2270 if(
name ==
"legend_nations_list") {
2271 return make_element_by_type<ledger_nations_listbox>(
state,
id);
2279 dcon::gui_def_id listbox_def_id{};
2280 dcon::gui_def_id sort_buttons_window_id{};
2336 window_element_base::on_create(
state);
2339 for(
uint32_t k = 0; k < total_commodities; ++k) {
2340 price_toggle_status.
data.push_back(
true);
2344 for(
uint32_t k = 0; k < total_nations; ++k) {
2345 nation_toggle_status.
data.push_back(
true);
2349 auto ptr = make_element_by_type<ledger_nation_ranking_listbox>(
state, listbox_def_id);
2350 nation_ranking_listbox = ptr.
get();
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));
2357 add_child_to_front(std::move(ptr));
2360 auto ptr = make_element_by_type<ledger_nation_comparison_listbox>(
state, listbox_def_id);
2361 nation_compare_listbox = ptr.
get();
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));
2368 add_child_to_front(std::move(ptr));
2371 auto ptr = make_element_by_type<ledger_nation_political_systems_listbox>(
state, listbox_def_id);
2372 nation_party_listbox = ptr.
get();
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));
2379 add_child_to_front(std::move(ptr));
2382 auto ptr = make_element_by_type<ledger_nation_political_reforms_listbox>(
state, listbox_def_id);
2383 nation_political_reforms_listbox = ptr.
get();
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));
2390 add_child_to_front(std::move(ptr));
2393 auto ptr = make_element_by_type<ledger_nation_social_reforms_listbox>(
state, listbox_def_id);
2394 nation_social_reforms_listbox = ptr.
get();
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));
2401 add_child_to_front(std::move(ptr));
2404 auto ptr = make_element_by_type<ledger_nation_population_listbox>(
state, listbox_def_id);
2405 nation_pops_listbox = ptr.
get();
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));
2412 add_child_to_front(std::move(ptr));
2415 auto ptr = make_element_by_type<ledger_province_listbox>(
state, listbox_def_id);
2416 provinces_listbox = ptr.
get();
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));
2423 add_child_to_front(std::move(ptr));
2426 auto ptr = make_element_by_type<ledger_province_population_listbox>(
state, listbox_def_id);
2427 provinces_pops_listbox = ptr.
get();
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));
2434 add_child_to_front(std::move(ptr));
2437 auto ptr = make_element_by_type<ledger_provinces_production_listbox>(
state, listbox_def_id);
2438 provinces_production_listbox = ptr.
get();
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));
2445 add_child_to_front(std::move(ptr));
2448 auto ptr = make_element_by_type<ledger_factories_production_listbox>(
state, listbox_def_id);
2449 factory_production_listbox = ptr.
get();
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));
2456 add_child_to_front(std::move(ptr));
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));
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));
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));
2483 impl_set(
state, payload);
2487 if(
name ==
"close") {
2488 auto ptr = make_element_by_type<generic_close_button>(
state,
id);
2489 ptr->set_button_text(
state,
"");
2491 }
else if(
name ==
"ledger_bg") {
2492 return make_element_by_type<draggable_target>(
state,
id);
2493 }
else if(
name ==
"ledger_linegraphs") {
2494 auto ptr = make_element_by_type<all_prices_graph>(
state,
id);
2495 commodity_linegraph = ptr.
get();
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();
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();
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();
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();
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);
2529 page_number_text->
set_text(
state, std::to_string(page_num.value));
2531 hide_sub_windows(
state);
2532 switch(page_num.value) {
2592 return message_result::consumed;
2594 current_sorting = any_cast<element_selection_wrapper<ledger_sort>>(payload).data;
2595 impl_on_update(
state);
2596 return message_result::consumed;
2599 return message_result::consumed;
2602 return message_result::consumed;
2604 return message_result::unseen;
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;
2614 return message_result::unseen;
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
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
virtual void on_create(sys::state &state) noexcept
void set_visible(sys::state &state, bool vis)
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
ledger_page_number content
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_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
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
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
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
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
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
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
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_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
std::vector< dcon::nation_id > row_contents
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
dcon::pop_type_id pop_type_id
void set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
#define assert(condition)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
constexpr uint32_t gdp_history_length
constexpr uint32_t price_history_length
int32_t most_recent_price_record_index(sys::state &state)
int32_t most_recent_gdp_record_index(sys::state &state)
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)
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
void send(sys::state &state, element_base *parent, T value)
std::variant< std::monostate, ledger_sort_type, dcon::issue_id, dcon::pop_type_id > type
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name