Skip to content

Commit b32d246

Browse files
authored
Merge pull request #592 from OpenVicProject/ui_for_budget_cuts
UI for budget cuts
2 parents a5ddb8a + decbe2e commit b32d246

File tree

12 files changed

+111
-41
lines changed

12 files changed

+111
-41
lines changed

extension/src/openvic-extension/components/budget/AdministrationBudget.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ AdministrationBudget::AdministrationBudget(
3838
"ADMINISTRATION","ADM_DESC"
3939
);
4040

41-
if (budget_label != nullptr) {
42-
budget_label->set_tooltip_string(
43-
Utilities::format(
44-
"%s\n--------------\n%s",
45-
budget_label->tr("DIST_ADMINISTRATION"),
46-
budget_label->tr("ADM_DESC")
47-
)
48-
);
49-
}
50-
5141
administrative_efficiency_tooltip_args.resize(7);
5242
administrative_efficiency_tooltip_args[1] = administrative_efficiency_label.tr("BUDGET_ADMIN_EFFICIENCY_DESC2");
5343
administrative_efficiency_tooltip_args[4] = administrative_efficiency_label.tr("ADM_EXPLAIN_DESC");
@@ -57,6 +47,10 @@ fixed_point_t AdministrationBudget::get_expenses() const {
5747
return std::max(fixed_point_t::_0, -get_balance());
5848
}
5949

50+
bool AdministrationBudget::was_budget_cut(CountryInstance const& country) const {
51+
return country.get_was_administration_budget_cut_yesterday();
52+
}
53+
6054
fixed_point_t AdministrationBudget::calculate_budget_and_update_custom(
6155
CountryInstance& country,
6256
const fixed_point_t scaled_value
@@ -146,6 +140,24 @@ fixed_point_t AdministrationBudget::calculate_budget_and_update_custom(
146140
administrative_efficiency_template % administrative_efficiency_tooltip_args
147141
);
148142

143+
if (budget_label != nullptr) {
144+
budget_label->set_tooltip_string(
145+
Utilities::format(
146+
"%s\n--------------\n%s%s",
147+
budget_label->tr("DIST_ADMINISTRATION"),
148+
was_budget_cut(country)
149+
? budget_label->tr("EXPENSE_NO_AFFORD").replace(
150+
Utilities::get_short_value_placeholder(),
151+
Utilities::float_to_string_dp_dynamic(
152+
country.get_actual_administration_spending().load()
153+
)
154+
) + "\n"
155+
: "",
156+
budget_label->tr("ADM_DESC")
157+
)
158+
);
159+
}
160+
149161
return scaled_value * country.get_projected_administration_spending_unscaled_by_slider_untracked();
150162
}
151163

extension/src/openvic-extension/components/budget/AdministrationBudget.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace OpenVic {
1313
CountryDefines const& country_defines;
1414
godot::Array administrative_efficiency_tooltip_args;
1515
GUILabel& administrative_efficiency_label;
16+
17+
bool was_budget_cut(CountryInstance const& country) const override;
1618
fixed_point_t calculate_budget_and_update_custom(
1719
CountryInstance& country,
1820
const fixed_point_t scaled_value

extension/src/openvic-extension/components/budget/EducationBudget.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "openvic-extension/classes/GUILabel.hpp"
66
#include "openvic-extension/classes/GUIScrollbar.hpp"
77
#include "openvic-extension/singletons/PlayerSingleton.hpp"
8+
#include "openvic-extension/utility/Utilities.hpp"
89

910
using namespace OpenVic;
1011

@@ -27,26 +28,38 @@ EducationBudget::EducationBudget(GUINode const& parent):
2728
parent, "./country_budget/education_desc",
2829
"EDUCATION","EDU_DESC"
2930
);
30-
31-
if (budget_label != nullptr) {
32-
budget_label->set_tooltip_string(
33-
Utilities::format(
34-
"%s\n--------------\n%s",
35-
budget_label->tr("DIST_EDUCATION"),
36-
budget_label->tr("EDU_DESC")
37-
)
38-
);
39-
}
4031
}
4132

