diff options
author | hop311 <hop3114@gmail.com> | 2024-02-24 14:17:07 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-02-24 14:17:07 +0100 |
commit | 843edde55306e3fbdb5e37ef9b7c09c7b53f50c4 (patch) | |
tree | 487fea19d42106c08b60f5bba99bc76485073002 /extension/src/openvic-extension/utility | |
parent | 5d7c6eafe35e2c6e952bc0b3f91d27d760c8e75e (diff) |
Added GUIScrollbar and GFXCorneredTileSupportingTexturescrollbar
Diffstat (limited to 'extension/src/openvic-extension/utility')
-rw-r--r-- | extension/src/openvic-extension/utility/UITools.cpp | 20 | ||||
-rw-r--r-- | extension/src/openvic-extension/utility/Utilities.cpp | 5 | ||||
-rw-r--r-- | extension/src/openvic-extension/utility/Utilities.hpp | 2 |
3 files changed, 22 insertions, 5 deletions
diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index a3e70b5..9cd5db0 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -16,6 +16,7 @@ #include "openvic-extension/classes/GFXMaskedFlagTexture.hpp" #include "openvic-extension/classes/GFXPieChartTexture.hpp" #include "openvic-extension/classes/GUIOverlappingElementsBox.hpp" +#include "openvic-extension/classes/GUIScrollbar.hpp" #include "openvic-extension/singletons/AssetManager.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -133,6 +134,8 @@ static bool generate_icon(generate_gui_args_t&& args) { 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)); + godot_texture_rect->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + 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()) { @@ -461,6 +464,7 @@ static bool generate_overlapping_elements(generate_gui_args_t&& args) { box, false, vformat("Failed to create GUIOverlappingElementsBox for GUI overlapping elements %s", overlapping_elements_name) ); + box->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); ret &= box->set_gui_overlapping_elements_box(&overlapping_elements) == OK; args.result = box; return ret; @@ -503,7 +507,21 @@ static bool generate_texteditbox(generate_gui_args_t&& args) { } static bool generate_scrollbar(generate_gui_args_t&& args) { - return generate_placeholder<GUI::Scrollbar>(std::move(args), { 1.0f, 0.0f, 0.0f, 0.3f }); + GUI::Scrollbar const& scrollbar = static_cast<GUI::Scrollbar const&>(args.element); + + const String scrollbar_name = std_view_to_godot_string(scrollbar.get_name()); + + GUIScrollbar* gui_scrollbar = nullptr; + bool ret = new_control(gui_scrollbar, scrollbar, args.name); + ERR_FAIL_NULL_V_MSG(gui_scrollbar, false, vformat("Failed to create GUIScrollbar for GUI scrollbar %s", scrollbar_name)); + + if (gui_scrollbar->set_gui_scrollbar(&scrollbar) != OK) { + UtilityFunctions::push_error("Error initialising GUIScrollbar for GUI scrollbar ", scrollbar_name); + ret = false; + } + + args.result = gui_scrollbar; + return ret; } /* Forward declaration for use in generate_window. */ diff --git a/extension/src/openvic-extension/utility/Utilities.cpp b/extension/src/openvic-extension/utility/Utilities.cpp index 5957b70..7450212 100644 --- a/extension/src/openvic-extension/utility/Utilities.cpp +++ b/extension/src/openvic-extension/utility/Utilities.cpp @@ -36,9 +36,8 @@ String Utilities::int_to_formatted_string(int64_t val) { return (negative ? "-" : "") + String::num_int64(val); } -/* Float to formatted to 4 decimal place string. */ -String Utilities::float_to_formatted_string(float val) { - static constexpr int64_t decimal_places = 4; +/* Float to string formatted with the specified number of decimal places. */ +String Utilities::float_to_formatted_string(float val, int32_t decimal_places) { return String::num(val, decimal_places).pad_decimals(decimal_places); } diff --git a/extension/src/openvic-extension/utility/Utilities.hpp b/extension/src/openvic-extension/utility/Utilities.hpp index 9b45abc..f39be3e 100644 --- a/extension/src/openvic-extension/utility/Utilities.hpp +++ b/extension/src/openvic-extension/utility/Utilities.hpp @@ -33,7 +33,7 @@ namespace OpenVic::Utilities { godot::String int_to_formatted_string(int64_t val); - godot::String float_to_formatted_string(float val); + godot::String float_to_formatted_string(float val, int32_t decimal_places); godot::String date_to_formatted_string(Date date); |