2024-01-24 22:11:09 +00:00
|
|
|
/**
|
|
|
|
* blackboard_plan_editor.h
|
|
|
|
* =============================================================================
|
|
|
|
* Copyright 2021-2024 Serhii Snitsaruk
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLACKBOARD_PLAN_EDITOR_H
|
|
|
|
#define BLACKBOARD_PLAN_EDITOR_H
|
|
|
|
|
2024-01-28 16:49:38 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2024-01-24 22:11:09 +00:00
|
|
|
#include "../blackboard/blackboard_plan.h"
|
|
|
|
|
|
|
|
#ifdef LIMBOAI_MODULE
|
|
|
|
#include "editor/editor_inspector.h"
|
|
|
|
#include "scene/gui/dialogs.h"
|
|
|
|
#endif // LIMBOAI_MODULE
|
|
|
|
|
2024-01-25 16:59:38 +00:00
|
|
|
#ifdef LIMBOAI_GDEXTENSION
|
|
|
|
#include <godot_cpp/classes/accept_dialog.hpp>
|
|
|
|
#include <godot_cpp/classes/editor_inspector_plugin.hpp>
|
2024-01-28 19:14:52 +00:00
|
|
|
#include <godot_cpp/classes/line_edit.hpp>
|
2024-01-25 16:59:38 +00:00
|
|
|
#include <godot_cpp/classes/panel_container.hpp>
|
|
|
|
#include <godot_cpp/classes/popup_menu.hpp>
|
|
|
|
#include <godot_cpp/classes/scroll_container.hpp>
|
|
|
|
#include <godot_cpp/classes/style_box_flat.hpp>
|
|
|
|
#include <godot_cpp/classes/v_box_container.hpp>
|
|
|
|
using namespace godot;
|
|
|
|
#endif // LIMBOAI_GDEXTENSION
|
|
|
|
|
2024-01-24 22:11:09 +00:00
|
|
|
// *****
|
|
|
|
|
|
|
|
class BlackboardPlanEditor : public AcceptDialog {
|
|
|
|
GDCLASS(BlackboardPlanEditor, AcceptDialog);
|
|
|
|
|
2024-01-28 16:49:38 +00:00
|
|
|
private:
|
|
|
|
static BlackboardPlanEditor *singleton;
|
|
|
|
|
2024-01-24 22:11:09 +00:00
|
|
|
private:
|
|
|
|
struct ThemeCache {
|
|
|
|
Ref<Texture2D> trash_icon;
|
|
|
|
Ref<Texture2D> grab_icon;
|
|
|
|
Ref<StyleBoxFlat> odd_style;
|
|
|
|
Ref<StyleBoxFlat> even_style;
|
|
|
|
Ref<StyleBoxFlat> header_style;
|
|
|
|
} theme_cache;
|
|
|
|
|
|
|
|
int last_index = 0;
|
|
|
|
int drag_mouse_y_delta = 0;
|
2024-01-25 21:01:14 +00:00
|
|
|
int drag_start = -1;
|
2024-01-24 23:23:34 +00:00
|
|
|
int drag_index = -1;
|
2024-01-24 22:11:09 +00:00
|
|
|
|
|
|
|
Ref<BlackboardPlan> plan;
|
2024-03-04 16:58:53 +00:00
|
|
|
StringName default_var_name;
|
2024-01-24 22:11:09 +00:00
|
|
|
|
|
|
|
VBoxContainer *rows_vbox;
|
|
|
|
Button *add_var_tool;
|
|
|
|
PanelContainer *header_row;
|
|
|
|
ScrollContainer *scroll_container;
|
|
|
|
PopupMenu *type_menu;
|
|
|
|
PopupMenu *hint_menu;
|
|
|
|
|
2024-01-28 19:14:52 +00:00
|
|
|
LineEdit *_get_name_edit(int p_row_index) const;
|
|
|
|
|
2024-01-24 22:11:09 +00:00
|
|
|
void _add_var();
|
|
|
|
void _trash_var(int p_index);
|
2024-03-04 16:58:53 +00:00
|
|
|
void _rename_var(const StringName &p_new_name, int p_index);
|
2024-01-24 22:11:09 +00:00
|
|
|
void _change_var_type(Variant::Type p_new_type, int p_index);
|
|
|
|
void _change_var_hint(PropertyHint p_new_hint, int p_index);
|
|
|
|
void _change_var_hint_string(const String &p_new_hint_string, int p_index);
|
|
|
|
|
|
|
|
void _show_button_popup(Button *p_button, PopupMenu *p_popup, int p_index);
|
|
|
|
void _type_chosen(int id);
|
|
|
|
void _hint_chosen(int id);
|
2024-01-28 20:03:22 +00:00
|
|
|
void _add_var_pressed();
|
2024-01-24 22:11:09 +00:00
|
|
|
|
|
|
|
void _drag_button_down(Control *p_row);
|
|
|
|
void _drag_button_up();
|
|
|
|
void _drag_button_gui_input(const Ref<InputEvent> &p_event);
|
|
|
|
|
|
|
|
void _refresh();
|
|
|
|
void _visibility_changed();
|
|
|
|
|
|
|
|
protected:
|
2024-01-25 16:59:38 +00:00
|
|
|
static void _bind_methods() {}
|
|
|
|
|
2024-01-24 22:11:09 +00:00
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
2024-01-28 16:49:38 +00:00
|
|
|
_FORCE_INLINE_ static BlackboardPlanEditor *get_singleton() { return singleton; }
|
|
|
|
|
2024-01-24 22:11:09 +00:00
|
|
|
void edit_plan(const Ref<BlackboardPlan> &p_plan);
|
2024-03-04 16:58:53 +00:00
|
|
|
void set_next_var_name(const StringName &p_name);
|
2024-01-24 22:11:09 +00:00
|
|
|
|
|
|
|
BlackboardPlanEditor();
|
|
|
|
};
|
|
|
|
|
|
|
|
// *****
|
|
|
|
|
|
|
|
class EditorInspectorPluginBBPlan : public EditorInspectorPlugin {
|
|
|
|
GDCLASS(EditorInspectorPluginBBPlan, EditorInspectorPlugin);
|
|
|
|
|
|
|
|
private:
|
|
|
|
BlackboardPlanEditor *plan_editor;
|
2024-01-24 23:23:34 +00:00
|
|
|
Ref<StyleBoxFlat> toolbar_style;
|
2024-01-24 22:11:09 +00:00
|
|
|
|
|
|
|
void _edit_plan(const Ref<BlackboardPlan> &p_plan);
|
|
|
|
void _open_base_plan(const Ref<BlackboardPlan> &p_plan);
|
|
|
|
|
2024-01-25 16:59:38 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods() {}
|
|
|
|
|
2024-01-24 22:11:09 +00:00
|
|
|
public:
|
2024-01-25 16:59:38 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2024-01-24 22:11:09 +00:00
|
|
|
virtual bool can_handle(Object *p_object) override;
|
|
|
|
virtual void parse_begin(Object *p_object) override;
|
2024-01-25 16:59:38 +00:00
|
|
|
#elif LIMBOAI_GDEXTENSION
|
|
|
|
virtual bool _can_handle(Object *p_object) const override;
|
|
|
|
virtual void _parse_begin(Object *p_object) override;
|
|
|
|
#endif
|
2024-01-24 22:11:09 +00:00
|
|
|
|
|
|
|
EditorInspectorPluginBBPlan();
|
|
|
|
};
|
|
|
|
|
2024-01-28 16:49:38 +00:00
|
|
|
#endif // TOOLS_ENABLED
|
|
|
|
|
2024-01-24 22:11:09 +00:00
|
|
|
#endif // BLACKBOARD_PLAN_EDITOR_H
|