Project Alice
Loading...
Searching...
No Matches
gui_budget_window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "color.hpp"
4#include "commands.hpp"
5#include "culture.hpp"
6#include "dcon_generated.hpp"
9#include "nations.hpp"
10#include "system_state.hpp"
11#include "text.hpp"
12
13namespace dcon {
15public:
21 return value;
22 }
23};
25 static dcon::text_key names[5];
26
27public:
29 void set_name(dcon::text_key text) noexcept {
30 names[value] = text;
31 }
32 dcon::text_key get_name() noexcept {
33 switch(value) {
34 case 0: // No needs fulfilled
35 case 1: // Some life needs
36 case 2: // All life needs, some everyday
37 case 3: // All everyday, some luxury
38 case 4: // All luxury
39 return names[value];
40 default:
41 return dcon::text_key{ 0 };
42 }
43 }
44};
45inline pop_satisfaction_wrapper_fat fatten(data_container const& c, pop_satisfaction_wrapper_id id) noexcept {
47}
48} // namespace dcon
49namespace ogl {
50template<>
52 switch(id.value) {
53 case 0: // red
54 return sys::pack_color(1.0f, 0.1f, 0.1f);
55 case 1: // yellow
56 return sys::pack_color(1.0f, 1.0f, 0.1f);
57 case 2: // green
58 return sys::pack_color(0.1f, 1.0f, 0.1f);
59 case 3: // blue
60 return sys::pack_color(0.1f, 0.1f, 1.0f);
61 case 4: // light blue
62 return sys::pack_color(0.1f, 1.0f, 1.0f);
63 }
64 return 0;
65}
66} // namespace ogl
67
68namespace ui {
69
71public:
72 void on_update(sys::state& state) noexcept override {
74 }
75};
76
78public:
79 void on_update(sys::state& state) noexcept override {
81 }
82};
83
85public:
86 void on_update(sys::state& state) noexcept override {
88 }
91 }
92 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
93 auto n = retrieve<dcon::nation_id>(state, parent);
94
95 float w_subsidies_amount =
98
99 if(w_subsidies_amount > 0.0f) {
102 auto box = text::open_layout_box(contents, 0);
103 text::localised_format_box(state, contents, box, "warsubsidies_income", m);
104 text::close_layout_box(contents, box);
105 } else if(w_subsidies_amount < 0.0f) {
108 auto box = text::open_layout_box(contents, 0);
109 text::localised_format_box(state, contents, box, "warsubsidies_expense", m);
110 text::close_layout_box(contents, box);
111 }
112
113 if(reparations_amount > 0.0f) {
116 auto box = text::open_layout_box(contents, 0);
117 text::localised_format_box(state, contents, box, "warindemnities_income", m);
118 text::close_layout_box(contents, box);
119 } else if(reparations_amount < 0.0f) {
122 auto box = text::open_layout_box(contents, 0);
123 text::localised_format_box(state, contents, box, "warindemnities_expense", m);
124 text::close_layout_box(contents, box);
125 }
126 }
127};
128
130public:
131 void on_update(sys::state& state) noexcept override {
133 }
134};
135
137public:
138 void on_update(sys::state& state) noexcept override {
139 set_text(state, text::format_percentage(state.world.nation_get_administrative_efficiency(state.local_player_nation)));
140 }
143 }
144 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
145 auto n = state.local_player_nation;
146
147 {
150 text::fp_percentage{ 1.0f + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::administrative_efficiency_modifier) });
151 auto box = text::open_layout_box(contents, 0);
152 text::localised_format_box(state, contents, box, "admin_explain_1", m);
153 text::close_layout_box(contents, box);
154 }
155 active_modifiers_description(state, contents, n, 15, sys::national_mod_offsets::administrative_efficiency_modifier,
156 false);
157 {
158 auto non_colonial = state.world.nation_get_non_colonial_population(n);
159 auto total = non_colonial > 0.0f ? state.world.nation_get_non_colonial_bureaucrats(n) / non_colonial : 0.0f;
160
163 auto box = text::open_layout_box(contents, 0);
164 text::localised_format_box(state, contents, box, "admin_explain_2", m);
165 text::close_layout_box(contents, box);
166 }
167 {
168 float issue_sum = 0.0f;
169 for(auto i : state.culture_definitions.social_issues) {
170 issue_sum = issue_sum + state.world.issue_option_get_administrative_multiplier(state.world.nation_get_issues(n, i));
171 }
172 auto from_issues = issue_sum * state.defines.bureaucracy_percentage_increment;
173
175 text::add_to_substitution_map(m, text::variable_type::val, text::fp_percentage{ (from_issues + state.defines.max_bureaucracy_percentage) });
176 text::add_to_substitution_map(m, text::variable_type::x, text::fp_percentage{ state.defines.max_bureaucracy_percentage });
178 auto box = text::open_layout_box(contents, 0);
179 text::localised_format_box(state, contents, box, "admin_explain_3", m);
180 text::close_layout_box(contents, box);
181 }
182 }
183};
184
185template<culture::pop_strata Strata>
187public:
189
190 void on_create(sys::state& state) noexcept override {
191 base_data.position.x -= 25;
192 base_data.size.x *= 2;
193 base_data.size.y *= 2;
194
195 is_coloured = true;
196 }
197
198 void on_update(sys::state& state) noexcept override {
199 if(parent == nullptr)
200 return;
201
202 float min = 0.f;
203
204 float max = 0.f;
205 for(auto prov : state.world.nation_get_province_ownership(state.local_player_nation)) {
206
207 for(auto pop_loc : prov.get_province().get_pop_location()) {
208 auto pop_id = pop_loc.get_pop();
209 auto pop_strata = state.world.pop_type_get_strata(state.world.pop_get_poptype(pop_id));
210 auto pop_size = pop_strata == uint8_t(Strata) ? state.world.pop_get_size(pop_id) : 0.f;
211
212 max += pop_size;
213 }
214 }
215
216 std::vector<float> datapoints(count);
217
218 float integral = 0.f;
219 float total_area = 0.f;
220
221 for(uint32_t i = 0; i < count; ++i) {
222 float cutoff = (float)i / count + 0.01f;
223 float value = 0.f;
224
225 for(auto prov : state.world.nation_get_province_ownership(state.local_player_nation)) {
226
227 for(auto pop_loc : prov.get_province().get_pop_location()) {
228 auto pop_id = pop_loc.get_pop();
229 auto pop_strata = state.world.pop_type_get_strata(state.world.pop_get_poptype(pop_id));
230 auto pop_size = pop_strata == uint8_t(Strata) ? state.world.pop_get_size(pop_id) : 0.f;
231
232 float total =
236
237 if(total / 3.f >= cutoff)
238 value += pop_size;
239
240 integral += total / 3.f * pop_size;
241 total_area += pop_size;
242 }
243 }
244
245 datapoints[i] = value;
246 }
247
248 float area_ratio = integral / (total_area + 0.0001f);
249 if(state.user_settings.color_blind_mode == sys::color_blind_mode::achroma) {
250 r = 0.f;
251 g = 0.f;
252 b = 0.f;
253 } else {
254 r = 1.f - area_ratio * 0.5f;
255 g = std::sqrt(area_ratio);
256 b = std::sqrt(area_ratio) * 0.8f;
257 }
258 set_data_points(state, datapoints, min, max);
259 }
260};
261
262template<culture::pop_strata Strata>
263class pop_satisfaction_piechart : public piechart<dcon::pop_satisfaction_wrapper_id> {
264protected:
265 void on_update(sys::state& state) noexcept override {
266 distribution.clear();
267
268 if(parent == nullptr)
269 return;
270
271 auto total = 0.f;
272 std::array<float, 5> sat_pool = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
273 for(auto prov : state.world.nation_get_province_ownership(state.local_player_nation)) {
274
275 for(auto pop_loc : prov.get_province().get_pop_location()) {
276 auto pop_id = pop_loc.get_pop();
277 auto pop_strata = state.world.pop_type_get_strata(state.world.pop_get_poptype(pop_id));
278 auto pop_size = pop_strata == uint8_t(Strata) ? state.world.pop_get_size(pop_id) : 0.f;
279 // All luxury needs
280 // OR All everyday needs
281 // OR All life needs
282 // OR Some life needs
283 // OR No needs fulfilled...
284 sat_pool[(pop_demographics::get_luxury_needs(state, pop_id) > 0.95f) ? 4
285 : (pop_demographics::get_everyday_needs(state, pop_id) > 0.95f) ? 3
286 : (pop_demographics::get_life_needs(state, pop_id) > 0.95f) ? 2
287 : (pop_demographics::get_life_needs(state, pop_id) > 0.01f) ? 1
288 : 0] += pop_size;
289 }
290 }
291
292 for(uint8_t i = 0; i < 5; i++)
293 distribution.emplace_back(dcon::pop_satisfaction_wrapper_id(i), sat_pool[i]);
294
296 }
297
298public:
299 void on_create(sys::state& state) noexcept override {
300 // Fill-in static information...
301 static bool has_run = false;
302 if(!has_run) {
304 .set_name(text::find_or_add_key(state, "BUDGET_STRATA_NO_NEED", false));
306 .set_name(text::find_or_add_key(state, "BUDGET_STRATA_NEED", false));
308 .set_name(text::find_or_add_key(state, "BUDGET_STRATA_NEED", false));
310 .set_name(text::find_or_add_key(state, "BUDGET_STRATA_NEED", false));
312 .set_name(text::find_or_add_key(state, "BUDGET_STRATA_NEED", false));
313 has_run = true;
314 }
316 }
317
319 text::columnar_layout& contents) noexcept override {
320 static const std::string needs_types[5] = {"no_need", "some_life_needs", "life_needs", "everyday_needs", "luxury_needs"};
321 auto fat_psw = dcon::fatten(state.world, psw);
322 auto box = text::open_layout_box(contents, 0);
323 auto sub = text::substitution_map{};
324 auto needs_type = text::produce_simple_string(state, needs_types[psw.value]);
326 text::add_to_substitution_map(sub, text::variable_type::type, std::string_view(needs_type));
327 text::add_to_layout_box(state, contents, box, fat_psw.get_name(), sub);
328 text::close_layout_box(contents, box);
329 }
330};
331
333 poor_tax,
335 rich_tax,
339 education,
340 admin,
341 social,
342 military,
343 tariffs,
345 raw,
346 //
347 overseas,
350 interest,
351 subsidies,
353 //
355};
356
358 linear,
360};
361
364 float amount = 0.f;
365};
366
367template<budget_slider_target SliderTarget, slider_scaling SliderDisplayScaling>
368class budget_slider : public scrollbar {
369public:
370
371 void on_create(sys::state& state) noexcept final {
375 switch(step) {
377 break;
378 case step_size::two:
379 break;
380 case step_size::one:
381 break;
384 break;
387 break;
390 break;
391 }
396
399
400 auto first_child = base_data.data.scrollbar.first_child;
401 auto num_children = base_data.data.scrollbar.num_children;
402
403 if(num_children >= 6) {
404 auto child_tag = dcon::gui_def_id(dcon::gui_def_id::value_base_t(5 + first_child.index()));
405 auto ch_res = make_element_by_type<image_element_base>(state, child_tag);
406 right_limit = ch_res.get();
408 add_child_to_back(std::move(ch_res));
409 }
410 if(num_children >= 5) {
411 auto child_tag = dcon::gui_def_id(dcon::gui_def_id::value_base_t(4 + first_child.index()));
412 auto ch_res = make_element_by_type<image_element_base>(state, child_tag);
413 left_limit = ch_res.get();
415 add_child_to_back(std::move(ch_res));
416 }
417
418 if(num_children >= 4) {
419 {
420 auto child_tag = dcon::gui_def_id(dcon::gui_def_id::value_base_t(2 + first_child.index()));
421 auto ch_res = make_element_by_type<scrollbar_slider>(state, child_tag);
422 slider = ch_res.get();
423 add_child_to_back(std::move(ch_res));
424 }
425 {
426 auto child_tag = dcon::gui_def_id(dcon::gui_def_id::value_base_t(0 + first_child.index()));
427 auto ch_res = make_element_by_type<scrollbar_left>(state, child_tag);
428 left = ch_res.get();
429 add_child_to_back(std::move(ch_res));
430
432 if(step_size::twenty_five == step)
433 left->step_size = 25;
434 else if(step_size::two == step)
435 left->step_size = 2;
436 else
437 left->step_size = 1;
438 }
439 {
440 auto child_tag = dcon::gui_def_id(dcon::gui_def_id::value_base_t(1 + first_child.index()));
441 auto ch_res = make_element_by_type<scrollbar_right>(state, child_tag);
442 //ui::element_base* test = ch_res.get();
443 right = ch_res.get();
444 add_child_to_back(std::move(ch_res));
445
446 if(step_size::twenty_five == step)
447 right->step_size = 25;
448 else if(step_size::two == step)
449 right->step_size = 2;
450 else
451 right->step_size = 1;
452 }
453 {
454 auto child_tag = dcon::gui_def_id(dcon::gui_def_id::value_base_t(3 + first_child.index()));
455 auto ch_res = make_element_by_type<scrollbar_track>(state, child_tag);
456 track = ch_res.get();
457 add_child_to_back(std::move(ch_res));
458
460 }
463 if(settings.vertical) {
467 // track->base_data.position.x = 0;
470 } else {
474 // track->base_data.position.y = 0;
477 }
478 }
479 }
480 }
481 void on_value_change(sys::state& state, int32_t v) noexcept final {
482 if(parent) {
483 float amount = float(v) / 100.0f;
484 switch(SliderDisplayScaling) {
486 break;
488 amount = amount * amount;
489 break;
490 default:
491 break;
492 }
493 send(state, parent, budget_slider_signal{ SliderTarget, amount });
494 }
495 if(state.ui_state.drag_target != slider)
496 commit_changes(state);
497 }
498
499 void on_update(sys::state& state) noexcept final {
500 switch(SliderTarget) {
502 auto min_tax =
503 int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::min_tax));
504 auto max_tax =
505 int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::max_tax));
506 if(max_tax <= 0)
507 max_tax = 100;
508 max_tax = std::max(min_tax, max_tax);
509
510 mutable_scrollbar_settings new_settings;
511 new_settings.lower_value = 0;
512 new_settings.upper_value = 100;
513 new_settings.using_limits = true;
514 new_settings.lower_limit = std::clamp(min_tax, 0, 100);
515 new_settings.upper_limit = std::clamp(max_tax, 0, 100);
516 change_settings(state, new_settings);
517 } break;
519 auto min_tax =
520 int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::min_tax));
521 auto max_tax =
522 int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::max_tax));
523 if(max_tax <= 0)
524 max_tax = 100;
525 max_tax = std::max(min_tax, max_tax);
526
527 mutable_scrollbar_settings new_settings;
528 new_settings.lower_value = 0;
529 new_settings.upper_value = 100;
530 new_settings.using_limits = true;
531 new_settings.lower_limit = std::clamp(min_tax, 0, 100);
532 new_settings.upper_limit = std::clamp(max_tax, 0, 100);
533 change_settings(state, new_settings);
534 } break;
536 auto min_tax =
537 int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::min_tax));
538 auto max_tax =
539 int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::max_tax));
540 if(max_tax <= 0)
541 max_tax = 100;
542 max_tax = std::max(min_tax, max_tax);
543
544 mutable_scrollbar_settings new_settings;
545 new_settings.lower_value = 0;
546 new_settings.upper_value = 100;
547 new_settings.using_limits = true;
548 new_settings.lower_limit = std::clamp(min_tax, 0, 100);
549 new_settings.upper_limit = std::clamp(max_tax, 0, 100);
550 change_settings(state, new_settings);
551 } break;
553 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation,
554 sys::national_mod_offsets::min_social_spending));
555 auto max_spend = int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation,
556 sys::national_mod_offsets::max_social_spending));
557 if(max_spend <= 0)
558 max_spend = 100;
559 max_spend = std::max(min_spend, max_spend);
560
561 mutable_scrollbar_settings new_settings;
562 new_settings.lower_value = 0;
563 new_settings.upper_value = 100;
564 new_settings.using_limits = true;
565 new_settings.lower_limit = std::clamp(min_spend, 0, 100);
566 new_settings.upper_limit = std::clamp(max_spend, 0, 100);
567 change_settings(state, new_settings);
568 } break;
570 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation,
571 sys::national_mod_offsets::min_military_spending));
572 auto max_spend = int32_t(100.0f * state.world.nation_get_modifier_values(state.local_player_nation,
573 sys::national_mod_offsets::max_military_spending));
574 if(max_spend <= 0)
575 max_spend = 100;
576 max_spend = std::max(min_spend, max_spend);
577
578 mutable_scrollbar_settings new_settings;
579 new_settings.lower_value = 0;
580 new_settings.upper_value = 100;
581 new_settings.using_limits = true;
582 new_settings.lower_limit = std::clamp(min_spend, 0, 100);
583 new_settings.upper_limit = std::clamp(max_spend, 0, 100);
584 change_settings(state, new_settings);
585 } break;
587 auto min_tariff = int32_t(
588 100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::min_tariff));
589 auto max_tariff = int32_t(
590 100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::max_tariff));
591 max_tariff = std::max(min_tariff, max_tariff);
592
593 mutable_scrollbar_settings new_settings;
594 new_settings.lower_value = 0;
595 new_settings.upper_value = 100;
596 new_settings.using_limits = true;
597 new_settings.lower_limit = std::clamp(min_tariff, 0, 100);
598 new_settings.upper_limit = std::clamp(max_tariff, 0, 100);
599 change_settings(state, new_settings);
600 } break;
602 {
603 auto min_domestic_investment = int32_t(
604 100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::min_domestic_investment));
605 auto max_domestic_investment = int32_t(
606 100.0f * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::max_domestic_investment));
607 if(max_domestic_investment <= 0)
608 max_domestic_investment = 100;
609 max_domestic_investment = std::max(min_domestic_investment, max_domestic_investment);
610
611 mutable_scrollbar_settings new_settings;
612 new_settings.lower_value = 0;
613 new_settings.upper_value = 100;
614 new_settings.using_limits = true;
615 new_settings.lower_limit = std::clamp(min_domestic_investment, 0, 100);
616 new_settings.upper_limit = std::clamp(max_domestic_investment, 0, 100);
617 change_settings(state, new_settings);
618 } break;
619 default:
620 break;
621 }
622
623 int32_t v = 0;
624 if(state.ui_state.drag_target == slider) {
625 v = int32_t(scaled_value());
626 } else {
629 }
630
631 if(parent) {
632 float amount = float(v) / 100.f;
633 switch(SliderDisplayScaling) {
635 break;
637 amount = amount * amount;
638 break;
639 default:
640 break;
641 }
642 Cyto::Any payload = budget_slider_signal{SliderTarget, amount};
643 parent->impl_set(state, payload);
644 }
645 }
646
647 virtual int32_t get_true_value(sys::state& state) noexcept {
648 return 0;
649 }
650
651 void on_drag_finish(sys::state& state) noexcept override {
652 commit_changes(state);
653 }
654
655private:
656 void commit_changes(sys::state& state) noexcept {
657 auto budget_settings = command::make_empty_budget_settings();
658 update_budget_settings(budget_settings);
659 command::change_budget_settings(state, state.local_player_nation, budget_settings);
660 }
661
662 void update_budget_settings(command::budget_settings_data& budget_settings) noexcept {
663 auto new_val = int8_t(scaled_value());
664 switch(SliderTarget) {
666 budget_settings.poor_tax = new_val;
667 break;
669 budget_settings.middle_tax = new_val;
670 break;
672 budget_settings.rich_tax = new_val;
673 break;
675 budget_settings.land_spending = new_val;
676 break;
678 budget_settings.naval_spending = new_val;
679 break;
681 budget_settings.construction_spending = new_val;
682 break;
684 budget_settings.education_spending = new_val;
685 break;
687 budget_settings.administrative_spending = new_val;
688 break;
690 budget_settings.social_spending = new_val;
691 break;
693 budget_settings.military_spending = new_val;
694 break;
696 budget_settings.tariffs = new_val;
697 break;
699 budget_settings.domestic_investment = new_val;
700 break;
702 budget_settings.overseas = new_val;
703 break;
704 default:
705 break;
706 }
707 }
708};
709
710
711class budget_poor_tax_slider : public budget_slider<budget_slider_target::poor_tax, slider_scaling::linear> {
712 int32_t get_true_value(sys::state& state) noexcept override {
713 return int32_t(state.world.nation_get_poor_tax(state.local_player_nation));
714 }
715 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
717 }
718 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
719 auto n = retrieve<dcon::nation_id>(state, parent);
720 auto box = text::open_layout_box(contents, 0);
721 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_poor_tax(n) });
722 text::close_layout_box(contents, box);
723
724 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::tax_efficiency, true);
725 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::min_tax, true);
726 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::max_tax, true);
727 }
728};
729
730class budget_middle_tax_slider : public budget_slider<budget_slider_target::middle_tax, slider_scaling::linear> {
731 int32_t get_true_value(sys::state& state) noexcept override {
732 return int32_t(state.world.nation_get_middle_tax(state.local_player_nation));
733 }
734 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
736 }
737 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
738 auto n = retrieve<dcon::nation_id>(state, parent);
739 auto box = text::open_layout_box(contents, 0);
740 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_middle_tax(n) });
741 text::close_layout_box(contents, box);
742
743 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::tax_efficiency, true);
744 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::min_tax, true);
745 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::max_tax, true);
746 }
747};
748
749class budget_rich_tax_slider : public budget_slider<budget_slider_target::rich_tax, slider_scaling::linear> {
750 int32_t get_true_value(sys::state& state) noexcept override {
751 return int32_t(state.world.nation_get_rich_tax(state.local_player_nation));
752 }
753 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
755 }
756 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
757 auto n = retrieve<dcon::nation_id>(state, parent);
758 auto box = text::open_layout_box(contents, 0);
759 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_rich_tax(n) });
760 text::close_layout_box(contents, box);
761
762 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::tax_efficiency, true);
763 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::min_tax, true);
764 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::max_tax, true);
765 }
766};
767
768class budget_army_stockpile_slider : public budget_slider<budget_slider_target::army_stock, slider_scaling::linear> {
769 int32_t get_true_value(sys::state& state) noexcept override {
770 return int32_t(state.world.nation_get_land_spending(state.local_player_nation));
771 }
772 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
774 }
775 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
776 auto n = retrieve<dcon::nation_id>(state, parent);
777 {
778 auto box = text::open_layout_box(contents, 0);
779 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_land_spending(n) });
780 text::close_layout_box(contents, box);
781 }
782 uint32_t total_commodities = state.world.commodity_size();
783 for(uint32_t i = 1; i < total_commodities; ++i) {
784 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
785 auto cost = state.world.commodity_get_current_price(cid);
786 auto amount = state.world.nation_get_army_demand(n, cid);
787 if(amount > 0.f) {
789 text::add_to_substitution_map(m, text::variable_type::name, state.world.commodity_get_name(cid));
793 auto box = text::open_layout_box(contents, 0);
794 text::localised_format_box(state, contents, box, "alice_spending_commodity", m);
795 text::close_layout_box(contents, box);
796 }
797 }
798 }
799};
800
801class budget_navy_stockpile_slider : public budget_slider<budget_slider_target::navy_stock, slider_scaling::linear> {
802 int32_t get_true_value(sys::state& state) noexcept override {
803 return int32_t(state.world.nation_get_naval_spending(state.local_player_nation));
804 }
805 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
807 }
808 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
809 auto n = retrieve<dcon::nation_id>(state, parent);
810 {
811 auto box = text::open_layout_box(contents, 0);
812 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_naval_spending(n) });
813 text::close_layout_box(contents, box);
814 }
815 uint32_t total_commodities = state.world.commodity_size();
816 for(uint32_t i = 1; i < total_commodities; ++i) {
817 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
818 auto cost = state.world.commodity_get_current_price(cid);
819 auto amount = state.world.nation_get_navy_demand(n, cid);
820 if(amount > 0.f) {
822 text::add_to_substitution_map(m, text::variable_type::name, state.world.commodity_get_name(cid));
826 auto box = text::open_layout_box(contents, 0);
827 text::localised_format_box(state, contents, box, "alice_spending_commodity", m);
828 text::close_layout_box(contents, box);
829 }
830 }
831 }
832};
833
834class budget_construction_stockpile_slider : public budget_slider<budget_slider_target::construction_stock, slider_scaling::linear> {
835 int32_t get_true_value(sys::state& state) noexcept override {
836 return int32_t(state.world.nation_get_construction_spending(state.local_player_nation));
837 }
838 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
840 }
841 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
842 auto n = retrieve<dcon::nation_id>(state, parent);
843 {
844 auto box = text::open_layout_box(contents, 0);
845 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_construction_spending(n) });
846 text::close_layout_box(contents, box);
847 }
848 std::vector<float> total;
849 total.resize(size_t(state.world.commodity_size()), 0.0f);
850
851 float admin_eff = state.world.nation_get_administrative_efficiency(n);
852 float admin_cost_factor = 2.0f - admin_eff;
853 for(auto lc : state.world.nation_get_province_land_construction(n)) {
854 auto province = state.world.pop_get_province_from_pop_location(state.world.province_land_construction_get_pop(lc));
855 if(state.world.province_get_nation_from_province_control(province) == n) {
856 auto& base_cost = state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(lc)].build_cost;
857 auto& current_purchased = state.world.province_land_construction_get_purchased_goods(lc);
858 float construction_time = float(state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(lc)].build_time);
859 //
860 float total_cost = 0.f;
861 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
862 if(auto cid = base_cost.commodity_type[i]; cid) {
863 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
864 float amount = state.world.nation_get_demand_satisfaction(n, cid) * base_cost.commodity_amounts[i] / construction_time;
865 float cost = state.world.commodity_get_current_price(cid);
866 total_cost += cost * amount;
867 total[base_cost.commodity_type[i].index()] += cost * amount;
868 }
869 } else {
870 break;
871 }
872 }
876 auto box = text::open_layout_box(contents, 0);
877 text::localised_format_box(state, contents, box, "alice_spending_land_construction", m);
878 text::close_layout_box(contents, box);
879 }
880 }
881 for(auto po : state.world.nation_get_province_ownership(n)) {
882 auto p = po.get_province();
883 if(state.world.province_get_nation_from_province_control(p) != n)
884 continue;
885 auto rng = state.world.province_get_province_naval_construction(p);
886 if(rng.begin() != rng.end()) {
887 auto c = *(rng.begin());
888 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
889 auto& current_purchased = c.get_purchased_goods();
890 float construction_time = float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
891 //
892 float total_cost = 0.f;
893 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
894 if(auto cid = base_cost.commodity_type[i]; cid) {
895 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
896 float amount = state.world.nation_get_demand_satisfaction(n, cid) * base_cost.commodity_amounts[i] / construction_time;
897 float cost = state.world.commodity_get_current_price(cid);
898 total_cost += cost * amount;
899 total[base_cost.commodity_type[i].index()] += cost * amount;
900 }
901 } else {
902 break;
903 }
904 }
908 auto box = text::open_layout_box(contents, 0);
909 text::localised_format_box(state, contents, box, "alice_spending_naval_construction", m);
910 text::close_layout_box(contents, box);
911 }
912 }
913 for(auto c : state.world.nation_get_province_building_construction(n)) {
914 if(n == c.get_province().get_nation_from_province_control() && !c.get_is_pop_project()) {
915 auto t = economy::province_building_type(c.get_type());
916 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
917 auto& current_purchased = c.get_purchased_goods();
918 float construction_time = float(state.economy_definitions.building_definitions[int32_t(t)].time);
919 //
920 float total_cost = 0.f;
921 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
922 if(auto cid = base_cost.commodity_type[i]; cid) {
923 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
924 float amount = state.world.nation_get_demand_satisfaction(n, cid) * base_cost.commodity_amounts[i] / construction_time;
925 float cost = state.world.commodity_get_current_price(cid);
926 total_cost += cost * amount;
927 total[base_cost.commodity_type[i].index()] += cost * amount;
928 }
929 } else {
930 break;
931 }
932 }
936 auto box = text::open_layout_box(contents, 0);
937 text::localised_format_box(state, contents, box, "alice_spending_building_construction", m);
938 text::close_layout_box(contents, box);
939 }
940 }
941 float factory_mod = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f;
942 for(auto c : state.world.nation_get_state_building_construction(n)) {
943 if(!c.get_is_pop_project()) {
944 auto& base_cost = c.get_type().get_construction_costs();
945 auto& current_purchased = c.get_purchased_goods();
946 float construction_time = float(c.get_type().get_construction_time()) * (c.get_is_upgrade() ? 0.1f : 1.0f);
947 //
948 float total_cost = 0.f;
949 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
950 if(auto cid = base_cost.commodity_type[i]; cid) {
951 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
952 float amount = state.world.nation_get_demand_satisfaction(n, cid) * base_cost.commodity_amounts[i] * factory_mod / construction_time;
953 float cost = state.world.commodity_get_current_price(cid);
954 total_cost += cost * amount;
955 total[base_cost.commodity_type[i].index()] += cost * amount;
956 }
957 } else {
958 break;
959 }
960 }
964 auto box = text::open_layout_box(contents, 0);
965 text::localised_format_box(state, contents, box, "alice_spending_factory_construction", m);
966 text::close_layout_box(contents, box);
967 }
968 }
969 uint32_t total_commodities = state.world.commodity_size();
970 bool is_spending = false;
971 for(uint32_t i = 1; i < total_commodities; ++i) {
972 is_spending = is_spending || (total[i] > 0.f);
973 }
974 if(is_spending) {
975 text::add_line(state, contents, "alice_spending_total");
976 for(uint32_t i = 1; i < total_commodities; ++i) {
977 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
978 auto cost = state.world.commodity_get_current_price(cid);
979 auto amount = total[i];
980 if(amount > 0.f) {
982 text::add_to_substitution_map(m, text::variable_type::name, state.world.commodity_get_name(cid));
986 auto box = text::open_layout_box(contents, 0);
987 text::localised_format_box(state, contents, box, "alice_spending_commodity", m);
988 text::close_layout_box(contents, box);
989 }
990 }
991 }
992 }
993};
994
995class budget_education_slider : public budget_slider<budget_slider_target::education, slider_scaling::quadratic> {
996 int32_t get_true_value(sys::state& state) noexcept override {
997 return int32_t(state.world.nation_get_education_spending(state.local_player_nation));
998 }
999 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1001 }
1002 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1003 auto n = retrieve<dcon::nation_id>(state, parent);
1004 auto box = text::open_layout_box(contents, 0);
1005 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_education_spending(n) });
1006 text::close_layout_box(contents, box);
1007 }
1008};
1009
1010class budget_administration_slider : public budget_slider<budget_slider_target::admin, slider_scaling::quadratic> {
1011 int32_t get_true_value(sys::state& state) noexcept override {
1012 return int32_t(state.world.nation_get_administrative_spending(state.local_player_nation));
1013 }
1014 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1016 }
1017 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1018 auto n = retrieve<dcon::nation_id>(state, parent);
1019 auto box = text::open_layout_box(contents, 0);
1020 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_administrative_spending(n) });
1021 text::close_layout_box(contents, box);
1022 }
1023};
1024
1025class budget_social_spending_slider : public budget_slider<budget_slider_target::social, slider_scaling::linear> {
1026 int32_t get_true_value(sys::state& state) noexcept override {
1027 return int32_t(state.world.nation_get_social_spending(state.local_player_nation));
1028 }
1029 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1031 }
1032 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1033 auto n = retrieve<dcon::nation_id>(state, parent);
1034 auto box = text::open_layout_box(contents, 0);
1035 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_social_spending(n) });
1036 text::close_layout_box(contents, box);
1037 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::min_social_spending, true);
1038 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::max_social_spending, true);
1039 }
1040};
1041
1042class budget_military_spending_slider : public budget_slider<budget_slider_target::military, slider_scaling::quadratic> {
1043 int32_t get_true_value(sys::state& state) noexcept override {
1044 return int32_t(state.world.nation_get_military_spending(state.local_player_nation));
1045 }
1046 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1048 }
1049 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1050 auto n = retrieve<dcon::nation_id>(state, parent);
1051 auto box = text::open_layout_box(contents, 0);
1052 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_military_spending(n) });
1053 text::close_layout_box(contents, box);
1054 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::min_military_spending, true);
1055 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::max_military_spending, true);
1056 }
1057};
1058
1059class budget_tariff_slider : public budget_slider<budget_slider_target::tariffs, slider_scaling::linear> {
1060 int32_t get_true_value(sys::state& state) noexcept override {
1061 return int32_t(state.world.nation_get_tariffs(state.local_player_nation));
1062 }
1063 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1065 }
1066 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1067 auto n = retrieve<dcon::nation_id>(state, parent);
1068 auto box = text::open_layout_box(contents, 0);
1069 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_tariffs(n) });
1070 text::close_layout_box(contents, box);
1071 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::tariff_efficiency_modifier, true);
1072 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::min_tariff, true);
1073 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::max_tariff, true);
1074 }
1075};
1076
1078private:
1079 std::array<float, size_t(budget_slider_target::target_count)> values;
1080 std::array<float, size_t(budget_slider_target::target_count)> multipliers;
1081
1082public:
1083 bool expense = false;
1084
1085 virtual void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept { }
1086
1087 void on_create(sys::state& state) noexcept override {
1090 for(uint8_t i = 0; i < uint8_t(budget_slider_target::target_count); ++i) {
1091 values[i] = 0.f;
1092 multipliers[i] = 1.f;
1093 }
1094 }
1095
1097 auto total = 0.f;
1099 total += values[i] * multipliers[i];
1100
1101 if(expense)
1102 total = -total;
1103
1104 if(total < 0.0f) {
1106 set_text(state, text::format_money(total)); //automatically adds a - when negative
1107 } else if(total > 0.0f) {
1110 } else {
1113 }
1114 }
1115
1116 void on_update(sys::state& state) noexcept override {
1117 put_values(state, values);
1119 }
1120
1123 }
1124 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1125 auto n = retrieve<dcon::nation_id>(state, parent);
1126 auto box = text::open_layout_box(contents, 0);
1127
1128 float total = 0.f;
1129 float total_exp = 0.f;
1130 float total_inc = 0.f;
1131 for(uint8_t i = 0; i < uint8_t(budget_slider_target::target_count); ++i) {
1132 float v = values[i] * multipliers[i];
1133 if(expense)
1134 v = -v;
1135 if(v < 0.f)
1136 total_exp += v;
1137 else
1138 total_inc += v;
1139 total += v;
1140 }
1141 if(total_inc != 0.f) {
1142 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_inc", text::variable_type::value, text::fp_currency{ total_inc });
1144 for(uint8_t i = 0; i < uint8_t(budget_slider_target::target_count); ++i) {
1145 float v = values[i] * multipliers[i];
1146 if(expense)
1147 v = -v;
1148 if(v > 0.f) {
1149 switch(budget_slider_target(i)) {
1151 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_1", text::variable_type::value, text::fp_currency{ v });
1152 break;
1154 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_2", text::variable_type::value, text::fp_currency{ v });
1155 break;
1157 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_3", text::variable_type::value, text::fp_currency{ v });
1158 break;
1160 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_4", text::variable_type::value, text::fp_currency{ v });
1161 break;
1163 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_17", text::variable_type::value, text::fp_currency{ v });
1164 break;
1166 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_16", text::variable_type::value, text::fp_currency{ v });
1167 break;
1168 default:
1169 break;
1170 }
1172 }
1173 }
1174 }
1175 if(total_exp != 0.f) {
1176 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_exp", text::variable_type::value, text::fp_currency{ total_exp });
1178 for(uint8_t i = 0; i < uint8_t(budget_slider_target::target_count); ++i) {
1179 float v = values[i] * multipliers[i];
1180 if(expense)
1181 v = -v;
1182 if(v < 0.f) {
1183 switch(budget_slider_target(i)) {
1185 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_5", text::variable_type::value, text::fp_currency{ v });
1186 break;
1188 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_6", text::variable_type::value, text::fp_currency{ v });
1189 break;
1191 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_7", text::variable_type::value, text::fp_currency{ v });
1192 break;
1194 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_8", text::variable_type::value, text::fp_currency{ v });
1195 break;
1197 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_9", text::variable_type::value, text::fp_currency{ v });
1198 break;
1200 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_10", text::variable_type::value, text::fp_currency{ v });
1201 break;
1203 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_11", text::variable_type::value, text::fp_currency{ v });
1204 break;
1206 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_12", text::variable_type::value, text::fp_currency{ v });
1207 break;
1209 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_13", text::variable_type::value, text::fp_currency{ v });
1210 break;
1212 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_14", text::variable_type::value, text::fp_currency{ v });
1213 break;
1215 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_15", text::variable_type::value, text::fp_currency{ v });
1216 break;
1217 default:
1218 break;
1219 }
1221 }
1222 }
1223 }
1224 if(total != 0.f) {
1225 text::localised_single_sub_box(state, contents, box, "alice_budget_scaled_net", text::variable_type::value, text::fp_currency{ total });
1227 }
1228 text::close_layout_box(contents, box);
1229 }
1230
1231 message_result set(sys::state& state, Cyto::Any& payload) noexcept override {
1232 if(payload.holds_type<budget_slider_signal>()) {
1233 auto sig = any_cast<budget_slider_signal>(payload);
1234 multipliers[uint8_t(sig.target)] = sig.amount;
1235 if(values[uint8_t(sig.target)] != 0.f)
1238 }
1240 }
1241};
1242
1244public:
1245 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1248 }
1249};
1250
1252public:
1253 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1258 }
1259};
1260
1262public:
1263 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1266 }
1267};
1268
1270public:
1271 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1274 }
1275};
1276
1278public:
1279 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1281 }
1282};
1283
1284template<culture::pop_strata Strata, budget_slider_target BudgetTarget>
1286 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1287 vals[uint8_t(BudgetTarget)] = economy::estimate_tax_income_by_strata(state, state.local_player_nation, Strata);
1288 }
1289};
1290
1291template<culture::income_type IncomeType, budget_slider_target BudgetTarget>
1293public:
1294 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1295 vals[uint8_t(BudgetTarget)] = economy::estimate_pop_payouts_by_income_type(state, state.local_player_nation, IncomeType);
1296 }
1297};
1298
1300public:
1301 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1303 }
1304};
1305
1307public:
1308 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1316 }
1317};
1318
1320public:
1321 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1334 * state.world.nation_get_domestic_investment_spending(state.local_player_nation) / 100.0f
1335 * state.world.nation_get_domestic_investment_spending(state.local_player_nation) / 100.0f;
1340 }
1341};
1342
1344public:
1345 void put_values(sys::state& state, std::array<float, size_t(budget_slider_target::target_count)>& vals) noexcept override {
1346 // income
1354
1355 // spend
1368 * state.world.nation_get_domestic_investment_spending(state.local_player_nation) / 100.0f
1369 * state.world.nation_get_domestic_investment_spending(state.local_player_nation) / 100.0f;
1370 // balance
1374 }
1375};
1376
1378public:
1379 void button_action(sys::state& state) noexcept override {
1380 if(parent) {
1381 Cyto::Any payload = element_selection_wrapper<bool>{bool{true}};
1382 parent->impl_get(state, payload);
1383 }
1384 }
1385};
1386
1387// NOTE for simplicity sake we use a payload with bool{true} for taking loan window and a payload with bool{false} for repaying
1388// loan window
1389
1391public:
1392 void button_action(sys::state& state) noexcept override {
1393 if(parent) {
1394 Cyto::Any payload = element_selection_wrapper<bool>{bool{false}};
1395 parent->impl_get(state, payload);
1396 }
1397 }
1398};
1399
1401public:
1402 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1403 if(name == "bg") {
1404 return make_element_by_type<image_element_base>(state, id);
1405 } else if(name == "take_loan_label") {
1406 return make_element_by_type<simple_text_element_base>(state, id);
1407 } else if(name == "ok") {
1408 return make_element_by_type<button_element_base>(state, id);
1409 } else if(name == "cancel") {
1410 return make_element_by_type<generic_close_button>(state, id);
1411 } else if(name == "money_value") {
1412 return make_element_by_type<simple_text_element_base>(state, id);
1413 } /*else if(name == "money_slider") {
1414 return nullptr;
1415 }*/
1416 else {
1417 return nullptr;
1418 }
1419 }
1420};
1421
1423public:
1424 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1425 if(name == "bg") {
1426 return make_element_by_type<image_element_base>(state, id);
1427 } else if(name == "repay_loan_label") {
1428 return make_element_by_type<simple_text_element_base>(state, id);
1429 } else if(name == "ok") {
1430 return make_element_by_type<button_element_base>(state, id);
1431 } else if(name == "cancel") {
1432 return make_element_by_type<generic_close_button>(state, id);
1433 } else if(name == "money_value") {
1434 return make_element_by_type<simple_text_element_base>(state, id);
1435 } /*else if(name == "money_slider") {
1436 return nullptr;
1437 }*/
1438 else {
1439 return nullptr;
1440 }
1441 }
1442};
1443
1445public:
1446 dcon::pop_type_id type{};
1447
1448 void set_type(sys::state& state, dcon::pop_type_id t) {
1449 type = t;
1450 frame = int32_t(state.world.pop_type_get_sprite(t) - 1);
1451 }
1452
1455 }
1456
1457 void on_update(sys::state& state) noexcept override {
1458 auto total_pop = state.world.nation_get_demographics(state.local_player_nation, demographics::to_key(state, type));
1459 disabled = total_pop < 1.0f;
1460 }
1461
1462 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1463 auto total = 0.f;
1464 std::array<float, 5> sat_pool = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
1465 for(auto prov : state.world.nation_get_province_ownership(state.local_player_nation)) {
1466 for(auto pop_loc : prov.get_province().get_pop_location()) {
1467 auto pop_id = pop_loc.get_pop();
1468 if(pop_id.get_poptype() == type) {
1469 auto pop_size = state.world.pop_get_size(pop_id);
1470 sat_pool[(pop_demographics::get_luxury_needs(state, pop_id) > 0.95f) ? 4
1471 : (pop_demographics::get_everyday_needs(state, pop_id) > 0.95f) ? 3
1472 : (pop_demographics::get_life_needs(state, pop_id) > 0.95f) ? 2
1473 : (pop_demographics::get_life_needs(state, pop_id) > 0.01f) ? 1
1474 : 0] += pop_size;
1475 total += pop_size;
1476 }
1477 }
1478 }
1479
1480
1481 if(total > 0.0f) {
1482 auto type_strata = state.world.pop_type_get_strata(type);
1483 float total_pop = 0.0f;
1485 total_pop = state.world.nation_get_demographics(state.local_player_nation, demographics::poor_total);
1486 } else if(culture::pop_strata(type_strata) == culture::pop_strata::middle) {
1487 total_pop = state.world.nation_get_demographics(state.local_player_nation, demographics::middle_total);
1488 } else {
1489 total_pop = state.world.nation_get_demographics(state.local_player_nation, demographics::rich_total);
1490 }
1491
1492 {
1493 auto box = text::open_layout_box(contents, 0);
1494 text::add_to_layout_box(state, contents, box, state.world.pop_type_get_name(type));
1495 text::close_layout_box(contents, box);
1496 }
1497 {
1498 auto box = text::open_layout_box(contents, 0);
1499 text::localised_single_sub_box(state, contents, box, std::string_view("percent_of_pop_strata"), text::variable_type::val, text::fp_percentage{total / total_pop});
1500 text::add_to_layout_box(state, contents, box, std::string("("));
1501 text::add_to_layout_box(state, contents, box, text::prettify(int64_t(total_pop)));
1502 text::add_to_layout_box(state, contents, box, std::string(")"));
1503 text::close_layout_box(contents, box);
1504 //percent_of_pop_strata
1505 }
1507 static const std::string needs_types[5] = {"no_need", "some_life_needs", "life_needs", "everyday_needs", "luxury_needs"};
1508 {
1509 auto box = text::open_layout_box(contents);
1510 auto sub = text::substitution_map{};
1511 auto needs_type = text::produce_simple_string(state, "no_need");
1513 text::add_to_substitution_map(sub, text::variable_type::type, std::string_view(needs_type));
1514 text::localised_format_box(state, contents, box, "budget_strata_no_need", sub);
1515 text::close_layout_box(contents, box);
1516 }
1517 {
1518 auto box = text::open_layout_box(contents);
1519 auto sub = text::substitution_map{};
1520 auto needs_type = text::produce_simple_string(state, "some_life_needs");
1522 text::add_to_substitution_map(sub, text::variable_type::type, std::string_view(needs_type));
1523 text::localised_format_box(state, contents, box, "budget_strata_need", sub);
1524 text::close_layout_box(contents, box);
1525 }
1526 {
1527 auto box = text::open_layout_box(contents);
1528 auto sub = text::substitution_map{};
1529 auto needs_type = text::produce_simple_string(state, "life_needs");
1531 text::add_to_substitution_map(sub, text::variable_type::type, std::string_view(needs_type));
1532 text::localised_format_box(state, contents, box, "budget_strata_need", sub);
1533 text::close_layout_box(contents, box);
1534 }
1535 {
1536 auto box = text::open_layout_box(contents);
1537 auto sub = text::substitution_map{};
1538 auto needs_type = text::produce_simple_string(state, "everyday_needs");
1540 text::add_to_substitution_map(sub, text::variable_type::type, std::string_view(needs_type));
1541 text::localised_format_box(state, contents, box, "budget_strata_need", sub);
1542 text::close_layout_box(contents, box);
1543 }
1544 {
1545 auto box = text::open_layout_box(contents);
1546 auto sub = text::substitution_map{};
1547 auto needs_type = text::produce_simple_string(state, "luxury_needs");
1549 text::add_to_substitution_map(sub, text::variable_type::type, std::string_view(needs_type));
1550 text::localised_format_box(state, contents, box, "budget_strata_need", sub);
1551 text::close_layout_box(contents, box);
1552 }
1553 } else {
1554 {
1555 auto box = text::open_layout_box(contents, 0);
1556 text::add_to_layout_box(state, contents, box, state.world.pop_type_get_name(type));
1557 text::close_layout_box(contents, box);
1558 }
1560 {
1561 auto box = text::open_layout_box(contents, 0);
1562 text::localised_format_box(state, contents, box, std::string_view("no_pops_of_type"));
1563 text::close_layout_box(contents, box);
1564 }
1565 }
1566
1567 }
1568};
1569
1571private:
1573
1574public:
1575 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1576 if(name == "pop") {
1577 auto ptr = make_element_by_type<tax_list_pop_type_icon>(state, id);
1578 pop_type_icon = ptr.get();
1579 return ptr;
1580 } else {
1581 return nullptr;
1582 }
1583 }
1584
1585 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1586 if(payload.holds_type<wrapped_listbox_row_content<dcon::pop_type_id>>()) {
1587 auto pop_type_id = any_cast<wrapped_listbox_row_content<dcon::pop_type_id>>(payload).content;
1588 pop_type_icon->set_type(state, pop_type_id);
1590 }
1592 }
1593};
1594
1595template<culture::pop_strata Strata>
1596class budget_pop_tax_list : public overlapping_listbox_element_base<budget_pop_list_item, dcon::pop_type_id> {
1597protected:
1598 std::string_view get_row_element_name() override {
1599 return "pop_listitem";
1600 }
1601
1602public:
1603 void on_create(sys::state& state) noexcept override {
1605 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
1606 if(state.world.pop_type_get_strata(pt) == uint8_t(Strata)) {
1607 row_contents.push_back(pt);
1608 }
1609 });
1610 update(state);
1611 }
1612};
1613
1614template<culture::income_type Income>
1615class budget_pop_income_list : public overlapping_listbox_element_base<budget_pop_list_item, dcon::pop_type_id> {
1616protected:
1617 std::string_view get_row_element_name() override {
1618 return "pop_listitem";
1619 }
1620
1621public:
1622 void on_create(sys::state& state) noexcept override {
1624 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
1625 if(state.world.pop_type_get_life_needs_income_type(pt) == uint8_t(Income) ||
1626 state.world.pop_type_get_everyday_needs_income_type(pt) == uint8_t(Income) ||
1627 state.world.pop_type_get_luxury_needs_income_type(pt) == uint8_t(Income)) {
1628 row_contents.push_back(pt);
1629 }
1630 });
1631 update(state);
1632 }
1633};
1634
1635template<culture::income_type Income>
1637protected:
1638 std::string_view get_row_element_name() override {
1639 return "pop_listitem_small";
1640 }
1641};
1642
1644public:
1645 message_result set(sys::state& state, Cyto::Any& payload) noexcept override {
1646 if(payload.holds_type<budget_slider_signal>()) {
1647 auto sig = any_cast<budget_slider_signal>(payload);
1648 if(sig.target == budget_slider_target::tariffs) {
1650 }
1652 }
1654 }
1655
1656 void on_update(sys::state& state) noexcept override {
1657 auto nation_id = retrieve<dcon::nation_id>(state, parent);
1658 set_text(state, text::format_percentage(float(state.world.nation_get_tariffs(nation_id)) / 100.0f));
1659 }
1660};
1661
1662class debt_piechart : public piechart<dcon::nation_id> {
1663public:
1664 void on_update(sys::state& state) noexcept override {
1665 distribution.clear();
1666 auto t = state.world.nation_get_stockpiles(state.local_player_nation, economy::money);
1667
1668 if(t < 0.0f) {
1669 int32_t num_gp = 7;
1670 if(t <= 1000.0f) {
1671 num_gp = 1;
1672 } else if(t <= 2000.0f) {
1673 num_gp = 2;
1674 } else if(t <= 4000.0f) {
1675 num_gp = 4;
1676 }
1677
1678 float share = 10.0f;
1679 for(auto n : state.nations_by_rank) {
1680 if(state.world.nation_get_is_great_power(n) && n != state.local_player_nation) {
1681 distribution.emplace_back(n, share);
1682 share -= 1.0f;
1683
1684 --num_gp;
1685 if(num_gp <= 0)
1686 break;
1687 }
1688 }
1689 }
1691 }
1692};
1693
1695 dcon::nation_id n;
1696 float amount;
1697
1698 bool operator==(debt_item_data o) const noexcept {
1699 return n == o.n && amount == o.amount;
1700 }
1701 bool operator!=(debt_item_data o) const noexcept {
1702 return !(*this == o);
1703 }
1704};
1705
1707public:
1708 void on_update(sys::state& state) noexcept override {
1709 debt_item_data dat = retrieve< debt_item_data>(state, parent);
1711 }
1712};
1713
1715public:
1716 void on_update(sys::state& state) noexcept override {
1717 debt_item_data dat = retrieve< debt_item_data>(state, parent);
1719 }
1720};
1721
1722
1723class debt_item : public listbox_row_element_base<debt_item_data> {
1724public:
1725 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1726 if(name == "who") {
1727 return make_element_by_type<debtor_name>(state, id);
1728 } else if(name == "debt") {
1729 return make_element_by_type<debtor_amount>(state, id);
1730 } else {
1731 return nullptr;
1732 }
1733 }
1734};
1735
1736class debt_listbox : public listbox_element_base<debt_item, debt_item_data> {
1737protected:
1738 std::string_view get_row_element_name() override {
1739 return "debt_listitem";
1740 }
1741
1742public:
1743 void on_update(sys::state& state) noexcept override {
1744 row_contents.clear();
1745
1746 auto t = state.world.nation_get_stockpiles(state.local_player_nation, economy::money);
1747
1748 if(t < 0.0f) {
1749 int32_t num_gp = 7;
1750 if(t <= 1000.0f) {
1751 num_gp = 1;
1752 } else if(t <= 2000.0f) {
1753 num_gp = 2;
1754 } else if(t <= 4000.0f) {
1755 num_gp = 4;
1756 }
1757
1758 float share = 10.0f;
1759 float total_shares = 0.0f;
1760 for(auto n : state.nations_by_rank) {
1761 if(state.world.nation_get_is_great_power(n) && n != state.local_player_nation) {
1762 row_contents.push_back(debt_item_data{n, share});
1763 total_shares += share;
1764 share -= 1.0f;
1765
1766 --num_gp;
1767 if(num_gp <= 0)
1768 break;
1769 }
1770 }
1771
1772 for(auto& r : row_contents) {
1773 r.amount = -t * r.amount / total_shares;
1774 }
1775 }
1776
1777 update(state);
1778 }
1779};
1780
1782public:
1783 void on_update(sys::state& state) noexcept override {
1784 frame = state.world.nation_get_is_debt_spending(state.local_player_nation) ? 1 : 0;
1785 disabled = false;
1786
1787 auto last_br = state.world.nation_get_bankrupt_until(state.local_player_nation);
1788 if(last_br && state.current_date < last_br)
1789 disabled = true;
1790 if(economy::max_loan(state, state.local_player_nation) <= 0.0f)
1791 disabled = true;
1792 }
1793 void button_action(sys::state& state) noexcept override {
1794 command::enable_debt(state, state.local_player_nation, !state.world.nation_get_is_debt_spending(state.local_player_nation));
1795 }
1798 }
1799
1800 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1801 auto last_br = state.world.nation_get_bankrupt_until(state.local_player_nation);
1802 if(last_br && state.current_date < last_br) {
1803 text::add_line(state, contents, "alice_currently_bankrupt", text::variable_type::x, last_br);
1804 } else if(economy::max_loan(state, state.local_player_nation) <= 0.0f) {
1805 text::add_line(state, contents, "alice_no_loans_possible");
1806 } else {
1807 text::add_line(state, contents, "alice_debt_spending");
1809 text::add_line(state, contents, "alice_loan_size", text::variable_type::x, text::fp_currency{ economy::max_loan(state, state.local_player_nation) });
1810 }
1811 }
1812};
1813
1814class domestic_investment_slider : public budget_slider<budget_slider_target::domestic_investment, slider_scaling::quadratic> {
1815 int32_t get_true_value(sys::state& state) noexcept override {
1816 return int32_t(state.world.nation_get_domestic_investment_spending(state.local_player_nation));
1817 }
1818 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1820 }
1821 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1822 auto n = retrieve<dcon::nation_id>(state, parent);
1823 auto box = text::open_layout_box(contents, 0);
1824 text::localised_single_sub_box(state, contents, box, "alice_budget_setting_percent", text::variable_type::perc, text::int_percentage{ state.world.nation_get_domestic_investment_spending(n) });
1826 text::close_layout_box(contents, box);
1827
1828 text::add_line(state, contents, "alice_domestic_investment_pops", text::variable_type::x, text::pretty_integer{ int32_t(state.world.nation_get_demographics(n, demographics::to_key(state, state.culture_definitions.capitalists)) + state.world.nation_get_demographics(n, demographics::to_key(state, state.culture_definitions.aristocrat))) });
1829 text::add_line(state, contents, "alice_domestic_investment_needs", text::variable_type::x, text::fp_currency{ state.world.nation_get_luxury_needs_costs(n, state.culture_definitions.capitalists) });
1830 }
1831};
1833public:
1834 void on_update(sys::state& state) noexcept override {
1835 float value = state.world.nation_get_domestic_investment_spending(state.local_player_nation) / 100.0f;
1836 set_text(state, text::format_money(economy::estimate_domestic_investment(state, state.local_player_nation) * value * value));
1837 }
1838};
1839
1840// overseas_maintenance
1841
1842
1843class overseas_maintenance_slider : public budget_slider<budget_slider_target::overseas, slider_scaling::linear> {
1844 int32_t get_true_value(sys::state& state) noexcept override {
1845 return int32_t(state.world.nation_get_overseas_spending(state.local_player_nation));
1846 }
1847 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
1849 }
1850 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1851 auto n = retrieve<dcon::nation_id>(state, parent);
1852 auto box = text::open_layout_box(contents, 0);
1853 text::close_layout_box(contents, box);
1854 }
1855};
1857public:
1858 void on_update(sys::state& state) noexcept override {
1859 float value = state.world.nation_get_overseas_spending(state.local_player_nation) / 100.0f;
1861 }
1862};
1863
1865private:
1866 budget_take_loan_window* budget_take_loan_win = nullptr;
1867 budget_repay_loan_window* budget_repay_loan_win = nullptr;
1868
1869public:
1870 void on_create(sys::state& state) noexcept override {
1872
1873 auto win1337 = make_element_by_type<budget_take_loan_window>(state, state.ui_state.defs_by_name.find(state.lookup_key("take_loan_window"))->second.definition);
1874 budget_take_loan_win = win1337.get();
1875 win1337->base_data.position.y -= 66; // Nudge >w<
1876 win1337->set_visible(state, false);
1877 add_child_to_front(std::move(win1337));
1878
1879 auto win101 = make_element_by_type<budget_repay_loan_window>(state, state.ui_state.defs_by_name.find(state.lookup_key("repay_loan_window"))->second.definition);
1880 budget_repay_loan_win = win101.get();
1881 win101->base_data.position.y -= 66; // Nudge >w<
1882 win101->set_visible(state, false);
1883 add_child_to_front(std::move(win101));
1884
1885 {
1886 auto elm = make_element_by_type<enable_debt_toggle>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_debt_checkbox"))->second.definition);
1887 add_child_to_front(std::move(elm));
1888 }
1889
1890 {
1891 auto elm = make_element_by_type<domestic_investment_slider>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_domestic_investment_slider"))->second.definition);
1892 add_child_to_front(std::move(elm));
1893 }
1894 {
1895 auto elm = make_element_by_type<simple_text_element_base>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_domestic_investment_label"))->second.definition);
1896 add_child_to_front(std::move(elm));
1897 }
1898 {
1899 auto elm = make_element_by_type<domestic_investment_estimated_text>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_domestic_investment_value"))->second.definition);
1900 add_child_to_front(std::move(elm));
1901 }
1902
1903 {
1904 auto elm = make_element_by_type<overseas_maintenance_slider>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_overseas_maintenance_slider"))->second.definition);
1905 add_child_to_front(std::move(elm));
1906 }
1907 {
1908 auto elm = make_element_by_type<simple_text_element_base>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_overseas_maintenance_label"))->second.definition);
1909 add_child_to_front(std::move(elm));
1910 }
1911 {
1912 auto elm = make_element_by_type<overseas_maintenance_estimated_text>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_overseas_maintenance_value"))->second.definition);
1913 add_child_to_front(std::move(elm));
1914 }
1915
1916 set_visible(state, false);
1917 }
1918
1919 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1920 if(name == "main_bg") {
1921 return make_element_by_type<image_element_base>(state, id);
1922 } else if(name == "bg_budget") {
1923 return make_element_by_type<opaque_element_base>(state, id);
1924 } else if(name == "tariff_mid") {
1925 return make_element_by_type<invisible_element>(state, id);
1926 } else if(name == "close_button") {
1927 return make_element_by_type<generic_close_button>(state, id);
1928 } else if(name == "tariffs_percent") {
1929 auto ptr = make_element_by_type<budget_tariff_percentage_text>(state, id);
1930 ptr->base_data.position.x += int16_t(10); //nudge
1931 return ptr;
1932 } else if(name == "total_funds_val") {
1933 return make_element_by_type<nation_budget_funds_text>(state, id);
1934 } else if(name == "national_bank_val") {
1935 return make_element_by_type<nation_budget_bank_text>(state, id);
1936 } else if(name == "debt_val") {
1937 return make_element_by_type<nation_budget_debt_text>(state, id);
1938 } else if(name == "interest_val") {
1939 return make_element_by_type<nation_budget_interest_text>(state, id);
1940 } else if(name == "tab_takenloans") {
1941 return make_element_by_type<invisible_element>(state, id);
1942 } else if(name == "tab_givenloans") {
1943 return make_element_by_type<invisible_element>(state, id);
1944 } else if(name == "givenloans_text") {
1945 return make_element_by_type<invisible_element>(state, id);
1946 } else if(name == "take_loan") {
1947 return make_element_by_type<invisible_element>(state, id);
1948 } else if(name == "repay_loan") {
1949 return make_element_by_type<invisible_element>(state, id);
1950 } else if(name == "gunboat_alert") {
1951 return make_element_by_type<invisible_element>(state, id);
1952 } else if(name == "chart_debt") {
1953 return make_element_by_type<debt_piechart>(state, id);
1954 } else if(name == "debt_listbox") {
1955 return make_element_by_type<debt_listbox>(state, id);
1956 } else if(name == "chart_0") {
1957 return make_element_by_type<satisfaction_graph<culture::pop_strata::poor>>(state, id);
1958 } else if(name == "chart_1") {
1959 return make_element_by_type<satisfaction_graph<culture::pop_strata::middle>>(state, id);
1960 } else if(name == "chart_2") {
1961 return make_element_by_type<satisfaction_graph<culture::pop_strata::rich>>(state, id);
1962 } else if(name == "overlay_0" || name == "overlay_1" || name == "overlay_2") {
1963 return make_element_by_type<invisible_element>(state, id);
1964 } else if(name == "nat_stock_val") {
1965 auto ptr = make_element_by_type<budget_actual_stockpile_spending_text>(state, id);
1966 ptr->expense = true;
1967 return ptr;
1968 } else if(name == "nat_stock_est") {
1969 auto ptr = make_element_by_type<budget_estimated_stockpile_spending_text>(state, id);
1970 ptr->expense = true;
1971 return ptr;
1972 } else if(name == "mil_cost_val") {
1973 auto ptr = make_element_by_type<budget_military_spending_text>(state, id);
1974 ptr->expense = true;
1975 return ptr;
1976 } else if(name == "overseas_cost_val") {
1977 auto ptr = make_element_by_type<budget_overseas_spending_text>(state, id);
1978 ptr->expense = true;
1979 return ptr;
1980 } else if(name == "tariff_val") {
1981 return make_element_by_type<budget_tariff_income_text>(state, id);
1982 } else if(name == "gold_inc") {
1983 return make_element_by_type<nation_gold_income_text>(state, id);
1984 } else if(name == "tax_0_inc") {
1985 return make_element_by_type<budget_stratified_tax_income_text<culture::pop_strata::poor, budget_slider_target::poor_tax>>( state, id);
1986 } else if(name == "tax_1_inc") {
1987 return make_element_by_type<budget_stratified_tax_income_text<culture::pop_strata::middle, budget_slider_target::middle_tax>>(state, id);
1988 } else if(name == "tax_2_inc") {
1989 return make_element_by_type<budget_stratified_tax_income_text<culture::pop_strata::rich, budget_slider_target::rich_tax>>( state, id);
1990 } else if(name == "exp_val_0") {
1991 auto ptr = make_element_by_type<budget_expenditure_text<culture::income_type::education, budget_slider_target::education>>( state, id);
1992 ptr->expense = true;
1993 return ptr;
1994 } else if(name == "exp_val_1") {
1995 auto ptr = make_element_by_type<budget_expenditure_text<culture::income_type::administration, budget_slider_target::admin>>(state, id);
1996 ptr->expense = true;
1997 return ptr;
1998 } else if(name == "exp_val_2") {
1999 auto ptr = make_element_by_type<budget_social_spending_text>(state, id);
2000 ptr->expense = true;
2001 return ptr;
2002 } else if(name == "exp_val_3") {
2003 auto ptr = make_element_by_type<budget_expenditure_text<culture::income_type::military, budget_slider_target::military>>(state, id);
2004 ptr->expense = true;
2005 return ptr;
2006 } else if(name == "admin_efficiency") {
2007 return make_element_by_type<nation_administrative_efficiency_text>(state, id);
2008 } else if(name == "interest_val") {
2009 return make_element_by_type<nation_loan_spending_text>(state, id);
2010 } else if(name == "ind_sub_val") {
2011 return make_element_by_type<nation_subsidy_spending_text>(state, id);
2012 } else if(name == "diplomatic_balance") {
2013 return make_element_by_type<nation_diplomatic_balance_text>(state, id);
2014 } else if(name == "total_inc") {
2015 return make_element_by_type<budget_income_projection_text>(state, id);
2016 } else if(name == "total_exp") {
2017 auto ptr = make_element_by_type<budget_expenditure_projection_text>(state, id);
2018 ptr->expense = true;
2019 return ptr;
2020 } else if(name == "balance") {
2021 return make_element_by_type<budget_balance_projection_text>(state, id);
2022 } else if(name == "tax_0_slider") {
2023 return make_element_by_type<budget_poor_tax_slider>(state, id);
2024 } else if(name == "tax_1_slider") {
2025 return make_element_by_type<budget_middle_tax_slider>(state, id);
2026 } else if(name == "tax_2_slider") {
2027 return make_element_by_type<budget_rich_tax_slider>(state, id);
2028 } else if(name == "land_stockpile_slider") {
2029 return make_element_by_type<budget_army_stockpile_slider>(state, id);
2030 } else if(name == "naval_stockpile_slider") {
2031 return make_element_by_type<budget_navy_stockpile_slider>(state, id);
2032 } else if(name == "projects_stockpile_slider") {
2033 return make_element_by_type<budget_construction_stockpile_slider>(state, id);
2034 } else if(name == "exp_0_slider") {
2035 return make_element_by_type<budget_education_slider>(state, id);
2036 } else if(name == "exp_1_slider") {
2037 return make_element_by_type<budget_administration_slider>(state, id);
2038 } else if(name == "exp_2_slider") {
2039 return make_element_by_type<budget_social_spending_slider>(state, id);
2040 } else if(name == "exp_3_slider") {
2041 return make_element_by_type<budget_military_spending_slider>(state, id);
2042 } else if(name == "tariff_slider") {
2043 return make_element_by_type<budget_tariff_slider>(state, id);
2044 } else if(name == "take_loan") {
2045 return make_element_by_type<budget_take_loan_button>(state, id);
2046 } else if(name == "repay_loan") {
2047 return make_element_by_type<budget_repay_loan_button>(state, id);
2048 } else if(name == "tax_0_pops") {
2049 return make_element_by_type<budget_pop_tax_list<culture::pop_strata::poor>>(state, id);
2050 } else if(name == "tax_1_pops") {
2051 return make_element_by_type<budget_pop_tax_list<culture::pop_strata::middle>>(state, id);
2052 } else if(name == "tax_2_pops") {
2053 return make_element_by_type<budget_pop_tax_list<culture::pop_strata::rich>>(state, id);
2054 } else if(name == "exp_0_pops") {
2055 return make_element_by_type<budget_small_pop_income_list<culture::income_type::education>>(state, id);
2056 } else if(name == "exp_1_pops") {
2057 return make_element_by_type<budget_small_pop_income_list<culture::income_type::administration>>(state, id);
2058 // } else if(name == "exp_2_pops") { // intentionally unused
2059 // return make_element_by_type<budget_pop_income_list<culture::income_type::reforms>>(state, id);
2060 } else if(name == "exp_3_pops") {
2061 return make_element_by_type<budget_pop_income_list<culture::income_type::military>>(state, id);
2062 } else {
2063 return nullptr;
2064 }
2065 }
2066
2067 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
2068 if(payload.holds_type<dcon::nation_id>()) {
2069 payload.emplace<dcon::nation_id>(state.local_player_nation);
2071 }
2072 //=====================================================================
2073 else if(payload.holds_type<element_selection_wrapper<bool>>()) {
2074 bool type = any_cast<element_selection_wrapper<bool>>(payload).data;
2075 if(type) { // Take Loan Win.
2076 budget_take_loan_win->set_visible(state, true);
2077 move_child_to_front(budget_take_loan_win);
2078 } else { // Repay Loan Win.
2079 budget_repay_loan_win->set_visible(state, true);
2080 move_child_to_front(budget_repay_loan_win);
2081 }
2083 } else if(payload.holds_type<budget_slider_signal>()) {
2084 impl_set(state, payload);
2085 }
2086
2088 }
2089};
2090
2091} // namespace ui
dcon::text_key get_name() noexcept
void set_name(dcon::text_key text) noexcept
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void on_create(sys::state &state) noexcept override
std::string_view get_row_element_name() 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::string_view get_row_element_name() override
void on_create(sys::state &state) noexcept override
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
message_result set(sys::state &state, Cyto::Any &payload) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
virtual void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept
void apply_multipliers(sys::state &state) noexcept
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept final
void on_create(sys::state &state) noexcept final
virtual int32_t get_true_value(sys::state &state) noexcept
void on_value_change(sys::state &state, int32_t v) noexcept final
void on_drag_finish(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
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 put_values(sys::state &state, std::array< float, size_t(budget_slider_target::target_count)> &vals) noexcept override
void on_update(sys::state &state) noexcept override
message_result set(sys::state &state, Cyto::Any &payload) 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
void on_create(sys::state &state) noexcept override
message_result impl_set(sys::state &state, Cyto::Any &payload) noexcept final
void add_child_to_back(std::unique_ptr< element_base > child) noexcept final
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
void move_child_to_front(element_base *child) noexcept final
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
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
message_result impl_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_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void button_action(sys::state &state) noexcept override
const uint32_t count
void set_data_points(sys::state &state, std::vector< float > const &datapoints) noexcept
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_update(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void populate_tooltip(sys::state &state, dcon::pop_satisfaction_wrapper_id psw, float percentage, text::columnar_layout &contents) 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
image_element_base * right_limit
scrollbar_slider * slider
void change_settings(sys::state &state, mutable_scrollbar_settings const &settings_s)
scrollbar_settings settings
scrollbar_right * right
scrollbar_left * left
scrollbar_track * track
float scaled_value() const
void update_raw_value(sys::state &state, int32_t v)
image_element_base * left_limit
void set_text(sys::state &state, std::string const &new_text)
void on_update(sys::state &state) noexcept override
void set_type(sys::state &state, dcon::pop_type_id t)
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_create(sys::state &state) noexcept override
budget_settings_data make_empty_budget_settings()
Definition: commands.hpp:586
void change_budget_settings(sys::state &state, dcon::nation_id source, budget_settings_data const &values)
Definition: commands.cpp:945
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr dcon::demographics_key middle_total(21)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
constexpr dcon::demographics_key rich_total(22)
constexpr dcon::demographics_key poor_total(20)
float estimate_reparations_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4655
float estimate_subsidy_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4641
float estimate_social_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4576
float estimate_tariff_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4572
float estimate_diplomatic_balance(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4700
float estimate_pop_payouts_by_income_type(sys::state &state, dcon::nation_id n, culture::income_type in)
Definition: economy.cpp:4602
float estimate_domestic_investment(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4706
float estimate_overseas_penalty_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:2354
float max_loan(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:73
float estimate_construction_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4740
float estimate_war_subsidies_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4645
float estimate_land_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4720
constexpr dcon::commodity_id money(0)
float estimate_war_subsidies_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4671
float estimate_reparations_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4683
float estimate_naval_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4730
float estimate_tax_income_by_strata(sys::state &state, dcon::nation_id n, culture::pop_strata ps)
Definition: economy.cpp:4629
float estimate_stockpile_filling_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:2339
province_building_type
Definition: constants.hpp:578
float interest_payment(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:62
float estimate_gold_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4558
Definition: color.hpp:6
uint32_t get_ui_color(sys::state &state, T id)
Definition: color.hpp:52
float get_luxury_needs(sys::state const &state, dcon::pop_id p)
float get_life_needs(sys::state const &state, dcon::pop_id p)
float get_everyday_needs(sys::state const &state, dcon::pop_id p)
Definition: prng.cpp:6
uint32_t pack_color(float r, float g, float b)
Definition: bmfont.cpp:118
void add_line_break_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1147
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
std::string format_money(float num)
Definition: text.cpp:1029
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
void localised_single_sub_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, variable_type subkey, substitution value)
Definition: text.cpp:1888
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1880
std::string prettify(int64_t num)
Definition: text.cpp:762
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
Definition: text.cpp:1152
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
Definition: text.cpp:1068
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
Definition: text.hpp:794
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
dcon::text_key get_name(sys::state &state, dcon::nation_id id)
Definition: text.cpp:880
std::string format_percentage(float num, size_t digits)
Definition: text.cpp:977
dcon::text_key find_or_add_key(sys::state &state, std::string_view key, bool as_unicode)
Definition: text.cpp:695
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
message_result
void active_modifiers_description(sys::state &state, text::layout_base &layout, dcon::nation_id n, int32_t identation, dcon::national_modifier_value nmid, bool header)
uint uint32_t
uchar uint8_t
static constexpr uint32_t set_size
budget_slider_target target
bool operator==(debt_item_data o) const noexcept
bool operator!=(debt_item_data o) const noexcept
element_type get_element_type() const
union ui::element_data::internal_data data
bool is_horizontal() const
step_size get_step_size() const
dcon::gui_def_id first_child
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name
element_base * drag_target