diff options
author | Hop311 <Hop3114@gmail.com> | 2024-01-01 20:45:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-01 20:45:57 +0100 |
commit | cf34ce1d7459ee91fc75e89835a8e7171fac636b (patch) | |
tree | 54c19503dc6e1bfbda1e11cf5f403e5038046cbe /extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp | |
parent | 8fc620484ac406c7a86b92553d77a0bd20e4143b (diff) | |
parent | c0cc6e202c33fb3889d0025b1b04148ae66545f2 (diff) |
Merge pull request #181 from OpenVicProject/ui-state-style
UI polish
Diffstat (limited to 'extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp')
-rw-r--r-- | extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp index 424be33..0a44e56 100644 --- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp @@ -13,15 +13,22 @@ 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); - bool can_update = true; - if (combined_image.is_null() || combined_image->get_size() != overlay_image->get_size()) { + /* 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(); + if (!can_update) { combined_image = Image::create( overlay_image->get_width(), overlay_image->get_height(), false, overlay_image->get_format() ); ERR_FAIL_NULL_V(combined_image, FAILED); - can_update = false; } if (mask_image.is_valid() && flag_image.is_valid()) { @@ -55,6 +62,7 @@ Error GFXMaskedFlagTexture::_generate_combined_image() { } else { set_image(combined_image); } + emit_signal(_signal_image_updated(), combined_image); return OK; } @@ -68,14 +76,29 @@ 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) { +Ref<GFXMaskedFlagTexture> GFXMaskedFlagTexture::make_gfx_masked_flag_texture( + GFX::MaskedFlag const* gfx_masked_flag, std::vector<Ref<GFXButtonStateTexture>> const& button_state_textures +) { 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; } |