Link to online docs in the code

This commit is contained in:
Serhii Snitsaruk 2024-01-13 22:40:27 +01:00
parent 2496869153
commit cbbc0b0135
7 changed files with 56 additions and 12 deletions

View File

@ -373,7 +373,7 @@ void LimboAIEditor::_on_tree_rmb(const Vector2 &p_menu_pos) {
menu->add_icon_shortcut(theme_cache.rename_task_icon, LW_GET_SHORTCUT("limbo_ai/rename_task"), ACTION_RENAME); menu->add_icon_shortcut(theme_cache.rename_task_icon, LW_GET_SHORTCUT("limbo_ai/rename_task"), ACTION_RENAME);
menu->add_icon_item(theme_cache.change_type_icon, TTR("Change Type"), ACTION_CHANGE_TYPE); menu->add_icon_item(theme_cache.change_type_icon, TTR("Change Type"), ACTION_CHANGE_TYPE);
menu->add_icon_item(theme_cache.edit_script_icon, TTR("Edit Script"), ACTION_EDIT_SCRIPT); menu->add_icon_item(theme_cache.edit_script_icon, TTR("Edit Script"), ACTION_EDIT_SCRIPT);
menu->add_icon_item(theme_cache.open_doc_icon, TTR("Open Documentation"), ACTION_OPEN_DOC); menu->add_icon_item(theme_cache.doc_icon, TTR("Open Documentation"), ACTION_OPEN_DOC);
menu->set_item_disabled(menu->get_item_index(ACTION_EDIT_SCRIPT), task->get_script() == Variant()); menu->set_item_disabled(menu->get_item_index(ACTION_EDIT_SCRIPT), task->get_script() == Variant());
menu->add_separator(); menu->add_separator();
@ -436,14 +436,17 @@ void LimboAIEditor::_action_selected(int p_id) {
Ref<BTTask> task = task_tree->get_selected(); Ref<BTTask> task = task_tree->get_selected();
ERR_FAIL_COND(task.is_null()); ERR_FAIL_COND(task.is_null());
String help_class; String help_class;
String res_path = task->get_path();
if (res_path.begins_with("res://")) { Ref<Script> sc = GET_SCRIPT(task);
help_class = "\"" + res_path.get_basename().to_pascal_case() + "\""; if (sc.is_valid() && sc->get_path().is_absolute_path()) {
} else { help_class = sc->get_path();
}
if (help_class.is_empty()) {
// Assuming context task is core class. // Assuming context task is core class.
help_class = task->get_class(); help_class = task->get_class();
} }
SHOW_DOC("class_name:" + help_class);
LimboUtility::get_singleton()->open_doc_class(help_class);
} break; } break;
case ACTION_MOVE_UP: { case ACTION_MOVE_UP: {
Ref<BTTask> sel = task_tree->get_selected(); Ref<BTTask> sel = task_tree->get_selected();
@ -590,7 +593,10 @@ void LimboAIEditor::_probability_popup_closed() {
void LimboAIEditor::_misc_option_selected(int p_id) { void LimboAIEditor::_misc_option_selected(int p_id) {
switch (p_id) { switch (p_id) {
case MISC_INTRODUCTION: { case MISC_INTRODUCTION: {
SHOW_DOC("class_name:BehaviorTree"); LimboUtility::get_singleton()->open_doc_introduction();
} break;
case MISC_ONLINE_DOCUMENTATION: {
LimboUtility::get_singleton()->open_doc_online();
} break; } break;
case MISC_OPEN_DEBUGGER: { case MISC_OPEN_DEBUGGER: {
ERR_FAIL_COND(LimboDebuggerPlugin::get_singleton() == nullptr); ERR_FAIL_COND(LimboDebuggerPlugin::get_singleton() == nullptr);
@ -938,7 +944,8 @@ void LimboAIEditor::_update_misc_menu() {
misc_menu->clear(); misc_menu->clear();
misc_menu->add_icon_item(theme_cache.open_doc_icon, TTR("Introduction"), MISC_INTRODUCTION); misc_menu->add_icon_item(theme_cache.introduction_icon, TTR("Introduction"), MISC_INTRODUCTION);
misc_menu->add_icon_item(theme_cache.doc_icon, TTR("Online Documentation"), MISC_ONLINE_DOCUMENTATION);
misc_menu->add_separator(); misc_menu->add_separator();
#ifdef LIMBOAI_MODULE #ifdef LIMBOAI_MODULE
@ -994,7 +1001,8 @@ void LimboAIEditor::_do_update_theme_item_cache() {
theme_cache.move_task_down_icon = get_theme_icon(LW_NAME(MoveDown), LW_NAME(EditorIcons)); theme_cache.move_task_down_icon = get_theme_icon(LW_NAME(MoveDown), LW_NAME(EditorIcons));
theme_cache.move_task_up_icon = get_theme_icon(LW_NAME(MoveUp), LW_NAME(EditorIcons)); theme_cache.move_task_up_icon = get_theme_icon(LW_NAME(MoveUp), LW_NAME(EditorIcons));
theme_cache.open_debugger_icon = get_theme_icon(LW_NAME(Debug), LW_NAME(EditorIcons)); theme_cache.open_debugger_icon = get_theme_icon(LW_NAME(Debug), LW_NAME(EditorIcons));
theme_cache.open_doc_icon = get_theme_icon(LW_NAME(Help), LW_NAME(EditorIcons)); theme_cache.doc_icon = get_theme_icon(LW_NAME(Help), LW_NAME(EditorIcons));
theme_cache.introduction_icon = get_theme_icon(LW_NAME(Info), LW_NAME(EditorIcons));
theme_cache.remove_task_icon = get_theme_icon(LW_NAME(Remove), LW_NAME(EditorIcons)); theme_cache.remove_task_icon = get_theme_icon(LW_NAME(Remove), LW_NAME(EditorIcons));
theme_cache.rename_task_icon = get_theme_icon(LW_NAME(Rename), LW_NAME(EditorIcons)); theme_cache.rename_task_icon = get_theme_icon(LW_NAME(Rename), LW_NAME(EditorIcons));
theme_cache.change_type_icon = get_theme_icon(LW_NAME(Reload), LW_NAME(EditorIcons)); theme_cache.change_type_icon = get_theme_icon(LW_NAME(Reload), LW_NAME(EditorIcons));

View File

@ -84,6 +84,7 @@ private:
enum MiscMenu { enum MiscMenu {
MISC_INTRODUCTION, MISC_INTRODUCTION,
MISC_ONLINE_DOCUMENTATION,
MISC_OPEN_DEBUGGER, MISC_OPEN_DEBUGGER,
MISC_PROJECT_SETTINGS, MISC_PROJECT_SETTINGS,
MISC_CREATE_SCRIPT_TEMPLATE, MISC_CREATE_SCRIPT_TEMPLATE,
@ -96,7 +97,8 @@ private:
Ref<Texture2D> move_task_down_icon; Ref<Texture2D> move_task_down_icon;
Ref<Texture2D> move_task_up_icon; Ref<Texture2D> move_task_up_icon;
Ref<Texture2D> open_debugger_icon; Ref<Texture2D> open_debugger_icon;
Ref<Texture2D> open_doc_icon; Ref<Texture2D> doc_icon;
Ref<Texture2D> introduction_icon;
Ref<Texture2D> percent_icon; Ref<Texture2D> percent_icon;
Ref<Texture2D> remove_task_icon; Ref<Texture2D> remove_task_icon;
Ref<Texture2D> rename_task_icon; Ref<Texture2D> rename_task_icon;

View File

@ -190,12 +190,12 @@ void TaskPalette::_menu_action_selected(int p_id) {
case MENU_OPEN_DOC: { case MENU_OPEN_DOC: {
String help_class; String help_class;
if (context_task.begins_with("res://")) { if (context_task.begins_with("res://")) {
help_class = "\"" + context_task.get_basename().to_pascal_case() + "\""; help_class = context_task;
} else { } else {
// Assuming context task is core class. // Assuming context task is core class.
help_class = context_task; help_class = context_task;
} }
SHOW_DOC("class_name:" + help_class); LimboUtility::get_singleton()->open_doc_class(help_class);
} break; } break;
case MENU_EDIT_SCRIPT: { case MENU_EDIT_SCRIPT: {
ERR_FAIL_COND(!context_task.begins_with("res://")); ERR_FAIL_COND(!context_task.begins_with("res://"));

View File

@ -79,6 +79,7 @@ LimboStringNames::LimboStringNames() {
Help = SN("Help"); Help = SN("Help");
icon_max_width = SN("icon_max_width"); icon_max_width = SN("icon_max_width");
id_pressed = SN("id_pressed"); id_pressed = SN("id_pressed");
Info = SN("Info");
item_collapsed = SN("item_collapsed"); item_collapsed = SN("item_collapsed");
item_selected = SN("item_selected"); item_selected = SN("item_selected");
LimboDeselectAll = SN("LimboDeselectAll"); LimboDeselectAll = SN("LimboDeselectAll");

View File

@ -93,6 +93,7 @@ public:
StringName Help; StringName Help;
StringName icon_max_width; StringName icon_max_width;
StringName id_pressed; StringName id_pressed;
StringName Info;
StringName item_collapsed; StringName item_collapsed;
StringName item_selected; StringName item_selected;
StringName LimboDeselectAll; StringName LimboDeselectAll;

View File

@ -16,6 +16,7 @@
#ifdef LIMBOAI_MODULE #ifdef LIMBOAI_MODULE
#include "core/error/error_macros.h" #include "core/error/error_macros.h"
#include "core/object/script_language.h" #include "core/object/script_language.h"
#include "core/os/os.h"
#include "core/variant/variant.h" #include "core/variant/variant.h"
#include "scene/resources/texture.h" #include "scene/resources/texture.h"
@ -30,6 +31,7 @@
#include "godot_cpp/classes/project_settings.hpp" #include "godot_cpp/classes/project_settings.hpp"
#include "godot_cpp/variant/dictionary.hpp" #include "godot_cpp/variant/dictionary.hpp"
#include "godot_cpp/variant/utility_functions.hpp" #include "godot_cpp/variant/utility_functions.hpp"
#include <godot_cpp/classes/os.hpp>
#include <godot_cpp/classes/resource_loader.hpp> #include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/script.hpp> #include <godot_cpp/classes/script.hpp>
#include <godot_cpp/classes/texture2d.hpp> #include <godot_cpp/classes/texture2d.hpp>
@ -314,6 +316,30 @@ Ref<Shortcut> LimboUtility::get_shortcut(const String &p_path) const {
return nullptr; return nullptr;
} }
void LimboUtility::open_doc_introduction() {
OS::get_singleton()->shell_open(vformat("https://limboai.readthedocs.io/en/%s/classes/class_behaviortree.html",
LIMBO_DOC_VERSION));
}
void LimboUtility::open_doc_online() {
OS::get_singleton()->shell_open(vformat("https://limboai.readthedocs.io/en/%s/index.html",
LIMBO_DOC_VERSION));
}
void LimboUtility::open_doc_class(const String &p_class_name) {
if (p_class_name.begins_with("res://")) {
SHOW_DOC(vformat("class_name:\"%s\"", p_class_name));
return;
}
#ifdef LIMBOAI_MODULE
SHOW_DOC("class_name:" + p_class_name);
#elif LIMBOAI_GDEXTENSION
OS::get_singleton()->shell_open(vformat("https://limboai.readthedocs.io/en/%s/classes/class_%s.html",
LIMBO_DOC_VERSION, p_class_name.to_lower()));
#endif
}
void LimboUtility::_bind_methods() { void LimboUtility::_bind_methods() {
ClassDB::bind_method(D_METHOD("decorate_var", "p_variable"), &LimboUtility::decorate_var); ClassDB::bind_method(D_METHOD("decorate_var", "p_variable"), &LimboUtility::decorate_var);
ClassDB::bind_method(D_METHOD("get_status_name", "p_status"), &LimboUtility::get_status_name); ClassDB::bind_method(D_METHOD("get_status_name", "p_status"), &LimboUtility::get_status_name);

View File

@ -36,6 +36,8 @@ using namespace godot;
#define LOGICAL_XOR(a, b) (a) ? !(b) : (b) #define LOGICAL_XOR(a, b) (a) ? !(b) : (b)
#define LIMBO_DOC_VERSION "latest"
class LimboUtility : public Object { class LimboUtility : public Object {
GDCLASS(LimboUtility, Object); GDCLASS(LimboUtility, Object);
@ -88,6 +90,10 @@ public:
bool is_shortcut(const String &p_path, const Ref<InputEvent> &p_event) const; bool is_shortcut(const String &p_path, const Ref<InputEvent> &p_event) const;
Ref<Shortcut> get_shortcut(const String &p_path) const; Ref<Shortcut> get_shortcut(const String &p_path) const;
void open_doc_introduction();
void open_doc_online();
void open_doc_class(const String &p_class_name);
LimboUtility(); LimboUtility();
~LimboUtility(); ~LimboUtility();
}; };