From c0cc6e202c33fb3889d0025b1b04148ae66545f2 Mon Sep 17 00:00:00 2001 From: hop311 Date: Sat, 30 Dec 2023 14:59:20 +0000 Subject: Added button state textures + block colour progress bars --- .../src/openvic-extension/utility/UITools.cpp | 118 +++++++++++++++++---- 1 file changed, 99 insertions(+), 19 deletions(-) (limited to 'extension/src/openvic-extension/utility') diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index 67ea8f5..409a3ba 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -11,6 +11,7 @@ #include #include +#include "openvic-extension/classes/GFXButtonStateTexture.hpp" #include "openvic-extension/classes/GFXIconTexture.hpp" #include "openvic-extension/classes/GFXMaskedFlagTexture.hpp" #include "openvic-extension/classes/GFXPieChartTexture.hpp" @@ -138,28 +139,75 @@ static bool generate_icon(generate_gui_args_t&& args) { godot_progress_bar, false, vformat("Failed to create TextureProgressBar for GUI icon %s", icon_name) ); - const StringName back_texture_file = - std_view_to_godot_string_name(icon.get_sprite()->cast_to()->get_back_texture_file()); - const Ref back_texture = args.asset_manager.get_texture(back_texture_file); + GFX::ProgressBar const* progress_bar = icon.get_sprite()->cast_to(); + + Ref back_texture; + if (!progress_bar->get_back_texture_file().empty()) { + const StringName back_texture_file = std_view_to_godot_string_name(progress_bar->get_back_texture_file()); + back_texture = args.asset_manager.get_texture(back_texture_file); + if (back_texture.is_null()) { + UtilityFunctions::push_error( + "Failed to load progress bar sprite back texture ", back_texture_file, " for GUI icon ", icon_name + ); + ret = false; + } + } + if (back_texture.is_null()) { + const Color back_colour = Utilities::to_godot_color(progress_bar->get_back_colour()); + back_texture = Utilities::make_solid_colour_texture( + back_colour, progress_bar->get_size().x, progress_bar->get_size().y + ); + if (back_texture.is_null()) { + UtilityFunctions::push_error( + "Failed to generate progress bar sprite ", back_colour, " back texture for GUI icon ", icon_name + ); + ret = false; + } + } if (back_texture.is_valid()) { godot_progress_bar->set_under_texture(back_texture); } else { - UtilityFunctions::push_error("Failed to load progress bar base sprite ", back_texture_file, " for GUI icon ", icon_name); + UtilityFunctions::push_error( + "Failed to create and set progress bar sprite back texture for GUI icon ", icon_name + ); ret = false; } - const StringName progress_texture_file = - std_view_to_godot_string_name(icon.get_sprite()->cast_to()->get_progress_texture_file()); - const Ref progress_texture = args.asset_manager.get_texture(progress_texture_file); + Ref progress_texture; + if (!progress_bar->get_progress_texture_file().empty()) { + const StringName progress_texture_file = std_view_to_godot_string_name(progress_bar->get_progress_texture_file()); + progress_texture = args.asset_manager.get_texture(progress_texture_file); + if (progress_texture.is_null()) { + UtilityFunctions::push_error( + "Failed to load progress bar sprite progress texture ", progress_texture_file, " for GUI icon ", icon_name + ); + ret = false; + } + } + if (progress_texture.is_null()) { + const Color progress_colour = Utilities::to_godot_color(progress_bar->get_progress_colour()); + progress_texture = Utilities::make_solid_colour_texture( + progress_colour, progress_bar->get_size().x, progress_bar->get_size().y + ); + if (progress_texture.is_null()) { + UtilityFunctions::push_error( + "Failed to generate progress bar sprite ", progress_colour, " progress texture for GUI icon ", icon_name + ); + ret = false; + } + } if (progress_texture.is_valid()) { godot_progress_bar->set_progress_texture(progress_texture); } else { UtilityFunctions::push_error( - "Failed to load progress bar base sprite ", progress_texture_file, " for GUI icon ", icon_name + "Failed to create and set progress bar sprite progress texture for GUI icon ", icon_name ); ret = false; } + // TODO - work out why progress bar is missing bottom border pixel (e.g. province building expansion bar) + godot_progress_bar->set_custom_minimum_size(Utilities::to_godot_fvec2(static_cast(progress_bar->get_size()))); + args.result = godot_progress_bar; } else if (icon.get_sprite()->is_type()) { TextureRect* godot_texture_rect = new_control(icon, args.name); @@ -202,23 +250,43 @@ static bool generate_button(generate_gui_args_t&& args) { Button* godot_button = new_control