From 97daa29eda75d0df6da52c6945088b968a0275d0 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sun, 7 Jan 2024 17:33:05 +0100 Subject: [PATCH] Port TaskPalette Not even sure if it works, since I need other bits before I test it. --- editor/task_palette.cpp | 179 +++++++++++++++++++++++------------- editor/task_palette.h | 36 +++++++- util/limbo_def.cpp | 20 +++- util/limbo_def.h | 27 ++++++ util/limbo_string_names.cpp | 22 +++++ util/limbo_string_names.h | 22 +++++ 6 files changed, 238 insertions(+), 68 deletions(-) diff --git a/editor/task_palette.cpp b/editor/task_palette.cpp index a462a8f..3e37068 100644 --- a/editor/task_palette.cpp +++ b/editor/task_palette.cpp @@ -11,9 +11,12 @@ #include "task_palette.h" -#include "modules/limboai/util/limbo_task_db.h" -#include "modules/limboai/util/limbo_utility.h" +#include "../util/limbo_def.h" +#include "../util/limbo_string_names.h" +#include "../util/limbo_task_db.h" +#include "../util/limbo_utility.h" +#ifdef LIMBO_MODULE #include "core/config/project_settings.h" #include "core/error/error_macros.h" #include "editor/editor_help.h" @@ -23,9 +26,38 @@ #include "editor/plugins/script_editor_plugin.h" #include "scene/gui/check_box.h" +#endif // LIMBO_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace godot; +#endif // LIMBOAI_GDEXTENSION + //**** TaskButton -Control *TaskButton::make_custom_tooltip(const String &p_text) const { +void TaskButton::_bind_methods() { +} + +Control *TaskButton::_do_make_tooltip(const String &p_text) const { +#ifdef LIMBOAI_MODULE EditorHelpBit *help_bit = memnew(EditorHelpBit); help_bit->get_rich_text()->set_custom_minimum_size(Size2(360 * EDSCALE, 1)); @@ -39,6 +71,13 @@ Control *TaskButton::make_custom_tooltip(const String &p_text) const { help_bit->set_text(help_text); return help_bit; +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION + // TODO: When we figure out how to retrieve documentation in GDEXTENSION, should add a tooltip control here. +#endif // LIMBOAI_GDEXTENSION + + return nullptr; } TaskButton::TaskButton() { @@ -50,7 +89,7 @@ TaskButton::TaskButton() { //**** TaskPaletteSection void TaskPaletteSection::_on_task_button_pressed(const String &p_task) { - emit_signal(SNAME("task_button_pressed"), p_task); + emit_signal(LSNAME(task_button_pressed), p_task); } void TaskPaletteSection::_on_task_button_gui_input(const Ref &p_event, const String &p_task) { @@ -59,8 +98,8 @@ void TaskPaletteSection::_on_task_button_gui_input(const Ref &p_even } Ref mb = p_event; - if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT) { - emit_signal(SNAME("task_button_rmb"), p_task); + if (mb.is_valid() && mb->get_button_index() == MBTN_RIGHT) { + emit_signal(LSNAME(task_button_rmb), p_task); } } @@ -88,34 +127,33 @@ void TaskPaletteSection::set_filter(String p_filter_text) { void TaskPaletteSection::add_task_button(const String &p_name, const Ref &icon, const String &p_tooltip, Variant p_meta) { TaskButton *btn = memnew(TaskButton); btn->set_text(p_name); - btn->set_icon(icon); + BUTTON_SET_ICON(btn, icon); btn->set_tooltip_text(p_tooltip); - btn->add_theme_constant_override(SNAME("icon_max_width"), 16 * EDSCALE); // Force user icons to be of the proper size. - btn->connect(SNAME("pressed"), callable_mp(this, &TaskPaletteSection::_on_task_button_pressed).bind(p_meta)); - btn->connect(SNAME("gui_input"), callable_mp(this, &TaskPaletteSection::_on_task_button_gui_input).bind(p_meta)); + btn->add_theme_constant_override(LSNAME(icon_max_width), 16 * EDSCALE); // Force user icons to be of the proper size. + btn->connect(LSNAME(pressed), callable_mp(this, &TaskPaletteSection::_on_task_button_pressed).bind(p_meta)); + btn->connect(LSNAME(gui_input), callable_mp(this, &TaskPaletteSection::_on_task_button_gui_input).bind(p_meta)); tasks_container->add_child(btn); } void TaskPaletteSection::set_collapsed(bool p_collapsed) { tasks_container->set_visible(!p_collapsed); - section_header->set_icon(p_collapsed ? theme_cache.arrow_right_icon : theme_cache.arrow_down_icon); + BUTTON_SET_ICON(section_header, (p_collapsed ? theme_cache.arrow_right_icon : theme_cache.arrow_down_icon)); } bool TaskPaletteSection::is_collapsed() const { return !tasks_container->is_visible(); } -void TaskPaletteSection::_update_theme_item_cache() { - VBoxContainer::_update_theme_item_cache(); - - theme_cache.arrow_down_icon = get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")); - theme_cache.arrow_right_icon = get_theme_icon(SNAME("GuiTreeArrowRight"), SNAME("EditorIcons")); +void TaskPaletteSection::_do_update_theme_item_cache() { + theme_cache.arrow_down_icon = get_theme_icon(LSNAME(GuiTreeArrowDown), LSNAME(EditorIcons)); + theme_cache.arrow_right_icon = get_theme_icon(LSNAME(GuiTreeArrowRight), LSNAME(EditorIcons)); } void TaskPaletteSection::_notification(int p_what) { if (p_what == NOTIFICATION_THEME_CHANGED) { - section_header->set_icon(is_collapsed() ? theme_cache.arrow_right_icon : theme_cache.arrow_down_icon); - section_header->add_theme_font_override(SNAME("font"), get_theme_font(SNAME("bold"), SNAME("EditorFonts"))); + _do_update_theme_item_cache(); + BUTTON_SET_ICON(section_header, (is_collapsed() ? theme_cache.arrow_right_icon : theme_cache.arrow_down_icon)); + section_header->add_theme_font_override(LSNAME(font), get_theme_font(LSNAME(bold), LSNAME(EditorFonts))); } } @@ -129,7 +167,7 @@ TaskPaletteSection::TaskPaletteSection(String p_category_name) { add_child(section_header); section_header->set_text(p_category_name); section_header->set_focus_mode(FOCUS_NONE); - section_header->connect("pressed", callable_mp(this, &TaskPaletteSection::_on_header_pressed)); + section_header->connect(LSNAME(pressed), callable_mp(this, &TaskPaletteSection::_on_header_pressed)); tasks_container = memnew(HFlowContainer); add_child(tasks_container); @@ -148,38 +186,36 @@ void TaskPalette::_menu_action_selected(int p_id) { case MENU_OPEN_DOC: { String help_class; if (context_task.begins_with("res://")) { - Ref