aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-08-30 23:31:52 +0200
committer GitHub <noreply@github.com>2024-08-30 23:31:52 +0200
commit74cd5d9c4236aef435dd64ffd8f10a7f98533e42 (patch)
tree34e0efee3d598bfbd8ed7e0921ceebc8addc2e07 /extension/src/openvic-extension/classes
parent2e0bc5b556b9c6df46a8cdd48d3f109e0ac76b63 (diff)
parentfb9672c39a2cba01b279a473e1f8076cea461393 (diff)
Merge pull request #255 from OpenVicProject/gov-flag-type
Use government based flag types in UI
Diffstat (limited to 'extension/src/openvic-extension/classes')
-rw-r--r--extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp42
-rw-r--r--extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp5
2 files changed, 37 insertions, 10 deletions
diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
index 3714c5f..41eaa4d 100644
--- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
+++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
@@ -96,7 +96,9 @@ Ref<GFXMaskedFlagTexture> GFXMaskedFlagTexture::make_gfx_masked_flag_texture(GFX
Ref<GFXMaskedFlagTexture> masked_flag_texture;
masked_flag_texture.instantiate();
ERR_FAIL_NULL_V(masked_flag_texture, nullptr);
+
ERR_FAIL_COND_V(masked_flag_texture->set_gfx_masked_flag(gfx_masked_flag) != OK, nullptr);
+
return masked_flag_texture;
}
@@ -116,10 +118,12 @@ Error GFXMaskedFlagTexture::set_gfx_masked_flag(GFX::MaskedFlag const* new_gfx_m
if (gfx_masked_flag == new_gfx_masked_flag) {
return OK;
}
+
if (new_gfx_masked_flag == nullptr) {
clear();
return OK;
}
+
AssetManager* asset_manager = AssetManager::get_singleton();
ERR_FAIL_NULL_V(asset_manager, FAILED);
@@ -142,8 +146,10 @@ Error GFXMaskedFlagTexture::set_gfx_masked_flag_name(String const& gfx_masked_fl
if (gfx_masked_flag_name.is_empty()) {
return set_gfx_masked_flag(nullptr);
}
+
GFX::Sprite const* sprite = UITools::get_gfx_sprite(gfx_masked_flag_name);
ERR_FAIL_NULL_V(sprite, FAILED);
+
GFX::MaskedFlag const* new_masked_flag = sprite->cast_to<GFX::MaskedFlag>();
ERR_FAIL_NULL_V_MSG(
new_masked_flag, FAILED, vformat(
@@ -152,6 +158,7 @@ Error GFXMaskedFlagTexture::set_gfx_masked_flag_name(String const& gfx_masked_fl
Utilities::std_to_godot_string(GFX::MaskedFlag::get_type_static())
)
);
+
return set_gfx_masked_flag(new_masked_flag);
}
@@ -165,8 +172,9 @@ Error GFXMaskedFlagTexture::set_flag_country_and_type(
if (flag_country == new_flag_country && flag_type == new_flag_type) {
return OK;
}
+
if (new_flag_country != nullptr) {
- GameSingleton* game_singleton = GameSingleton::get_singleton();
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, FAILED);
flag_image_rect = game_singleton->get_flag_sheet_rect(new_flag_country->get_index(), new_flag_type);
@@ -181,6 +189,7 @@ Error GFXMaskedFlagTexture::set_flag_country_and_type(
flag_type = String {};
flag_image.unref();
}
+
return _generate_combined_image();
}
@@ -190,32 +199,49 @@ Error GFXMaskedFlagTexture::set_flag_country_name_and_type(
if (new_flag_country_name.is_empty()) {
return set_flag_country_and_type(nullptr, {});
}
- GameSingleton* game_singleton = GameSingleton::get_singleton();
+
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, FAILED);
+
CountryDefinition const* new_flag_country =
game_singleton->get_definition_manager().get_country_definition_manager().get_country_definition_by_identifier(
Utilities::godot_to_std_string(new_flag_country_name)
);
ERR_FAIL_NULL_V_MSG(new_flag_country, FAILED, vformat("Country not found: %s", new_flag_country_name));
+
return set_flag_country_and_type(new_flag_country, new_flag_type);
}
-Error GFXMaskedFlagTexture::set_flag_country(CountryDefinition const* new_flag_country) {
- // TODO - get country's current flag type from the game state
- return set_flag_country_and_type( new_flag_country, {});
+Error GFXMaskedFlagTexture::set_flag_country(CountryInstance const* new_flag_country) {
+ if (new_flag_country == nullptr || new_flag_country->get_country_definition() == nullptr) {
+ return set_flag_country_and_type(nullptr, {});
+ }
+
+ GovernmentType const* government_type = new_flag_country->get_flag_government_type();
+
+ const StringName new_flag_type = government_type != nullptr
+ ? Utilities::std_to_godot_string(government_type->get_flag_type()) : String {};
+
+ return set_flag_country_and_type(new_flag_country->get_country_definition(), new_flag_type);
}
Error GFXMaskedFlagTexture::set_flag_country_name(String const& new_flag_country_name) {
if (new_flag_country_name.is_empty()) {
return set_flag_country(nullptr);
}
- GameSingleton* game_singleton = GameSingleton::get_singleton();
+
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, FAILED);
- CountryDefinition const* new_flag_country =
- game_singleton->get_definition_manager().get_country_definition_manager().get_country_definition_by_identifier(
+
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, FAILED);
+
+ CountryInstance const* new_flag_country =
+ instance_manager->get_country_instance_manager().get_country_instance_by_identifier(
Utilities::godot_to_std_string(new_flag_country_name)
);
ERR_FAIL_NULL_V_MSG(new_flag_country, FAILED, vformat("Country not found: %s", new_flag_country_name));
+
return set_flag_country(new_flag_country);
}
diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp
index 3d361e4..b26f0dd 100644
--- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp
+++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp
@@ -6,6 +6,7 @@
namespace OpenVic {
struct CountryDefinition;
+ struct CountryInstance;
class GFXMaskedFlagTexture : public GFXButtonStateHavingTexture {
GDCLASS(GFXMaskedFlagTexture, GFXButtonStateHavingTexture)
@@ -55,9 +56,9 @@ namespace OpenVic {
/* Look up the specified country's current flag type, then call set_flag_country_and_type
* with the country and its flag type as arguments. */
- godot::Error set_flag_country(CountryDefinition const* new_flag_country);
+ godot::Error set_flag_country(CountryInstance const* new_flag_country);
- /* Look up the country with the specified identifier, then call set_flag_country with the country its argument. */
+ /* Look up the country with the specified identifier, then call set_flag_country with the country as its argument. */
godot::Error set_flag_country_name(godot::String const& new_flag_country_name);
/* Return the name of the selected flag's country, or an empty String if it's null. */