diff options
14 files changed, 335 insertions, 294 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation -Subproject 5216e893ebc5253b123bbf15b7509745d38f5a8 +Subproject 147e0a772dc768bd90fdccdd2536f14c11238d5 diff --git a/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp b/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp index e6dff1f..dcee965 100644 --- a/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp @@ -1,5 +1,7 @@ #include "GFXButtonStateTexture.hpp" +#include <godot_cpp/variant/utility_functions.hpp> + #include "openvic-extension/utility/ClassBindings.hpp" using namespace OpenVic; @@ -9,8 +11,6 @@ void GFXButtonStateTexture::_bind_methods() { OV_BIND_METHOD(GFXButtonStateTexture::set_button_state, { "new_button_state" }); OV_BIND_METHOD(GFXButtonStateTexture::get_button_state); - OV_BIND_SMETHOD(get_generate_state_image_func_name); - OV_BIND_SMETHOD(button_state_to_theme_name, { "button_state" }); OV_BIND_METHOD(GFXButtonStateTexture::get_button_state_theme); @@ -24,14 +24,14 @@ void GFXButtonStateTexture::_bind_methods() { GFXButtonStateTexture::GFXButtonStateTexture() : button_state { HOVER } {} Ref<GFXButtonStateTexture> GFXButtonStateTexture::make_gfx_button_state_texture( - ButtonState button_state, Ref<Image> const& source_image + ButtonState button_state, Ref<Image> const& source_image, Rect2i const& region ) { Ref<GFXButtonStateTexture> button_state_texture; button_state_texture.instantiate(); ERR_FAIL_NULL_V(button_state_texture, nullptr); button_state_texture->set_button_state(button_state); if (source_image.is_valid()) { - ERR_FAIL_COND_V(button_state_texture->generate_state_image(source_image) != OK, nullptr); + ERR_FAIL_COND_V(button_state_texture->generate_state_image(source_image, region) != OK, nullptr); } return button_state_texture; } @@ -41,14 +41,16 @@ void GFXButtonStateTexture::set_button_state(ButtonState new_button_state) { button_state = new_button_state; } -Error GFXButtonStateTexture::generate_state_image(Ref<Image> const& source_image) { +Error GFXButtonStateTexture::generate_state_image(Ref<Image> const& source_image, Rect2i const& region) { ERR_FAIL_COND_V(source_image.is_null() || source_image->is_empty(), FAILED); + const Rect2i source_image_rect { {}, source_image->get_size() }; + ERR_FAIL_COND_V(!region.has_area() || !source_image_rect.encloses(region), FAILED); /* Whether we've already set the ImageTexture to an image of the right dimensions and format, * and so can update it without creating and setting a new image, or not. */ - const bool can_update = state_image.is_valid() && state_image->get_size() == source_image->get_size() + const bool can_update = state_image.is_valid() && state_image->get_size() == region.get_size() && state_image->get_format() == source_image->get_format(); if (!can_update) { - state_image = Image::create(source_image->get_width(), source_image->get_height(), false, source_image->get_format()); + state_image = Image::create(region.size.width, region.size.height, false, source_image->get_format()); ERR_FAIL_NULL_V(state_image, FAILED); } @@ -67,7 +69,7 @@ Error GFXButtonStateTexture::generate_state_image(Ref<Image> const& source_image for (Vector2i point { 0, 0 }; point.y < state_image->get_height(); ++point.y) { for (point.x = 0; point.x < state_image->get_width(); ++point.x) { - state_image->set_pixelv(point, colour_func(source_image->get_pixelv(point))); + state_image->set_pixelv(point, colour_func(source_image->get_pixelv(region.position + point))); } } @@ -79,16 +81,11 @@ Error GFXButtonStateTexture::generate_state_image(Ref<Image> const& source_image return OK; } -StringName const& GFXButtonStateTexture::get_generate_state_image_func_name() { - static const StringName generate_state_image_func_name = "generate_state_image"; - return generate_state_image_func_name; -} - StringName const& GFXButtonStateTexture::button_state_to_theme_name(ButtonState button_state) { static const StringName theme_name_hover = "hover"; static const StringName theme_name_pressed = "pressed"; static const StringName theme_name_disabled = "disabled"; - static const StringName theme_name_error = ""; + static const StringName theme_name_error = "INVALID BUTTON STATE"; switch (button_state) { case HOVER: return theme_name_hover; @@ -104,3 +101,39 @@ StringName const& GFXButtonStateTexture::button_state_to_theme_name(ButtonState StringName const& GFXButtonStateTexture::get_button_state_theme() const { return button_state_to_theme_name(button_state); } + +void GFXButtonStateHavingTexture::_bind_methods() { + OV_BIND_METHOD(GFXButtonStateHavingTexture::get_button_state_texture, { "button_state" }); +} + +void GFXButtonStateHavingTexture::_update_button_states() { + for (Ref<GFXButtonStateTexture>& button_state_texture : button_state_textures) { + if (button_state_texture.is_valid()) { + button_state_texture->generate_state_image(button_image, get_region()); + } + } +} + +void GFXButtonStateHavingTexture::_clear_button_states() { + set_atlas(nullptr); + set_region({}); + button_image.unref(); + for (Ref<GFXButtonStateTexture>& button_state_texture : button_state_textures) { + button_state_texture.unref(); + } +} + +GFXButtonStateHavingTexture::GFXButtonStateHavingTexture() : button_image {}, button_state_textures {} {} + +Ref<GFXButtonStateTexture> GFXButtonStateHavingTexture::get_button_state_texture( + GFXButtonStateTexture::ButtonState button_state +) { + const size_t button_state_index = button_state; + ERR_FAIL_COND_V(button_state_index >= button_state_textures.size(), nullptr); + Ref<GFXButtonStateTexture>& button_state_texture = button_state_textures[button_state_index]; + if (button_state_texture.is_null()) { + button_state_texture = GFXButtonStateTexture::make_gfx_button_state_texture(button_state, button_image, get_region()); + ERR_FAIL_NULL_V(button_state_texture, nullptr); + } + return button_state_texture; +} diff --git a/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp b/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp index 32f4087..c98159d 100644 --- a/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp @@ -1,5 +1,6 @@ #pragma once +#include <godot_cpp/classes/atlas_texture.hpp> #include <godot_cpp/classes/image_texture.hpp> #include <openvic-simulation/utility/Getters.hpp> @@ -12,7 +13,8 @@ namespace OpenVic { enum ButtonState { HOVER, PRESSED, - DISABLED + DISABLED, + BUTTON_STATE_COUNT }; private: @@ -27,20 +29,38 @@ namespace OpenVic { /* Create a GFXButtonStateTexture using the specified godot::Image. Returns nullptr if generate_state_image fails. */ static godot::Ref<GFXButtonStateTexture> make_gfx_button_state_texture( - ButtonState button_state, godot::Ref<godot::Image> const& source_image = nullptr + ButtonState button_state, godot::Ref<godot::Image> const& source_image, godot::Rect2i const& region ); /* Set the ButtonState to be generated by this class (calling this does not trigger state image generation). */ void set_button_state(ButtonState new_button_state); - /* Generate a modified version of source_image and update the underlying godot::ImageTexture to use it. */ - godot::Error generate_state_image(godot::Ref<godot::Image> const& source_image); - - static godot::StringName const& get_generate_state_image_func_name(); + /* Generate a modified version of the given region of source_image + * and update the underlying godot::ImageTexture to use it. */ + godot::Error generate_state_image(godot::Ref<godot::Image> const& source_image, godot::Rect2i const& region); static godot::StringName const& button_state_to_theme_name(ButtonState button_state); godot::StringName const& get_button_state_theme() const; }; + + class GFXButtonStateHavingTexture : public godot::AtlasTexture { + GDCLASS(GFXButtonStateHavingTexture, godot::AtlasTexture) + + std::array<godot::Ref<GFXButtonStateTexture>, GFXButtonStateTexture::BUTTON_STATE_COUNT> button_state_textures; + + protected: + static void _bind_methods(); + + godot::Ref<godot::Image> button_image; + + void _update_button_states(); + void _clear_button_states(); + + GFXButtonStateHavingTexture(); + + public: + godot::Ref<GFXButtonStateTexture> get_button_state_texture(GFXButtonStateTexture::ButtonState button_state); + }; } VARIANT_ENUM_CAST(OpenVic::GFXButtonStateTexture::ButtonState); diff --git a/extension/src/openvic-extension/classes/GFXIconTexture.cpp b/extension/src/openvic-extension/classes/GFXIconTexture.cpp deleted file mode 100644 index 99df7e4..0000000 --- a/extension/src/openvic-extension/classes/GFXIconTexture.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include "GFXIconTexture.hpp" - -#include <godot_cpp/variant/utility_functions.hpp> - -#include "openvic-extension/singletons/AssetManager.hpp" -#include "openvic-extension/utility/ClassBindings.hpp" -#include "openvic-extension/utility/UITools.hpp" -#include "openvic-extension/utility/Utilities.hpp" - -using namespace godot; -using namespace OpenVic; - -using OpenVic::Utilities::std_view_to_godot_string; -using OpenVic::Utilities::std_view_to_godot_string_name; - -StringName const& GFXIconTexture::_signal_image_updated() { - static const StringName signal_image_updated = "image_updated"; - return signal_image_updated; -} - -void GFXIconTexture::_bind_methods() { - OV_BIND_METHOD(GFXIconTexture::clear); - - OV_BIND_METHOD(GFXIconTexture::set_gfx_texture_sprite_name, { "gfx_texture_sprite_name", "icon" }, DEFVAL(GFX::NO_FRAMES)); - OV_BIND_METHOD(GFXIconTexture::get_gfx_texture_sprite_name); - - OV_BIND_METHOD(GFXIconTexture::set_icon_index, { "new_icon_index" }); - OV_BIND_METHOD(GFXIconTexture::get_icon_index); - OV_BIND_METHOD(GFXIconTexture::get_icon_count); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_index"), "set_icon_index", "get_icon_index"); - - ADD_SIGNAL( - MethodInfo(_signal_image_updated(), PropertyInfo(Variant::OBJECT, "source_image", PROPERTY_HINT_RESOURCE_TYPE, "Image")) - ); -} - -GFXIconTexture::GFXIconTexture() - : gfx_texture_sprite { nullptr }, icon_index { GFX::NO_FRAMES }, icon_count { GFX::NO_FRAMES } {} - -Ref<GFXIconTexture> GFXIconTexture::make_gfx_icon_texture( - GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon, - std::vector<Ref<GFXButtonStateTexture>> const& button_state_textures -) { - Ref<GFXIconTexture> icon_texture; - icon_texture.instantiate(); - ERR_FAIL_NULL_V(icon_texture, nullptr); - - for (Ref<GFXButtonStateTexture> const& button_state_texture : button_state_textures) { - icon_texture->connect( - _signal_image_updated(), - Callable { *button_state_texture, GFXButtonStateTexture::get_generate_state_image_func_name() }, - CONNECT_PERSIST - ); - } - - ERR_FAIL_COND_V(icon_texture->set_gfx_texture_sprite(gfx_texture_sprite, icon) != OK, nullptr); - return icon_texture; -} - -void GFXIconTexture::clear() { - gfx_texture_sprite = nullptr; - set_atlas(nullptr); - set_region({}); - icon_index = GFX::NO_FRAMES; - icon_count = GFX::NO_FRAMES; -} - -Error GFXIconTexture::set_gfx_texture_sprite(GFX::TextureSprite const* new_gfx_texture_sprite, GFX::frame_t icon) { - if (gfx_texture_sprite != new_gfx_texture_sprite) { - if (new_gfx_texture_sprite == nullptr) { - clear(); - return OK; - } - AssetManager* asset_manager = AssetManager::get_singleton(); - ERR_FAIL_NULL_V(asset_manager, FAILED); - - const StringName texture_file = std_view_to_godot_string_name(new_gfx_texture_sprite->get_texture_file()); - - /* Needed for GFXButtonStateTexture, AssetManager::get_texture will re-use this image from its internal cache. */ - const Ref<Image> image = asset_manager->get_image(texture_file); - ERR_FAIL_NULL_V_MSG(image, FAILED, vformat("Failed to load image: %s", texture_file)); - - const Ref<ImageTexture> texture = asset_manager->get_texture(texture_file); - ERR_FAIL_NULL_V_MSG(texture, FAILED, vformat("Failed to load texture: %s", texture_file)); - - sprite_image = image; - gfx_texture_sprite = new_gfx_texture_sprite; - set_atlas(texture); - icon_index = GFX::NO_FRAMES; - icon_count = gfx_texture_sprite->get_no_of_frames(); - } - return set_icon_index(icon); -} - -Error GFXIconTexture::set_gfx_texture_sprite_name(String const& gfx_texture_sprite_name, GFX::frame_t icon) { - if (gfx_texture_sprite_name.is_empty()) { - return set_gfx_texture_sprite(nullptr); - } - GFX::Sprite const* sprite = UITools::get_gfx_sprite(gfx_texture_sprite_name); - ERR_FAIL_NULL_V(sprite, FAILED); - GFX::TextureSprite const* new_texture_sprite = sprite->cast_to<GFX::TextureSprite>(); - ERR_FAIL_NULL_V_MSG( - new_texture_sprite, FAILED, vformat( - "Invalid type for GFX sprite %s: %s (expected %s)", gfx_texture_sprite_name, - std_view_to_godot_string(sprite->get_type()), std_view_to_godot_string(GFX::TextureSprite::get_type_static()) - ) - ); - return set_gfx_texture_sprite(new_texture_sprite, icon); -} - -String GFXIconTexture::get_gfx_texture_sprite_name() const { - return gfx_texture_sprite != nullptr ? std_view_to_godot_string(gfx_texture_sprite->get_name()) : String {}; -} - -Error GFXIconTexture::set_icon_index(int32_t new_icon_index) { - const Ref<Texture2D> atlas_texture = get_atlas(); - ERR_FAIL_NULL_V(atlas_texture, FAILED); - const Vector2 size = atlas_texture->get_size(); - if (icon_count <= GFX::NO_FRAMES) { - if (new_icon_index > GFX::NO_FRAMES) { - UtilityFunctions::push_warning("Invalid icon index ", new_icon_index, " for texture with no frames!"); - } - icon_index = GFX::NO_FRAMES; - set_region({ {}, size }); - emit_signal(_signal_image_updated(), sprite_image); - return OK; - } - if (GFX::NO_FRAMES < new_icon_index && new_icon_index <= icon_count) { - icon_index = new_icon_index; - } else { - icon_index = 1; - if (new_icon_index > icon_count) { - UtilityFunctions::push_warning( - "Invalid icon index ", new_icon_index, " out of count ", icon_count, " - defaulting to ", icon_index - ); - } - } - set_region({ (icon_index - 1) * size.x / icon_count, 0, size.x / icon_count, size.y }); - emit_signal(_signal_image_updated(), sprite_image->get_region(get_region())); - return OK; -} diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp index 0a44e56..2c315a9 100644 --- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp @@ -13,28 +13,31 @@ using OpenVic::Utilities::godot_to_std_string; using OpenVic::Utilities::std_view_to_godot_string; using OpenVic::Utilities::std_view_to_godot_string_name; -StringName const& GFXMaskedFlagTexture::_signal_image_updated() { - static const StringName signal_image_updated = "image_updated"; - return signal_image_updated; -} - Error GFXMaskedFlagTexture::_generate_combined_image() { ERR_FAIL_NULL_V(overlay_image, FAILED); /* Whether we've already set the ImageTexture to an image of the right dimensions and format, * and so can update it without creating and setting a new image, or not. */ - const bool can_update = combined_image.is_valid() && combined_image->get_size() == overlay_image->get_size() - && combined_image->get_format() == overlay_image->get_format(); + bool can_update = button_image.is_valid() && button_image->get_size() == overlay_image->get_size() + && button_image->get_format() == overlay_image->get_format(); if (!can_update) { - combined_image = Image::create( + button_image = Image::create( overlay_image->get_width(), overlay_image->get_height(), false, overlay_image->get_format() ); - ERR_FAIL_NULL_V(combined_image, FAILED); + ERR_FAIL_NULL_V(button_image, FAILED); + } + + if (combined_texture.is_null()) { + can_update = false; + combined_texture.instantiate(); + ERR_FAIL_NULL_V(combined_texture, FAILED); + set_atlas(combined_texture); + set_region({ {}, button_image->get_size() }); } if (mask_image.is_valid() && flag_image.is_valid()) { - const Vector2i centre_translation = (mask_image->get_size() - combined_image->get_size()) / 2; - for (Vector2i combined_image_point { 0, 0 }; combined_image_point.y < combined_image->get_height(); ++combined_image_point.y) { - for (combined_image_point.x = 0; combined_image_point.x < combined_image->get_width(); ++combined_image_point.x) { + const Vector2i centre_translation = (mask_image->get_size() - button_image->get_size()) / 2; + for (Vector2i combined_image_point { 0, 0 }; combined_image_point.y < button_image->get_height(); ++combined_image_point.y) { + for (combined_image_point.x = 0; combined_image_point.x < button_image->get_width(); ++combined_image_point.x) { const Color overlay_image_colour = overlay_image->get_pixelv(combined_image_point); // Translate to mask_image coordinates, keeping the centres of each image aligned. const Vector2i mask_image_point = combined_image_point + centre_translation; @@ -47,22 +50,22 @@ Error GFXMaskedFlagTexture::_generate_combined_image() { const Vector2i flag_image_point = mask_image_point * flag_image->get_size() / mask_image->get_size(); Color flag_image_colour = flag_image->get_pixelv(flag_image_point); flag_image_colour.a = mask_image_colour.a; - combined_image->set_pixelv(combined_image_point, flag_image_colour.blend(overlay_image_colour)); + button_image->set_pixelv(combined_image_point, flag_image_colour.blend(overlay_image_colour)); } else { - combined_image->set_pixelv(combined_image_point, overlay_image_colour); + button_image->set_pixelv(combined_image_point, overlay_image_colour); } } } } else { - combined_image->blit_rect(overlay_image, overlay_image->get_used_rect(), {}); + button_image->blit_rect(overlay_image, overlay_image->get_used_rect(), {}); } if (can_update) { - update(combined_image); + combined_texture->update(button_image); } else { - set_image(combined_image); + combined_texture->set_image(button_image); } - emit_signal(_signal_image_updated(), combined_image); + _update_button_states(); return OK; } @@ -76,29 +79,14 @@ void GFXMaskedFlagTexture::_bind_methods() { OV_BIND_METHOD(GFXMaskedFlagTexture::set_flag_country_name, { "new_flag_country_name" }); OV_BIND_METHOD(GFXMaskedFlagTexture::get_flag_country_name); OV_BIND_METHOD(GFXMaskedFlagTexture::get_flag_type); - - ADD_SIGNAL( - MethodInfo(_signal_image_updated(), PropertyInfo(Variant::OBJECT, "source_image", PROPERTY_HINT_RESOURCE_TYPE, "Image")) - ); } GFXMaskedFlagTexture::GFXMaskedFlagTexture() : gfx_masked_flag { nullptr }, flag_country { nullptr } {} -Ref<GFXMaskedFlagTexture> GFXMaskedFlagTexture::make_gfx_masked_flag_texture( - GFX::MaskedFlag const* gfx_masked_flag, std::vector<Ref<GFXButtonStateTexture>> const& button_state_textures -) { +Ref<GFXMaskedFlagTexture> GFXMaskedFlagTexture::make_gfx_masked_flag_texture(GFX::MaskedFlag const* gfx_masked_flag) { Ref<GFXMaskedFlagTexture> masked_flag_texture; masked_flag_texture.instantiate(); ERR_FAIL_NULL_V(masked_flag_texture, nullptr); - - for (Ref<GFXButtonStateTexture> const& button_state_texture : button_state_textures) { - masked_flag_texture->connect( - _signal_image_updated(), - Callable { *button_state_texture, GFXButtonStateTexture::get_generate_state_image_func_name() }, - CONNECT_PERSIST - ); - } - ERR_FAIL_COND_V(masked_flag_texture->set_gfx_masked_flag(gfx_masked_flag) != OK, nullptr); return masked_flag_texture; } @@ -108,6 +96,8 @@ void GFXMaskedFlagTexture::clear() { flag_country = nullptr; flag_type = String {}; + _clear_button_states(); + overlay_image.unref(); mask_image.unref(); flag_image.unref(); diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp index 294b842..1e85dd8 100644 --- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp @@ -1,23 +1,20 @@ #pragma once -#include <godot_cpp/classes/image_texture.hpp> - #include <openvic-simulation/country/Country.hpp> #include <openvic-simulation/interface/GFX.hpp> #include "openvic-extension/classes/GFXButtonStateTexture.hpp" namespace OpenVic { - class GFXMaskedFlagTexture : public godot::ImageTexture { - GDCLASS(GFXMaskedFlagTexture, godot::ImageTexture) + class GFXMaskedFlagTexture : public GFXButtonStateHavingTexture { + GDCLASS(GFXMaskedFlagTexture, GFXButtonStateHavingTexture) GFX::MaskedFlag const* PROPERTY(gfx_masked_flag); Country const* PROPERTY(flag_country); godot::StringName PROPERTY(flag_type); - godot::Ref<godot::Image> overlay_image, mask_image, flag_image, combined_image; - - static godot::StringName const& _signal_image_updated(); + godot::Ref<godot::Image> overlay_image, mask_image, flag_image; + godot::Ref<godot::ImageTexture> combined_texture; godot::Error _generate_combined_image(); @@ -27,12 +24,8 @@ namespace OpenVic { public: GFXMaskedFlagTexture(); - /* Create a GFXMaskedFlagTexture using the specified GFX::MaskedFlag. Returns nullptr if gfx_masked_flag fails. - * Connects the provided GFXButtonStateTextures (if any) to the GFXMaskedFlagTexture's image_updated signal. */ - static godot::Ref<GFXMaskedFlagTexture> make_gfx_masked_flag_texture( - GFX::MaskedFlag const* gfx_masked_flag, - std::vector<godot::Ref<GFXButtonStateTexture>> const& button_state_textures = {} - ); + /* Create a GFXMaskedFlagTexture using the specified GFX::MaskedFlag. Returns nullptr if gfx_masked_flag fails. */ + static godot::Ref<GFXMaskedFlagTexture> make_gfx_masked_flag_texture(GFX::MaskedFlag const* gfx_masked_flag); /* Reset gfx_masked_flag, flag_country and flag_type to nullptr/an empty string, and unreference all images. * This does not affect the godot::ImageTexture, which cannot be reset to a null or empty image. */ diff --git a/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp b/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp new file mode 100644 index 0000000..e002461 --- /dev/null +++ b/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp @@ -0,0 +1,159 @@ +#include "GFXSpriteTexture.hpp" + +#include <godot_cpp/classes/rendering_server.hpp> +#include <godot_cpp/variant/utility_functions.hpp> + +#include "openvic-extension/singletons/AssetManager.hpp" +#include "openvic-extension/utility/ClassBindings.hpp" +#include "openvic-extension/utility/UITools.hpp" +#include "openvic-extension/utility/Utilities.hpp" + +using namespace godot; +using namespace OpenVic; + +using OpenVic::Utilities::std_view_to_godot_string; +using OpenVic::Utilities::std_view_to_godot_string_name; + +void GFXSpriteTexture::_bind_methods() { + OV_BIND_METHOD(GFXSpriteTexture::clear); + + OV_BIND_METHOD(GFXSpriteTexture::set_gfx_texture_sprite_name, { "gfx_texture_sprite_name", "icon" }, DEFVAL(GFX::NO_FRAMES)); + OV_BIND_METHOD(GFXSpriteTexture::get_gfx_texture_sprite_name); + + OV_BIND_METHOD(GFXSpriteTexture::set_icon_index, { "new_icon_index" }); + OV_BIND_METHOD(GFXSpriteTexture::get_icon_index); + OV_BIND_METHOD(GFXSpriteTexture::get_icon_count); + + OV_BIND_METHOD(GFXSpriteTexture::is_cornered_tile_texture); + OV_BIND_METHOD(GFXSpriteTexture::draw_rect_cornered, { "to_canvas_item", "rect" }); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_index"), "set_icon_index", "get_icon_index"); +} + +GFXSpriteTexture::GFXSpriteTexture() + : gfx_texture_sprite { nullptr }, icon_index { GFX::NO_FRAMES }, icon_count { GFX::NO_FRAMES }, + cornered_tile_texture { false }, cornered_tile_border_size {} {} + +Ref<GFXSpriteTexture> GFXSpriteTexture::make_gfx_sprite_texture(GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon) { + Ref<GFXSpriteTexture> texture; + texture.instantiate(); + ERR_FAIL_NULL_V(texture, nullptr); + ERR_FAIL_COND_V(texture->set_gfx_texture_sprite(gfx_texture_sprite, icon) != OK, nullptr); + return texture; +} + +void GFXSpriteTexture::clear() { + gfx_texture_sprite = nullptr; + _clear_button_states(); + icon_index = GFX::NO_FRAMES; + icon_count = GFX::NO_FRAMES; + cornered_tile_texture = false; + cornered_tile_border_size = {}; +} + +Error GFXSpriteTexture::set_gfx_texture_sprite(GFX::TextureSprite const* new_gfx_texture_sprite, GFX::frame_t icon) { + if (gfx_texture_sprite != new_gfx_texture_sprite) { + if (new_gfx_texture_sprite == nullptr) { + clear(); + return OK; + } + AssetManager* asset_manager = AssetManager::get_singleton(); + ERR_FAIL_NULL_V(asset_manager, FAILED); + + const StringName texture_file = std_view_to_godot_string_name(new_gfx_texture_sprite->get_texture_file()); + + /* Needed for GFXButtonStateTexture, AssetManager::get_texture will re-use this image from its internal cache. */ + const Ref<Image> image = asset_manager->get_image(texture_file); + ERR_FAIL_NULL_V_MSG(image, FAILED, vformat("Failed to load image: %s", texture_file)); + + const Ref<ImageTexture> texture = asset_manager->get_texture(texture_file); + ERR_FAIL_NULL_V_MSG(texture, FAILED, vformat("Failed to load texture: %s", texture_file)); + + button_image = image; + gfx_texture_sprite = new_gfx_texture_sprite; + set_atlas(texture); + icon_index = GFX::NO_FRAMES; + + GFX::IconTextureSprite const* const icon_texture_sprite = gfx_texture_sprite->cast_to<GFX::IconTextureSprite>(); + if (icon_texture_sprite != nullptr) { + icon_count = icon_texture_sprite->get_no_of_frames(); + } else { + icon_count = GFX::NO_FRAMES; + } + + GFX::CorneredTileTextureSprite const* const cornered_tile_texture_sprite = + gfx_texture_sprite->cast_to<GFX::CorneredTileTextureSprite>(); + if (cornered_tile_texture_sprite != nullptr) { + cornered_tile_texture = true; + cornered_tile_border_size = Utilities::to_godot_ivec2(cornered_tile_texture_sprite->get_border_size()); + } else { + cornered_tile_texture = false; + cornered_tile_border_size = {}; + } + } + return set_icon_index(icon); +} + +Error GFXSpriteTexture::set_gfx_texture_sprite_name(String const& gfx_texture_sprite_name, GFX::frame_t icon) { + if (gfx_texture_sprite_name.is_empty()) { + return set_gfx_texture_sprite(nullptr); + } + GFX::Sprite const* sprite = UITools::get_gfx_sprite(gfx_texture_sprite_name); + ERR_FAIL_NULL_V(sprite, FAILED); + GFX::TextureSprite const* new_texture_sprite = sprite->cast_to<GFX::TextureSprite>(); + ERR_FAIL_NULL_V_MSG( + new_texture_sprite, FAILED, vformat( + "Invalid type for GFX sprite %s: %s (expected %s)", gfx_texture_sprite_name, + std_view_to_godot_string(sprite->get_type()), std_view_to_godot_string(GFX::TextureSprite::get_type_static()) + ) + ); + return set_gfx_texture_sprite(new_texture_sprite, icon); +} + +String GFXSpriteTexture::get_gfx_texture_sprite_name() const { + return gfx_texture_sprite != nullptr ? std_view_to_godot_string(gfx_texture_sprite->get_name()) : String {}; +} + +Error GFXSpriteTexture::set_icon_index(int32_t new_icon_index) { + const Ref<Texture2D> atlas_texture = get_atlas(); + ERR_FAIL_NULL_V(atlas_texture, FAILED); + const Vector2 size = atlas_texture->get_size(); + if (icon_count <= GFX::NO_FRAMES) { + if (new_icon_index > GFX::NO_FRAMES) { + UtilityFunctions::push_warning("Invalid icon index ", new_icon_index, " for texture with no frames!"); + } + icon_index = GFX::NO_FRAMES; + set_region({ {}, size }); + } else { + if (GFX::NO_FRAMES < new_icon_index && new_icon_index <= icon_count) { + icon_index = new_icon_index; + } else { + icon_index = 1; + if (new_icon_index > icon_count) { + UtilityFunctions::push_warning( + "Invalid icon index ", new_icon_index, " out of count ", icon_count, " - defaulting to ", icon_index + ); + } + } + set_region({ (icon_index - 1) * size.x / icon_count, 0, size.x / icon_count, size.y }); + } + _update_button_states(); + return OK; +} + +void GFXSpriteTexture::draw_rect_cornered(RID const& to_canvas_item, Rect2 const& rect) const { + const Ref<Texture2D> atlas_texture = get_atlas(); + if (atlas_texture.is_valid()) { + if (cornered_tile_texture) { + RenderingServer* rendering_server = RenderingServer::get_singleton(); + if (rendering_server != nullptr) { + rendering_server->canvas_item_add_nine_patch( + to_canvas_item, rect, { {}, atlas_texture->get_size() }, atlas_texture->get_rid(), + cornered_tile_border_size, atlas_texture->get_size() - cornered_tile_border_size + ); + } + } else { + draw_rect(to_canvas_item, rect, false); + } + } +} diff --git a/extension/src/openvic-extension/classes/GFXIconTexture.hpp b/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp index 06dac34..783dfba 100644 --- a/extension/src/openvic-extension/classes/GFXIconTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp @@ -7,39 +7,37 @@ #include "openvic-extension/classes/GFXButtonStateTexture.hpp" namespace OpenVic { - class GFXIconTexture : public godot::AtlasTexture { - GDCLASS(GFXIconTexture, godot::AtlasTexture) + class GFXSpriteTexture : public GFXButtonStateHavingTexture { + GDCLASS(GFXSpriteTexture, GFXButtonStateHavingTexture) /* PROPERTY automatically defines getter functions: * - get_gfx_texture_sprite * - get_icon_index - * - get_icon_count */ + * - get_icon_count + * - is_cornered_tile_texture */ GFX::TextureSprite const* PROPERTY(gfx_texture_sprite); GFX::frame_t PROPERTY(icon_index); GFX::frame_t PROPERTY(icon_count); - - godot::Ref<godot::Image> sprite_image; - - static godot::StringName const& _signal_image_updated(); + bool PROPERTY_CUSTOM_PREFIX(cornered_tile_texture, is); + godot::Vector2i cornered_tile_border_size; protected: static void _bind_methods(); public: - GFXIconTexture(); - - /* Create a GFXIconTexture using the specified GFX::TextureSprite and icon index. Returns nullptr if - * set_gfx_texture_sprite fails. Connects the provided GFXButtonStateTextures (if any) to the - * GFXIconTexture's image_updated signal. */ - static godot::Ref<GFXIconTexture> make_gfx_icon_texture( - GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES, - std::vector<godot::Ref<GFXButtonStateTexture>> const& button_state_textures = {} + GFXSpriteTexture(); + + /* Create a GFXSpriteTexture using the specified GFX::TextureSprite and icon index. Returns nullptr if + * set_gfx_texture_sprite fails. */ + static godot::Ref<GFXSpriteTexture> make_gfx_sprite_texture( + GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES ); /* Discard the GFX::TextureSprite, atlas texture and icon index. */ void clear(); - /* Set the GFX::TextureSprite, load its texture as an atlas and set its displayed icon */ + /* Set the GFX::TextureSprite, load its texture as an atlas, check if it is an IconTextureSprite, + * and if so set its icon count and the current displayed icon. */ godot::Error set_gfx_texture_sprite( GFX::TextureSprite const* new_gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES ); @@ -58,5 +56,8 @@ namespace OpenVic { * If zero is used but icon_count is non-zero, icon_index defaults to icon_count (the last frame, * not the first frame because it is often empty). */ godot::Error set_icon_index(GFX::frame_t new_icon_index); + + /* Equivalent to draw_rect, but draws a 9 patch texture if this is a cornered tile texture. */ + void draw_rect_cornered(godot::RID const& to_canvas_item, godot::Rect2 const& rect) const; }; } diff --git a/extension/src/openvic-extension/classes/GUINode.cpp b/extension/src/openvic-extension/classes/GUINode.cpp index f95e3cd..a038df7 100644 --- a/extension/src/openvic-extension/classes/GUINode.cpp +++ b/extension/src/openvic-extension/classes/GUINode.cpp @@ -20,7 +20,7 @@ using namespace OpenVic; F(GUIOverlappingElementsBox, gui_overlapping_elements_box) #define APPLY_TO_TEXTURE_TYPES(F) \ - F(GFXIconTexture, gfx_icon_texture) \ + F(GFXSpriteTexture, gfx_sprite_texture) \ F(GFXMaskedFlagTexture, gfx_masked_flag_texture) \ F(GFXPieChartTexture, gfx_pie_chart_texture) diff --git a/extension/src/openvic-extension/classes/GUINode.hpp b/extension/src/openvic-extension/classes/GUINode.hpp index 0fbfc66..42074e3 100644 --- a/extension/src/openvic-extension/classes/GUINode.hpp +++ b/extension/src/openvic-extension/classes/GUINode.hpp @@ -9,7 +9,7 @@ #include <openvic-simulation/interface/GUI.hpp> -#include "openvic-extension/classes/GFXIconTexture.hpp" +#include "openvic-extension/classes/GFXSpriteTexture.hpp" #include "openvic-extension/classes/GFXMaskedFlagTexture.hpp" #include "openvic-extension/classes/GFXPieChartTexture.hpp" #include "openvic-extension/classes/GUIOverlappingElementsBox.hpp" @@ -52,12 +52,12 @@ namespace OpenVic { /* Helper functions to get textures from TextureRects and Buttons. */ static godot::Ref<godot::Texture2D> get_texture_from_node(godot::Node* node); - static godot::Ref<GFXIconTexture> get_gfx_icon_texture_from_node(godot::Node* node); + static godot::Ref<GFXSpriteTexture> get_gfx_sprite_texture_from_node(godot::Node* node); static godot::Ref<GFXMaskedFlagTexture> get_gfx_masked_flag_texture_from_node(godot::Node* node); static godot::Ref<GFXPieChartTexture> get_gfx_pie_chart_texture_from_node(godot::Node* node); godot::Ref<godot::Texture2D> get_texture_from_nodepath(godot::NodePath const& path) const; - godot::Ref<GFXIconTexture> get_gfx_icon_texture_from_nodepath(godot::NodePath const& path) const; + godot::Ref<GFXSpriteTexture> get_gfx_sprite_texture_from_nodepath(godot::NodePath const& path) const; godot::Ref<GFXMaskedFlagTexture> get_gfx_masked_flag_texture_from_nodepath(godot::NodePath const& path) const; godot::Ref<GFXPieChartTexture> get_gfx_pie_chart_texture_from_nodepath(godot::NodePath const& path) const; diff --git a/extension/src/openvic-extension/register_types.cpp b/extension/src/openvic-extension/register_types.cpp index 046bc60..431de02 100644 --- a/extension/src/openvic-extension/register_types.cpp +++ b/extension/src/openvic-extension/register_types.cpp @@ -3,7 +3,7 @@ #include <godot_cpp/classes/engine.hpp> #include "openvic-extension/classes/GFXButtonStateTexture.hpp" -#include "openvic-extension/classes/GFXIconTexture.hpp" +#include "openvic-extension/classes/GFXSpriteTexture.hpp" #include "openvic-extension/classes/GFXMaskedFlagTexture.hpp" #include "openvic-extension/classes/GFXPieChartTexture.hpp" #include "openvic-extension/classes/GUINode.hpp" @@ -45,7 +45,8 @@ void initialize_openvic_types(ModuleInitializationLevel p_level) { ClassDB::register_class<MapMesh>(); ClassDB::register_class<GFXButtonStateTexture>(); - ClassDB::register_class<GFXIconTexture>(); + ClassDB::register_abstract_class<GFXButtonStateHavingTexture>(); + ClassDB::register_class<GFXSpriteTexture>(); ClassDB::register_class<GFXMaskedFlagTexture>(); ClassDB::register_class<GFXPieChartTexture>(); ClassDB::register_class<GUINode>(); diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index 1fcc574..a3e70b5 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -12,7 +12,7 @@ #include <godot_cpp/variant/utility_functions.hpp> #include "openvic-extension/classes/GFXButtonStateTexture.hpp" -#include "openvic-extension/classes/GFXIconTexture.hpp" +#include "openvic-extension/classes/GFXSpriteTexture.hpp" #include "openvic-extension/classes/GFXMaskedFlagTexture.hpp" #include "openvic-extension/classes/GFXPieChartTexture.hpp" #include "openvic-extension/classes/GUIOverlappingElementsBox.hpp" @@ -128,17 +128,17 @@ static bool generate_icon(generate_gui_args_t&& args) { /* Change to use sprite type to choose Godot node type! */ bool ret = true; if (icon.get_sprite() != nullptr) { - if (icon.get_sprite()->is_type<GFX::TextureSprite>()) { + if (icon.get_sprite()->is_type<GFX::IconTextureSprite>()) { TextureRect* godot_texture_rect = nullptr; ret &= new_control(godot_texture_rect, icon, args.name); ERR_FAIL_NULL_V_MSG(godot_texture_rect, false, vformat("Failed to create TextureRect for GUI icon %s", icon_name)); - GFX::TextureSprite const* texture_sprite = icon.get_sprite()->cast_to<GFX::TextureSprite>(); - Ref<GFXIconTexture> texture = GFXIconTexture::make_gfx_icon_texture(texture_sprite, icon.get_frame()); + GFX::IconTextureSprite const* texture_sprite = icon.get_sprite()->cast_to<GFX::IconTextureSprite>(); + Ref<GFXSpriteTexture> texture = GFXSpriteTexture::make_gfx_sprite_texture(texture_sprite, icon.get_frame()); if (texture.is_valid()) { godot_texture_rect->set_texture(texture); } else { - UtilityFunctions::push_error("Failed to make GFXIconTexture for GUI icon ", icon_name); + UtilityFunctions::push_error("Failed to make GFXSpriteTexture for GUI icon ", icon_name); ret = false; } @@ -290,35 +290,18 @@ static bool generate_button(generate_gui_args_t&& args) { godot_button->set_text(std_view_to_godot_string(button.get_text())); } - using enum GFXButtonStateTexture::ButtonState; - static constexpr std::array<GFXButtonStateTexture::ButtonState, 3> button_states { HOVER, PRESSED, DISABLED }; - - std::vector<Ref<GFXButtonStateTexture>> button_state_textures; - for (GFXButtonStateTexture::ButtonState button_state : button_states) { - Ref<GFXButtonStateTexture> button_state_texture = GFXButtonStateTexture::make_gfx_button_state_texture(button_state); - if (button_state_texture.is_valid()) { - button_state_textures.push_back(button_state_texture); - } else { - UtilityFunctions::push_error( - "Failed to make ", GFXButtonStateTexture::button_state_to_theme_name(button_state), - " GFXButtonStateTexture for GUI button ", button_name - ); - ret = false; - } - } - if (button.get_sprite() != nullptr) { - Ref<Texture2D> texture; - if (button.get_sprite()->is_type<GFX::TextureSprite>()) { - GFX::TextureSprite const* texture_sprite = button.get_sprite()->cast_to<GFX::TextureSprite>(); - texture = GFXIconTexture::make_gfx_icon_texture(texture_sprite, 0, button_state_textures); + Ref<GFXButtonStateHavingTexture> texture; + if (button.get_sprite()->is_type<GFX::IconTextureSprite>()) { + GFX::IconTextureSprite const* texture_sprite = button.get_sprite()->cast_to<GFX::IconTextureSprite>(); + texture = GFXSpriteTexture::make_gfx_sprite_texture(texture_sprite); if (texture.is_null()) { - UtilityFunctions::push_error("Failed to make GFXIconTexture for GUI button ", button_name); + UtilityFunctions::push_error("Failed to make GFXSpriteTexture for GUI button ", button_name); ret = false; } } else if (button.get_sprite()->is_type<GFX::MaskedFlag>()) { GFX::MaskedFlag const* masked_flag = button.get_sprite()->cast_to<GFX::MaskedFlag>(); - texture = GFXMaskedFlagTexture::make_gfx_masked_flag_texture(masked_flag, button_state_textures); + texture = GFXMaskedFlagTexture::make_gfx_masked_flag_texture(masked_flag); if (texture.is_null()) { UtilityFunctions::push_error("Failed to make GFXMaskedFlagTexture for GUI button ", button_name); ret = false; @@ -332,20 +315,23 @@ static bool generate_button(generate_gui_args_t&& args) { if (texture.is_valid()) { godot_button->set_custom_minimum_size(texture->get_size()); - const auto add_stylebox = [godot_button, &button_name](StringName const& theme_name, Ref<Texture2D> const& texture) -> bool { - Ref<StyleBoxTexture> stylebox; - stylebox.instantiate(); - ERR_FAIL_NULL_V(stylebox, false); - stylebox->set_texture(texture); - godot_button->add_theme_stylebox_override(theme_name, stylebox); - return true; - }; - static const StringName theme_name_normal = "normal"; ret &= add_theme_stylebox(godot_button, theme_name_normal, texture); - for (Ref<GFXButtonStateTexture> const& button_state_texture : button_state_textures) { - ret &= add_theme_stylebox(godot_button, button_state_texture->get_button_state_theme(), button_state_texture); + using enum GFXButtonStateTexture::ButtonState; + for (GFXButtonStateTexture::ButtonState button_state : { HOVER, PRESSED, DISABLED }) { + Ref<GFXButtonStateTexture> button_state_texture = texture->get_button_state_texture(button_state); + if (button_state_texture.is_valid()) { + ret &= add_theme_stylebox( + godot_button, button_state_texture->get_button_state_theme(), button_state_texture + ); + } else { + UtilityFunctions::push_error( + "Failed to make ", GFXButtonStateTexture::button_state_to_theme_name(button_state), + " GFXButtonStateTexture for GUI button ", button_name + ); + ret = false; + } } } } else { @@ -387,21 +373,21 @@ static bool generate_checkbox(generate_gui_args_t&& args) { ERR_FAIL_NULL_V_MSG(godot_checkbox, false, vformat("Failed to create CheckBox for GUI checkbox %s", checkbox_name)); if (checkbox.get_sprite() != nullptr) { - GFX::TextureSprite const* texture_sprite = checkbox.get_sprite()->cast_to<GFX::TextureSprite>(); + GFX::IconTextureSprite const* texture_sprite = checkbox.get_sprite()->cast_to<GFX::IconTextureSprite>(); if (texture_sprite != nullptr) { - Ref<GFXIconTexture> icon_texture = GFXIconTexture::make_gfx_icon_texture(texture_sprite, 1); + Ref<GFXSpriteTexture> icon_texture = GFXSpriteTexture::make_gfx_sprite_texture(texture_sprite, 1); if (icon_texture.is_valid()) { godot_checkbox->set_custom_minimum_size(icon_texture->get_size()); godot_checkbox->add_theme_icon_override("unchecked", icon_texture); } else { - UtilityFunctions::push_error("Failed to make unchecked GFXIconTexture for GUI checkbox ", checkbox_name); + UtilityFunctions::push_error("Failed to make unchecked GFXSpriteTexture for GUI checkbox ", checkbox_name); ret = false; } - icon_texture = GFXIconTexture::make_gfx_icon_texture(texture_sprite, 2); + icon_texture = GFXSpriteTexture::make_gfx_sprite_texture(texture_sprite, 2); if (icon_texture.is_valid()) { godot_checkbox->add_theme_icon_override("checked", icon_texture); } else { - UtilityFunctions::push_error("Failed to make checked GFXIconTexture for GUI checkbox ", checkbox_name); + UtilityFunctions::push_error("Failed to make checked GFXSpriteTexture for GUI checkbox ", checkbox_name); ret = false; } } else { diff --git a/game/src/Game/GameSession/ProvinceOverviewPanel.gd b/game/src/Game/GameSession/ProvinceOverviewPanel.gd index cb76241..bf3c3dc 100644 --- a/game/src/Game/GameSession/ProvinceOverviewPanel.gd +++ b/game/src/Game/GameSession/ProvinceOverviewPanel.gd @@ -5,23 +5,23 @@ var _province_name_label : Label var _region_name_label : Label var _slave_status_icon : TextureRect var _colony_status_button : Button -var _colony_status_button_texture : GFXIconTexture +var _colony_status_button_texture : GFXSpriteTexture var _administrative_percentage_label : Label var _owner_percentage_label : Label var _province_modifiers_overlapping_elements_box : GUIOverlappingElementsBox -var _terrain_type_texture : GFXIconTexture +var _terrain_type_texture : GFXSpriteTexture var _life_rating_bar : TextureProgressBar var _controller_flag_texture : GFXMaskedFlagTexture # Statistics -var _rgo_icon_texture : GFXIconTexture +var _rgo_icon_texture : GFXSpriteTexture var _rgo_produced_label : Label var _rgo_income_label : Label -var _rgo_employment_percentage_texture : GFXIconTexture +var _rgo_employment_percentage_texture : GFXSpriteTexture var _rgo_employment_population_label : Label var _rgo_employment_percentage_label : Label var _crime_name_label : Label -var _crime_icon_texture : GFXIconTexture +var _crime_icon_texture : GFXSpriteTexture var _crime_fighting_label : Label var _total_population_label : Label var _migration_label : Label @@ -44,7 +44,7 @@ class BuildingSlot: var _slot_index : int var _slot_node : Control - var _building_icon : GFXIconTexture + var _building_icon : GFXSpriteTexture var _expand_button : Button var _expanding_icon : TextureRect var _expanding_progress_bar : TextureProgressBar @@ -64,7 +64,7 @@ class BuildingSlot: var icon := _slot_node.get_node("build_icon%d" % icon_index) if icon: if icon_index == _slot_index: - _building_icon = GUINode.get_gfx_icon_texture_from_node(icon) + _building_icon = GUINode.get_gfx_sprite_texture_from_node(icon) else: icon.hide() @@ -133,12 +133,12 @@ func _ready() -> void: _province_name_label = get_label_from_nodepath(^"./province_view/province_view_header/province_name") _region_name_label = get_label_from_nodepath(^"./province_view/province_view_header/state_name") _slave_status_icon = get_texture_rect_from_nodepath(^"./province_view/province_view_header/slave_state_icon") - var slave_status_icon_texture : GFXIconTexture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_view_header/slave_state_icon") + var slave_status_icon_texture : GFXSpriteTexture = get_gfx_sprite_texture_from_nodepath(^"./province_view/province_view_header/slave_state_icon") if slave_status_icon_texture: slave_status_icon_texture.set_icon_index(GameSingleton.get_slave_pop_icon_index()) _colony_status_button = get_button_from_nodepath(^"./province_view/province_view_header/colony_button") - _colony_status_button_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_view_header/colony_button") - var admin_icon_texture : GFXIconTexture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_view_header/admin_icon") + _colony_status_button_texture = get_gfx_sprite_texture_from_nodepath(^"./province_view/province_view_header/colony_button") + var admin_icon_texture : GFXSpriteTexture = get_gfx_sprite_texture_from_nodepath(^"./province_view/province_view_header/admin_icon") if admin_icon_texture: admin_icon_texture.set_icon_index(GameSingleton.get_administrative_pop_icon_index()) _administrative_percentage_label = get_label_from_nodepath(^"./province_view/province_view_header/admin_efficiency") @@ -146,19 +146,19 @@ func _ready() -> void: _province_modifiers_overlapping_elements_box = get_gui_overlapping_elements_box_from_nodepath(^"./province_view/province_view_header/province_modifiers") if _province_modifiers_overlapping_elements_box and _province_modifiers_overlapping_elements_box.set_gui_child_element_name("province_interface", "prov_state_modifier") != OK: _province_modifiers_overlapping_elements_box = null # hide province modifiers box since we can't do anything with it - _terrain_type_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_view_header/prov_terrain") + _terrain_type_texture = get_gfx_sprite_texture_from_nodepath(^"./province_view/province_view_header/prov_terrain") _life_rating_bar = get_progress_bar_from_nodepath(^"./province_view/province_view_header/liferating") _controller_flag_texture = get_gfx_masked_flag_texture_from_nodepath(^"./province_view/province_view_header/controller_flag") # Statistics - _rgo_icon_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_statistics/goods_type") + _rgo_icon_texture = get_gfx_sprite_texture_from_nodepath(^"./province_view/province_statistics/goods_type") _rgo_produced_label = get_label_from_nodepath(^"./province_view/province_statistics/produced") _rgo_income_label = get_label_from_nodepath(^"./province_view/province_statistics/income") - _rgo_employment_percentage_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_statistics/employment_ratio") + _rgo_employment_percentage_texture = get_gfx_sprite_texture_from_nodepath(^"./province_view/province_statistics/employment_ratio") _rgo_employment_population_label = get_label_from_nodepath(^"./province_view/province_statistics/rgo_population") _rgo_employment_percentage_label = get_label_from_nodepath(^"./province_view/province_statistics/rgo_percent") _crime_name_label = get_label_from_nodepath(^"./province_view/province_statistics/crime_name") - _crime_icon_texture = get_gfx_icon_texture_from_nodepath(^"./province_view/province_statistics/crime_icon") + _crime_icon_texture = get_gfx_sprite_texture_from_nodepath(^"./province_view/province_statistics/crime_icon") _crime_fighting_label = get_label_from_nodepath(^"./province_view/province_statistics/crimefight_percent") _total_population_label = get_label_from_nodepath(^"./province_view/province_statistics/total_population") _migration_label = get_label_from_nodepath(^"./province_view/province_statistics/migration") @@ -280,7 +280,7 @@ func _update_info() -> void: # TODO - replace example icons with those from the province's list of modifier instances _province_modifiers_overlapping_elements_box.set_child_count(8) for i : int in _province_modifiers_overlapping_elements_box.get_child_count(): - var icon : GFXIconTexture = GUINode.get_gfx_icon_texture_from_node( + var icon : GFXSpriteTexture = GUINode.get_gfx_sprite_texture_from_node( _province_modifiers_overlapping_elements_box.get_child(i).get_node(^"./modifier") ) if icon: diff --git a/game/src/Game/GameSession/Topbar.gd b/game/src/Game/GameSession/Topbar.gd index 3cfc0e6..e660c6a 100644 --- a/game/src/Game/GameSession/Topbar.gd +++ b/game/src/Game/GameSession/Topbar.gd @@ -5,13 +5,13 @@ extends GUINode var _speed_up_button : Button var _speed_down_button : Button var _speed_indicator_button : Button -var _speed_indicator_texture : GFXIconTexture +var _speed_indicator_texture : GFXSpriteTexture var _date_label : Label var _country_name_label : Label # NationManagement.Screen-Button var _nation_management_buttons : Dictionary -# NationManagement.Screen-GFXIconTexture +# NationManagement.Screen-GFXSpriteTexture var _nation_management_button_textures : Dictionary func _ready() -> void: @@ -54,7 +54,7 @@ func _ready() -> void: _speed_indicator_button = get_button_from_nodepath(^"./topbar/speed_indicator") if _speed_indicator_button: _speed_indicator_button.pressed.connect(_on_play_pause_button_pressed) - _speed_indicator_texture = GUINode.get_gfx_icon_texture_from_node(_speed_indicator_button) + _speed_indicator_texture = GUINode.get_gfx_sprite_texture_from_node(_speed_indicator_button) # Nation management screens const screen_nodepaths : Dictionary = { @@ -73,7 +73,7 @@ func _ready() -> void: button.pressed.connect( Events.NationManagementScreens.toggle_nation_management_screen.bind(screen) ) - var icon : GFXIconTexture = get_gfx_icon_texture_from_node(button) + var icon : GFXSpriteTexture = get_gfx_sprite_texture_from_node(button) if icon: _nation_management_buttons[screen] = button _nation_management_button_textures[screen] = icon |