Skip to content

Commit

Permalink
Add military menu control script + better modifier tooltip functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hop311 committed Jan 26, 2025
1 parent f40562b commit d5e626b
Show file tree
Hide file tree
Showing 16 changed files with 1,841 additions and 91 deletions.
2 changes: 1 addition & 1 deletion extension/deps/openvic-simulation
Submodule openvic-simulation updated 33 files
+12 −25 src/openvic-simulation/InstanceManager.cpp
+72 −83 src/openvic-simulation/country/CountryInstance.cpp
+7 −4 src/openvic-simulation/country/CountryInstance.hpp
+1 −3 src/openvic-simulation/economy/production/ProductionType.cpp
+1 −1 src/openvic-simulation/economy/production/ProductionType.hpp
+23 −20 src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
+1 −1 src/openvic-simulation/interface/UI.cpp
+5 −2 src/openvic-simulation/map/Crime.cpp
+2 −2 src/openvic-simulation/map/MapDefinition.cpp
+9 −2 src/openvic-simulation/map/MapInstance.cpp
+43 −56 src/openvic-simulation/map/ProvinceInstance.cpp
+13 −27 src/openvic-simulation/map/ProvinceInstance.hpp
+39 −11 src/openvic-simulation/map/TerrainType.cpp
+25 −6 src/openvic-simulation/map/TerrainType.hpp
+1 −1 src/openvic-simulation/military/Deployment.cpp
+4 −2 src/openvic-simulation/military/UnitType.cpp
+2 −2 src/openvic-simulation/modifier/Modifier.cpp
+1 −1 src/openvic-simulation/modifier/Modifier.hpp
+9 −1 src/openvic-simulation/modifier/ModifierEffect.hpp
+0 −1 src/openvic-simulation/modifier/ModifierEffectCache.cpp
+0 −1 src/openvic-simulation/modifier/ModifierEffectCache.hpp
+3 −6 src/openvic-simulation/modifier/ModifierManager.cpp
+15 −48 src/openvic-simulation/modifier/ModifierSum.cpp
+88 −43 src/openvic-simulation/modifier/ModifierSum.hpp
+0 −11 src/openvic-simulation/modifier/ModifierValue.cpp
+0 −1 src/openvic-simulation/modifier/ModifierValue.hpp
+1 −1 src/openvic-simulation/pop/Culture.cpp
+1 −1 src/openvic-simulation/pop/PopType.cpp
+9 −15 src/openvic-simulation/research/Technology.cpp
+1 −1 src/openvic-simulation/research/Technology.hpp
+12 −0 src/openvic-simulation/types/IdentifierRegistry.hpp
+29 −13 src/openvic-simulation/types/fixed_point/FixedPoint.hpp
+3 −3 src/openvic-simulation/utility/Getters.hpp
12 changes: 12 additions & 0 deletions extension/doc_classes/AssetManager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<tutorials>
</tutorials>
<methods>
<method name="get_currency_texture" qualifiers="const">
<return type="GFXSpriteTexture" />
<param index="0" name="height" type="float" />
<description>
</description>
</method>
<method name="get_font">
<return type="FontFile" />
<param index="0" name="name" type="StringName" />
Expand All @@ -20,6 +26,12 @@
<description>
</description>
</method>
<method name="get_leader_texture">
<return type="ImageTexture" />
<param index="0" name="name" type="String" />
<description>
</description>
</method>
<method name="get_texture">
<return type="ImageTexture" />
<param index="0" name="path" type="StringName" />
Expand Down
7 changes: 7 additions & 0 deletions extension/doc_classes/GUINode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<method name="format_province_name" qualifiers="static">
<return type="String" />
<param index="0" name="province_identifier" type="String" />
<param index="1" name="ignore_empty" type="bool" default="false" />
<description>
</description>
</method>
Expand Down Expand Up @@ -223,6 +224,12 @@
<description>
</description>
</method>
<method name="int_to_string_commas" qualifiers="static">
<return type="String" />
<param index="0" name="val" type="int" />
<description>
</description>
</method>
<method name="int_to_string_suffixed" qualifiers="static">
<return type="String" />
<param index="0" name="val" type="int" />
Expand Down
31 changes: 31 additions & 0 deletions extension/doc_classes/MenuSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@
<description>
</description>
</method>
<method name="get_military_menu_info">
<return type="Dictionary" />
<param index="0" name="leader_sort_key" type="int" enum="MenuSingleton.LeaderSortKey" />
<param index="1" name="sort_leaders_descending" type="bool" />
<param index="2" name="army_sort_key" type="int" enum="MenuSingleton.UnitGroupSortKey" />
<param index="3" name="sort_armies_descending" type="bool" />
<param index="4" name="navy_sort_key" type="int" enum="MenuSingleton.UnitGroupSortKey" />
<param index="5" name="sort_navies_descending" type="bool" />
<description>
</description>
</method>
<method name="get_population_menu_distribution_info" qualifiers="const">
<return type="Array[]" />
<description>
Expand Down Expand Up @@ -326,5 +337,25 @@
</constant>
<constant name="SORT_LITERACY" value="17" enum="PopSortKey">
</constant>
<constant name="LEADER_SORT_NONE" value="0" enum="LeaderSortKey">
</constant>
<constant name="LEADER_SORT_PRESTIGE" value="1" enum="LeaderSortKey">
</constant>
<constant name="LEADER_SORT_TYPE" value="2" enum="LeaderSortKey">
</constant>
<constant name="LEADER_SORT_NAME" value="3" enum="LeaderSortKey">
</constant>
<constant name="LEADER_SORT_ASSIGNMENT" value="4" enum="LeaderSortKey">
</constant>
<constant name="MAX_LEADER_SORT_KEY" value="5" enum="LeaderSortKey">
</constant>
<constant name="UNIT_GROUP_SORT_NONE" value="0" enum="UnitGroupSortKey">
</constant>
<constant name="UNIT_GROUP_SORT_NAME" value="1" enum="UnitGroupSortKey">
</constant>
<constant name="UNIT_GROUP_SORT_STRENGTH" value="2" enum="UnitGroupSortKey">
</constant>
<constant name="MAX_UNIT_GROUP_SORT_KEY" value="3" enum="UnitGroupSortKey">
</constant>
</constants>
</class>
13 changes: 10 additions & 3 deletions extension/src/openvic-extension/classes/GUINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ void GUINode::_bind_methods() {
OV_BIND_METHOD(GUINode::remove_nodes, { "paths" });

OV_BIND_SMETHOD(int_to_string_suffixed, { "val" });
OV_BIND_SMETHOD(int_to_string_commas, { "val" });
OV_BIND_SMETHOD(float_to_string_suffixed, { "val" });
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" });
OV_BIND_SMETHOD(format_province_name, { "province_identifier", "ignore_empty" }, DEFVAL(false));
}

