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) --- .../src/openvic-extension/classes/GUITextLabel.hpp | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 extension/src/openvic-extension/classes/GUITextLabel.hpp (limited to 'extension/src/openvic-extension/classes/GUITextLabel.hpp') diff --git a/extension/src/openvic-extension/classes/GUITextLabel.hpp b/extension/src/openvic-extension/classes/GUITextLabel.hpp new file mode 100644 index 0000000..b29870e --- /dev/null +++ b/extension/src/openvic-extension/classes/GUITextLabel.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include + +#include + +namespace OpenVic { + class GUITextLabel : public godot::RichTextLabel { + GDCLASS(GUITextLabel, godot::RichTextLabel) + + using colour_instructions_t = std::vector>; + + GUI::Text const* PROPERTY(gui_text); + + godot::String PROPERTY(text); + godot::Dictionary PROPERTY(substitution_dict); + godot::HorizontalAlignment PROPERTY(alignment); + real_t font_height; + GFX::Font::colour_codes_t const* colour_codes; + int32_t PROPERTY(max_lines); + + bool update_queued; + + protected: + static void _bind_methods(); + + void _notification(int what); + + public: + GUITextLabel(); + + /* Reset gui_text to nullptr and reset current text. */ + void clear(); + + /* Set the GUI::Text. */ + godot::Error set_gui_text(GUI::Text const* new_gui_text); + + /* Return the name of the GUI::Text, or an empty String if it's null. */ + godot::String get_gui_text_name() const; + + void set_text(godot::String const& new_text); + void add_substitution(godot::String const& key, godot::String const& value); + void set_substitution_dict(godot::Dictionary const& new_substitution_dict); + void clear_substitutions(); + + /* Any text going over this number of lines will be trimmed and replaced with an ellipsis. + * Values less than 1 indicate no limit. Default value: 1. */ + void set_max_lines(int32_t new_max_lines); + + private: + godot::Error _update_font(); + + void _queue_update(); + void _update_text(); + void _generate_text(godot::String const& display_text, colour_instructions_t const& colour_instructions); + }; +} -- cgit v1.2.3-56-ga3b1