Fix: User icons are not showing in the task palette

This commit is contained in:
Serhii Snitsaruk 2024-01-10 19:16:43 +01:00
parent 1dfa3e9808
commit 8e9cc74857
2 changed files with 22 additions and 2 deletions

View File

@ -23,6 +23,7 @@
#ifdef LIMBOAI_GDEXTENSION #ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/editor_interface.hpp> #include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/script.hpp>
using namespace godot; using namespace godot;
#endif // LIMBOAI_GDEXTENSION #endif // LIMBOAI_GDEXTENSION
@ -68,7 +69,10 @@ void TaskTree::_update_item(TreeItem *p_item) {
} }
String type_arg; String type_arg;
if (task->get_script() != Variant()) { if (task->get_script() != Variant()) {
type_arg = task->get_path(); Ref<Script> sc = task->get_script();
if (sc.is_valid()) {
type_arg = sc->get_path();
}
} }
if (type_arg.is_empty()) { if (type_arg.is_empty()) {
type_arg = task->get_class(); type_arg = task->get_class();

View File

@ -30,8 +30,11 @@
#include "bt/tasks/bt_task.h" #include "bt/tasks/bt_task.h"
#include "godot_cpp/classes/input_event_key.hpp" #include "godot_cpp/classes/input_event_key.hpp"
#include "godot_cpp/classes/project_settings.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/resource_loader.hpp> #include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/script.hpp>
#include <godot_cpp/classes/texture2d.hpp> #include <godot_cpp/classes/texture2d.hpp>
#include <godot_cpp/classes/theme.hpp> #include <godot_cpp/classes/theme.hpp>
#include <godot_cpp/core/error_macros.hpp> #include <godot_cpp/core/error_macros.hpp>
@ -112,8 +115,21 @@ Ref<Texture2D> LimboUtility::get_task_icon(String p_class_or_script_path) const
#ifdef LIMBOAI_GDEXTENSION #ifdef LIMBOAI_GDEXTENSION
String path; String path;
if (p_class_or_script_path.begins_with("res://")) { if (p_class_or_script_path.begins_with("res://")) {
path = p_class_or_script_path; TypedArray<Dictionary> classes = ProjectSettings::get_singleton()->get_global_class_list();
for (int i = 0; i < classes.size(); i++) {
if (classes[i].get("path") == p_class_or_script_path) {
path = classes[i].get("icon");
break;
}
}
if (path.is_empty()) {
Ref<Script> sc = RESOURCE_LOAD(p_class_or_script_path, "Script");
if (sc.is_valid()) {
path = "res://addons/limboai/icons/" + sc->get_instance_base_type() + ".svg";
}
}
} else { } else {
// Assuming global class.
path = "res://addons/limboai/icons/" + p_class_or_script_path + ".svg"; path = "res://addons/limboai/icons/" + p_class_or_script_path + ".svg";
} }