#pragma once
#include "core/templates/list.h"
#include "scene/resources/texture.h"
class ConfigFile;
class EditorPlugin;
class EditorUndoRedoManager;
class PopupMenu;
class EditorSelectionHistory {
struct _Object {
Ref<RefCounted> ref;
ObjectID object;
String property;
bool inspector_only = false;
};
struct HistoryElement {
Vector<_Object> path;
int level = 0;
};
friend class EditorData;
Vector<HistoryElement> history;
int current_elem_idx;
public:
void cleanup_history();
bool is_at_beginning() const;
bool is_at_end() const;
void add_object(ObjectID p_object, const String &p_property = String(), bool p_inspector_only = false);
void replace_object(ObjectID p_old_object, ObjectID p_new_object);
int get_history_len();
int get_history_pos();
ObjectID get_history_obj(int p_obj) const;
bool next();
bool previous();
ObjectID get_current();
bool is_current_inspector_only() const;
int get_path_size() const;
ObjectID get_path_object(int p_index) const;
String get_path_property(int p_index) const;
void clear();
EditorSelectionHistory();
};
class EditorSelection;
class EditorData {
public:
struct CustomType {
String name;
Ref<Script> script;
Ref<Texture2D> icon;
};
struct EditedScene {
Node *root = nullptr;
String path;
uint64_t file_modified_time = 0;
Dictionary editor_states;
List<Node *> selection;
Vector<EditorSelectionHistory::HistoryElement> history_stored;
int history_current = 0;
Dictionary custom_state;
NodePath live_edit_root;
int history_id = 0;
uint64_t last_checked_version = 0;
};
private:
Vector<EditorPlugin *> editor_plugins;
HashMap<StringName, EditorPlugin *> extension_editor_plugins;
struct PropertyData {
String name;
Variant value;
};
HashMap<String, Vector<CustomType>> custom_types;
List<PropertyData> clipboard;
EditorUndoRedoManager *undo_redo_manager;
Vector<Callable> undo_redo_callbacks;
HashMap<StringName, Callable> move_element_functions;
Vector<EditedScene> edited_scene;
int current_edited_scene = -1;
int last_created_scene = 1;
bool _find_updated_instances(Node *p_root, Node *p_node, HashSet<String> &checked_paths);
HashMap<StringName, String> _script_class_icon_paths;
HashMap<String, StringName> _script_class_file_to_path;
HashMap<String, Ref<Texture2D>> _script_icon_cache;
Ref<Texture2D> _load_script_icon(const String &p_path) const;
public:
EditorPlugin *get_handling_main_editor(Object *p_object);
Vector<EditorPlugin *> get_handling_sub_editors(Object *p_object);
EditorPlugin *get_editor_by_name(const String &p_name);
void copy_object_params(Object *p_object);
void paste_object_params(Object *p_object);
Dictionary get_editor_plugin_states() const;
Dictionary get_scene_editor_states(int p_idx) const;
void set_editor_plugin_states(const Dictionary &p_states);
void get_editor_breakpoints(List<String> *p_breakpoints);
void clear_editor_states();
void save_editor_external_data();
void apply_changes_in_editors();
void add_editor_plugin(EditorPlugin *p_plugin);
void remove_editor_plugin(EditorPlugin *p_plugin);
int get_editor_plugin_count() const;
EditorPlugin *get_editor_plugin(int p_idx);
void add_extension_editor_plugin(const StringName &p_class_name, EditorPlugin *p_plugin);
void remove_extension_editor_plugin(const StringName &p_class_name);
bool has_extension_editor_plugin(const StringName &p_class_name);
EditorPlugin *get_extension_editor_plugin(const StringName &p_class_name);
void add_undo_redo_inspector_hook_callback(Callable p_callable);
void remove_undo_redo_inspector_hook_callback(Callable p_callable);
const Vector<Callable> get_undo_redo_inspector_hook_callback();
void add_move_array_element_function(const StringName &p_class, Callable p_callable);
void remove_move_array_element_function(const StringName &p_class);
Callable get_move_array_element_function(const StringName &p_class) const;
void save_editor_global_states();
void add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon);
Variant instantiate_custom_type(const String &p_type, const String &p_inherits);
void remove_custom_type(const String &p_type);
const HashMap<String, Vector<CustomType>> &get_custom_types() const { return custom_types; }
const CustomType *get_custom_type_by_name(const String &p_name) const;
const CustomType *get_custom_type_by_path(const String &p_path) const;
bool is_type_recognized(const String &p_type) const;
void instantiate_object_properties(Object *p_object);
int add_edited_scene(int p_at_pos);
void move_edited_scene_index(int p_idx, int p_to_idx);
void remove_scene(int p_idx);
void set_edited_scene(int p_idx);
void set_edited_scene_root(Node *p_root);
int get_edited_scene() const;
int get_edited_scene_from_path(const String &p_path) const;
Node *get_edited_scene_root(int p_idx = -1);
int get_edited_scene_count() const;
Vector<EditedScene> get_edited_scenes() const;
String get_scene_title(int p_idx, bool p_always_strip_extension = false) const;
String get_scene_path(int p_idx) const;
String get_scene_type(int p_idx) const;
void set_scene_path(int p_idx, const String &p_path);
Ref<Script> get_scene_root_script(int p_idx) const;
void set_scene_modified_time(int p_idx, uint64_t p_time);
uint64_t get_scene_modified_time(int p_idx) const;
void clear_edited_scenes();
void set_edited_scene_live_edit_root(const NodePath &p_root);
NodePath get_edited_scene_live_edit_root();
bool check_and_update_scene(int p_idx);
void move_edited_scene_to_index(int p_idx);
bool call_build();
void set_scene_as_saved(int p_idx);
bool is_scene_changed(int p_idx);
int get_scene_history_id_from_path(const String &p_path) const;
int get_current_edited_scene_history_id() const;
int get_scene_history_id(int p_idx) const;
void set_plugin_window_layout(Ref<ConfigFile> p_layout);
void get_plugin_window_layout(Ref<ConfigFile> p_layout);
void save_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history, const Dictionary &p_custom);
Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history);
void notify_edited_scene_changed();
void notify_resource_saved(const Ref<Resource> &p_resource);
void notify_scene_saved(const String &p_path);
bool script_class_is_parent(const String &p_class, const String &p_inherits);
Variant script_class_instance(const String &p_class);
Ref<Script> script_class_load_script(const String &p_class) const;
StringName script_class_get_name(const String &p_path) const;
void script_class_set_name(const String &p_path, const StringName &p_class);
String script_class_get_icon_path(const String &p_class, bool *r_valid = nullptr) const;
void script_class_set_icon_path(const String &p_class, const String &p_icon_path);
void script_class_clear_icon_paths() { _script_class_icon_paths.clear(); }
void script_class_save_global_classes();
void script_class_load_icon_paths();
Ref<Texture2D> extension_class_get_icon(const String &p_class) const;
Ref<Texture2D> get_script_icon(const String &p_script_path);
void clear_script_icon_cache();
EditorData();
~EditorData();
};
class EditorSelection : public Object {
GDCLASS(EditorSelection, Object);
HashMap<Node *, Object *> selection;
bool emitted = false;
bool changed = false;
bool node_list_changed = false;
void _node_removed(Node *p_node);
List<Object *> editor_plugins;
List<Node *> top_selected_node_list;
void _update_node_list();
void _emit_change();
protected:
static void _bind_methods();
public:
void add_node(Node *p_node);
void remove_node(Node *p_node);
bool is_selected(Node *p_node) const;
template <typename T>
T *get_node_editor_data(Node *p_node) {
if (!selection.has(p_node)) {
return nullptr;
}
return Object::cast_to<T>(selection[p_node]);
}
void add_editor_plugin(Object *p_object);
void update();
void clear();
const List<Node *> &get_top_selected_node_list();
TypedArray<Node> get_top_selected_nodes();
List<Node *> get_full_selected_node_list();
TypedArray<Node> get_selected_nodes();
HashMap<Node *, Object *> &get_selection() { return selection; }
~EditorSelection();
};