2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_data.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* 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
|
|
|
#include "editor_data.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/config/project_settings.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/io/resource_loader.h"
|
|
|
|
#include "core/os/dir_access.h"
|
|
|
|
#include "core/os/file_access.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "editor_node.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "editor_settings.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/resources/packed_scene.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-01-08 05:50:51 +00:00
|
|
|
void EditorHistory::cleanup_history() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < history.size(); i++) {
|
|
|
|
bool fail = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < history[i].path.size(); j++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!history[i].path[j].ref.is_null()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-01-08 05:50:51 +00:00
|
|
|
Object *obj = ObjectDB::get_instance(history[i].path[j].object);
|
|
|
|
if (obj) {
|
|
|
|
Node *n = Object::cast_to<Node>(obj);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (n && n->is_inside_tree()) {
|
2018-01-08 05:50:51 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
if (!n) { // Possibly still alive
|
2018-01-08 05:50:51 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-01-08 05:50:51 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (j <= history[i].level) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//before or equal level, complete fail
|
2017-03-05 15:44:50 +00:00
|
|
|
fail = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
//after level, clip
|
2018-07-25 01:11:03 +00:00
|
|
|
history.write[i].path.resize(j);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fail) {
|
|
|
|
history.remove(i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current >= history.size()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
current = history.size() - 1;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Object *obj = ObjectDB::get_instance(p_object);
|
|
|
|
ERR_FAIL_COND(!obj);
|
2017-08-24 20:58:51 +00:00
|
|
|
Reference *r = Object::cast_to<Reference>(obj);
|
2014-02-10 01:10:30 +00:00
|
|
|
Obj o;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r) {
|
2017-03-05 15:44:50 +00:00
|
|
|
o.ref = REF(r);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
o.object = p_object;
|
|
|
|
o.property = p_property;
|
2018-06-19 01:10:48 +00:00
|
|
|
o.inspector_only = p_inspector_only;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
History h;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool has_prev = current >= 0 && current < history.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (has_prev) {
|
2017-03-05 15:44:50 +00:00
|
|
|
history.resize(current + 1); //clip history to next
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_property != "" && has_prev) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//add a sub property
|
2018-07-25 01:11:03 +00:00
|
|
|
History &pr = history.write[current];
|
2017-03-05 15:44:50 +00:00
|
|
|
h = pr;
|
|
|
|
h.path.resize(h.level + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
h.path.push_back(o);
|
|
|
|
h.level++;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_level_change != -1 && has_prev) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//add a sub property
|
2018-07-25 01:11:03 +00:00
|
|
|
History &pr = history.write[current];
|
2017-03-05 15:44:50 +00:00
|
|
|
h = pr;
|
|
|
|
ERR_FAIL_INDEX(p_level_change, h.path.size());
|
|
|
|
h.level = p_level_change;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
//add a new node
|
|
|
|
h.path.push_back(o);
|
2017-03-05 15:44:50 +00:00
|
|
|
h.level = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
history.push_back(h);
|
|
|
|
current++;
|
|
|
|
}
|
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
void EditorHistory::add_object_inspector_only(ObjectID p_object) {
|
|
|
|
_add_object(p_object, "", -1, true);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void EditorHistory::add_object(ObjectID p_object) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_add_object(p_object, "", -1);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorHistory::add_object(ObjectID p_object, const String &p_subprop) {
|
|
|
|
_add_object(p_object, p_subprop, -1);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorHistory::add_object(ObjectID p_object, int p_relevel) {
|
|
|
|
_add_object(p_object, "", p_relevel);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-01 03:49:47 +00:00
|
|
|
int EditorHistory::get_history_len() {
|
|
|
|
return history.size();
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2015-09-01 03:49:47 +00:00
|
|
|
int EditorHistory::get_history_pos() {
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
bool EditorHistory::is_history_obj_inspector_only(int p_obj) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_obj, history.size(), false);
|
|
|
|
ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), false);
|
|
|
|
return history[p_obj].path[history[p_obj].level].inspector_only;
|
|
|
|
}
|
|
|
|
|
2015-09-01 03:49:47 +00:00
|
|
|
ObjectID EditorHistory::get_history_obj(int p_obj) const {
|
2020-02-12 17:24:06 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_obj, history.size(), ObjectID());
|
|
|
|
ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), ObjectID());
|
2015-09-01 03:49:47 +00:00
|
|
|
return history[p_obj].path[history[p_obj].level].object;
|
|
|
|
}
|
|
|
|
|
2017-09-01 15:54:57 +00:00
|
|
|
bool EditorHistory::is_at_beginning() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
return current <= 0;
|
2015-09-01 03:49:47 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2015-09-01 03:49:47 +00:00
|
|
|
bool EditorHistory::is_at_end() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
return ((current + 1) >= history.size());
|
2015-09-01 03:49:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
bool EditorHistory::next() {
|
2018-01-08 05:50:51 +00:00
|
|
|
cleanup_history();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if ((current + 1) < history.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
current++;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorHistory::previous() {
|
2018-01-08 05:50:51 +00:00
|
|
|
cleanup_history();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current > 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
current--;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-19 01:10:48 +00:00
|
|
|
bool EditorHistory::is_current_inspector_only() const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current < 0 || current >= history.size()) {
|
2018-06-19 01:10:48 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-06-19 01:10:48 +00:00
|
|
|
|
|
|
|
const History &h = history[current];
|
|
|
|
return h.path[h.level].inspector_only;
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
ObjectID EditorHistory::get_current() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current < 0 || current >= history.size()) {
|
2020-02-12 17:24:06 +00:00
|
|
|
return ObjectID();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
History &h = history.write[current];
|
2014-02-10 01:10:30 +00:00
|
|
|
Object *obj = ObjectDB::get_instance(h.path[h.level].object);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!obj) {
|
2020-02-12 17:24:06 +00:00
|
|
|
return ObjectID();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-07 10:17:31 +00:00
|
|
|
return obj->get_instance_id();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int EditorHistory::get_path_size() const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current < 0 || current >= history.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return 0;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const History &h = history[current];
|
2014-02-10 01:10:30 +00:00
|
|
|
return h.path.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectID EditorHistory::get_path_object(int p_index) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current < 0 || current >= history.size()) {
|
2020-02-12 17:24:06 +00:00
|
|
|
return ObjectID();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const History &h = history[current];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-12 17:24:06 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_index, h.path.size(), ObjectID());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Object *obj = ObjectDB::get_instance(h.path[p_index].object);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!obj) {
|
2020-02-12 17:24:06 +00:00
|
|
|
return ObjectID();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-07 10:17:31 +00:00
|
|
|
return obj->get_instance_id();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String EditorHistory::get_path_property(int p_index) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current < 0 || current >= history.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return "";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const History &h = history[current];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_index, h.path.size(), "");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return h.path[p_index].property;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorHistory::clear() {
|
|
|
|
history.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
current = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorHistory::EditorHistory() {
|
2017-03-05 15:44:50 +00:00
|
|
|
current = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorPlugin *EditorData::get_editor(Object *p_object) {
|
2020-03-13 08:33:35 +00:00
|
|
|
// We need to iterate backwards so that we can check user-created plugins first.
|
|
|
|
// Otherwise, it would not be possible for plugins to handle CanvasItem and Spatial nodes.
|
|
|
|
for (int i = editor_plugins.size() - 1; i > -1; i--) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return editor_plugins[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorPlugin *EditorData::get_subeditor(Object *p_object) {
|
2020-03-13 08:33:35 +00:00
|
|
|
for (int i = editor_plugins.size() - 1; i > -1; i--) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return editor_plugins[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector<EditorPlugin *> EditorData::get_subeditors(Object *p_object) {
|
|
|
|
Vector<EditorPlugin *> sub_plugins;
|
2020-03-13 08:33:35 +00:00
|
|
|
for (int i = editor_plugins.size() - 1; i > -1; i--) {
|
2016-03-29 23:02:53 +00:00
|
|
|
if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
|
|
|
|
sub_plugins.push_back(editor_plugins[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sub_plugins;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorPlugin *EditorData::get_editor(String p_name) {
|
2020-03-13 08:33:35 +00:00
|
|
|
for (int i = editor_plugins.size() - 1; i > -1; i--) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (editor_plugins[i]->get_name() == p_name) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return editor_plugins[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::copy_object_params(Object *p_object) {
|
|
|
|
clipboard.clear();
|
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
p_object->get_property_list(&pinfo);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!(E->get().usage & PROPERTY_USAGE_EDITOR) || E->get().name == "script" || E->get().name == "scripts") {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
PropertyData pd;
|
2017-03-05 15:44:50 +00:00
|
|
|
pd.name = E->get().name;
|
|
|
|
pd.value = p_object->get(pd.name);
|
2014-02-10 01:10:30 +00:00
|
|
|
clipboard.push_back(pd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::get_editor_breakpoints(List<String> *p_breakpoints) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins[i]->get_breakpoints(p_breakpoints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary EditorData::get_editor_states() const {
|
|
|
|
Dictionary metadata;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
|
|
|
Dictionary state = editor_plugins[i]->get_state();
|
2020-12-15 12:04:21 +00:00
|
|
|
if (state.is_empty()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
metadata[editor_plugins[i]->get_name()] = state;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary EditorData::get_scene_editor_states(int p_idx) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), Dictionary());
|
2016-07-08 16:36:57 +00:00
|
|
|
EditedScene es = edited_scene[p_idx];
|
|
|
|
return es.editor_states;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::set_editor_states(const Dictionary &p_states) {
|
2014-02-10 01:10:30 +00:00
|
|
|
List<Variant> keys;
|
|
|
|
p_states.get_key_list(&keys);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
List<Variant>::Element *E = keys.front();
|
|
|
|
for (; E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
String name = E->get();
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = -1;
|
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
|
|
|
if (editor_plugins[i]->get_name() == name) {
|
|
|
|
idx = i;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx == -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins[idx]->set_state(p_states[name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-09 12:08:41 +00:00
|
|
|
void EditorData::notify_edited_scene_changed() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2015-12-09 12:08:41 +00:00
|
|
|
editor_plugins[i]->edited_scene_changed();
|
2017-07-06 07:18:20 +00:00
|
|
|
editor_plugins[i]->notify_scene_changed(get_edited_scene_root());
|
2015-12-09 12:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 21:43:29 +00:00
|
|
|
void EditorData::notify_resource_saved(const Ref<Resource> &p_resource) {
|
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
|
|
|
editor_plugins[i]->notify_resource_saved(p_resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void EditorData::clear_editor_states() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins[i]->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::save_editor_external_data() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins[i]->save_external_data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::apply_changes_in_editors() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins[i]->apply_changes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::save_editor_global_states() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins[i]->save_global_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::restore_editor_global_states() {
|
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins[i]->restore_global_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::paste_object_params(Object *p_object) {
|
2020-02-29 03:25:28 +00:00
|
|
|
ERR_FAIL_NULL(p_object);
|
|
|
|
undo_redo.create_action(TTR("Paste Params"));
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<PropertyData>::Element *E = clipboard.front(); E; E = E->next()) {
|
2020-02-29 03:25:28 +00:00
|
|
|
String name = E->get().name;
|
|
|
|
undo_redo.add_do_property(p_object, name, E->get().value);
|
|
|
|
undo_redo.add_undo_property(p_object, name, p_object->get(name));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-02-29 03:25:28 +00:00
|
|
|
undo_redo.commit_action();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 15:55:22 +00:00
|
|
|
bool EditorData::call_build() {
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
for (int i = 0; i < editor_plugins.size() && result; i++) {
|
|
|
|
result &= editor_plugins[i]->build();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
UndoRedo &EditorData::get_undo_redo() {
|
|
|
|
return undo_redo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::remove_editor_plugin(EditorPlugin *p_plugin) {
|
2020-04-01 23:20:12 +00:00
|
|
|
p_plugin->undo_redo = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins.erase(p_plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::add_editor_plugin(EditorPlugin *p_plugin) {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_plugin->undo_redo = &undo_redo;
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_plugins.push_back(p_plugin);
|
|
|
|
}
|
|
|
|
|
2016-02-28 02:10:44 +00:00
|
|
|
int EditorData::get_editor_plugin_count() const {
|
|
|
|
return editor_plugins.size();
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2016-02-28 02:10:44 +00:00
|
|
|
EditorPlugin *EditorData::get_editor_plugin(int p_idx) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, editor_plugins.size(), nullptr);
|
2016-02-28 02:10:44 +00:00
|
|
|
return editor_plugins[p_idx];
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
void EditorData::add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon) {
|
2019-09-25 08:28:50 +00:00
|
|
|
ERR_FAIL_COND_MSG(p_script.is_null(), "It's not a reference to a valid Script object.");
|
2014-02-10 01:10:30 +00:00
|
|
|
CustomType ct;
|
2017-03-05 15:44:50 +00:00
|
|
|
ct.name = p_type;
|
|
|
|
ct.icon = p_icon;
|
|
|
|
ct.script = p_script;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!custom_types.has(p_inherits)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
custom_types[p_inherits] = Vector<CustomType>();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
custom_types[p_inherits].push_back(ct);
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:25:05 +00:00
|
|
|
Variant EditorData::instance_custom_type(const String &p_type, const String &p_inherits) {
|
2018-02-25 00:41:26 +00:00
|
|
|
if (get_custom_types().has(p_inherits)) {
|
|
|
|
for (int i = 0; i < get_custom_types()[p_inherits].size(); i++) {
|
|
|
|
if (get_custom_types()[p_inherits][i].name == p_type) {
|
|
|
|
Ref<Script> script = get_custom_types()[p_inherits][i].script;
|
|
|
|
|
2021-01-06 19:25:05 +00:00
|
|
|
Variant ob = ClassDB::instance(p_inherits);
|
|
|
|
ERR_FAIL_COND_V(!ob, Variant());
|
|
|
|
Node *n = Object::cast_to<Node>(ob);
|
|
|
|
if (n) {
|
|
|
|
n->set_name(p_type);
|
2018-02-25 00:41:26 +00:00
|
|
|
}
|
2021-01-06 19:25:05 +00:00
|
|
|
((Object *)ob)->set_script(script);
|
2018-02-25 00:41:26 +00:00
|
|
|
return ob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:25:05 +00:00
|
|
|
return Variant();
|
2018-02-25 00:41:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::remove_custom_type(const String &p_type) {
|
2020-03-17 06:33:00 +00:00
|
|
|
for (Map<String, Vector<CustomType>>::Element *E = custom_types.front(); E; E = E->next()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < E->get().size(); i++) {
|
|
|
|
if (E->get()[i].name == p_type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
E->get().remove(i);
|
2020-12-15 12:04:21 +00:00
|
|
|
if (E->get().is_empty()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
custom_types.erase(E->key());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
int EditorData::add_edited_scene(int p_at_pos) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_at_pos < 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_at_pos = edited_scene.size();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-06-22 03:03:19 +00:00
|
|
|
EditedScene es;
|
2020-04-01 23:20:12 +00:00
|
|
|
es.root = nullptr;
|
2019-08-15 17:47:21 +00:00
|
|
|
es.path = String();
|
2017-03-05 15:44:50 +00:00
|
|
|
es.history_current = -1;
|
|
|
|
es.version = 0;
|
|
|
|
es.live_edit_root = NodePath(String("/root"));
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_at_pos == edited_scene.size()) {
|
2015-06-22 03:03:19 +00:00
|
|
|
edited_scene.push_back(es);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
edited_scene.insert(p_at_pos, es);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current_edited_scene < 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
current_edited_scene = 0;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-06-22 03:03:19 +00:00
|
|
|
return p_at_pos;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::move_edited_scene_index(int p_idx, int p_to_idx) {
|
|
|
|
ERR_FAIL_INDEX(p_idx, edited_scene.size());
|
|
|
|
ERR_FAIL_INDEX(p_to_idx, edited_scene.size());
|
2018-07-25 01:11:03 +00:00
|
|
|
SWAP(edited_scene.write[p_idx], edited_scene.write[p_to_idx]);
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
2019-06-04 03:36:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::remove_scene(int p_idx) {
|
|
|
|
ERR_FAIL_INDEX(p_idx, edited_scene.size());
|
2017-07-06 07:18:20 +00:00
|
|
|
if (edited_scene[p_idx].root) {
|
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
|
|
|
editor_plugins[i]->notify_scene_closed(edited_scene[p_idx].root->get_filename());
|
|
|
|
}
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
memdelete(edited_scene[p_idx].root);
|
2017-07-06 07:18:20 +00:00
|
|
|
}
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (current_edited_scene > p_idx) {
|
2015-06-22 03:03:19 +00:00
|
|
|
current_edited_scene--;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (current_edited_scene == p_idx && current_edited_scene > 0) {
|
2015-06-22 03:03:19 +00:00
|
|
|
current_edited_scene--;
|
|
|
|
}
|
|
|
|
|
|
|
|
edited_scene.remove(p_idx);
|
|
|
|
}
|
2015-12-13 23:39:01 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorData::_find_updated_instances(Node *p_root, Node *p_node, Set<String> &checked_paths) {
|
2017-01-14 11:26:56 +00:00
|
|
|
/*
|
|
|
|
if (p_root!=p_node && p_node->get_owner()!=p_root && !p_root->is_editable_instance(p_node->get_owner()))
|
|
|
|
return false;
|
|
|
|
*/
|
2015-12-13 23:39:01 +00:00
|
|
|
|
|
|
|
Ref<SceneState> ss;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_node == p_root) {
|
|
|
|
ss = p_node->get_scene_inherited_state();
|
|
|
|
} else if (p_node->get_filename() != String()) {
|
|
|
|
ss = p_node->get_scene_instance_state();
|
2015-12-13 23:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ss.is_valid()) {
|
|
|
|
String path = ss->get_path();
|
|
|
|
|
|
|
|
if (!checked_paths.has(path)) {
|
|
|
|
uint64_t modified_time = FileAccess::get_modified_time(path);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (modified_time != ss->get_last_modified_time()) {
|
2015-12-13 23:39:01 +00:00
|
|
|
return true; //external scene changed
|
|
|
|
}
|
|
|
|
|
|
|
|
checked_paths.insert(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
|
|
|
bool found = _find_updated_instances(p_root, p_node->get_child(i), checked_paths);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (found) {
|
2015-12-13 23:39:01 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-12-13 23:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorData::check_and_update_scene(int p_idx) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), false);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!edited_scene[p_idx].root) {
|
2015-12-13 23:39:01 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-12-13 23:39:01 +00:00
|
|
|
|
|
|
|
Set<String> checked_scenes;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool must_reload = _find_updated_instances(edited_scene[p_idx].root, edited_scene[p_idx].root, checked_scenes);
|
2015-12-13 23:39:01 +00:00
|
|
|
|
|
|
|
if (must_reload) {
|
|
|
|
Ref<PackedScene> pscene;
|
|
|
|
pscene.instance();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorProgress ep("update_scene", TTR("Updating Scene"), 2);
|
2018-04-22 17:36:01 +00:00
|
|
|
ep.step(TTR("Storing local changes..."), 0);
|
2015-12-13 23:39:01 +00:00
|
|
|
//pack first, so it stores diffs to previous version of saved scene
|
|
|
|
Error err = pscene->pack(edited_scene[p_idx].root);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(err != OK, false);
|
2018-04-22 17:36:01 +00:00
|
|
|
ep.step(TTR("Updating scene..."), 1);
|
2017-01-10 04:04:31 +00:00
|
|
|
Node *new_scene = pscene->instance(PackedScene::GEN_EDIT_STATE_MAIN);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!new_scene, false);
|
2015-12-13 23:39:01 +00:00
|
|
|
|
|
|
|
//transfer selection
|
2017-03-05 15:44:50 +00:00
|
|
|
List<Node *> new_selection;
|
2018-07-25 01:11:03 +00:00
|
|
|
for (List<Node *>::Element *E = edited_scene.write[p_idx].selection.front(); E; E = E->next()) {
|
2015-12-13 23:39:01 +00:00
|
|
|
NodePath p = edited_scene[p_idx].root->get_path_to(E->get());
|
|
|
|
Node *new_node = new_scene->get_node(p);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (new_node) {
|
2015-12-13 23:39:01 +00:00
|
|
|
new_selection.push_back(new_node);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-12-13 23:39:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
new_scene->set_filename(edited_scene[p_idx].root->get_filename());
|
2015-12-13 23:39:01 +00:00
|
|
|
|
|
|
|
memdelete(edited_scene[p_idx].root);
|
2018-07-25 01:11:03 +00:00
|
|
|
edited_scene.write[p_idx].root = new_scene;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (new_scene->get_filename() != "") {
|
2019-08-15 17:47:21 +00:00
|
|
|
edited_scene.write[p_idx].path = new_scene->get_filename();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-07-25 01:11:03 +00:00
|
|
|
edited_scene.write[p_idx].selection = new_selection;
|
2015-12-13 23:39:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
int EditorData::get_edited_scene() const {
|
|
|
|
return current_edited_scene;
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::set_edited_scene(int p_idx) {
|
|
|
|
ERR_FAIL_INDEX(p_idx, edited_scene.size());
|
|
|
|
current_edited_scene = p_idx;
|
2015-06-22 03:03:19 +00:00
|
|
|
//swap
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *EditorData::get_edited_scene_root(int p_idx) {
|
2016-06-26 03:54:17 +00:00
|
|
|
if (p_idx < 0) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), nullptr);
|
2016-06-26 03:54:17 +00:00
|
|
|
return edited_scene[current_edited_scene].root;
|
|
|
|
} else {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), nullptr);
|
2016-06-26 03:54:17 +00:00
|
|
|
return edited_scene[p_idx].root;
|
|
|
|
}
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::set_edited_scene_root(Node *p_root) {
|
|
|
|
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
|
2018-07-25 01:11:03 +00:00
|
|
|
edited_scene.write[current_edited_scene].root = p_root;
|
2019-08-15 17:47:21 +00:00
|
|
|
if (p_root) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_root->get_filename() != "") {
|
2019-08-15 17:47:21 +00:00
|
|
|
edited_scene.write[current_edited_scene].path = p_root->get_filename();
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2019-08-15 17:47:21 +00:00
|
|
|
p_root->set_filename(edited_scene[current_edited_scene].path);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-15 17:47:21 +00:00
|
|
|
}
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int EditorData::get_edited_scene_count() const {
|
|
|
|
return edited_scene.size();
|
|
|
|
}
|
|
|
|
|
2017-07-06 07:18:20 +00:00
|
|
|
Vector<EditorData::EditedScene> EditorData::get_edited_scenes() const {
|
|
|
|
Vector<EditedScene> out_edited_scenes_list = Vector<EditedScene>();
|
|
|
|
|
|
|
|
for (int i = 0; i < edited_scene.size(); i++) {
|
|
|
|
out_edited_scenes_list.push_back(edited_scene[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out_edited_scenes_list;
|
|
|
|
}
|
|
|
|
|
2017-08-12 16:52:50 +00:00
|
|
|
void EditorData::set_edited_scene_version(uint64_t version, int p_scene_idx) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
|
2017-08-12 16:52:50 +00:00
|
|
|
if (p_scene_idx < 0) {
|
2018-07-25 01:11:03 +00:00
|
|
|
edited_scene.write[current_edited_scene].version = version;
|
2016-06-26 03:54:17 +00:00
|
|
|
} else {
|
2017-08-12 16:52:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_scene_idx, edited_scene.size());
|
2018-07-25 01:11:03 +00:00
|
|
|
edited_scene.write[p_scene_idx].version = version;
|
2016-06-26 03:54:17 +00:00
|
|
|
}
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint64_t EditorData::get_scene_version(int p_idx) const {
|
2019-12-10 04:13:02 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), 0);
|
2015-06-22 03:03:19 +00:00
|
|
|
return edited_scene[p_idx].version;
|
|
|
|
}
|
|
|
|
|
2015-07-24 17:18:02 +00:00
|
|
|
String EditorData::get_scene_type(int p_idx) const {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!edited_scene[p_idx].root) {
|
2015-07-24 17:18:02 +00:00
|
|
|
return "";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-01-03 02:03:46 +00:00
|
|
|
return edited_scene[p_idx].root->get_class();
|
2015-07-24 17:18:02 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2016-01-23 21:28:30 +00:00
|
|
|
void EditorData::move_edited_scene_to_index(int p_idx) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
|
|
|
|
ERR_FAIL_INDEX(p_idx, edited_scene.size());
|
2016-01-23 21:28:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
EditedScene es = edited_scene[current_edited_scene];
|
2016-01-23 21:28:30 +00:00
|
|
|
edited_scene.remove(current_edited_scene);
|
2017-03-05 15:44:50 +00:00
|
|
|
edited_scene.insert(p_idx, es);
|
|
|
|
current_edited_scene = p_idx;
|
2016-01-23 21:28:30 +00:00
|
|
|
}
|
2015-07-26 13:44:10 +00:00
|
|
|
|
|
|
|
Ref<Script> EditorData::get_scene_root_script(int p_idx) const {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), Ref<Script>());
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!edited_scene[p_idx].root) {
|
2015-07-26 13:44:10 +00:00
|
|
|
return Ref<Script>();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Script> s = edited_scene[p_idx].root->get_script();
|
2015-08-29 16:02:56 +00:00
|
|
|
if (!s.is_valid() && edited_scene[p_idx].root->get_child_count()) {
|
2015-07-26 13:44:10 +00:00
|
|
|
Node *n = edited_scene[p_idx].root->get_child(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
while (!s.is_valid() && n && n->get_filename() == String()) {
|
|
|
|
s = n->get_script();
|
|
|
|
n = n->get_parent();
|
2015-07-26 13:44:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
String EditorData::get_scene_title(int p_idx) const {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!edited_scene[p_idx].root) {
|
2017-12-02 09:58:58 +00:00
|
|
|
return TTR("[empty]");
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
if (edited_scene[p_idx].root->get_filename() == "") {
|
2017-12-02 09:58:58 +00:00
|
|
|
return TTR("[unsaved]");
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-06-15 15:30:03 +00:00
|
|
|
bool show_ext = EDITOR_DEF("interface/scene_tabs/show_extension", false);
|
|
|
|
String name = edited_scene[p_idx].root->get_filename().get_file();
|
|
|
|
if (!show_ext) {
|
|
|
|
name = name.get_basename();
|
|
|
|
}
|
|
|
|
return name;
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 19:32:12 +00:00
|
|
|
void EditorData::set_scene_path(int p_idx, const String &p_path) {
|
|
|
|
ERR_FAIL_INDEX(p_idx, edited_scene.size());
|
2019-08-15 17:47:21 +00:00
|
|
|
edited_scene.write[p_idx].path = p_path;
|
2017-12-26 19:32:12 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!edited_scene[p_idx].root) {
|
2017-12-26 19:32:12 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-12-26 19:32:12 +00:00
|
|
|
edited_scene[p_idx].root->set_filename(p_path);
|
|
|
|
}
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
String EditorData::get_scene_path(int p_idx) const {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2019-08-15 17:47:21 +00:00
|
|
|
if (edited_scene[p_idx].root) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (edited_scene[p_idx].root->get_filename() == "") {
|
2019-08-15 17:47:21 +00:00
|
|
|
edited_scene[p_idx].root->set_filename(edited_scene[p_idx].path);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2019-08-15 17:47:21 +00:00
|
|
|
return edited_scene[p_idx].root->get_filename();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-08-15 17:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return edited_scene[p_idx].path;
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::set_edited_scene_live_edit_root(const NodePath &p_root) {
|
|
|
|
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
edited_scene.write[current_edited_scene].live_edit_root = p_root;
|
2015-08-02 15:29:37 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2015-08-02 15:29:37 +00:00
|
|
|
NodePath EditorData::get_edited_scene_live_edit_root() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), String());
|
2015-08-02 15:29:37 +00:00
|
|
|
|
|
|
|
return edited_scene[current_edited_scene].live_edit_root;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void EditorData::save_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history, const Dictionary &p_custom) {
|
|
|
|
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
EditedScene &es = edited_scene.write[current_edited_scene];
|
2019-11-10 08:32:07 +00:00
|
|
|
es.selection = p_selection->get_full_selected_node_list();
|
2017-03-05 15:44:50 +00:00
|
|
|
es.history_current = p_history->current;
|
|
|
|
es.history_stored = p_history->history;
|
|
|
|
es.editor_states = get_editor_states();
|
|
|
|
es.custom_state = p_custom;
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary EditorData::restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), Dictionary());
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2018-07-25 01:11:03 +00:00
|
|
|
EditedScene &es = edited_scene.write[current_edited_scene];
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_history->current = es.history_current;
|
|
|
|
p_history->history = es.history_stored;
|
2015-06-22 03:03:19 +00:00
|
|
|
|
|
|
|
p_selection->clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Node *>::Element *E = es.selection.front(); E; E = E->next()) {
|
2015-06-22 03:03:19 +00:00
|
|
|
p_selection->add_node(E->get());
|
|
|
|
}
|
|
|
|
set_editor_states(es.editor_states);
|
|
|
|
|
|
|
|
return es.custom_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::clear_edited_scenes() {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < edited_scene.size(); i++) {
|
2015-06-22 03:03:19 +00:00
|
|
|
if (edited_scene[i].root) {
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(edited_scene[i].root);
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
edited_scene.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::set_plugin_window_layout(Ref<ConfigFile> p_layout) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2015-06-22 03:03:19 +00:00
|
|
|
editor_plugins[i]->set_window_layout(p_layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::get_plugin_window_layout(Ref<ConfigFile> p_layout) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < editor_plugins.size(); i++) {
|
2015-06-22 03:03:19 +00:00
|
|
|
editor_plugins[i]->get_window_layout(p_layout);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-07-25 19:43:17 +00:00
|
|
|
bool EditorData::script_class_is_parent(const String &p_class, const String &p_inherits) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!ScriptServer::is_global_class(p_class)) {
|
2018-07-25 19:43:17 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-07-25 19:43:17 +00:00
|
|
|
String base = script_class_get_base(p_class);
|
2019-11-06 12:10:25 +00:00
|
|
|
Ref<Script> script = script_class_load_script(p_class);
|
2018-10-16 18:42:06 +00:00
|
|
|
Ref<Script> base_script = script->get_base_script();
|
|
|
|
|
2018-07-25 19:43:17 +00:00
|
|
|
while (p_inherits != base) {
|
|
|
|
if (ClassDB::class_exists(base)) {
|
|
|
|
return ClassDB::is_parent_class(base, p_inherits);
|
|
|
|
} else if (ScriptServer::is_global_class(base)) {
|
|
|
|
base = script_class_get_base(base);
|
2018-10-16 18:42:06 +00:00
|
|
|
} else if (base_script.is_valid()) {
|
|
|
|
return ClassDB::is_parent_class(base_script->get_instance_base_type(), p_inherits);
|
2018-07-25 19:43:17 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-02 21:40:51 +00:00
|
|
|
StringName EditorData::script_class_get_base(const String &p_class) const {
|
2019-11-06 12:10:25 +00:00
|
|
|
Ref<Script> script = script_class_load_script(p_class);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (script.is_null()) {
|
2018-07-25 19:43:17 +00:00
|
|
|
return StringName();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-07-25 19:43:17 +00:00
|
|
|
|
|
|
|
Ref<Script> base_script = script->get_base_script();
|
|
|
|
if (base_script.is_null()) {
|
|
|
|
return ScriptServer::get_global_class_base(p_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
return script->get_language()->get_global_class_name(base_script->get_path());
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:25:05 +00:00
|
|
|
Variant EditorData::script_class_instance(const String &p_class) {
|
2018-07-29 03:36:43 +00:00
|
|
|
if (ScriptServer::is_global_class(p_class)) {
|
2021-01-06 19:25:05 +00:00
|
|
|
Variant obj = ClassDB::instance(ScriptServer::get_global_class_native_base(p_class));
|
2018-07-29 03:36:43 +00:00
|
|
|
if (obj) {
|
2019-11-06 12:10:25 +00:00
|
|
|
Ref<Script> script = script_class_load_script(p_class);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (script.is_valid()) {
|
2021-01-06 19:25:05 +00:00
|
|
|
((Object *)obj)->set_script(script);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-07-29 03:36:43 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
2021-01-06 19:25:05 +00:00
|
|
|
return Variant();
|
2018-07-29 03:36:43 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 12:10:25 +00:00
|
|
|
Ref<Script> EditorData::script_class_load_script(const String &p_class) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!ScriptServer::is_global_class(p_class)) {
|
2019-11-06 12:10:25 +00:00
|
|
|
return Ref<Script>();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-11-06 12:10:25 +00:00
|
|
|
|
|
|
|
String path = ScriptServer::get_global_class_path(p_class);
|
|
|
|
return ResourceLoader::load(path, "Script");
|
|
|
|
}
|
|
|
|
|
2018-09-02 21:40:51 +00:00
|
|
|
void EditorData::script_class_set_icon_path(const String &p_class, const String &p_icon_path) {
|
|
|
|
_script_class_icon_paths[p_class] = p_icon_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorData::script_class_get_icon_path(const String &p_class) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!ScriptServer::is_global_class(p_class)) {
|
2018-09-02 21:40:51 +00:00
|
|
|
return String();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-09-02 21:40:51 +00:00
|
|
|
|
|
|
|
String current = p_class;
|
|
|
|
String ret = _script_class_icon_paths[current];
|
2020-12-15 12:04:21 +00:00
|
|
|
while (ret.is_empty()) {
|
2018-09-02 21:40:51 +00:00
|
|
|
current = script_class_get_base(current);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!ScriptServer::is_global_class(current)) {
|
2018-09-02 21:40:51 +00:00
|
|
|
return String();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-09-02 21:40:51 +00:00
|
|
|
ret = _script_class_icon_paths.has(current) ? _script_class_icon_paths[current] : String();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName EditorData::script_class_get_name(const String &p_path) const {
|
|
|
|
return _script_class_file_to_path.has(p_path) ? _script_class_file_to_path[p_path] : StringName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::script_class_set_name(const String &p_path, const StringName &p_class) {
|
|
|
|
_script_class_file_to_path[p_path] = p_class;
|
|
|
|
}
|
|
|
|
|
2018-07-29 03:36:43 +00:00
|
|
|
void EditorData::script_class_save_icon_paths() {
|
|
|
|
List<StringName> keys;
|
|
|
|
_script_class_icon_paths.get_key_list(&keys);
|
|
|
|
|
|
|
|
Dictionary d;
|
|
|
|
for (List<StringName>::Element *E = keys.front(); E; E = E->next()) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (ScriptServer::is_global_class(E->get())) {
|
2018-09-02 21:40:51 +00:00
|
|
|
d[E->get()] = _script_class_icon_paths[E->get()];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-07-29 03:36:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 12:04:21 +00:00
|
|
|
if (d.is_empty()) {
|
2020-10-05 19:45:54 +00:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting("_global_script_class_icons")) {
|
|
|
|
ProjectSettings::get_singleton()->clear("_global_script_class_icons");
|
|
|
|
}
|
2020-10-03 08:36:07 +00:00
|
|
|
} else {
|
|
|
|
ProjectSettings::get_singleton()->set("_global_script_class_icons", d);
|
|
|
|
}
|
2018-07-29 03:36:43 +00:00
|
|
|
ProjectSettings::get_singleton()->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorData::script_class_load_icon_paths() {
|
|
|
|
script_class_clear_icon_paths();
|
|
|
|
|
2018-11-16 14:26:55 +00:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting("_global_script_class_icons")) {
|
|
|
|
Dictionary d = ProjectSettings::get_singleton()->get("_global_script_class_icons");
|
|
|
|
List<Variant> keys;
|
|
|
|
d.get_key_list(&keys);
|
2018-07-29 03:36:43 +00:00
|
|
|
|
2018-11-16 14:26:55 +00:00
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
|
|
|
String name = E->get().operator String();
|
|
|
|
_script_class_icon_paths[name] = d[name];
|
2018-09-02 21:40:51 +00:00
|
|
|
|
2018-11-16 14:26:55 +00:00
|
|
|
String path = ScriptServer::get_global_class_path(name);
|
|
|
|
script_class_set_name(path, name);
|
|
|
|
}
|
2018-07-29 03:36:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorData::EditorData() {
|
2017-03-05 15:44:50 +00:00
|
|
|
current_edited_scene = -1;
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//load_imported_scenes_from_globals();
|
2018-07-29 03:36:43 +00:00
|
|
|
script_class_load_icon_paths();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////
|
|
|
|
void EditorSelection::_node_removed(Node *p_node) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!selection.has(p_node)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Object *meta = selection[p_node];
|
2020-05-14 14:41:43 +00:00
|
|
|
if (meta) {
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(meta);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
selection.erase(p_node);
|
2017-03-05 15:44:50 +00:00
|
|
|
changed = true;
|
|
|
|
nl_changed = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSelection::add_node(Node *p_node) {
|
2016-02-27 03:32:00 +00:00
|
|
|
ERR_FAIL_NULL(p_node);
|
2016-08-23 17:19:48 +00:00
|
|
|
ERR_FAIL_COND(!p_node->is_inside_tree());
|
2020-05-14 14:41:43 +00:00
|
|
|
if (selection.has(p_node)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
changed = true;
|
|
|
|
nl_changed = true;
|
2020-04-01 23:20:12 +00:00
|
|
|
Object *meta = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Object *>::Element *E = editor_plugins.front(); E; E = E->next()) {
|
|
|
|
meta = E->get()->call("_get_editor_data", p_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (meta) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
selection[p_node] = meta;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-21 17:28:45 +00:00
|
|
|
p_node->connect("tree_exiting", callable_mp(this, &EditorSelection::_node_removed), varray(p_node), CONNECT_ONESHOT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//emit_signal("selection_changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSelection::remove_node(Node *p_node) {
|
2016-02-27 03:32:00 +00:00
|
|
|
ERR_FAIL_NULL(p_node);
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!selection.has(p_node)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
changed = true;
|
|
|
|
nl_changed = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
Object *meta = selection[p_node];
|
2020-05-14 14:41:43 +00:00
|
|
|
if (meta) {
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(meta);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
selection.erase(p_node);
|
2020-02-21 17:28:45 +00:00
|
|
|
p_node->disconnect("tree_exiting", callable_mp(this, &EditorSelection::_node_removed));
|
2014-02-10 01:10:30 +00:00
|
|
|
//emit_signal("selection_changed");
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool EditorSelection::is_selected(Node *p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return selection.has(p_node);
|
|
|
|
}
|
|
|
|
|
2016-09-10 20:50:20 +00:00
|
|
|
Array EditorSelection::_get_transformable_selected_nodes() {
|
2016-02-27 03:32:00 +00:00
|
|
|
Array ret;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Node *>::Element *E = selected_node_list.front(); E; E = E->next()) {
|
2016-02-27 03:32:00 +00:00
|
|
|
ret.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-04-21 15:16:45 +00:00
|
|
|
TypedArray<Node> EditorSelection::get_selected_nodes() {
|
|
|
|
TypedArray<Node> ret;
|
2016-09-10 20:50:20 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2016-09-10 20:50:20 +00:00
|
|
|
ret.push_back(E->key());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void EditorSelection::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear);
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node);
|
2018-01-21 06:12:25 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::get_selected_nodes);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::_get_transformable_selected_nodes);
|
2017-12-18 13:12:57 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_emit_change"), &EditorSelection::_emit_change);
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("selection_changed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSelection::add_editor_plugin(Object *p_object) {
|
|
|
|
editor_plugins.push_back(p_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSelection::_update_nl() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!nl_changed) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
selected_node_list.clear();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *parent = E->key();
|
2017-03-05 15:44:50 +00:00
|
|
|
parent = parent->get_parent();
|
|
|
|
bool skip = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
while (parent) {
|
|
|
|
if (selection.has(parent)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
skip = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
parent = parent->get_parent();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (skip) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
selected_node_list.push_back(E->key());
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
nl_changed = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSelection::update() {
|
|
|
|
_update_nl();
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!changed) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
changed = false;
|
2017-12-18 13:12:57 +00:00
|
|
|
if (!emitted) {
|
|
|
|
emitted = true;
|
|
|
|
call_deferred("_emit_change");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSelection::_emit_change() {
|
2017-10-23 19:21:15 +00:00
|
|
|
emit_signal("selection_changed");
|
2017-12-18 13:12:57 +00:00
|
|
|
emitted = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
List<Node *> &EditorSelection::get_selected_node_list() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (changed) {
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_nl();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
return selected_node_list;
|
|
|
|
}
|
|
|
|
|
2019-11-04 15:45:16 +00:00
|
|
|
List<Node *> EditorSelection::get_full_selected_node_list() {
|
|
|
|
List<Node *> node_list;
|
|
|
|
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
|
|
|
|
node_list.push_back(E->key());
|
|
|
|
}
|
|
|
|
|
|
|
|
return node_list;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void EditorSelection::clear() {
|
2020-12-15 12:04:21 +00:00
|
|
|
while (!selection.is_empty()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
remove_node(selection.front()->key());
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
changed = true;
|
|
|
|
nl_changed = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorSelection::EditorSelection() {
|
2017-12-18 13:12:57 +00:00
|
|
|
emitted = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
changed = false;
|
|
|
|
nl_changed = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorSelection::~EditorSelection() {
|
|
|
|
clear();
|
|
|
|
}
|