2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_data.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef EDITOR_DATA_H
|
|
|
|
#define EDITOR_DATA_H
|
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/object/undo_redo.h"
|
|
|
|
#include "core/templates/list.h"
|
|
|
|
#include "core/templates/pair.h"
|
2017-03-05 13:21:25 +00:00
|
|
|
#include "editor/editor_plugin.h"
|
2017-07-06 07:18:20 +00:00
|
|
|
#include "editor/plugins/script_editor_plugin.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/resources/texture.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
class EditorHistory {
|
|
|
|
enum {
|
2017-03-05 15:44:50 +00:00
|
|
|
HISTORY_MAX = 64
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Obj {
|
2015-08-25 03:08:45 +00:00
|
|
|
REF ref;
|
2014-02-10 01:10:30 +00:00
|
|
|
ObjectID object;
|
|
|
|
String property;
|
2020-11-24 09:12:55 +00:00
|
|
|
bool inspector_only = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct History {
|
|
|
|
Vector<Obj> path;
|
2020-11-24 09:12:55 +00:00
|
|
|
int level = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
friend class EditorData;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector<History> history;
|
|
|
|
int current;
|
|
|
|
|
|
|
|
//Vector<EditorPlugin*> editor_plugins;
|
|
|
|
|
|
|
|
struct PropertyData {
|
|
|
|
String name;
|
|
|
|
Variant value;
|
|
|
|
};
|
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
void _add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only = false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
public:
|
2018-01-08 05:50:51 +00:00
|
|
|
void cleanup_history();
|
|
|
|
|
2017-09-01 15:54:57 +00:00
|
|
|
bool is_at_beginning() const;
|
2015-09-01 03:49:47 +00:00
|
|
|
bool is_at_end() const;
|
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
void add_object_inspector_only(ObjectID p_object);
|
2014-02-10 01:10:30 +00:00
|
|
|
void add_object(ObjectID p_object);
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_object(ObjectID p_object, const String &p_subprop);
|
|
|
|
void add_object(ObjectID p_object, int p_relevel);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-09-01 03:49:47 +00:00
|
|
|
int get_history_len();
|
|
|
|
int get_history_pos();
|
|
|
|
ObjectID get_history_obj(int p_obj) const;
|
2018-06-19 01:10:48 +00:00
|
|
|
bool is_history_obj_inspector_only(int p_obj) const;
|
2015-09-01 03:49:47 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
bool next();
|
|
|
|
bool previous();
|
|
|
|
ObjectID get_current();
|
2018-06-19 01:10:48 +00:00
|
|
|
bool is_current_inspector_only() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int get_path_size() const;
|
|
|
|
ObjectID get_path_object(int p_index) const;
|
|
|
|
String get_path_property(int p_index) const;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
EditorHistory();
|
|
|
|
};
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
class EditorSelection;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class EditorData {
|
|
|
|
public:
|
|
|
|
struct CustomType {
|
|
|
|
String name;
|
|
|
|
Ref<Script> script;
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> icon;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-07-06 07:18:20 +00:00
|
|
|
struct EditedScene {
|
2020-11-24 09:12:55 +00:00
|
|
|
Node *root = nullptr;
|
2019-08-15 17:47:21 +00:00
|
|
|
String path;
|
2017-07-06 07:18:20 +00:00
|
|
|
Dictionary editor_states;
|
|
|
|
List<Node *> selection;
|
|
|
|
Vector<EditorHistory::History> history_stored;
|
2020-11-24 09:12:55 +00:00
|
|
|
int history_current = 0;
|
2017-07-06 07:18:20 +00:00
|
|
|
Dictionary custom_state;
|
2020-11-24 09:12:55 +00:00
|
|
|
uint64_t version = 0;
|
2017-07-06 07:18:20 +00:00
|
|
|
NodePath live_edit_root;
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
private:
|
|
|
|
Vector<EditorPlugin *> editor_plugins;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
struct PropertyData {
|
|
|
|
String name;
|
|
|
|
Variant value;
|
|
|
|
};
|
2020-03-17 06:33:00 +00:00
|
|
|
Map<String, Vector<CustomType>> custom_types;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<PropertyData> clipboard;
|
|
|
|
UndoRedo undo_redo;
|
|
|
|
|
|
|
|
void _cleanup_history();
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
Vector<EditedScene> edited_scene;
|
|
|
|
int current_edited_scene;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool _find_updated_instances(Node *p_root, Node *p_node, Set<String> &checked_paths);
|
2015-12-13 23:39:01 +00:00
|
|
|
|
2018-07-29 03:36:43 +00:00
|
|
|
HashMap<StringName, String> _script_class_icon_paths;
|
2018-09-02 21:40:51 +00:00
|
|
|
HashMap<String, StringName> _script_class_file_to_path;
|
2018-07-29 03:36:43 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorPlugin *get_editor(Object *p_object);
|
|
|
|
EditorPlugin *get_subeditor(Object *p_object);
|
|
|
|
Vector<EditorPlugin *> get_subeditors(Object *p_object);
|
|
|
|
EditorPlugin *get_editor(String p_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void copy_object_params(Object *p_object);
|
|
|
|
void paste_object_params(Object *p_object);
|
|
|
|
|
|
|
|
Dictionary get_editor_states() const;
|
2016-07-08 16:36:57 +00:00
|
|
|
Dictionary get_scene_editor_states(int p_idx) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_editor_states(const Dictionary &p_states);
|
2014-02-10 01:10:30 +00:00
|
|
|
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);
|
|
|
|
|
2016-02-28 02:10:44 +00:00
|
|
|
int get_editor_plugin_count() const;
|
|
|
|
EditorPlugin *get_editor_plugin(int p_idx);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
UndoRedo &get_undo_redo();
|
|
|
|
|
|
|
|
void save_editor_global_states();
|
|
|
|
void restore_editor_global_states();
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
void add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon);
|
2021-01-06 19:25:05 +00:00
|
|
|
Variant instance_custom_type(const String &p_type, const String &p_inherits);
|
2017-03-05 15:44:50 +00:00
|
|
|
void remove_custom_type(const String &p_type);
|
2020-03-17 06:33:00 +00:00
|
|
|
const Map<String, Vector<CustomType>> &get_custom_types() const { return custom_types; }
|
2015-06-22 03:03:19 +00:00
|
|
|
|
|
|
|
int add_edited_scene(int p_at_pos);
|
2017-03-05 15:44:50 +00:00
|
|
|
void move_edited_scene_index(int p_idx, int p_to_idx);
|
2015-06-22 03:03:19 +00:00
|
|
|
void remove_scene(int p_idx);
|
|
|
|
void set_edited_scene(int p_idx);
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_edited_scene_root(Node *p_root);
|
2015-06-22 03:03:19 +00:00
|
|
|
int get_edited_scene() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *get_edited_scene_root(int p_idx = -1);
|
2015-06-22 03:03:19 +00:00
|
|
|
int get_edited_scene_count() const;
|
2017-07-06 07:18:20 +00:00
|
|
|
Vector<EditedScene> get_edited_scenes() const;
|
2015-06-22 03:03:19 +00:00
|
|
|
String get_scene_title(int p_idx) const;
|
|
|
|
String get_scene_path(int p_idx) const;
|
2015-07-24 17:18:02 +00:00
|
|
|
String get_scene_type(int p_idx) const;
|
2017-12-26 19:32:12 +00:00
|
|
|
void set_scene_path(int p_idx, const String &p_path);
|
2015-07-26 13:44:10 +00:00
|
|
|
Ref<Script> get_scene_root_script(int p_idx) const;
|
2016-06-26 03:54:17 +00:00
|
|
|
void set_edited_scene_version(uint64_t version, int p_scene_idx = -1);
|
2015-06-22 03:03:19 +00:00
|
|
|
uint64_t get_scene_version(int p_idx) const;
|
|
|
|
void clear_edited_scenes();
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_edited_scene_live_edit_root(const NodePath &p_root);
|
2015-08-02 15:29:37 +00:00
|
|
|
NodePath get_edited_scene_live_edit_root();
|
2015-12-13 23:39:01 +00:00
|
|
|
bool check_and_update_scene(int p_idx);
|
2016-01-23 21:28:30 +00:00
|
|
|
void move_edited_scene_to_index(int p_idx);
|
2018-01-08 15:55:22 +00:00
|
|
|
bool call_build();
|
2015-06-22 03:03:19 +00:00
|
|
|
|
|
|
|
void set_plugin_window_layout(Ref<ConfigFile> p_layout);
|
|
|
|
void get_plugin_window_layout(Ref<ConfigFile> p_layout);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void save_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history, const Dictionary &p_custom);
|
2015-06-22 03:03:19 +00:00
|
|
|
Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history);
|
2015-12-09 12:08:41 +00:00
|
|
|
void notify_edited_scene_changed();
|
2018-01-12 21:43:29 +00:00
|
|
|
void notify_resource_saved(const Ref<Resource> &p_resource);
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2018-07-25 19:43:17 +00:00
|
|
|
bool script_class_is_parent(const String &p_class, const String &p_inherits);
|
2018-09-02 21:40:51 +00:00
|
|
|
StringName script_class_get_base(const String &p_class) const;
|
2021-01-06 19:25:05 +00:00
|
|
|
Variant script_class_instance(const String &p_class);
|
2018-09-02 21:40:51 +00:00
|
|
|
|
2019-11-06 12:10:25 +00:00
|
|
|
Ref<Script> script_class_load_script(const String &p_class) const;
|
|
|
|
|
2018-09-02 21:40:51 +00:00
|
|
|
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) const;
|
|
|
|
void script_class_set_icon_path(const String &p_class, const String &p_icon_path);
|
2018-07-29 03:36:43 +00:00
|
|
|
void script_class_clear_icon_paths() { _script_class_icon_paths.clear(); }
|
|
|
|
void script_class_save_icon_paths();
|
|
|
|
void script_class_load_icon_paths();
|
2018-07-25 19:43:17 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorData();
|
|
|
|
};
|
|
|
|
|
|
|
|
class EditorSelection : public Object {
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(EditorSelection, Object);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-18 13:12:57 +00:00
|
|
|
private:
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<Node *, Object *> selection;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-18 13:12:57 +00:00
|
|
|
bool emitted;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool changed;
|
|
|
|
bool nl_changed;
|
|
|
|
|
|
|
|
void _node_removed(Node *p_node);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
List<Object *> editor_plugins;
|
|
|
|
List<Node *> selected_node_list;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _update_nl();
|
2016-09-10 20:50:20 +00:00
|
|
|
Array _get_transformable_selected_nodes();
|
2017-12-18 13:12:57 +00:00
|
|
|
void _emit_change();
|
2016-09-10 20:50:20 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2020-04-21 15:16:45 +00:00
|
|
|
TypedArray<Node> get_selected_nodes();
|
2014-02-10 01:10:30 +00:00
|
|
|
void add_node(Node *p_node);
|
|
|
|
void remove_node(Node *p_node);
|
|
|
|
bool is_selected(Node *) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
template <class T>
|
|
|
|
T *get_node_editor_data(Node *p_node) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!selection.has(p_node)) {
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-08-24 20:58:51 +00:00
|
|
|
return Object::cast_to<T>(selection[p_node]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void add_editor_plugin(Object *p_object);
|
|
|
|
|
|
|
|
void update();
|
|
|
|
void clear();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
List<Node *> &get_selected_node_list();
|
2019-11-04 15:45:16 +00:00
|
|
|
List<Node *> get_full_selected_node_list();
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<Node *, Object *> &get_selection() { return selection; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
EditorSelection();
|
|
|
|
~EditorSelection();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EDITOR_DATA_H
|