From 73497b19080300f95aef74a9cfe133b739c3300d Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sun, 7 Jan 2024 13:45:27 +0100 Subject: [PATCH] Port ModSwitchButton --- editor/mode_switch_button.cpp | 8 ++++++-- editor/mode_switch_button.h | 17 ++++++++++++++++- util/limbo_string_names.cpp | 2 ++ util/limbo_string_names.h | 2 ++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/editor/mode_switch_button.cpp b/editor/mode_switch_button.cpp index b50fa6e..11e0e07 100644 --- a/editor/mode_switch_button.cpp +++ b/editor/mode_switch_button.cpp @@ -11,9 +11,13 @@ #include "mode_switch_button.h" +#include "../util/limbo_string_names.h" + +#ifdef LIMBOAI_MODULE #include "core/error/error_macros.h" #include "core/object/object.h" #include "core/variant/variant.h" +#endif // LIMBOAI_MODULE void ModeSwitchButton::add_mode(int p_id, const Ref &p_icon, const String &p_tooltip) { bool unique_id = true; @@ -50,7 +54,7 @@ void ModeSwitchButton::set_mode(int p_id, bool p_no_signal) { _set_mode_by_index(idx); if (!p_no_signal) { - emit_signal(SNAME("mode_changed")); + emit_signal(LSNAME(mode_changed)); } } @@ -69,5 +73,5 @@ void ModeSwitchButton::_bind_methods() { } ModeSwitchButton::ModeSwitchButton() { - call_deferred(SNAME("connect"), SNAME("pressed"), callable_mp(this, &ModeSwitchButton::next_mode)); + call_deferred(LSNAME(connect), LSNAME(pressed), callable_mp(this, &ModeSwitchButton::next_mode)); } diff --git a/editor/mode_switch_button.h b/editor/mode_switch_button.h index b27e92e..baa3a5a 100644 --- a/editor/mode_switch_button.h +++ b/editor/mode_switch_button.h @@ -12,11 +12,26 @@ #ifndef MODE_SWITCH_BUTTON #define MODE_SWITCH_BUTTON +#ifdef LIMBOAI_MODULE #include "scene/gui/button.h" #include "core/typedefs.h" #include "scene/resources/texture.h" +#define SET_ICON(m_tex) set_icon(m_tex) +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include +#include +#include + +using namespace godot; + +#define SET_BUTTON_ICON(m_tex) set_button_icon(m_tex) + +#endif // LIMBOAI_GDEXTENSION + class ModeSwitchButton : public Button { GDCLASS(ModeSwitchButton, Button); @@ -32,7 +47,7 @@ private: _FORCE_INLINE_ void _set_mode_by_index(int p_index) { current_mode_index = p_index; - set_icon(modes[current_mode_index].icon); + SET_BUTTON_ICON(modes[current_mode_index].icon); if (!modes[current_mode_index].tooltip.is_empty()) { set_tooltip_text(modes[current_mode_index].tooltip); } diff --git a/util/limbo_string_names.cpp b/util/limbo_string_names.cpp index 91e90d8..d4ac276 100644 --- a/util/limbo_string_names.cpp +++ b/util/limbo_string_names.cpp @@ -53,6 +53,8 @@ LimboStringNames::LimboStringNames() { item_collapsed = SN("item_collapsed"); pressed = SN("pressed"); StatusWarning = SN("StatusWarning"); + mode_changed = SN("mode_changed"); + connect = SN("connect"); EVENT_FINISHED = "finished"; repeat_forever.parse_utf8("Repeat ∞"); diff --git a/util/limbo_string_names.h b/util/limbo_string_names.h index 7e3a48d..4aa4da9 100644 --- a/util/limbo_string_names.h +++ b/util/limbo_string_names.h @@ -72,6 +72,8 @@ public: StringName item_collapsed; StringName pressed; StringName StatusWarning; + StringName mode_changed; + StringName connect; String EVENT_FINISHED; String repeat_forever;