Skip to content

Commit

Permalink
Add Budget Menu behaviour script
Browse files Browse the repository at this point in the history
  • Loading branch information
Hop311 committed Feb 27, 2025
1 parent 9e5fc1b commit 9ee9151
Show file tree
Hide file tree
Showing 18 changed files with 1,709 additions and 263 deletions.
20 changes: 20 additions & 0 deletions extension/doc_classes/GFXPieChartTexture.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,25 @@
<description>
</description>
</method>
<method name="slice_colour_key" qualifiers="static">
<return type="StringName" />
<description>
</description>
</method>
<method name="slice_identifier_key" qualifiers="static">
<return type="StringName" />
<description>
</description>
</method>
<method name="slice_tooltip_key" qualifiers="static">
<return type="StringName" />
<description>
</description>
</method>
<method name="slice_weight_key" qualifiers="static">
<return type="StringName" />
<description>
</description>
</method>
</methods>
</class>
2 changes: 2 additions & 0 deletions extension/doc_classes/GUINode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<method name="float_to_string_suffixed" qualifiers="static">
<return type="String" />
<param index="0" name="val" type="float" />
<param index="1" name="post_number_string" type="String" default="&quot;&quot;" />
<description>
</description>
</method>
Expand Down Expand Up @@ -336,6 +337,7 @@
<method name="int_to_string_suffixed" qualifiers="static">
<return type="String" />
<param index="0" name="val" type="int" />
<param index="1" name="post_number_string" type="String" default="&quot;&quot;" />
<description>
</description>
</method>
Expand Down
20 changes: 20 additions & 0 deletions extension/doc_classes/MenuSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@
<description>
</description>
</method>
<method name="get_budget_menu_info" qualifiers="const">
<return type="Dictionary" />
<param index="0" name="strata_tax_sliders" type="GUIScrollbar[]" />
<param index="1" name="land_spending_slider" type="GUIScrollbar" />
<param index="2" name="naval_spending_slider" type="GUIScrollbar" />
<param index="3" name="construction_spending_slider" type="GUIScrollbar" />
<param index="4" name="education_spending_slider" type="GUIScrollbar" />
<param index="5" name="administration_spending_slider" type="GUIScrollbar" />
<param index="6" name="social_spending_slider" type="GUIScrollbar" />
<param index="7" name="military_spending_slider" type="GUIScrollbar" />
<param index="8" name="tariff_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="get_budget_menu_setup_info" qualifiers="const">
<return type="Dictionary" />
<param index="0" name="tariff_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="get_country_adjective_from_identifier" qualifiers="const">
<return type="String" />
<param index="0" name="country_identifier" type="String" />
Expand Down
55 changes: 55 additions & 0 deletions extension/doc_classes/PlayerSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<description>
</description>
</method>
<method name="set_administration_spending_slider_value">
<return type="void" />
<param index="0" name="administration_spending_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="set_auto_assign_leaders" qualifiers="const">
<return type="void" />
<param index="0" name="value" type="bool" />
Expand All @@ -58,6 +64,18 @@
<description>
</description>
</method>
<method name="set_construction_spending_slider_value">
<return type="void" />
<param index="0" name="construction_spending_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="set_education_spending_slider_value">
<return type="void" />
<param index="0" name="education_spending_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="set_good_automated" qualifiers="const">
<return type="void" />
<param index="0" name="good_index" type="int" />
Expand All @@ -73,12 +91,30 @@
<description>
</description>
</method>
<method name="set_land_spending_slider_value">
<return type="void" />
<param index="0" name="land_spending_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="set_military_spending_slider_value">
<return type="void" />
<param index="0" name="military_spending_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="set_mobilise" qualifiers="const">
<return type="void" />
<param index="0" name="value" type="bool" />
<description>
</description>
</method>
<method name="set_naval_spending_slider_value">
<return type="void" />
<param index="0" name="naval_spending_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="set_player_country_by_province_index">
<return type="void" />
<param index="0" name="province_index" type="int" />
Expand All @@ -91,6 +127,25 @@
<description>
</description>
</method>
<method name="set_social_spending_slider_value">
<return type="void" />
<param index="0" name="social_spending_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="set_strata_tax_slider_value">
<return type="void" />
<param index="0" name="strata" type="int" />
<param index="1" name="tax_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="set_tariff_rate_slider_value">
<return type="void" />
<param index="0" name="tariff_rate_slider" type="GUIScrollbar" />
<description>
</description>
</method>
<method name="toggle_paused" qualifiers="const">
<return type="void" />
<description>
Expand Down
21 changes: 13 additions & 8 deletions extension/src/openvic-extension/classes/GFXPieChartTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ using namespace godot;
using namespace OpenVic;
using namespace OpenVic::Utilities::literals;

