2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* limbo_debugger_plugin.cpp
|
|
|
|
* =============================================================================
|
2024-03-21 20:38:57 +00:00
|
|
|
* Copyright 2021-2024 Serhii Snitsaruk
|
2023-07-21 09:50:06 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-04-16 09:30:31 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "limbo_debugger_plugin.h"
|
2023-07-20 16:35:36 +00:00
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
#include "../../bt/behavior_tree.h"
|
|
|
|
#include "../../editor/debugger/behavior_tree_data.h"
|
|
|
|
#include "../../editor/debugger/behavior_tree_view.h"
|
2024-02-17 13:56:19 +00:00
|
|
|
#include "../../util/limbo_compat.h"
|
2024-01-10 00:17:09 +00:00
|
|
|
#include "../../util/limbo_utility.h"
|
2023-07-20 16:35:36 +00:00
|
|
|
#include "limbo_debugger.h"
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "core/debugger/engine_debugger.h"
|
2023-12-12 22:37:28 +00:00
|
|
|
#include "core/error/error_macros.h"
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "core/math/math_defs.h"
|
|
|
|
#include "core/object/callable_method_pointer.h"
|
|
|
|
#include "core/os/memory.h"
|
|
|
|
#include "core/string/print_string.h"
|
2023-04-16 08:34:13 +00:00
|
|
|
#include "core/string/ustring.h"
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "core/variant/array.h"
|
2023-12-12 22:37:28 +00:00
|
|
|
#include "editor/editor_interface.h"
|
2024-02-17 13:56:19 +00:00
|
|
|
#include "editor/editor_paths.h"
|
2023-12-12 22:37:28 +00:00
|
|
|
#include "editor/filesystem_dock.h"
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "editor/plugins/editor_debugger_plugin.h"
|
2024-02-02 20:04:19 +00:00
|
|
|
#include "editor/themes/editor_scale.h"
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "scene/gui/box_container.h"
|
|
|
|
#include "scene/gui/control.h"
|
|
|
|
#include "scene/gui/item_list.h"
|
|
|
|
#include "scene/gui/label.h"
|
2023-04-15 07:01:37 +00:00
|
|
|
#include "scene/gui/line_edit.h"
|
2024-02-17 13:56:19 +00:00
|
|
|
#include "scene/gui/separator.h"
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "scene/gui/split_container.h"
|
2023-08-20 09:34:13 +00:00
|
|
|
#include "scene/gui/tab_container.h"
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "scene/gui/texture_rect.h"
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif // LIMBOAI_MODULE
|
2024-01-09 20:47:22 +00:00
|
|
|
|
|
|
|
#ifdef LIMBOAI_GDEXTENSION
|
2024-02-17 13:56:19 +00:00
|
|
|
#include <godot_cpp/classes/config_file.hpp>
|
2024-01-09 20:47:22 +00:00
|
|
|
#include <godot_cpp/classes/editor_interface.hpp>
|
2024-02-17 13:56:19 +00:00
|
|
|
#include <godot_cpp/classes/editor_paths.hpp>
|
2024-01-09 20:47:22 +00:00
|
|
|
#include <godot_cpp/classes/file_system_dock.hpp>
|
|
|
|
#include <godot_cpp/classes/resource_loader.hpp>
|
|
|
|
#include <godot_cpp/classes/tab_container.hpp>
|
2024-02-17 13:56:19 +00:00
|
|
|
#include <godot_cpp/classes/v_separator.hpp>
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif // LIMBOAI_GDEXTENSION
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-08-20 09:34:13 +00:00
|
|
|
//**** LimboDebuggerTab
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
void LimboDebuggerTab::_reset_controls() {
|
2024-08-03 09:07:06 +00:00
|
|
|
bt_instance_list->clear();
|
2023-04-13 07:29:45 +00:00
|
|
|
bt_view->clear();
|
2023-04-15 07:01:37 +00:00
|
|
|
alert_box->hide();
|
2024-01-09 20:47:22 +00:00
|
|
|
info_message->set_text(TTR("Run project to start debugging."));
|
2023-04-15 07:01:37 +00:00
|
|
|
info_message->show();
|
2024-01-09 20:47:22 +00:00
|
|
|
resource_header->set_disabled(true);
|
|
|
|
resource_header->set_text(TTR("Inactive"));
|
2023-04-13 07:29:45 +00:00
|
|
|
}
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
void LimboDebuggerTab::start_session() {
|
2024-08-03 09:07:06 +00:00
|
|
|
bt_instance_list->clear();
|
2023-04-15 07:01:37 +00:00
|
|
|
bt_view->clear();
|
|
|
|
alert_box->hide();
|
2024-01-09 20:47:22 +00:00
|
|
|
info_message->set_text(TTR("Pick a player from the list to display behavior tree."));
|
2023-04-15 07:01:37 +00:00
|
|
|
info_message->show();
|
2024-01-09 20:47:22 +00:00
|
|
|
session->send_message("limboai:start_session", Array());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LimboDebuggerTab::stop_session() {
|
|
|
|
_reset_controls();
|
2023-04-13 07:29:45 +00:00
|
|
|
session->send_message("limboai:stop_session", Array());
|
|
|
|
}
|
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
void LimboDebuggerTab::update_active_bt_instances(const Array &p_data) {
|
|
|
|
active_bt_instances.clear();
|
|
|
|
for (int i = 0; i < p_data.size(); i += 2) {
|
|
|
|
BTInstanceInfo info{ p_data[i], p_data[i + 1] };
|
|
|
|
|
|
|
|
active_bt_instances.push_back(info);
|
2023-04-15 07:01:37 +00:00
|
|
|
}
|
2024-08-03 09:07:06 +00:00
|
|
|
_update_bt_instance_list(active_bt_instances, filter_players->get_text());
|
2023-04-15 07:01:37 +00:00
|
|
|
}
|
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
uint64_t LimboDebuggerTab::get_selected_bt_instance_id() {
|
|
|
|
if (!bt_instance_list->is_anything_selected()) {
|
|
|
|
return 0;
|
2023-04-15 07:01:37 +00:00
|
|
|
}
|
2024-08-03 09:07:06 +00:00
|
|
|
return bt_instance_list->get_item_metadata(bt_instance_list->get_selected_items()[0]);
|
2023-04-15 07:01:37 +00:00
|
|
|
}
|
|
|
|
|
2024-02-03 15:31:21 +00:00
|
|
|
void LimboDebuggerTab::update_behavior_tree(const Ref<BehaviorTreeData> &p_data) {
|
2024-08-03 09:07:06 +00:00
|
|
|
resource_header->set_text(p_data->source_bt_path);
|
2023-12-12 22:37:28 +00:00
|
|
|
resource_header->set_disabled(false);
|
2023-04-15 07:01:37 +00:00
|
|
|
bt_view->update_tree(p_data);
|
|
|
|
info_message->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LimboDebuggerTab::_show_alert(const String &p_message) {
|
|
|
|
alert_message->set_text(p_message);
|
|
|
|
alert_box->set_visible(!p_message.is_empty());
|
|
|
|
}
|
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
void LimboDebuggerTab::_update_bt_instance_list(const Vector<BTInstanceInfo> &p_instances, const String &p_filter) {
|
2023-04-13 07:29:45 +00:00
|
|
|
// Remember selected item.
|
2024-08-03 09:07:06 +00:00
|
|
|
uint64_t selected_instance_id = 0;
|
|
|
|
if (bt_instance_list->is_anything_selected()) {
|
|
|
|
selected_instance_id = uint64_t(bt_instance_list->get_item_metadata(bt_instance_list->get_selected_items()[0]));
|
2023-04-13 07:29:45 +00:00
|
|
|
}
|
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
bt_instance_list->clear();
|
2023-04-13 07:29:45 +00:00
|
|
|
int select_idx = -1;
|
2023-04-15 07:01:37 +00:00
|
|
|
bool selection_filtered_out = false;
|
2024-08-06 19:34:06 +00:00
|
|
|
String filter = p_filter.to_lower();
|
2024-08-03 09:07:06 +00:00
|
|
|
for (const BTInstanceInfo &info : p_instances) {
|
2024-08-06 19:34:06 +00:00
|
|
|
if (filter.is_empty() || info.owner_node_path.to_lower().contains(filter)) {
|
2024-08-03 09:07:06 +00:00
|
|
|
int idx = bt_instance_list->add_item(info.owner_node_path);
|
|
|
|
bt_instance_list->set_item_metadata(idx, info.instance_id);
|
2023-04-15 07:01:37 +00:00
|
|
|
// Make item text shortened from the left, e.g ".../Agent/BTPlayer".
|
2024-08-03 09:07:06 +00:00
|
|
|
bt_instance_list->set_item_text_direction(idx, TEXT_DIRECTION_RTL);
|
|
|
|
if (info.instance_id == selected_instance_id) {
|
2023-04-15 07:01:37 +00:00
|
|
|
select_idx = idx;
|
|
|
|
}
|
2024-08-03 09:07:06 +00:00
|
|
|
} else if (info.instance_id == selected_instance_id) {
|
2023-04-15 07:01:37 +00:00
|
|
|
selection_filtered_out = true;
|
2023-04-13 07:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore selected item.
|
|
|
|
if (select_idx > -1) {
|
2024-08-03 09:07:06 +00:00
|
|
|
bt_instance_list->select(select_idx);
|
|
|
|
} else if (selected_instance_id != 0) {
|
2023-04-15 07:01:37 +00:00
|
|
|
if (selection_filtered_out) {
|
|
|
|
session->send_message("limboai:untrack_bt_player", Array());
|
|
|
|
bt_view->clear();
|
|
|
|
_show_alert("");
|
|
|
|
} else {
|
2024-08-03 09:07:06 +00:00
|
|
|
_show_alert(TTR("Behavior tree instance is no longer present."));
|
2023-04-15 07:01:37 +00:00
|
|
|
}
|
2023-04-13 07:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
void LimboDebuggerTab::_bt_instance_selected(int p_idx) {
|
2023-04-15 07:01:37 +00:00
|
|
|
alert_box->hide();
|
2023-04-13 07:29:45 +00:00
|
|
|
bt_view->clear();
|
2023-04-15 07:01:37 +00:00
|
|
|
info_message->set_text(TTR("Waiting for behavior tree update."));
|
|
|
|
info_message->show();
|
2023-12-12 22:37:28 +00:00
|
|
|
resource_header->set_text(TTR("Waiting for data"));
|
|
|
|
resource_header->set_disabled(true);
|
2023-07-20 18:10:02 +00:00
|
|
|
Array msg_data;
|
2024-08-03 09:07:06 +00:00
|
|
|
msg_data.push_back(bt_instance_list->get_item_metadata(p_idx));
|
2023-07-20 18:10:02 +00:00
|
|
|
session->send_message("limboai:track_bt_player", msg_data);
|
2023-04-15 07:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LimboDebuggerTab::_filter_changed(String p_text) {
|
2024-08-03 09:07:06 +00:00
|
|
|
_update_bt_instance_list(active_bt_instances, p_text);
|
2023-04-13 07:29:45 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 10:13:00 +00:00
|
|
|
void LimboDebuggerTab::_window_visibility_changed(bool p_visible) {
|
|
|
|
make_floating->set_visible(!p_visible);
|
|
|
|
}
|
|
|
|
|
2023-12-12 22:37:28 +00:00
|
|
|
void LimboDebuggerTab::_resource_header_pressed() {
|
|
|
|
String bt_path = resource_header->get_text();
|
|
|
|
if (bt_path.is_empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2024-03-20 13:19:49 +00:00
|
|
|
FS_DOCK_SELECT_FILE(bt_path.get_slice("::", 0));
|
2024-01-09 20:47:22 +00:00
|
|
|
Ref<BehaviorTree> bt = RESOURCE_LOAD(bt_path, "BehaviorTree");
|
2023-12-12 22:37:28 +00:00
|
|
|
ERR_FAIL_COND_MSG(!bt.is_valid(), "Failed to load BehaviorTree. Wrong resource path?");
|
|
|
|
EditorInterface::get_singleton()->edit_resource(bt);
|
|
|
|
}
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
void LimboDebuggerTab::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
2023-08-29 10:54:38 +00:00
|
|
|
void LimboDebuggerTab::_notification(int p_what) {
|
2024-01-09 20:47:22 +00:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_READY: {
|
|
|
|
resource_header->connect(LW_NAME(pressed), callable_mp(this, &LimboDebuggerTab::_resource_header_pressed));
|
|
|
|
filter_players->connect(LW_NAME(text_changed), callable_mp(this, &LimboDebuggerTab::_filter_changed));
|
2024-08-03 09:07:06 +00:00
|
|
|
bt_instance_list->connect(LW_NAME(item_selected), callable_mp(this, &LimboDebuggerTab::_bt_instance_selected));
|
2024-02-17 13:56:19 +00:00
|
|
|
update_interval->connect("value_changed", callable_mp(bt_view, &BehaviorTreeView::set_update_interval_msec));
|
|
|
|
|
|
|
|
Ref<ConfigFile> cf;
|
|
|
|
cf.instantiate();
|
2024-09-19 14:39:49 +00:00
|
|
|
String conf_path = LAYOUT_CONFIG_FILE();
|
2024-02-17 13:56:19 +00:00
|
|
|
if (cf->load(conf_path) == OK) {
|
2024-09-19 14:39:49 +00:00
|
|
|
Variant value = cf->get_value("LimboAI", "debugger_update_interval_msec", 0);
|
2024-02-17 13:56:19 +00:00
|
|
|
update_interval->set_value(value);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
Ref<ConfigFile> cf;
|
|
|
|
cf.instantiate();
|
2024-09-19 14:39:49 +00:00
|
|
|
String conf_path = LAYOUT_CONFIG_FILE();
|
2024-02-17 13:56:19 +00:00
|
|
|
cf->load(conf_path);
|
2024-09-19 14:39:49 +00:00
|
|
|
cf->set_value("LimboAI", "debugger_update_interval_msec", update_interval->get_value());
|
2024-02-17 13:56:19 +00:00
|
|
|
cf->save(conf_path);
|
2024-01-09 20:47:22 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
|
|
alert_icon->set_texture(get_theme_icon(LW_NAME(StatusWarning), LW_NAME(EditorIcons)));
|
2024-11-03 00:55:48 +00:00
|
|
|
resource_header->set_button_icon(LimboUtility::get_singleton()->get_task_icon("BehaviorTree"));
|
2024-01-09 20:47:22 +00:00
|
|
|
} break;
|
2023-08-29 10:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
void LimboDebuggerTab::setup(Ref<EditorDebuggerSession> p_session, CompatWindowWrapper *p_wrapper) {
|
2023-04-13 07:29:45 +00:00
|
|
|
session = p_session;
|
2023-08-02 10:13:00 +00:00
|
|
|
window_wrapper = p_wrapper;
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
if (p_wrapper->is_window_available()) {
|
|
|
|
make_floating = memnew(CompatScreenSelect);
|
|
|
|
make_floating->set_flat(true);
|
|
|
|
make_floating->set_tooltip_text(TTR("Make the LimboAI Debugger floating."));
|
|
|
|
make_floating->connect(LW_NAME(request_open_in_screen), callable_mp(window_wrapper, &CompatWindowWrapper::enable_window_on_screen).bind(true));
|
|
|
|
toolbar->add_child(make_floating);
|
|
|
|
p_wrapper->connect(LW_NAME(window_visibility_changed), callable_mp(this, &LimboDebuggerTab::_window_visibility_changed));
|
|
|
|
}
|
|
|
|
|
|
|
|
_reset_controls();
|
|
|
|
}
|
|
|
|
|
|
|
|
LimboDebuggerTab::LimboDebuggerTab() {
|
2023-08-02 10:13:00 +00:00
|
|
|
root_vb = memnew(VBoxContainer);
|
|
|
|
add_child(root_vb);
|
|
|
|
|
|
|
|
toolbar = memnew(HBoxContainer);
|
|
|
|
root_vb->add_child(toolbar);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-12-12 22:37:28 +00:00
|
|
|
resource_header = memnew(Button);
|
|
|
|
toolbar->add_child(resource_header);
|
|
|
|
resource_header->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
|
|
|
|
resource_header->set_focus_mode(FOCUS_NONE);
|
|
|
|
resource_header->add_theme_constant_override("hseparation", 8);
|
|
|
|
resource_header->set_text(TTR("Inactive"));
|
|
|
|
resource_header->set_tooltip_text(TTR("Debugged BehaviorTree resource.\nClick to open."));
|
|
|
|
resource_header->set_disabled(true);
|
|
|
|
|
2024-02-17 13:56:19 +00:00
|
|
|
Label *interval_label = memnew(Label);
|
|
|
|
toolbar->add_child(interval_label);
|
|
|
|
interval_label->set_text(TTR("Update Interval:"));
|
|
|
|
interval_label->set_h_size_flags(SIZE_EXPAND | SIZE_SHRINK_END);
|
|
|
|
|
|
|
|
update_interval = memnew(EditorSpinSlider);
|
|
|
|
toolbar->add_child(update_interval);
|
|
|
|
update_interval->set_min(0);
|
|
|
|
update_interval->set_max(1000);
|
|
|
|
update_interval->set_step(1.0);
|
|
|
|
update_interval->set_suffix("ms");
|
|
|
|
update_interval->set_custom_minimum_size(Vector2(100 * EDSCALE, 0));
|
|
|
|
|
|
|
|
VSeparator *sep = memnew(VSeparator);
|
|
|
|
toolbar->add_child(sep);
|
|
|
|
|
2023-04-13 07:29:45 +00:00
|
|
|
hsc = memnew(HSplitContainer);
|
2023-08-02 10:13:00 +00:00
|
|
|
hsc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
hsc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
root_vb->add_child(hsc);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-04-15 07:01:37 +00:00
|
|
|
VBoxContainer *list_box = memnew(VBoxContainer);
|
|
|
|
hsc->add_child(list_box);
|
|
|
|
|
|
|
|
filter_players = memnew(LineEdit);
|
|
|
|
filter_players->set_placeholder(TTR("Filter Players"));
|
|
|
|
list_box->add_child(filter_players);
|
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
bt_instance_list = memnew(ItemList);
|
|
|
|
bt_instance_list->set_custom_minimum_size(Size2(240.0 * EDSCALE, 0.0));
|
|
|
|
bt_instance_list->set_h_size_flags(SIZE_FILL);
|
|
|
|
bt_instance_list->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
list_box->add_child(bt_instance_list);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
|
|
|
view_box = memnew(VBoxContainer);
|
2023-04-15 07:01:37 +00:00
|
|
|
hsc->add_child(view_box);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-04-15 07:01:37 +00:00
|
|
|
bt_view = memnew(BehaviorTreeView);
|
|
|
|
bt_view->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
bt_view->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
view_box->add_child(bt_view);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-04-15 07:01:37 +00:00
|
|
|
alert_box = memnew(HBoxContainer);
|
|
|
|
alert_box->hide();
|
|
|
|
view_box->add_child(alert_box);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-04-15 07:01:37 +00:00
|
|
|
alert_icon = memnew(TextureRect);
|
|
|
|
alert_box->add_child(alert_icon);
|
|
|
|
alert_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-04-15 07:01:37 +00:00
|
|
|
alert_message = memnew(Label);
|
|
|
|
alert_box->add_child(alert_message);
|
|
|
|
alert_message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-04-15 07:01:37 +00:00
|
|
|
info_message = memnew(Label);
|
|
|
|
info_message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
|
|
|
|
info_message->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
|
|
|
info_message->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
|
|
|
|
info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
|
|
|
|
info_message->set_anchors_and_offsets_preset(PRESET_FULL_RECT, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
|
|
|
|
|
|
|
|
bt_view->add_child(info_message);
|
2023-04-13 07:29:45 +00:00
|
|
|
}
|
|
|
|
|
2023-08-20 09:34:13 +00:00
|
|
|
//**** LimboDebuggerPlugin
|
|
|
|
|
|
|
|
LimboDebuggerPlugin *LimboDebuggerPlugin::singleton = nullptr;
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-08-02 10:13:00 +00:00
|
|
|
void LimboDebuggerPlugin::_window_visibility_changed(bool p_visible) {
|
|
|
|
}
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2024-04-21 11:04:16 +00:00
|
|
|
void LimboDebuggerPlugin::setup_session(int p_session_id) {
|
2024-01-13 16:10:42 +00:00
|
|
|
#elif LIMBOAI_GDEXTENSION
|
2024-04-21 11:04:16 +00:00
|
|
|
void LimboDebuggerPlugin::_setup_session(int32_t p_session_id) {
|
2024-01-09 20:47:22 +00:00
|
|
|
#endif
|
2024-04-21 11:04:16 +00:00
|
|
|
Ref<EditorDebuggerSession> session = get_session(p_session_id);
|
|
|
|
ERR_FAIL_COND(session.is_null());
|
2023-08-02 10:13:00 +00:00
|
|
|
|
2024-04-21 11:04:16 +00:00
|
|
|
CompatWindowWrapper *session_window = memnew(CompatWindowWrapper);
|
|
|
|
session_window->set_window_title(vformat(TTR("%s - Godot Engine"), TTR("LimboAI Debugger")));
|
|
|
|
session_window->set_margins_enabled(true);
|
2023-08-02 10:13:00 +00:00
|
|
|
|
2024-04-21 11:04:16 +00:00
|
|
|
LimboDebuggerTab *tab = memnew(LimboDebuggerTab());
|
|
|
|
tab->setup(session, session_window);
|
2023-04-13 07:29:45 +00:00
|
|
|
tab->set_name("LimboAI");
|
2024-04-21 11:04:16 +00:00
|
|
|
session_window->set_wrapped_control(tab);
|
|
|
|
session_window->set_name("LimboAI");
|
2023-08-02 10:13:00 +00:00
|
|
|
|
2024-04-21 11:04:16 +00:00
|
|
|
session_window->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
session_window->connect(LW_NAME(window_visibility_changed), callable_mp(this, &LimboDebuggerPlugin::_window_visibility_changed));
|
2023-08-02 10:13:00 +00:00
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
session->connect(LW_NAME(started), callable_mp(tab, &LimboDebuggerTab::start_session));
|
|
|
|
session->connect(LW_NAME(stopped), callable_mp(tab, &LimboDebuggerTab::stop_session));
|
2024-04-21 11:04:16 +00:00
|
|
|
session->add_session_tab(session_window);
|
|
|
|
|
|
|
|
session_windows[p_session_id] = session_window;
|
2023-04-13 07:29:45 +00:00
|
|
|
}
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2024-04-21 11:04:16 +00:00
|
|
|
bool LimboDebuggerPlugin::capture(const String &p_message, const Array &p_data, int p_session_id) {
|
2024-01-13 16:10:42 +00:00
|
|
|
#elif LIMBOAI_GDEXTENSION
|
2024-04-21 11:04:16 +00:00
|
|
|
bool LimboDebuggerPlugin::_capture(const String &p_message, const Array &p_data, int32_t p_session_id) {
|
2024-01-09 20:47:22 +00:00
|
|
|
#endif
|
2024-04-21 11:04:16 +00:00
|
|
|
ERR_FAIL_COND_V(!session_windows.has(p_session_id), false);
|
|
|
|
LimboDebuggerTab *tab = Object::cast_to<LimboDebuggerTab>(session_windows[p_session_id]->get_wrapped_control());
|
|
|
|
ERR_FAIL_NULL_V(tab, false);
|
2023-04-13 07:29:45 +00:00
|
|
|
bool captured = true;
|
2023-04-15 07:01:37 +00:00
|
|
|
if (p_message == "limboai:active_bt_players") {
|
2024-08-03 09:07:06 +00:00
|
|
|
tab->update_active_bt_instances(p_data);
|
2023-04-13 07:29:45 +00:00
|
|
|
} else if (p_message == "limboai:bt_update") {
|
2024-02-03 15:31:21 +00:00
|
|
|
Ref<BehaviorTreeData> data = BehaviorTreeData::deserialize(p_data);
|
2024-08-03 09:07:06 +00:00
|
|
|
if (data->bt_instance_id == tab->get_selected_bt_instance_id()) {
|
2023-04-15 07:01:37 +00:00
|
|
|
tab->update_behavior_tree(data);
|
|
|
|
}
|
2023-04-13 07:29:45 +00:00
|
|
|
} else {
|
|
|
|
captured = false;
|
|
|
|
}
|
|
|
|
return captured;
|
|
|
|
}
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2023-04-13 07:29:45 +00:00
|
|
|
bool LimboDebuggerPlugin::has_capture(const String &p_capture) const {
|
2024-01-13 16:10:42 +00:00
|
|
|
#elif LIMBOAI_GDEXTENSION
|
2024-01-09 20:47:22 +00:00
|
|
|
bool LimboDebuggerPlugin::_has_capture(const String &p_capture) const {
|
|
|
|
#endif
|
2023-04-13 07:29:45 +00:00
|
|
|
return p_capture == "limboai";
|
|
|
|
}
|
|
|
|
|
2024-04-21 11:04:16 +00:00
|
|
|
CompatWindowWrapper *LimboDebuggerPlugin::get_first_session_window() const {
|
|
|
|
ERR_FAIL_COND_V(session_windows.is_empty(), nullptr);
|
|
|
|
return session_windows.begin()->value;
|
2023-08-20 09:34:13 +00:00
|
|
|
}
|
|
|
|
|
2024-04-21 11:04:16 +00:00
|
|
|
int LimboDebuggerPlugin::get_first_session_tab_index() const {
|
|
|
|
ERR_FAIL_COND_V(session_windows.is_empty(), -1);
|
|
|
|
CompatWindowWrapper *window_wrapper = session_windows.begin()->value;
|
2023-08-20 09:34:13 +00:00
|
|
|
TabContainer *c = Object::cast_to<TabContainer>(window_wrapper->get_parent());
|
|
|
|
ERR_FAIL_COND_V(c == nullptr, -1);
|
|
|
|
return c->get_tab_idx_from_control(window_wrapper);
|
|
|
|
}
|
|
|
|
|
2024-01-09 20:47:22 +00:00
|
|
|
void LimboDebuggerPlugin::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
2023-04-13 07:29:45 +00:00
|
|
|
LimboDebuggerPlugin::LimboDebuggerPlugin() {
|
2023-08-20 09:34:13 +00:00
|
|
|
singleton = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LimboDebuggerPlugin::~LimboDebuggerPlugin() {
|
|
|
|
singleton = nullptr;
|
2023-04-15 07:01:37 +00:00
|
|
|
}
|
2023-04-16 09:30:31 +00:00
|
|
|
|
2024-01-11 10:22:02 +00:00
|
|
|
#endif // ! TOOLS_ENABLED
|