aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-08-28 19:46:30 +0200
committer hop311 <hop3114@gmail.com>2024-08-28 23:51:31 +0200
commit88acb31bd43f0e163522837bb1d0dd7da2977c4a (patch)
tree241cbf8cf21a7cdfe1c870469ac3b3ef3064bdb3 /extension/src/openvic-extension/singletons
parentd7672f406406eea46625bc725690651f28211e19 (diff)
Switch to using custom UI nodes
Diffstat (limited to 'extension/src/openvic-extension/singletons')
-rw-r--r--extension/src/openvic-extension/singletons/AssetManager.cpp23
-rw-r--r--extension/src/openvic-extension/singletons/AssetManager.hpp6
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp2
3 files changed, 30 insertions, 1 deletions
diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp
index d17edd0..3b37c8c 100644
--- a/extension/src/openvic-extension/singletons/AssetManager.cpp
+++ b/extension/src/openvic-extension/singletons/AssetManager.cpp
@@ -120,6 +120,29 @@ Ref<ImageTexture> AssetManager::get_texture(StringName const& path, LoadFlags lo
}
}
+Ref<StyleBoxTexture> AssetManager::make_stylebox_texture(Ref<Texture2D> const& texture, Vector2 const& border) {
+ ERR_FAIL_NULL_V(texture, nullptr);
+
+ Ref<StyleBoxTexture> stylebox;
+ stylebox.instantiate();
+ ERR_FAIL_NULL_V(stylebox, nullptr);
+
+ stylebox->set_texture(texture);
+
+ static const StringName changed_signal = "changed";
+ static const StringName emit_changed_func = "emit_changed";
+ texture->connect(changed_signal, Callable { *stylebox, emit_changed_func }, Object::CONNECT_PERSIST);
+
+ if (border != Vector2 {}) {
+ stylebox->set_texture_margin(SIDE_LEFT, border.x);
+ stylebox->set_texture_margin(SIDE_RIGHT, border.x);
+ stylebox->set_texture_margin(SIDE_TOP, border.y);
+ stylebox->set_texture_margin(SIDE_BOTTOM, border.y);
+ }
+
+ return stylebox;
+}
+
Ref<FontFile> AssetManager::get_font(StringName const& name) {
const font_map_t::const_iterator it = fonts.find(name);
if (it != fonts.end()) {
diff --git a/extension/src/openvic-extension/singletons/AssetManager.hpp b/extension/src/openvic-extension/singletons/AssetManager.hpp
index deca309..96cb880 100644
--- a/extension/src/openvic-extension/singletons/AssetManager.hpp
+++ b/extension/src/openvic-extension/singletons/AssetManager.hpp
@@ -3,7 +3,9 @@
#include <godot_cpp/classes/atlas_texture.hpp>
#include <godot_cpp/classes/font_file.hpp>
#include <godot_cpp/classes/image_texture.hpp>
+#include <godot_cpp/classes/style_box_texture.hpp>
#include <godot_cpp/core/class_db.hpp>
+#include <godot_cpp/variant/vector2.hpp>
#include <openvic-simulation/interface/GFXSprite.hpp>
@@ -68,6 +70,10 @@ namespace OpenVic {
godot::StringName const& path, LoadFlags load_flags = LOAD_FLAG_CACHE_TEXTURE
);
+ static godot::Ref<godot::StyleBoxTexture> make_stylebox_texture(
+ godot::Ref<godot::Texture2D> const& texture, godot::Vector2 const& border = {}
+ );
+
/* Search for and load a font with the specified name from the game defines' font directory, first checking the
* AssetManager's font cache in case it has already been loaded, and returning nullptr if font loading fails. */
godot::Ref<godot::FontFile> get_font(godot::StringName const& name);
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index 7a5f47f..b95bc15 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -561,7 +561,7 @@ Error MenuSingleton::generate_search_cache() {
return OK;
}
-void MenuSingleton::update_search_results(godot::String const& text) {
+void MenuSingleton::update_search_results(String const& text) {
// Sanatise input
const String search_text = text.strip_edges().to_lower();