StringName const& GFXPieChartTexture::_slice_identifier_key() {
StringName const& GFXPieChartTexture::slice_identifier_key() {
static const StringName slice_identifier_key = "identifier";
return slice_identifier_key;
}
StringName const& GFXPieChartTexture::_slice_tooltip_key() {
StringName const& GFXPieChartTexture::slice_tooltip_key() {
static const StringName slice_tooltip_key = "tooltip";
return slice_tooltip_key;
}
StringName const& GFXPieChartTexture::_slice_colour_key() {
StringName const& GFXPieChartTexture::slice_colour_key() {
static const StringName slice_colour_key = "colour";
return slice_colour_key;
}
StringName const& GFXPieChartTexture::_slice_weight_key() {
StringName const& GFXPieChartTexture::slice_weight_key() {
static const StringName slice_weight_key = "weight";
return slice_weight_key;
}
Expand Down Expand Up @@ -117,13 +117,13 @@ Error GFXPieChartTexture::set_slices_array(godot_pie_chart_data_t const& new_sli
for (int32_t i = 0; i < new_slices.size(); ++i) {
Dictionary const& slice_dict = new_slices[i];
ERR_CONTINUE_MSG(
!slice_dict.has(_slice_identifier_key()) || !slice_dict.has(_slice_tooltip_key()) ||
!slice_dict.has(_slice_colour_key()) || !slice_dict.has(_slice_weight_key()),
!slice_dict.has(slice_identifier_key()) || !slice_dict.has(slice_tooltip_key()) ||
!slice_dict.has(slice_colour_key()) || !slice_dict.has(slice_weight_key()),
vformat("Invalid slice keys at index %d", i)
);
const slice_t slice {
slice_dict[_slice_identifier_key()], slice_dict[_slice_tooltip_key()], slice_dict[_slice_colour_key()],
slice_dict[_slice_weight_key()]
slice_dict[slice_identifier_key()], slice_dict[slice_tooltip_key()], slice_dict[slice_colour_key()],
slice_dict[slice_weight_key()]
};
if (slice.weight > 0.0f) {
total_weight += slice.weight;
Expand All @@ -134,6 +134,11 @@ Error GFXPieChartTexture::set_slices_array(godot_pie_chart_data_t const& new_sli
}

void GFXPieChartTexture::_bind_methods() {
OV_BIND_SMETHOD(slice_identifier_key);
OV_BIND_SMETHOD(slice_tooltip_key);
OV_BIND_SMETHOD(slice_colour_key);
OV_BIND_SMETHOD(slice_weight_key);

OV_BIND_METHOD(GFXPieChartTexture::clear);

OV_BIND_METHOD(GFXPieChartTexture::set_gfx_pie_chart_name, { "gfx_pie_chart_name" });
Expand Down
18 changes: 9 additions & 9 deletions extension/src/openvic-extension/classes/GFXPieChartTexture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ namespace OpenVic {
float weight;
};

static godot::StringName const& slice_identifier_key();
static godot::StringName const& slice_tooltip_key();
static godot::StringName const& slice_colour_key();
static godot::StringName const& slice_weight_key();

private:
GFX::PieChart const* PROPERTY(gfx_pie_chart, nullptr);
std::vector<slice_t> slices;
float PROPERTY(total_weight, 0.0f);
godot::Ref<godot::Image> pie_chart_image;

static godot::StringName const& _slice_identifier_key();
static godot::StringName const& _slice_tooltip_key();
static godot::StringName const& _slice_colour_key();
static godot::StringName const& _slice_weight_key();

godot::Error _generate_pie_chart_image();

public:
Expand Down Expand Up @@ -98,10 +98,10 @@ namespace OpenVic {
for (size_t index = 0; index < array.size(); ++index) {
auto const& [key, value] = sorted_distribution[index];
Dictionary sub_dict;
sub_dict[_slice_identifier_key()] = Utilities::std_to_godot_string(key->get_identifier());
sub_dict[_slice_tooltip_key()] = make_tooltip(key, value, total_weight);
sub_dict[_slice_colour_key()] = Utilities::to_godot_color(key->get_colour());
sub_dict[_slice_weight_key()] = value;
sub_dict[slice_identifier_key()] = Utilities::std_to_godot_string(key->get_identifier());
sub_dict[slice_tooltip_key()] = make_tooltip(key, value, total_weight);
sub_dict[slice_colour_key()] = Utilities::to_godot_color(key->get_colour());
sub_dict[slice_weight_key()] = value;
array[index] = std::move(sub_dict);
}
return array;
Expand Down
12 changes: 6 additions & 6 deletions extension/src/openvic-extension/classes/GUINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ void GUINode::_bind_methods() {
OV_BIND_METHOD(GUINode::remove_node, { "path" });
OV_BIND_METHOD(GUINode::remove_nodes, { "paths" });

OV_BIND_SMETHOD(int_to_string_suffixed, { "val" });
OV_BIND_SMETHOD(int_to_string_suffixed, { "val", "post_number_string" }, DEFVAL(String {}));
OV_BIND_SMETHOD(int_to_string_commas, { "val" });
OV_BIND_SMETHOD(float_to_string_suffixed, { "val" });
OV_BIND_SMETHOD(float_to_string_suffixed, { "val", "post_number_string" }, DEFVAL(String {}));
OV_BIND_SMETHOD(float_to_string_dp, { "val", "decimal_places" });
OV_BIND_SMETHOD(float_to_string_dp_dynamic, { "val" });
OV_BIND_SMETHOD(format_province_name, { "province_identifier", "ignore_empty" }, DEFVAL(false));
Expand Down Expand Up @@ -235,16 +235,16 @@ Error GUINode::remove_nodes(TypedArray<NodePath> const& paths) const {
return ret;
}

String GUINode::int_to_string_suffixed(int64_t val) {
return Utilities::int_to_string_suffixed(val);
String GUINode::int_to_string_suffixed(int64_t val, String const& post_number_string) {
return Utilities::int_to_string_suffixed(val, post_number_string);
}

String GUINode::int_to_string_commas(int64_t val) {
return Utilities::int_to_string_commas(val);
}

String GUINode::float_to_string_suffixed(float val) {
return Utilities::float_to_string_suffixed(val);
String GUINode::float_to_string_suffixed(float val, String const& post_number_string) {
return Utilities::float_to_string_suffixed(val, post_number_string);
}

String GUINode::float_to_string_dp(float val, int32_t decimal_places) {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/openvic-extension/classes/GUINode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ namespace OpenVic {
godot::Error remove_node(godot::NodePath const& path) const;
godot::Error remove_nodes(godot::TypedArray<godot::NodePath> const& paths) const;

static godot::String int_to_string_suffixed(int64_t val);
static godot::String int_to_string_suffixed(int64_t val, godot::String const& post_number_string = {});
static godot::String int_to_string_commas(int64_t val);
static godot::String float_to_string_suffixed(float val);
static godot::String float_to_string_suffixed(float val, godot::String const& post_number_string = {});
static godot::String float_to_string_dp(float val, int32_t decimal_places);
// 3dp if abs(val) < 2 else 2dp if abs(val) < 10 else 1dp
static godot::String float_to_string_dp_dynamic(float val);
Expand Down
Loading

0 comments on commit 9ee9151

Please sign in to comment.