summaryrefslogtreecommitdiff
path: root/editor/editor_data.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_data.cpp')
-rw-r--r--editor/editor_data.cpp106
1 files changed, 85 insertions, 21 deletions
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 95ed40d889..729f6f50ef 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -62,7 +62,7 @@ void EditorHistory::cleanup_history() {
fail = true;
} else {
//after level, clip
- history[i].path.resize(j);
+ history.write[i].path.resize(j);
}
break;
@@ -78,7 +78,7 @@ void EditorHistory::cleanup_history() {
current = history.size() - 1;
}
-void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int p_level_change) {
+void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only) {
Object *obj = ObjectDB::get_instance(p_object);
ERR_FAIL_COND(!obj);
@@ -88,6 +88,7 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int
o.ref = REF(r);
o.object = p_object;
o.property = p_property;
+ o.inspector_only = p_inspector_only;
History h;
@@ -99,14 +100,14 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int
if (p_property != "" && has_prev) {
//add a sub property
- History &pr = history[current];
+ History &pr = history.write[current];
h = pr;
h.path.resize(h.level + 1);
h.path.push_back(o);
h.level++;
} else if (p_level_change != -1 && has_prev) {
//add a sub property
- History &pr = history[current];
+ History &pr = history.write[current];
h = pr;
ERR_FAIL_INDEX(p_level_change, h.path.size());
h.level = p_level_change;
@@ -120,6 +121,11 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int
current++;
}
+void EditorHistory::add_object_inspector_only(ObjectID p_object) {
+
+ _add_object(p_object, "", -1, true);
+}
+
void EditorHistory::add_object(ObjectID p_object) {
_add_object(p_object, "", -1);
@@ -142,6 +148,13 @@ int EditorHistory::get_history_pos() {
return current;
}
+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;
+}
+
ObjectID EditorHistory::get_history_obj(int p_obj) const {
ERR_FAIL_INDEX_V(p_obj, history.size(), 0);
ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), 0);
@@ -180,12 +193,20 @@ bool EditorHistory::previous() {
return true;
}
+bool EditorHistory::is_current_inspector_only() const {
+
+ if (current < 0 || current >= history.size())
+ return false;
+
+ const History &h = history[current];
+ return h.path[h.level].inspector_only;
+}
ObjectID EditorHistory::get_current() {
if (current < 0 || current >= history.size())
return 0;
- History &h = history[current];
+ History &h = history.write[current];
Object *obj = ObjectDB::get_instance(h.path[h.level].object);
if (!obj)
return 0;
@@ -364,6 +385,14 @@ void EditorData::notify_edited_scene_changed() {
}
}
+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);
+ }
+}
+
void EditorData::clear_editor_states() {
for (int i = 0; i < editor_plugins.size(); i++) {
@@ -412,6 +441,18 @@ void EditorData::paste_object_params(Object *p_object) {
}
}
+bool EditorData::call_build() {
+
+ bool result = true;
+
+ for (int i = 0; i < editor_plugins.size() && result; i++) {
+
+ result &= editor_plugins[i]->build();
+ }
+
+ return result;
+}
+
UndoRedo &EditorData::get_undo_redo() {
return undo_redo;
@@ -452,6 +493,31 @@ void EditorData::add_custom_type(const String &p_type, const String &p_inherits,
custom_types[p_inherits].push_back(ct);
}
+Object *EditorData::instance_custom_type(const String &p_type, const String &p_inherits) {
+
+ 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<Texture> icon = get_custom_types()[p_inherits][i].icon;
+ Ref<Script> script = get_custom_types()[p_inherits][i].script;
+
+ Object *ob = ClassDB::instance(p_inherits);
+ ERR_FAIL_COND_V(!ob, NULL);
+ if (ob->is_class("Node")) {
+ ob->call("set_name", p_type);
+ }
+ ob->set_script(script.get_ref_ptr());
+ if (icon.is_valid())
+ ob->set_meta("_editor_icon", icon);
+ return ob;
+ }
+ }
+ }
+
+ return NULL;
+}
+
void EditorData::remove_custom_type(const String &p_type) {
for (Map<String, Vector<CustomType> >::Element *E = custom_types.front(); E; E = E->next()) {
@@ -492,7 +558,7 @@ 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());
- SWAP(edited_scene[p_idx], edited_scene[p_to_idx]);
+ SWAP(edited_scene.write[p_idx], edited_scene.write[p_to_idx]);
}
void EditorData::remove_scene(int p_idx) {
ERR_FAIL_INDEX(p_idx, edited_scene.size());
@@ -563,24 +629,22 @@ bool EditorData::check_and_update_scene(int p_idx) {
bool must_reload = _find_updated_instances(edited_scene[p_idx].root, edited_scene[p_idx].root, checked_scenes);
- print_line("MUST RELOAD? " + itos(must_reload));
-
if (must_reload) {
Ref<PackedScene> pscene;
pscene.instance();
EditorProgress ep("update_scene", TTR("Updating Scene"), 2);
- ep.step(TTR("Storing local changes.."), 0);
+ ep.step(TTR("Storing local changes..."), 0);
//pack first, so it stores diffs to previous version of saved scene
Error err = pscene->pack(edited_scene[p_idx].root);
ERR_FAIL_COND_V(err != OK, false);
- ep.step(TTR("Updating scene.."), 1);
+ ep.step(TTR("Updating scene..."), 1);
Node *new_scene = pscene->instance(PackedScene::GEN_EDIT_STATE_MAIN);
ERR_FAIL_COND_V(!new_scene, false);
//transfer selection
List<Node *> new_selection;
- for (List<Node *>::Element *E = edited_scene[p_idx].selection.front(); E; E = E->next()) {
+ for (List<Node *>::Element *E = edited_scene.write[p_idx].selection.front(); E; E = E->next()) {
NodePath p = edited_scene[p_idx].root->get_path_to(E->get());
Node *new_node = new_scene->get_node(p);
if (new_node)
@@ -590,8 +654,8 @@ bool EditorData::check_and_update_scene(int p_idx) {
new_scene->set_filename(edited_scene[p_idx].root->get_filename());
memdelete(edited_scene[p_idx].root);
- edited_scene[p_idx].root = new_scene;
- edited_scene[p_idx].selection = new_selection;
+ edited_scene.write[p_idx].root = new_scene;
+ edited_scene.write[p_idx].selection = new_selection;
return true;
}
@@ -621,7 +685,7 @@ Node *EditorData::get_edited_scene_root(int p_idx) {
void EditorData::set_edited_scene_root(Node *p_root) {
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
- edited_scene[current_edited_scene].root = p_root;
+ edited_scene.write[current_edited_scene].root = p_root;
}
int EditorData::get_edited_scene_count() const {
@@ -643,10 +707,10 @@ Vector<EditorData::EditedScene> EditorData::get_edited_scenes() const {
void EditorData::set_edited_scene_version(uint64_t version, int p_scene_idx) {
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
if (p_scene_idx < 0) {
- edited_scene[current_edited_scene].version = version;
+ edited_scene.write[current_edited_scene].version = version;
} else {
ERR_FAIL_INDEX(p_scene_idx, edited_scene.size());
- edited_scene[p_scene_idx].version = version;
+ edited_scene.write[p_scene_idx].version = version;
}
}
@@ -729,7 +793,7 @@ String EditorData::get_scene_path(int p_idx) const {
void EditorData::set_edited_scene_live_edit_root(const NodePath &p_root) {
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
- edited_scene[current_edited_scene].live_edit_root = p_root;
+ edited_scene.write[current_edited_scene].live_edit_root = p_root;
}
NodePath EditorData::get_edited_scene_live_edit_root() {
@@ -742,7 +806,7 @@ void EditorData::save_edited_scene_state(EditorSelection *p_selection, EditorHis
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
- EditedScene &es = edited_scene[current_edited_scene];
+ EditedScene &es = edited_scene.write[current_edited_scene];
es.selection = p_selection->get_selected_node_list();
es.history_current = p_history->current;
es.history_stored = p_history->history;
@@ -753,7 +817,7 @@ void EditorData::save_edited_scene_state(EditorSelection *p_selection, EditorHis
Dictionary EditorData::restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history) {
ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), Dictionary());
- EditedScene &es = edited_scene[current_edited_scene];
+ EditedScene &es = edited_scene.write[current_edited_scene];
p_history->current = es.history_current;
p_history->history = es.history_stored;
@@ -867,7 +931,7 @@ Array EditorSelection::_get_transformable_selected_nodes() {
return ret;
}
-Array EditorSelection::_get_selected_nodes() {
+Array EditorSelection::get_selected_nodes() {
Array ret;
@@ -885,7 +949,7 @@ void EditorSelection::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear);
ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node);
ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node);
- ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::_get_selected_nodes);
+ ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::get_selected_nodes);
ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::_get_transformable_selected_nodes);
ClassDB::bind_method(D_METHOD("_emit_change"), &EditorSelection::_emit_change);
ADD_SIGNAL(MethodInfo("selection_changed"));