4233
fixed_point_t EducationBudget::get_expenses() const {
4334
return std::max(fixed_point_t::_0, -get_balance());
4435
}
4536

37+
bool EducationBudget::was_budget_cut(CountryInstance const& country) const {
38+
return country.get_was_education_budget_cut_yesterday();
39+
}
40+
4641
fixed_point_t EducationBudget::calculate_budget_and_update_custom(
4742
CountryInstance& country,
4843
const fixed_point_t scaled_value
4944
) {
45+
if (budget_label != nullptr) {
46+
budget_label->set_tooltip_string(
47+
Utilities::format(
48+
"%s\n--------------\n%s%s",
49+
budget_label->tr("DIST_EDUCATION"),
50+
was_budget_cut(country)
51+
? budget_label->tr("EXPENSE_NO_AFFORD").replace(
52+
Utilities::get_short_value_placeholder(),
53+
Utilities::float_to_string_dp_dynamic(
54+
country.get_actual_education_spending().load()
55+
)
56+
) + "\n"
57+
: "",
58+
budget_label->tr("EDU_DESC")
59+
)
60+
);
61+
}
62+
5063
return scaled_value * country.get_projected_education_spending_unscaled_by_slider_untracked();
5164
}
5265

extension/src/openvic-extension/components/budget/EducationBudget.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace OpenVic {
77
struct EducationBudget : public SliderBudgetComponent, public BudgetExpenseComponent {
88
private:
9+
bool was_budget_cut(CountryInstance const& country) const override;
910
fixed_point_t calculate_budget_and_update_custom(
1011
CountryInstance& country,
1112
const fixed_point_t scaled_value

extension/src/openvic-extension/components/budget/MilitaryBudget.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "openvic-extension/classes/GUILabel.hpp"
66
#include "openvic-extension/classes/GUIScrollbar.hpp"
77
#include "openvic-extension/singletons/PlayerSingleton.hpp"
8+
#include "openvic-extension/utility/Utilities.hpp"
89

910
using namespace OpenVic;
1011

@@ -27,26 +28,38 @@ MilitaryBudget::MilitaryBudget(GUINode const& parent):
2728
parent, "./country_budget/mil_spend_desc",
2829
"MILITARY_SPENDING","DEFENCE_DESC"
2930
);
30-
31-
if (budget_label != nullptr) {
32-
budget_label->set_tooltip_string(
33-
Utilities::format(
34-
"%s\n--------------\n%s",
35-
budget_label->tr("DIST_DEFENCE"),
36-
budget_label->tr("DEFENCE_DESC")
37-
)
38-
);
39-
}
4031
}
4132

4233
fixed_point_t MilitaryBudget::get_expenses() const {
4334
return std::max(fixed_point_t::_0, -get_balance());
4435
}
4536

37+
bool MilitaryBudget::was_budget_cut(CountryInstance const& country) const {
38+
return country.get_was_military_budget_cut_yesterday();
39+
}
40+
4641
fixed_point_t MilitaryBudget::calculate_budget_and_update_custom(
4742
CountryInstance& country,
4843
const fixed_point_t scaled_value
4944
) {
45+
if (budget_label != nullptr) {
46+
budget_label->set_tooltip_string(
47+
Utilities::format(
48+
"%s\n--------------\n%s%s",
49+
budget_label->tr("DIST_DEFENCE"),
50+
was_budget_cut(country)
51+
? budget_label->tr("EXPENSE_NO_AFFORD").replace(
52+
Utilities::get_short_value_placeholder(),
53+
Utilities::float_to_string_dp_dynamic(
54+
country.get_actual_military_spending().load()
55+
)
56+
) + "\n"
57+
: "",
58+
budget_label->tr("DEFENCE_DESC")
59+
)
60+
);
61+
}
62+
5063
return scaled_value * country.get_projected_military_spending_unscaled_by_slider_untracked();
5164
}
5265

extension/src/openvic-extension/components/budget/MilitaryBudget.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace OpenVic {
77
struct MilitaryBudget : public SliderBudgetComponent, public BudgetExpenseComponent {
88
private:
9+
bool was_budget_cut(CountryInstance const& country) const override;
910
fixed_point_t calculate_budget_and_update_custom(
1011
CountryInstance& country,
1112
const fixed_point_t scaled_value

extension/src/openvic-extension/components/budget/SocialBudget.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "openvic-extension/classes/GUINode.hpp"
88
#include "openvic-extension/classes/GUIScrollbar.hpp"
99
#include "openvic-extension/singletons/PlayerSingleton.hpp"
10+
#include "openvic-extension/utility/Utilities.hpp"
1011

1112
using namespace OpenVic;
1213

@@ -31,26 +32,39 @@ SocialBudget::SocialBudget(GUINode const& parent):
3132
parent, "./country_budget/soc_stand_desc",
3233
"SOCIAL_SPENDING","SOCIAL_DESC2"
3334
);
34-
35-
if (budget_label != nullptr) {
36-
budget_label->set_tooltip_string(
37-
Utilities::format(
38-
"%s\n--------------\n%s",
39-
budget_label->tr("DIST_SOCIAL"),
40-
budget_label->tr("SOCIAL_DESC2")
41-
)
42-
);
43-
}
4435
}
4536

4637
fixed_point_t SocialBudget::get_expenses() const {
4738
return std::max(fixed_point_t::_0, -get_balance());
4839
}
4940

41+
bool SocialBudget::was_budget_cut(CountryInstance const& country) const {
42+
return country.get_was_social_budget_cut_yesterday();
43+
}
44+
5045
fixed_point_t SocialBudget::calculate_budget_and_update_custom(
5146
CountryInstance& country,
5247
const fixed_point_t scaled_value
5348
) {
49+
if (budget_label != nullptr) {
50+
budget_label->set_tooltip_string(
51+
Utilities::format(
52+
"%s\n--------------\n%s%s",
53+
budget_label->tr("DIST_SOCIAL"),
54+
was_budget_cut(country)
55+
? budget_label->tr("EXPENSE_NO_AFFORD").replace(
56+
Utilities::get_short_value_placeholder(),
57+
Utilities::float_to_string_dp_dynamic(
58+
country.get_actual_pensions_spending().load()
59+
+ country.get_actual_unemployment_subsidies_spending().load()
60+
)
61+
) + "\n"
62+
: "",
63+
budget_label->tr("SOCIAL_DESC2")
64+
)
65+
);
66+
}
67+
5468
const fixed_point_t pensions = scaled_value * country.get_projected_pensions_spending_unscaled_by_slider_untracked();
5569
pensions_label.set_text(
5670
Utilities::cash_to_string_dp_dynamic(pensions)

extension/src/openvic-extension/components/budget/SocialBudget.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace OpenVic {
88
private:
99
GUILabel& pensions_label;
1010
GUILabel& unemployment_subsidies_label;
11+
12+
bool was_budget_cut(CountryInstance const& country) const override;
1113
fixed_point_t calculate_budget_and_update_custom(
1214
CountryInstance& country,
1315
const fixed_point_t scaled_value

extension/src/openvic-extension/components/budget/TariffBudget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ fixed_point_t TariffBudget::get_income() const {
5454
return std::max(fixed_point_t::_0, get_balance());
5555
}
5656

57+
bool TariffBudget::was_budget_cut(CountryInstance const& country) const {
58+
return country.get_was_import_subsidies_budget_cut_yesterday();
59+
}
60+
5761
fixed_point_t TariffBudget::calculate_budget_and_update_custom(
5862
CountryInstance& country,
5963
const fixed_point_t scaled_value

extension/src/openvic-extension/components/budget/TariffBudget.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace OpenVic {
1616
private:
1717
godot::Array slider_tooltip_args;
1818

19+
bool was_budget_cut(CountryInstance const& country) const override;
1920
fixed_point_t calculate_budget_and_update_custom(
2021
CountryInstance& country,
2122
const fixed_point_t scaled_value

0 commit comments

Comments
 (0)