Port ModSwitchButton

This commit is contained in:
Serhii Snitsaruk 2024-01-07 13:45:27 +01:00
parent f9ad9cc794
commit 73497b1908
4 changed files with 26 additions and 3 deletions

View File

@ -11,9 +11,13 @@
#include "mode_switch_button.h" #include "mode_switch_button.h"
#include "../util/limbo_string_names.h"
#ifdef LIMBOAI_MODULE
#include "core/error/error_macros.h" #include "core/error/error_macros.h"
#include "core/object/object.h" #include "core/object/object.h"
#include "core/variant/variant.h" #include "core/variant/variant.h"
#endif // LIMBOAI_MODULE
void ModeSwitchButton::add_mode(int p_id, const Ref<Texture2D> &p_icon, const String &p_tooltip) { void ModeSwitchButton::add_mode(int p_id, const Ref<Texture2D> &p_icon, const String &p_tooltip) {
bool unique_id = true; bool unique_id = true;
@ -50,7 +54,7 @@ void ModeSwitchButton::set_mode(int p_id, bool p_no_signal) {
_set_mode_by_index(idx); _set_mode_by_index(idx);
if (!p_no_signal) { if (!p_no_signal) {
emit_signal(SNAME("mode_changed")); emit_signal(LSNAME(mode_changed));
} }
} }
@ -69,5 +73,5 @@ void ModeSwitchButton::_bind_methods() {
} }
ModeSwitchButton::ModeSwitchButton() { 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));
} }

View File

@ -12,11 +12,26 @@
#ifndef MODE_SWITCH_BUTTON #ifndef MODE_SWITCH_BUTTON
#define MODE_SWITCH_BUTTON #define MODE_SWITCH_BUTTON
#ifdef LIMBOAI_MODULE
#include "scene/gui/button.h" #include "scene/gui/button.h"
#include "core/typedefs.h" #include "core/typedefs.h"
#include "scene/resources/texture.h" #include "scene/resources/texture.h"
#define SET_ICON(m_tex) set_icon(m_tex)
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/texture2d.hpp>
#include <godot_cpp/templates/vector.hpp>
using namespace godot;
#define SET_BUTTON_ICON(m_tex) set_button_icon(m_tex)
#endif // LIMBOAI_GDEXTENSION
class ModeSwitchButton : public Button { class ModeSwitchButton : public Button {
GDCLASS(ModeSwitchButton, Button); GDCLASS(ModeSwitchButton, Button);
@ -32,7 +47,7 @@ private:
_FORCE_INLINE_ void _set_mode_by_index(int p_index) { _FORCE_INLINE_ void _set_mode_by_index(int p_index) {
current_mode_index = 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()) { if (!modes[current_mode_index].tooltip.is_empty()) {
set_tooltip_text(modes[current_mode_index].tooltip); set_tooltip_text(modes[current_mode_index].tooltip);
} }

View File

@ -53,6 +53,8 @@ LimboStringNames::LimboStringNames() {
item_collapsed = SN("item_collapsed"); item_collapsed = SN("item_collapsed");
pressed = SN("pressed"); pressed = SN("pressed");
StatusWarning = SN("StatusWarning"); StatusWarning = SN("StatusWarning");
mode_changed = SN("mode_changed");
connect = SN("connect");
EVENT_FINISHED = "finished"; EVENT_FINISHED = "finished";
repeat_forever.parse_utf8("Repeat ∞"); repeat_forever.parse_utf8("Repeat ∞");

View File

@ -72,6 +72,8 @@ public:
StringName item_collapsed; StringName item_collapsed;
StringName pressed; StringName pressed;
StringName StatusWarning; StringName StatusWarning;
StringName mode_changed;
StringName connect;
String EVENT_FINISHED; String EVENT_FINISHED;
String repeat_forever; String repeat_forever;