From b3dedc737e232a011e7fc12ea9aef6fefadce5b9 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 17 Aug 2023 18:14:24 +0200 Subject: [PATCH] Add a popup menu for tasks in the TaskPanel Adds such menu items (similar to task popup menu): - Edit Script - Open Documentation --- editor/limbo_ai_editor_plugin.cpp | 64 +++++++++++++++++++++++++++++-- editor/limbo_ai_editor_plugin.h | 15 +++++++- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 1d3471a..1089e75 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -343,10 +343,21 @@ TaskTree::~TaskTree() { //**** TaskSection -void TaskSection::_on_task_button_pressed(const StringName &p_task) { +void TaskSection::_on_task_button_pressed(const String &p_task) { emit_signal(SNAME("task_button_pressed"), p_task); } +void TaskSection::_on_task_button_gui_input(const Ref &p_event, const String &p_task) { + if (!p_event->is_pressed()) { + return; + } + + Ref mb = p_event; + if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT) { + emit_signal(SNAME("task_button_rmb"), p_task); + } +} + void TaskSection::_on_header_pressed() { set_collapsed(!is_collapsed()); } @@ -373,7 +384,8 @@ void TaskSection::add_task_button(String p_name, const Ref &icon, Varia btn->set_text(p_name); btn->set_icon(icon); btn->add_theme_constant_override(SNAME("icon_max_width"), 16 * EDSCALE); // Force user icons to be of the proper size. - btn->connect("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)); tasks_container->add_child(btn); } @@ -395,6 +407,7 @@ void TaskSection::_notification(int p_what) { void TaskSection::_bind_methods() { ADD_SIGNAL(MethodInfo("task_button_pressed")); + ADD_SIGNAL(MethodInfo("task_button_rmb")); } TaskSection::TaskSection(String p_category_name) { @@ -415,10 +428,48 @@ TaskSection::~TaskSection() { //**** TaskPanel -void TaskPanel::_on_task_button_pressed(const StringName &p_task) { +void TaskPanel::_menu_action_selected(int p_id) { + ERR_FAIL_COND(context_task.is_empty()); + switch (p_id) { + case MENU_OPEN_DOC: { + String help_class; + if (context_task.begins_with("res://")) { + Ref