| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/templates/list.h" |
| 34 |
#include "scene/main/node.h" |
| 35 |
#include "scene/resources/texture.h" |
| 36 |
|
| 37 |
class ConfigFile; |
| 38 |
class EditorPlugin; |
| 39 |
class EditorUndoRedoManager; |
| 40 |
class PopupMenu; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
class EditorSelectionHistory { |
| 48 |
|
| 49 |
struct _Object { |
| 50 |
Ref<RefCounted> ref; |
| 51 |
ObjectID object; |
| 52 |
String property; |
| 53 |
bool inspector_only = false; |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
struct HistoryElement { |
| 58 |
|
| 59 |
|
| 60 |
Vector<_Object> path; |
| 61 |
|
| 62 |
int level = 0; |
| 63 |
}; |
| 64 |
friend class EditorData; |
| 65 |
|
| 66 |
Vector<HistoryElement> history; |
| 67 |
int current_elem_idx; |
| 68 |
|
| 69 |
public: |
| 70 |
void cleanup_history(); |
| 71 |
|
| 72 |
bool is_at_beginning() const; |
| 73 |
bool is_at_end() const; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
void add_object(ObjectID p_object, const String &p_property = String(), bool p_inspector_only = false); |
| 78 |
void replace_object(ObjectID p_old_object, ObjectID p_new_object); |
| 79 |
|
| 80 |
int get_history_len(); |
| 81 |
int get_history_pos(); |
| 82 |
|
| 83 |
|
| 84 |
ObjectID get_history_obj(int p_obj) const; |
| 85 |
|
| 86 |
bool next(); |
| 87 |
bool previous(); |
| 88 |
ObjectID get_current(); |
| 89 |
bool is_current_inspector_only() const; |
| 90 |
|
| 91 |
|
| 92 |
int get_path_size() const; |
| 93 |
|
| 94 |
ObjectID get_path_object(int p_index) const; |
| 95 |
|
| 96 |
String get_path_property(int p_index) const; |
| 97 |
|
| 98 |
void clear(); |
| 99 |
|
| 100 |
EditorSelectionHistory(); |
| 101 |
}; |
| 102 |
|
| 103 |
class EditorSelection; |
| 104 |
|
| 105 |
class EditorData { |
| 106 |
public: |
| 107 |
struct CustomType { |
| 108 |
String name; |
| 109 |
Ref<Script> script; |
| 110 |
Ref<Texture2D> icon; |
| 111 |
}; |
| 112 |
|
| 113 |
struct EditedScene { |
| 114 |
Node *root = nullptr; |
| 115 |
String path; |
| 116 |
uint64_t file_modified_time = 0; |
| 117 |
Dictionary editor_states; |
| 118 |
List<Node *> selection; |
| 119 |
Vector<EditorSelectionHistory::HistoryElement> history_stored; |
| 120 |
int history_current = 0; |
| 121 |
Dictionary custom_state; |
| 122 |
NodePath live_edit_root; |
| 123 |
int history_id = 0; |
| 124 |
uint64_t last_checked_version = 0; |
| 125 |
}; |
| 126 |
|
| 127 |
private: |
| 128 |
Vector<EditorPlugin *> editor_plugins; |
| 129 |
HashMap<StringName, EditorPlugin *> extension_editor_plugins; |
| 130 |
|
| 131 |
struct PropertyData { |
| 132 |
String name; |
| 133 |
Variant value; |
| 134 |
}; |
| 135 |
HashMap<String, Vector<CustomType>> custom_types; |
| 136 |
|
| 137 |
List<PropertyData> clipboard; |
| 138 |
EditorUndoRedoManager *undo_redo_manager; |
| 139 |
Vector<Callable> undo_redo_callbacks; |
| 140 |
HashMap<StringName, Callable> move_element_functions; |
| 141 |
|
| 142 |
Vector<EditedScene> edited_scene; |
| 143 |
int current_edited_scene = -1; |
| 144 |
int last_created_scene = 1; |
| 145 |
|
| 146 |
bool _find_updated_instances(Node *p_root, Node *p_node, HashSet<String> &checked_paths); |
| 147 |
|
| 148 |
HashMap<StringName, String> _script_class_icon_paths; |
| 149 |
HashMap<String, StringName> _script_class_file_to_path; |
| 150 |
HashMap<String, Ref<Texture2D>> _script_icon_cache; |
| 151 |
|
| 152 |
Ref<Texture2D> _load_script_icon(const String &p_path) const; |
| 153 |
|
| 154 |
public: |
| 155 |
EditorPlugin *get_handling_main_editor(Object *p_object); |
| 156 |
Vector<EditorPlugin *> get_handling_sub_editors(Object *p_object); |
| 157 |
EditorPlugin *get_editor_by_name(const String &p_name); |
| 158 |
|
| 159 |
void copy_object_params(Object *p_object); |
| 160 |
void paste_object_params(Object *p_object); |
| 161 |
|
| 162 |
Dictionary get_editor_plugin_states() const; |
| 163 |
Dictionary get_scene_editor_states(int p_idx) const; |
| 164 |
void set_editor_plugin_states(const Dictionary &p_states); |
| 165 |
void get_editor_breakpoints(List<String> *p_breakpoints); |
| 166 |
void clear_editor_states(); |
| 167 |
void save_editor_external_data(); |
| 168 |
void apply_changes_in_editors(); |
| 169 |
|
| 170 |
void add_editor_plugin(EditorPlugin *p_plugin); |
| 171 |
void remove_editor_plugin(EditorPlugin *p_plugin); |
| 172 |
|
| 173 |
int get_editor_plugin_count() const; |
| 174 |
EditorPlugin *get_editor_plugin(int p_idx); |
| 175 |
|
| 176 |
void add_extension_editor_plugin(const StringName &p_class_name, EditorPlugin *p_plugin); |
| 177 |
void remove_extension_editor_plugin(const StringName &p_class_name); |
| 178 |
bool has_extension_editor_plugin(const StringName &p_class_name); |
| 179 |
EditorPlugin *get_extension_editor_plugin(const StringName &p_class_name); |
| 180 |
|
| 181 |
void add_undo_redo_inspector_hook_callback(Callable p_callable); |
| 182 |
void remove_undo_redo_inspector_hook_callback(Callable p_callable); |
| 183 |
const Vector<Callable> get_undo_redo_inspector_hook_callback(); |
| 184 |
|
| 185 |
void add_move_array_element_function(const StringName &p_class, Callable p_callable); |
| 186 |
void remove_move_array_element_function(const StringName &p_class); |
| 187 |
Callable get_move_array_element_function(const StringName &p_class) const; |
| 188 |
|
| 189 |
void save_editor_global_states(); |
| 190 |
|
| 191 |
void add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon); |
| 192 |
Variant instantiate_custom_type(const String &p_type, const String &p_inherits); |
| 193 |
void remove_custom_type(const String &p_type); |
| 194 |
const HashMap<String, Vector<CustomType>> &get_custom_types() const { return custom_types; } |
| 195 |
const CustomType *get_custom_type_by_name(const String &p_name) const; |
| 196 |
const CustomType *get_custom_type_by_path(const String &p_path) const; |
| 197 |
bool is_type_recognized(const String &p_type) const; |
| 198 |
|
| 199 |
void instantiate_object_properties(Object *p_object); |
| 200 |
|
| 201 |
int add_edited_scene(int p_at_pos); |
| 202 |
void move_edited_scene_index(int p_idx, int p_to_idx); |
| 203 |
void remove_scene(int p_idx); |
| 204 |
void set_edited_scene(int p_idx); |
| 205 |
void set_edited_scene_root(Node *p_root); |
| 206 |
int get_edited_scene() const; |
| 207 |
int get_edited_scene_from_path(const String &p_path) const; |
| 208 |
Node *get_edited_scene_root(int p_idx = -1); |
| 209 |
int get_edited_scene_count() const; |
| 210 |
Vector<EditedScene> get_edited_scenes() const; |
| 211 |
|
| 212 |
String get_scene_title(int p_idx, bool p_always_strip_extension = false) const; |
| 213 |
String get_scene_path(int p_idx) const; |
| 214 |
String get_scene_type(int p_idx) const; |
| 215 |
void set_scene_path(int p_idx, const String &p_path); |
| 216 |
Ref<Script> get_scene_root_script(int p_idx) const; |
| 217 |
void set_scene_modified_time(int p_idx, uint64_t p_time); |
| 218 |
uint64_t get_scene_modified_time(int p_idx) const; |
| 219 |
void clear_edited_scenes(); |
| 220 |
void set_edited_scene_live_edit_root(const NodePath &p_root); |
| 221 |
NodePath get_edited_scene_live_edit_root(); |
| 222 |
bool check_and_update_scene(int p_idx); |
| 223 |
bool reload_scene_from_memory(int p_idx, bool p_mark_unsaved); |
| 224 |
void move_edited_scene_to_index(int p_idx); |
| 225 |
|
| 226 |
bool call_build(); |
| 227 |
|
| 228 |
void set_scene_as_saved(int p_idx); |
| 229 |
bool is_scene_changed(int p_idx); |
| 230 |
|
| 231 |
int get_scene_history_id_from_path(const String &p_path) const; |
| 232 |
int get_current_edited_scene_history_id() const; |
| 233 |
int get_scene_history_id(int p_idx) const; |
| 234 |
|
| 235 |
void set_plugin_window_layout(Ref<ConfigFile> p_layout); |
| 236 |
void get_plugin_window_layout(Ref<ConfigFile> p_layout); |
| 237 |
|
| 238 |
void save_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history, const Dictionary &p_custom); |
| 239 |
Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history); |
| 240 |
void notify_edited_scene_changed(); |
| 241 |
void notify_resource_saved(const Ref<Resource> &p_resource); |
| 242 |
void notify_scene_saved(const String &p_path); |
| 243 |
|
| 244 |
bool script_class_is_parent(const String &p_class, const String &p_inherits); |
| 245 |
Variant script_class_instance(const String &p_class); |
| 246 |
|
| 247 |
Ref<Script> script_class_load_script(const String &p_class) const; |
| 248 |
|
| 249 |
StringName script_class_get_name(const String &p_path) const; |
| 250 |
void script_class_set_name(const String &p_path, const StringName &p_class); |
| 251 |
|
| 252 |
String script_class_get_icon_path(const String &p_class, bool *r_valid = nullptr) const; |
| 253 |
void script_class_set_icon_path(const String &p_class, const String &p_icon_path); |
| 254 |
void script_class_clear_icon_paths() { _script_class_icon_paths.clear(); } |
| 255 |
void script_class_save_global_classes(); |
| 256 |
void script_class_load_icon_paths(); |
| 257 |
|
| 258 |
Ref<Texture2D> extension_class_get_icon(const String &p_class) const; |
| 259 |
|
| 260 |
Ref<Texture2D> get_script_icon(const String &p_script_path); |
| 261 |
void clear_script_icon_cache(); |
| 262 |
|
| 263 |
EditorData(); |
| 264 |
~EditorData(); |
| 265 |
}; |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
class EditorSelection : public Object { |
| 274 |
GDCLASS(EditorSelection, Object); |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
HashMap<ObjectID, Object *> selection; |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
bool emitted = false; |
| 283 |
|
| 284 |
bool changed = false; |
| 285 |
bool node_list_changed = false; |
| 286 |
|
| 287 |
void _node_removed(Node *p_node); |
| 288 |
|
| 289 |
|
| 290 |
List<Object *> editor_plugins; |
| 291 |
LocalVector<ObjectID> top_selected_node_list; |
| 292 |
|
| 293 |
void _update_node_list(); |
| 294 |
void _emit_change(); |
| 295 |
|
| 296 |
protected: |
| 297 |
static void _bind_methods(); |
| 298 |
|
| 299 |
public: |
| 300 |
void add_node(Node *p_node); |
| 301 |
void remove_node(Node *p_node); |
| 302 |
bool is_selected(Node *p_node) const; |
| 303 |
|
| 304 |
template <typename T> |
| 305 |
T *get_node_editor_data(Node *p_node) { |
| 306 |
if (!p_node) { |
| 307 |
return nullptr; |
| 308 |
} |
| 309 |
ObjectID nid = p_node->get_instance_id(); |
| 310 |
if (!selection.has(nid)) { |
| 311 |
return nullptr; |
| 312 |
} |
| 313 |
return Object::cast_to<T>(selection[nid]); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
void add_editor_plugin(Object *p_object); |
| 318 |
|
| 319 |
void update(); |
| 320 |
void clear(); |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
List<Node *> get_top_selected_node_list(); |
| 325 |
|
| 326 |
TypedArray<Node> get_top_selected_nodes(); |
| 327 |
|
| 328 |
List<Node *> get_full_selected_node_list(); |
| 329 |
|
| 330 |
TypedArray<Node> get_selected_nodes(); |
| 331 |
|
| 332 |
HashMap<ObjectID, Object *> &get_selection() { return selection; } |
| 333 |
|
| 334 |
~EditorSelection(); |
| 335 |
}; |