From f39a362b8577b784e6ede370ba89025f5432dda3 Mon Sep 17 00:00:00 2001 From: Justin McGettigan Date: Tue, 25 Jul 2023 00:09:52 -0400 Subject: [PATCH 01/56] Implemented the initial V2 of a basic symbol tooltip. Created a new class for it. --- editor/editor_help.cpp | 3 +- editor/editor_help.h | 2 + editor/plugins/script_text_editor.cpp | 6 + editor/plugins/script_text_editor.h | 3 + editor/symbol_tooltip.cpp | 286 ++++++++++++++++++++++++++ editor/symbol_tooltip.h | 71 +++++++ 6 files changed, 370 insertions(+), 1 deletion(-) create mode 100644 editor/symbol_tooltip.cpp create mode 100644 editor/symbol_tooltip.h diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 2cbbb59be26b..cd1cc9938a85 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1955,7 +1955,8 @@ void EditorHelp::_help_callback(const String &p_topic) { } } -static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control *p_owner_node, const String &p_class = "") { +// TODO: Should probably move this to a shared utility file/class so it can be accessed by both 'editor_help.cpp' and 'symbol_tooltip.cpp' +void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control *p_owner_node, const String &p_class = "") { DocTools *doc = EditorHelp::get_doc_data(); String base_path; diff --git a/editor/editor_help.h b/editor/editor_help.h index 0aa8302b27c6..3609f36838bf 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -251,4 +251,6 @@ class EditorHelpBit : public MarginContainer { EditorHelpBit(); }; +void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control *p_owner_node); + #endif // EDITOR_HELP_H diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 321c0f34b59a..4e20e9c060b9 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1859,6 +1859,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data void ScriptTextEditor::_text_edit_gui_input(const Ref &ev) { Ref mb = ev; + Ref mm = ev; Ref k = ev; Point2 local_pos; bool create_menu = false; @@ -1867,6 +1868,8 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref &ev) { if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) { local_pos = mb->get_global_position() - tx->get_global_position(); create_menu = true; + } else if (mm.is_valid()) { + symbol_tooltip->update_symbol_tooltip(mm->get_position()); } else if (k.is_valid() && k->is_action("ui_menu", true)) { tx->adjust_viewport_to_caret(0); local_pos = tx->get_caret_draw_pos(0); @@ -2322,6 +2325,9 @@ ScriptTextEditor::ScriptTextEditor() { connection_info_dialog = memnew(ConnectionInfoDialog); SET_DRAG_FORWARDING_GCD(code_editor->get_text_editor(), ScriptTextEditor); + + symbol_tooltip = memnew(SymbolTooltip(code_editor)); + add_child(symbol_tooltip); } ScriptTextEditor::~ScriptTextEditor() { diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index d275013b9165..a27a94beca1f 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -34,6 +34,7 @@ #include "script_editor_plugin.h" #include "editor/code_editor.h" +#include "editor/symbol_tooltip.h" #include "scene/gui/color_picker.h" #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" @@ -156,6 +157,8 @@ class ScriptTextEditor : public ScriptEditorBase { void _enable_code_editor(); + SymbolTooltip *symbol_tooltip = nullptr; + protected: void _update_breakpoint_list(); void _breakpoint_item_pressed(int p_idx); diff --git a/editor/symbol_tooltip.cpp b/editor/symbol_tooltip.cpp new file mode 100644 index 000000000000..866463421dbf --- /dev/null +++ b/editor/symbol_tooltip.cpp @@ -0,0 +1,286 @@ +/**************************************************************************/ +/* symbol_tooltip.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "symbol_tooltip.h" +#include "editor/plugins/script_text_editor.h" +#include "editor_help.h" +#include "editor_node.h" + +SymbolTooltip::SymbolTooltip(CodeTextEditor* code_editor) : code_editor(code_editor) { //(CodeTextEditor* code_editor) : code_editor(code_editor) { + // Initialize the tooltip components + + // Set the tooltip's theme (PanelContainer's theme) + //set_theme(EditorNode::get_singleton()->get_gui_base()->get_theme()); + hide(); + set_theme(_create_panel_theme()); + + // Create VBoxContainer to hold the tooltip's header and body + layout_container = memnew(VBoxContainer); + add_child(layout_container); + + // Create RichTextLabel for the tooltip's header + header_label = memnew(RichTextLabel); + header_label->set_use_bbcode(true); + header_label->set_selection_enabled(true); + header_label->set_custom_minimum_size(Size2(0, 50)); + header_label->set_focus_mode(FOCUS_ALL); + header_label->set_theme(_create_header_label_theme()); + layout_container->add_child(header_label); + + // Create RichTextLabel for the tooltip's body + body_label = memnew(RichTextLabel); + body_label->set_use_bbcode(true); + body_label->set_selection_enabled(true); + body_label->set_focus_mode(FOCUS_ALL); + body_label->set_v_size_flags(SIZE_EXPAND_FILL); + body_label->set_theme(_create_body_label_theme()); + layout_container->add_child(body_label); + + + // Connect the tooltip's update function to the mouse motion signal + // connect("mouse_motion", callable_mp(this, &SymbolTooltip::_update_symbol_tooltip)); +} + +void SymbolTooltip::update_symbol_tooltip(const Vector2 &mouse_position) { + // Get the word under the mouse cursor + CodeEdit *text_editor = code_editor->get_text_editor(); + String _symbol_word = text_editor->get_word_at_pos(mouse_position); + if (!_symbol_word.is_empty()) { + symbol_word = _symbol_word; + header_content = symbol_word; + } + + // Get the symbol type of the word under the mouse cursor + //String symbol_type = text_editor->get_symbol_type_at_pos(mouse_position); + //String symbol_info = text_editor->get_symbol_info_at_pos(mouse_position); + // symbol_info is a string containing the symbol's type, name, and documentation + + // Retrieve the EditorInterface singleton + //EditorInterface *editor_interface = EditorInterface::get_singleton(); + + // Retrieve the currently active ScriptTextEditor + //ScriptTextEditor *script_editor = editor_interface->get_editor_viewport()->get_script_text_editor(); + //ScriptLanguage *language; + + //ScriptTextEditor *script_editor = text_editor.script //EditorNode::get_script_text_editor(); + + Node *base = get_tree()->get_edited_scene_root(); + Ref