Skip to content

Commit

Permalink
Add military menu control script
Browse files Browse the repository at this point in the history
  • Loading branch information
Hop311 committed Jan 19, 2025
1 parent bc8a7de commit 2b3e018
Show file tree
Hide file tree
Showing 15 changed files with 1,455 additions and 43 deletions.
2 changes: 1 addition & 1 deletion extension/deps/openvic-simulation
Submodule openvic-simulation updated 30 files
+2 −2 src/openvic-simulation/InstanceManager.cpp
+90 −28 src/openvic-simulation/country/CountryInstance.cpp
+67 −16 src/openvic-simulation/country/CountryInstance.hpp
+11 −0 src/openvic-simulation/dataloader/Dataloader.cpp
+14 −1 src/openvic-simulation/defines/Define.cpp
+14 −2 src/openvic-simulation/history/CountryHistory.cpp
+3 −2 src/openvic-simulation/history/CountryHistory.hpp
+1 −0 src/openvic-simulation/map/MapInstance.hpp
+16 −16 src/openvic-simulation/map/ProvinceInstance.cpp
+6 −2 src/openvic-simulation/map/ProvinceInstance.hpp
+95 −55 src/openvic-simulation/military/Deployment.cpp
+3 −1 src/openvic-simulation/military/Deployment.hpp
+18 −4 src/openvic-simulation/military/Leader.cpp
+5 −1 src/openvic-simulation/military/Leader.hpp
+40 −0 src/openvic-simulation/military/LeaderTrait.cpp
+12 −0 src/openvic-simulation/military/LeaderTrait.hpp
+3 −3 src/openvic-simulation/military/UnitInstance.hpp
+56 −19 src/openvic-simulation/military/UnitInstanceGroup.cpp
+7 −1 src/openvic-simulation/military/UnitInstanceGroup.hpp
+50 −0 src/openvic-simulation/military/UnitType.hpp
+2 −0 src/openvic-simulation/modifier/Modifier.hpp
+111 −45 src/openvic-simulation/modifier/ModifierManager.cpp
+3 −4 src/openvic-simulation/modifier/ModifierManager.hpp
+0 −2 src/openvic-simulation/modifier/StaticModifierCache.cpp
+1 −1 src/openvic-simulation/politics/Issue.cpp
+131 −1 src/openvic-simulation/pop/Culture.cpp
+17 −0 src/openvic-simulation/pop/Culture.hpp
+14 −0 src/openvic-simulation/types/FlagStrings.cpp
+4 −0 src/openvic-simulation/types/FlagStrings.hpp
+1 −2 src/openvic-simulation/types/IdentifierRegistry.hpp
2 changes: 1 addition & 1 deletion extension/src/openvic-extension/classes/GUIListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Error GUIListBox::set_gui_listbox(GUI::ListBox const* new_gui_listbox) {
if (scrollbar_control != nullptr) {
scrollbar = Object::cast_to<GUIScrollbar>(scrollbar_control);
if (scrollbar != nullptr) {
add_child(scrollbar, false, INTERNAL_MODE_FRONT);
add_child(scrollbar, false, INTERNAL_MODE_BACK);

const Size2 size = Utilities::to_godot_fvec2(gui_listbox->get_size());
Vector2 position = Utilities::to_godot_fvec2(gui_listbox->get_scrollbar_offset());
Expand Down
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
9 changes: 9 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,7 @@ 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" });

BIND_ENUM_CONSTANT(LOAD_FLAG_NONE);
BIND_ENUM_CONSTANT(LOAD_FLAG_CACHE_IMAGE);
Expand Down Expand Up @@ -195,6 +196,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 +217,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 +233,7 @@ Ref<GFXSpriteTexture> AssetManager::get_currency_texture(real_t height) const {
return currency_texture_small;
}
}

Ref<ImageTexture> AssetManager::get_leader_texture(std::string_view name) {
return get_texture(Utilities::std_to_godot_string(CultureManager::make_leader_picture_path(name)));
}
4 changes: 4 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,15 @@ 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::string_view name);
};
}

Expand Down
Loading

0 comments on commit 2b3e018

Please sign in to comment.