GUINode::GUINode() {
Expand Down Expand Up @@ -233,6 +234,10 @@ String GUINode::int_to_string_suffixed(int64_t val) {
return Utilities::int_to_string_suffixed(val);
}

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);
}
Expand All @@ -245,13 +250,15 @@ String GUINode::float_to_string_dp_dynamic(float val) {
return Utilities::float_to_string_dp_dynamic(val);
}

String GUINode::format_province_name(String const& province_identifier) {
String GUINode::format_province_name(String const& province_identifier, bool ignore_empty) {
if (!province_identifier.is_empty()) {
static const String province_prefix = "PROV";
return province_prefix + province_identifier;
} else {
} else if (!ignore_empty) {
static const String no_province = "NO PROVINCE";
return no_province;
} else {
return {};
}
}

Expand Down
5 changes: 4 additions & 1 deletion extension/src/openvic-extension/classes/GUINode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ namespace OpenVic {
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_commas(int64_t val);
static godot::String float_to_string_suffixed(float val);
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);
static godot::String format_province_name(godot::String const& province_identifier);
// The "ignore_empty" argument refers to what this function produces when given an empty string - if the argument
// is false then empty inputs are replaced with "NO PROVINCE", otherwise they return the empty string unchanged.
static godot::String format_province_name(godot::String const& province_identifier, bool ignore_empty = false);

godot::Ref<godot::BitMap> get_click_mask() const;
void set_click_mask(godot::Ref<godot::BitMap> const& mask);
Expand Down
2 changes: 1 addition & 1 deletion extension/src/openvic-extension/classes/GUIScrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ Error GUIScrollbar::set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar) {
fixed_point_t step_size = gui_scrollbar->get_step_size();
if (step_size <= 0) {
UtilityFunctions::push_error(
"Invalid step size ", Utilities::std_to_godot_string(step_size.to_string()), " for GUIScrollbar ",
"Invalid step size ", Utilities::fixed_point_to_string_dp(step_size, -1), " for GUIScrollbar ",
gui_scrollbar_name, " - not positive! Defaulting to 1."
);
step_size = 1;
Expand Down
14 changes: 14 additions & 0 deletions extension/src/openvic-extension/singletons/AssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void AssetManager::_bind_methods() {
OV_BIND_METHOD(AssetManager::get_image, { "path", "load_flags" }, DEFVAL(LOAD_FLAG_CACHE_IMAGE));
OV_BIND_METHOD(AssetManager::get_texture, { "path", "load_flags" }, DEFVAL(LOAD_FLAG_CACHE_TEXTURE));
OV_BIND_METHOD(AssetManager::get_font, { "name" });
OV_BIND_METHOD(AssetManager::get_currency_texture, { "height" });
OV_BIND_METHOD(AssetManager::get_leader_texture, { "name" });

BIND_ENUM_CONSTANT(LOAD_FLAG_NONE);
BIND_ENUM_CONSTANT(LOAD_FLAG_CACHE_IMAGE);
Expand Down Expand Up @@ -195,6 +197,8 @@ Error AssetManager::preload_textures() {
static const String currency_sprite_medium = "GFX_tooltip_money_small";
static const String currency_sprite_small = "GFX_tooltip_money";

static const String missing_leader_sprite = "GFX_leader_generic0";

constexpr auto load = [](String const& sprite_name, Ref<GFXSpriteTexture>& texture) -> bool {
GFX::Sprite const* sprite = UITools::get_gfx_sprite(sprite_name);
ERR_FAIL_NULL_V(sprite, false);
Expand All @@ -214,6 +218,8 @@ Error AssetManager::preload_textures() {
ret &= load(currency_sprite_medium, currency_texture_medium);
ret &= load(currency_sprite_small, currency_texture_small);

ret &= load(missing_leader_sprite, missing_leader_texture);

return ERR(ret);
}

Expand All @@ -228,3 +234,11 @@ Ref<GFXSpriteTexture> AssetManager::get_currency_texture(real_t height) const {
return currency_texture_small;
}
}

Ref<ImageTexture> AssetManager::get_leader_texture_std(std::string_view name) {
return get_texture(Utilities::std_to_godot_string(CultureManager::make_leader_picture_path(name)));
}

Ref<ImageTexture> AssetManager::get_leader_texture(String const& name) {
return get_leader_texture_std(Utilities::godot_to_std_string(name));
}
5 changes: 5 additions & 0 deletions extension/src/openvic-extension/singletons/AssetManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ namespace OpenVic {
godot::Ref<GFXSpriteTexture> PROPERTY(currency_texture_medium); // 24x24
godot::Ref<GFXSpriteTexture> PROPERTY(currency_texture_small); // 16x16

godot::Ref<GFXSpriteTexture> PROPERTY(missing_leader_texture);

public:
godot::Error preload_textures();

/* Get the largest currency texture with height less than the specified font height. */
godot::Ref<GFXSpriteTexture> get_currency_texture(real_t height) const;

godot::Ref<godot::ImageTexture> get_leader_texture_std(std::string_view name);
godot::Ref<godot::ImageTexture> get_leader_texture(godot::String const& name);
};
}

Expand Down
Loading

0 comments on commit d5e626b

Please sign in to comment.