Add documentation tooltips for tasks in the panel

This commit is contained in:
Serhii Snitsaruk 2023-08-23 13:06:18 +02:00
parent 2fdcff4886
commit 067f73e11e
2 changed files with 51 additions and 4 deletions

View File

@ -54,6 +54,7 @@
#include "editor/debugger/editor_debugger_node.h" #include "editor/debugger/editor_debugger_node.h"
#include "editor/debugger/script_editor_debugger.h" #include "editor/debugger/script_editor_debugger.h"
#include "editor/editor_file_system.h" #include "editor/editor_file_system.h"
#include "editor/editor_help.h"
#include "editor/editor_inspector.h" #include "editor/editor_inspector.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/editor_paths.h" #include "editor/editor_paths.h"
@ -356,6 +357,26 @@ TaskTree::~TaskTree() {
//**** TaskTree ^ //**** TaskTree ^
//**** TaskButton
Control *TaskButton::make_custom_tooltip(const String &p_text) const {
EditorHelpBit *help_bit = memnew(EditorHelpBit);
help_bit->get_rich_text()->set_custom_minimum_size(Size2(360 * EDSCALE, 1));
String help_text;
if (!p_text.is_empty()) {
help_text = p_text;
} else {
help_text = "[i]" + TTR("No description.") + "[/i]";
}
help_bit->set_text(help_text);
return help_bit;
}
//**** TaskButton ^
//**** TaskSection //**** TaskSection
void TaskSection::_on_task_button_pressed(const String &p_task) { void TaskSection::_on_task_button_pressed(const String &p_task) {
@ -394,10 +415,11 @@ void TaskSection::set_filter(String p_filter_text) {
} }
} }
void TaskSection::add_task_button(String p_name, const Ref<Texture> &icon, Variant p_meta) { void TaskSection::add_task_button(const String &p_name, const Ref<Texture> &icon, const String &p_tooltip, Variant p_meta) {
Button *btn = memnew(Button); TaskButton *btn = memnew(TaskButton);
btn->set_text(p_name); btn->set_text(p_name);
btn->set_icon(icon); btn->set_icon(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->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, &TaskSection::_on_task_button_pressed).bind(p_meta)); btn->connect(SNAME("pressed"), callable_mp(this, &TaskSection::_on_task_button_pressed).bind(p_meta));
btn->connect(SNAME("gui_input"), callable_mp(this, &TaskSection::_on_task_button_gui_input).bind(p_meta)); btn->connect(SNAME("gui_input"), callable_mp(this, &TaskSection::_on_task_button_gui_input).bind(p_meta));
@ -582,13 +604,31 @@ void TaskPanel::refresh() {
TaskSection *sec = memnew(TaskSection(cat)); TaskSection *sec = memnew(TaskSection(cat));
for (String task_meta : tasks) { for (String task_meta : tasks) {
Ref<Texture2D> icon = LimboUtility::get_singleton()->get_task_icon(task_meta); Ref<Texture2D> icon = LimboUtility::get_singleton()->get_task_icon(task_meta);
String tname; String tname;
DocTools *dd = EditorHelp::get_doc_data();
HashMap<String, DocData::ClassDoc>::Iterator E;
if (task_meta.begins_with("res:")) { if (task_meta.begins_with("res:")) {
tname = task_meta.get_file().get_basename().trim_prefix("BT").to_pascal_case(); tname = task_meta.get_file().get_basename().trim_prefix("BT").to_pascal_case();
E = dd->class_list.find(vformat("\"%s\"", task_meta.trim_prefix("res://")));
if (!E) {
E = dd->class_list.find(tname);
}
} else { } else {
tname = task_meta.trim_prefix("BT"); tname = task_meta.trim_prefix("BT");
E = dd->class_list.find(task_meta);
} }
sec->add_task_button(tname, icon, task_meta);
String descr;
if (E) {
if (E->value.description.is_empty() || E->value.description.length() > 1000) {
descr = DTR(E->value.brief_description);
} else {
descr = DTR(E->value.description);
}
}
sec->add_task_button(tname, icon, descr, task_meta);
} }
sec->set_filter(""); sec->set_filter("");
sec->connect(SNAME("task_button_pressed"), callable_mp(this, &TaskPanel::_on_task_button_pressed)); sec->connect(SNAME("task_button_pressed"), callable_mp(this, &TaskPanel::_on_task_button_pressed));

View File

@ -76,6 +76,13 @@ public:
~TaskTree(); ~TaskTree();
}; };
class TaskButton : public Button {
GDCLASS(TaskButton, Button);
public:
virtual Control *make_custom_tooltip(const String &p_text) const override;
};
class TaskSection : public VBoxContainer { class TaskSection : public VBoxContainer {
GDCLASS(TaskSection, VBoxContainer); GDCLASS(TaskSection, VBoxContainer);
@ -94,7 +101,7 @@ protected:
public: public:
void set_filter(String p_filter); void set_filter(String p_filter);
void add_task_button(String p_name, const Ref<Texture> &icon, Variant p_meta); void add_task_button(const String &p_name, const Ref<Texture> &icon, const String &p_tooltip, Variant p_meta);
void set_collapsed(bool p_collapsed); void set_collapsed(bool p_collapsed);
bool is_collapsed() const; bool is_collapsed() const;