From 7c85ab11e840c281a2499dcc6dd3219c33e7d37f Mon Sep 17 00:00:00 2001 From: hop311 Date: Thu, 15 Aug 2024 00:13:54 +0100 Subject: Add GUITextLabel (colour code + currency icon support) --- .../openvic-extension/singletons/AssetManager.cpp | 42 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'extension/src/openvic-extension/singletons/AssetManager.cpp') diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp index eec1ada..d17edd0 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.cpp +++ b/extension/src/openvic-extension/singletons/AssetManager.cpp @@ -4,6 +4,7 @@ #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/utility/ClassBindings.hpp" +#include "openvic-extension/utility/UITools.hpp" #include "openvic-extension/utility/Utilities.hpp" using namespace godot; @@ -119,7 +120,7 @@ Ref AssetManager::get_texture(StringName const& path, LoadFlags lo } } -Ref AssetManager::get_font(StringName const& name) { +Ref AssetManager::get_font(StringName const& name) { const font_map_t::const_iterator it = fonts.find(name); if (it != fonts.end()) { ERR_FAIL_NULL_V_MSG(it->second, nullptr, vformat("Failed to load font previously: %s", name)); @@ -152,7 +153,7 @@ Ref AssetManager::get_font(StringName const& name) { ERR_FAIL_V_MSG(nullptr, vformat("Failed to look up font: %s", font_path)); } - const Ref font = Utilities::load_godot_font(lookedup_font_path, image); + const Ref font = Utilities::load_godot_font(lookedup_font_path, image); if (font.is_null()) { fonts.emplace(name, nullptr); @@ -165,3 +166,40 @@ Ref AssetManager::get_font(StringName const& name) { fonts.emplace(name, font); return font; } + +Error AssetManager::preload_textures() { + static const String currency_sprite_big = "GFX_tooltip_money_big"; + static const String currency_sprite_medium = "GFX_tooltip_money_small"; + static const String currency_sprite_small = "GFX_tooltip_money"; + + constexpr auto load = [](String const& sprite_name, Ref& texture) -> bool { + GFX::Sprite const* sprite = UITools::get_gfx_sprite(sprite_name); + ERR_FAIL_NULL_V(sprite, false); + + GFX::IconTextureSprite const* icon_sprite = sprite->cast_to(); + ERR_FAIL_NULL_V(icon_sprite, false); + + texture = GFXSpriteTexture::make_gfx_sprite_texture(icon_sprite); + ERR_FAIL_NULL_V(texture, false); + + return true; + }; + + bool ret = true; + + ret &= load(currency_sprite_big, currency_texture_big); + ret &= load(currency_sprite_medium, currency_texture_medium); + ret &= load(currency_sprite_small, currency_texture_small); + + return ERR(ret); +} + +Ref const& AssetManager::get_currency_texture(real_t height) const { + if (height > currency_texture_big->get_height()) { + return currency_texture_big; + } else if (height > currency_texture_medium->get_height()) { + return currency_texture_medium; + } else { + return currency_texture_small; + } +} -- cgit v1.2.3-56-ga3b1