Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add military menu control script #348

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 18 additions & 0 deletions extension/doc_classes/MenuSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<description>
</description>
</method>
<method name="get_military_menu_info">
<return type="Dictionary" />
<param index="0" name="leader_sort_key" type="int" enum="MenuSingleton.LeaderSortKey" />
<description>
</description>
</method>
<method name="get_population_menu_distribution_info" qualifiers="const">
<return type="Array[]" />
<description>
Expand Down Expand Up @@ -326,5 +332,17 @@
</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>
</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
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
Loading