diff options
Diffstat (limited to 'editor/editor_data.cpp')
-rw-r--r-- | editor/editor_data.cpp | 499 |
1 files changed, 222 insertions, 277 deletions
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index d2fa40e08c..d92a348df9 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -28,30 +28,30 @@ /*************************************************************************/ #include "editor_data.h" -#include "global_config.h" +#include "editor_node.h" #include "editor_settings.h" -#include "os/dir_access.h" +#include "global_config.h" #include "io/resource_loader.h" -#include "scene/resources/packed_scene.h" +#include "os/dir_access.h" #include "os/file_access.h" -#include "editor_node.h" +#include "scene/resources/packed_scene.h" void EditorHistory::_cleanup_history() { - for(int i=0;i<history.size();i++) { + for (int i = 0; i < history.size(); i++) { - bool fail=false; + bool fail = false; - for(int j=0;j<history[i].path.size();j++) { + for (int j = 0; j < history[i].path.size(); j++) { if (!history[i].path[j].ref.is_null()) continue; if (ObjectDB::get_instance(history[i].path[j].object)) continue; //has isntance, try next - if (j<=history[i].level) { + if (j <= history[i].level) { //before or equal level, complete fail - fail=true; + fail = true; } else { //after level, clip history[i].path.resize(j); @@ -66,46 +66,46 @@ void EditorHistory::_cleanup_history() { } } - if (current>=history.size()) - current=history.size()-1; + if (current >= history.size()) + 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) { Object *obj = ObjectDB::get_instance(p_object); ERR_FAIL_COND(!obj); Reference *r = obj->cast_to<Reference>(); Obj o; if (r) - o.ref=REF(r); - o.object=p_object; - o.property=p_property; + o.ref = REF(r); + o.object = p_object; + o.property = p_property; History h; - bool has_prev = current>=0 && current<history.size(); + bool has_prev = current >= 0 && current < history.size(); if (has_prev) { - history.resize(current+1); //clip history to next + history.resize(current + 1); //clip history to next } - if (p_property!="" && has_prev) { + if (p_property != "" && has_prev) { //add a sub property History &pr = history[current]; - h=pr; - h.path.resize(h.level+1); + h = pr; + h.path.resize(h.level + 1); h.path.push_back(o); h.level++; - } else if (p_level_change!=-1 && has_prev) { + } else if (p_level_change != -1 && has_prev) { //add a sub property History &pr = history[current]; - h=pr; - ERR_FAIL_INDEX(p_level_change,h.path.size()); - h.level=p_level_change; + h = pr; + ERR_FAIL_INDEX(p_level_change, h.path.size()); + h.level = p_level_change; } else { //add a new node h.path.push_back(o); - h.level=0; + h.level = 0; } history.push_back(h); @@ -114,17 +114,17 @@ void EditorHistory::_add_object(ObjectID p_object,const String& p_property,int p void EditorHistory::add_object(ObjectID p_object) { - _add_object(p_object,"",-1); + _add_object(p_object, "", -1); } -void EditorHistory::add_object(ObjectID p_object,const String& p_subprop) { +void EditorHistory::add_object(ObjectID p_object, const String &p_subprop) { - _add_object(p_object,p_subprop,-1); + _add_object(p_object, p_subprop, -1); } -void EditorHistory::add_object(ObjectID p_object,int p_relevel){ +void EditorHistory::add_object(ObjectID p_object, int p_relevel) { - _add_object(p_object,"",p_relevel); + _add_object(p_object, "", p_relevel); } int EditorHistory::get_history_len() { @@ -135,26 +135,24 @@ int EditorHistory::get_history_pos() { } 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); + ERR_FAIL_INDEX_V(p_obj, history.size(), 0); + ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), 0); return history[p_obj].path[history[p_obj].level].object; } bool EditorHistory::is_at_begining() const { - return current<=0; + return current <= 0; } bool EditorHistory::is_at_end() const { - return ((current+1)>=history.size()); + return ((current + 1) >= history.size()); } - bool EditorHistory::next() { - _cleanup_history(); - if ((current+1)<history.size()) + if ((current + 1) < history.size()) current++; else return false; @@ -164,10 +162,9 @@ bool EditorHistory::next() { bool EditorHistory::previous() { - _cleanup_history(); - if (current>0) + if (current > 0) current--; else return false; @@ -177,11 +174,10 @@ bool EditorHistory::previous() { ObjectID EditorHistory::get_current() { - - if (current<0 || current >=history.size()) + if (current < 0 || current >= history.size()) return 0; - History &h=history[current]; + History &h = history[current]; Object *obj = ObjectDB::get_instance(h.path[h.level].object); if (!obj) return 0; @@ -191,22 +187,21 @@ ObjectID EditorHistory::get_current() { int EditorHistory::get_path_size() const { - if (current<0 || current >=history.size()) + if (current < 0 || current >= history.size()) return 0; - const History &h=history[current]; + const History &h = history[current]; return h.path.size(); - } ObjectID EditorHistory::get_path_object(int p_index) const { - if (current<0 || current >=history.size()) + if (current < 0 || current >= history.size()) return 0; - const History &h=history[current]; + const History &h = history[current]; - ERR_FAIL_INDEX_V(p_index,h.path.size(),0); + ERR_FAIL_INDEX_V(p_index, h.path.size(), 0); Object *obj = ObjectDB::get_instance(h.path[p_index].object); if (!obj) @@ -217,31 +212,30 @@ ObjectID EditorHistory::get_path_object(int p_index) const { String EditorHistory::get_path_property(int p_index) const { - if (current<0 || current >=history.size()) + if (current < 0 || current >= history.size()) return ""; - const History &h=history[current]; + const History &h = history[current]; - ERR_FAIL_INDEX_V(p_index,h.path.size(),""); + ERR_FAIL_INDEX_V(p_index, h.path.size(), ""); return h.path[p_index].property; - } void EditorHistory::clear() { history.clear(); - current=-1; + current = -1; } EditorHistory::EditorHistory() { - current=-1; + current = -1; } -EditorPlugin* EditorData::get_editor(Object *p_object) { +EditorPlugin *EditorData::get_editor(Object *p_object) { - for (int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { if (editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) return editor_plugins[i]; @@ -250,9 +244,9 @@ EditorPlugin* EditorData::get_editor(Object *p_object) { return NULL; } -EditorPlugin* EditorData::get_subeditor(Object *p_object) { +EditorPlugin *EditorData::get_subeditor(Object *p_object) { - for (int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) return editor_plugins[i]; @@ -261,8 +255,8 @@ EditorPlugin* EditorData::get_subeditor(Object *p_object) { return NULL; } -Vector<EditorPlugin*> EditorData::get_subeditors(Object* p_object) { - Vector<EditorPlugin*> sub_plugins; +Vector<EditorPlugin *> EditorData::get_subeditors(Object *p_object) { + Vector<EditorPlugin *> sub_plugins; for (int i = 0; i < editor_plugins.size(); i++) { if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) { sub_plugins.push_back(editor_plugins[i]); @@ -271,11 +265,11 @@ Vector<EditorPlugin*> EditorData::get_subeditors(Object* p_object) { return sub_plugins; } -EditorPlugin* EditorData::get_editor(String p_name) { +EditorPlugin *EditorData::get_editor(String p_name) { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { - if (editor_plugins[i]->get_name()==p_name) + if (editor_plugins[i]->get_name() == p_name) return editor_plugins[i]; } @@ -289,79 +283,73 @@ void EditorData::copy_object_params(Object *p_object) { List<PropertyInfo> pinfo; p_object->get_property_list(&pinfo); - for( List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage&PROPERTY_USAGE_EDITOR)) + if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) continue; PropertyData pd; - pd.name=E->get().name; - pd.value=p_object->get(pd.name); + pd.name = E->get().name; + pd.value = p_object->get(pd.name); clipboard.push_back(pd); } } void EditorData::get_editor_breakpoints(List<String> *p_breakpoints) { - - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->get_breakpoints(p_breakpoints); } - - } Dictionary EditorData::get_editor_states() const { Dictionary metadata; - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { - Dictionary state=editor_plugins[i]->get_state(); + Dictionary state = editor_plugins[i]->get_state(); if (state.empty()) continue; - metadata[editor_plugins[i]->get_name()]=state; + metadata[editor_plugins[i]->get_name()] = state; } return metadata; - } -Dictionary EditorData::get_scene_editor_states(int p_idx) const -{ - ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),Dictionary()); +Dictionary EditorData::get_scene_editor_states(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), Dictionary()); EditedScene es = edited_scene[p_idx]; return es.editor_states; } -void EditorData::set_editor_states(const Dictionary& p_states) { +void EditorData::set_editor_states(const Dictionary &p_states) { List<Variant> keys; p_states.get_key_list(&keys); - List<Variant>::Element *E=keys.front(); - for(;E;E=E->next()) { + List<Variant>::Element *E = keys.front(); + for (; E; E = E->next()) { String name = E->get(); - int idx=-1; - for(int i=0;i<editor_plugins.size();i++) { + int idx = -1; + for (int i = 0; i < editor_plugins.size(); i++) { - if (editor_plugins[i]->get_name()==name) { - idx=i; + if (editor_plugins[i]->get_name() == name) { + idx = i; break; } } - if (idx==-1) + if (idx == -1) continue; editor_plugins[idx]->set_state(p_states[name]); } - } void EditorData::notify_edited_scene_changed() { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->edited_scene_changed(); } @@ -369,16 +357,15 @@ void EditorData::notify_edited_scene_changed() { void EditorData::clear_editor_states() { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->clear(); } - } void EditorData::save_editor_external_data() { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->save_external_data(); } @@ -386,42 +373,36 @@ void EditorData::save_editor_external_data() { void EditorData::apply_changes_in_editors() { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->apply_changes(); } - } void EditorData::save_editor_global_states() { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->save_global_state(); } } -void EditorData::restore_editor_global_states(){ +void EditorData::restore_editor_global_states() { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->restore_global_state(); } - } - void EditorData::paste_object_params(Object *p_object) { + for (List<PropertyData>::Element *E = clipboard.front(); E; E = E->next()) { - for( List<PropertyData>::Element *E=clipboard.front();E;E=E->next()) { - - p_object->set( E->get().name, E->get().value); + p_object->set(E->get().name, E->get().value); } - } - UndoRedo &EditorData::get_undo_redo() { return undo_redo; @@ -429,14 +410,13 @@ UndoRedo &EditorData::get_undo_redo() { void EditorData::remove_editor_plugin(EditorPlugin *p_plugin) { - p_plugin->undo_redo=NULL; + p_plugin->undo_redo = NULL; editor_plugins.erase(p_plugin); - } void EditorData::add_editor_plugin(EditorPlugin *p_plugin) { - p_plugin->undo_redo=&undo_redo; + p_plugin->undo_redo = &undo_redo; editor_plugins.push_back(p_plugin); } @@ -445,32 +425,30 @@ int EditorData::get_editor_plugin_count() const { } EditorPlugin *EditorData::get_editor_plugin(int p_idx) { - ERR_FAIL_INDEX_V(p_idx,editor_plugins.size(),NULL); + ERR_FAIL_INDEX_V(p_idx, editor_plugins.size(), NULL); return editor_plugins[p_idx]; } - -void EditorData::add_custom_type(const String& p_type, const String& p_inherits,const Ref<Script>& p_script,const Ref<Texture>& p_icon ) { +void EditorData::add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture> &p_icon) { ERR_FAIL_COND(p_script.is_null()); CustomType ct; - ct.name=p_type; - ct.icon=p_icon; - ct.script=p_script; + ct.name = p_type; + ct.icon = p_icon; + ct.script = p_script; if (!custom_types.has(p_inherits)) { - custom_types[p_inherits]=Vector<CustomType>(); + custom_types[p_inherits] = Vector<CustomType>(); } custom_types[p_inherits].push_back(ct); } -void EditorData::remove_custom_type(const String& p_type){ - +void EditorData::remove_custom_type(const String &p_type) { - for (Map<String,Vector<CustomType> >::Element *E=custom_types.front();E;E=E->next()) { + for (Map<String, Vector<CustomType> >::Element *E = custom_types.front(); E; E = E->next()) { - for(int i=0;i<E->get().size();i++) { - if (E->get()[i].name==p_type) { + for (int i = 0; i < E->get().size(); i++) { + if (E->get()[i].name == p_type) { E->get().remove(i); if (E->get().empty()) { custom_types.erase(E->key()); @@ -479,51 +457,49 @@ void EditorData::remove_custom_type(const String& p_type){ } } } - } int EditorData::add_edited_scene(int p_at_pos) { - if (p_at_pos<0) - p_at_pos=edited_scene.size(); + if (p_at_pos < 0) + p_at_pos = edited_scene.size(); EditedScene es; - es.root=NULL; - es.history_current=-1; - es.version=0; - es.live_edit_root=NodePath(String("/root")); + es.root = NULL; + es.history_current = -1; + es.version = 0; + es.live_edit_root = NodePath(String("/root")); - if (p_at_pos==edited_scene.size()) + if (p_at_pos == edited_scene.size()) edited_scene.push_back(es); else - edited_scene.insert(p_at_pos,es); + edited_scene.insert(p_at_pos, es); - if (current_edited_scene<0) - current_edited_scene=0; + if (current_edited_scene < 0) + current_edited_scene = 0; return p_at_pos; } -void EditorData::move_edited_scene_index(int p_idx,int p_to_idx){ +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]); + 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]); } -void EditorData::remove_scene(int p_idx){ - ERR_FAIL_INDEX(p_idx,edited_scene.size()); +void EditorData::remove_scene(int p_idx) { + ERR_FAIL_INDEX(p_idx, edited_scene.size()); if (edited_scene[p_idx].root) memdelete(edited_scene[p_idx].root); - if (current_edited_scene>p_idx) + if (current_edited_scene > p_idx) current_edited_scene--; - else if (current_edited_scene==p_idx && current_edited_scene>0) { + else if (current_edited_scene == p_idx && current_edited_scene > 0) { current_edited_scene--; } edited_scene.remove(p_idx); - } -bool EditorData::_find_updated_instances(Node* p_root,Node *p_node,Set<String> &checked_paths) { +bool EditorData::_find_updated_instances(Node *p_root, Node *p_node, Set<String> &checked_paths) { /* if (p_root!=p_node && p_node->get_owner()!=p_root && !p_root->is_editable_instance(p_node->get_owner())) @@ -532,10 +508,10 @@ bool EditorData::_find_updated_instances(Node* p_root,Node *p_node,Set<String> & Ref<SceneState> ss; - 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(); + 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(); } if (ss.is_valid()) { @@ -544,18 +520,17 @@ bool EditorData::_find_updated_instances(Node* p_root,Node *p_node,Set<String> & if (!checked_paths.has(path)) { uint64_t modified_time = FileAccess::get_modified_time(path); - if (modified_time!=ss->get_last_modified_time()) { + if (modified_time != ss->get_last_modified_time()) { return true; //external scene changed } checked_paths.insert(path); } - } - for(int i=0;i<p_node->get_child_count();i++) { + 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); + bool found = _find_updated_instances(p_root, p_node->get_child(i), checked_paths); if (found) return true; } @@ -563,79 +538,75 @@ bool EditorData::_find_updated_instances(Node* p_root,Node *p_node,Set<String> & return false; } - bool EditorData::check_and_update_scene(int p_idx) { - ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),false); + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), false); if (!edited_scene[p_idx].root) return false; Set<String> checked_scenes; + bool must_reload = _find_updated_instances(edited_scene[p_idx].root, edited_scene[p_idx].root, checked_scenes); - 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)); + 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); + EditorProgress ep("update_scene", TTR("Updating Scene"), 2); + 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); + ERR_FAIL_COND_V(err != OK, false); + ep.step(TTR("Updating scene.."), 1); Node *new_scene = pscene->instance(PackedScene::GEN_EDIT_STATE_MAIN); - ERR_FAIL_COND_V(!new_scene,false); + 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()) { + List<Node *> new_selection; + for (List<Node *>::Element *E = edited_scene[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) new_selection.push_back(new_node); } - new_scene->set_filename( edited_scene[p_idx].root->get_filename() ); + 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[p_idx].root = new_scene; + edited_scene[p_idx].selection = new_selection; return true; - } return false; - } int EditorData::get_edited_scene() const { return current_edited_scene; } -void EditorData::set_edited_scene(int p_idx){ +void EditorData::set_edited_scene(int p_idx) { - ERR_FAIL_INDEX(p_idx,edited_scene.size()); - current_edited_scene=p_idx; + ERR_FAIL_INDEX(p_idx, edited_scene.size()); + current_edited_scene = p_idx; //swap } -Node* EditorData::get_edited_scene_root(int p_idx){ +Node *EditorData::get_edited_scene_root(int p_idx) { if (p_idx < 0) { - ERR_FAIL_INDEX_V(current_edited_scene,edited_scene.size(),NULL); + ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), NULL); return edited_scene[current_edited_scene].root; } else { - ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),NULL); + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), NULL); return edited_scene[p_idx].root; } } -void EditorData::set_edited_scene_root(Node* p_root) { +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; + ERR_FAIL_INDEX(current_edited_scene, edited_scene.size()); + edited_scene[current_edited_scene].root = p_root; } int EditorData::get_edited_scene_count() const { @@ -644,123 +615,111 @@ int EditorData::get_edited_scene_count() const { } void EditorData::set_edited_scene_version(uint64_t version, int scene_idx) { - ERR_FAIL_INDEX(current_edited_scene,edited_scene.size()); + ERR_FAIL_INDEX(current_edited_scene, edited_scene.size()); if (scene_idx < 0) { - edited_scene[current_edited_scene].version=version; + edited_scene[current_edited_scene].version = version; } else { - ERR_FAIL_INDEX(scene_idx,edited_scene.size()); - edited_scene[scene_idx].version=version; + ERR_FAIL_INDEX(scene_idx, edited_scene.size()); + edited_scene[scene_idx].version = version; } - } -uint64_t EditorData::get_edited_scene_version() const{ +uint64_t EditorData::get_edited_scene_version() const { - ERR_FAIL_INDEX_V(current_edited_scene,edited_scene.size(),0); + ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), 0); return edited_scene[current_edited_scene].version; - } -uint64_t EditorData::get_scene_version(int p_idx) const{ - ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),false); +uint64_t EditorData::get_scene_version(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), false); return edited_scene[p_idx].version; } String EditorData::get_scene_type(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),String()); + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); if (!edited_scene[p_idx].root) return ""; return edited_scene[p_idx].root->get_class(); - } void EditorData::move_edited_scene_to_index(int p_idx) { - ERR_FAIL_INDEX(current_edited_scene,edited_scene.size()); - ERR_FAIL_INDEX(p_idx,edited_scene.size()); + ERR_FAIL_INDEX(current_edited_scene, edited_scene.size()); + ERR_FAIL_INDEX(p_idx, edited_scene.size()); - EditedScene es=edited_scene[current_edited_scene]; + EditedScene es = edited_scene[current_edited_scene]; edited_scene.remove(current_edited_scene); - edited_scene.insert(p_idx,es); - current_edited_scene=p_idx; + edited_scene.insert(p_idx, es); + current_edited_scene = p_idx; } Ref<Script> EditorData::get_scene_root_script(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),Ref<Script>()); + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), Ref<Script>()); if (!edited_scene[p_idx].root) return Ref<Script>(); - Ref<Script> s=edited_scene[p_idx].root->get_script(); + Ref<Script> s = edited_scene[p_idx].root->get_script(); if (!s.is_valid() && edited_scene[p_idx].root->get_child_count()) { Node *n = edited_scene[p_idx].root->get_child(0); - while(!s.is_valid() && n && n->get_filename()==String()) { - s=n->get_script(); - n=n->get_parent(); + while (!s.is_valid() && n && n->get_filename() == String()) { + s = n->get_script(); + n = n->get_parent(); } } return s; } String EditorData::get_scene_title(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),String()); + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); if (!edited_scene[p_idx].root) return "[empty]"; - if (edited_scene[p_idx].root->get_filename()=="") + if (edited_scene[p_idx].root->get_filename() == "") return "[unsaved]"; return edited_scene[p_idx].root->get_filename().get_file(); } - String EditorData::get_scene_path(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),String()); + ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); if (!edited_scene[p_idx].root) return ""; return edited_scene[p_idx].root->get_filename(); - } -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; +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; } NodePath EditorData::get_edited_scene_live_edit_root() { - ERR_FAIL_INDEX_V(current_edited_scene,edited_scene.size(),String()); + ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), String()); return edited_scene[current_edited_scene].live_edit_root; - - - } +void EditorData::save_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history, const Dictionary &p_custom) { -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()); + ERR_FAIL_INDEX(current_edited_scene, edited_scene.size()); - EditedScene &es=edited_scene[current_edited_scene]; + EditedScene &es = edited_scene[current_edited_scene]; es.selection = p_selection->get_selected_node_list(); - es.history_current=p_history->current; - es.history_stored=p_history->history; - es.editor_states=get_editor_states(); - es.custom_state=p_custom; - + es.history_current = p_history->current; + es.history_stored = p_history->history; + es.editor_states = get_editor_states(); + es.custom_state = p_custom; } 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]; + ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), Dictionary()); - p_history->current=es.history_current; - p_history->history=es.history_stored; + EditedScene &es = edited_scene[current_edited_scene]; + p_history->current = es.history_current; + p_history->history = es.history_stored; p_selection->clear(); - for(List<Node*>::Element *E=es.selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = es.selection.front(); E; E = E->next()) { p_selection->add_node(E->get()); } set_editor_states(es.editor_states); @@ -768,34 +727,31 @@ Dictionary EditorData::restore_edited_scene_state(EditorSelection *p_selection, return es.custom_state; } - void EditorData::clear_edited_scenes() { - for(int i=0;i<edited_scene.size();i++) { + for (int i = 0; i < edited_scene.size(); i++) { if (edited_scene[i].root) { - memdelete( edited_scene[i].root ); + memdelete(edited_scene[i].root); } } edited_scene.clear(); } - - void EditorData::set_plugin_window_layout(Ref<ConfigFile> p_layout) { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->set_window_layout(p_layout); } } void EditorData::get_plugin_window_layout(Ref<ConfigFile> p_layout) { - for(int i=0;i<editor_plugins.size();i++) { + for (int i = 0; i < editor_plugins.size(); i++) { editor_plugins[i]->get_window_layout(p_layout); } } EditorData::EditorData() { - current_edited_scene=-1; + current_edited_scene = -1; //load_imported_scenes_from_globals(); } @@ -810,8 +766,8 @@ void EditorSelection::_node_removed(Node *p_node) { if (meta) memdelete(meta); selection.erase(p_node); - changed=true; - nl_changed=true; + changed = true; + nl_changed = true; } void EditorSelection::add_node(Node *p_node) { @@ -821,20 +777,19 @@ void EditorSelection::add_node(Node *p_node) { if (selection.has(p_node)) return; - changed=true; - nl_changed=true; - Object *meta=NULL; - for(List<Object*>::Element *E=editor_plugins.front();E;E=E->next()) { + changed = true; + nl_changed = true; + Object *meta = NULL; + for (List<Object *>::Element *E = editor_plugins.front(); E; E = E->next()) { - meta = E->get()->call("_get_editor_data",p_node); + meta = E->get()->call("_get_editor_data", p_node); if (meta) { break; } - } - selection[p_node]=meta; + selection[p_node] = meta; - p_node->connect("tree_exited",this,"_node_removed",varray(p_node),CONNECT_ONESHOT); + p_node->connect("tree_exited", this, "_node_removed", varray(p_node), CONNECT_ONESHOT); //emit_signal("selection_changed"); } @@ -846,16 +801,16 @@ void EditorSelection::remove_node(Node *p_node) { if (!selection.has(p_node)) return; - changed=true; - nl_changed=true; + changed = true; + nl_changed = true; Object *meta = selection[p_node]; if (meta) memdelete(meta); selection.erase(p_node); - p_node->disconnect("tree_exited",this,"_node_removed"); + p_node->disconnect("tree_exited", this, "_node_removed"); //emit_signal("selection_changed"); } -bool EditorSelection::is_selected(Node * p_node) const { +bool EditorSelection::is_selected(Node *p_node) const { return selection.has(p_node); } @@ -864,7 +819,7 @@ Array EditorSelection::_get_transformable_selected_nodes() { Array ret; - for (List<Node*>::Element *E=selected_node_list.front();E;E=E->next()) { + for (List<Node *>::Element *E = selected_node_list.front(); E; E = E->next()) { ret.push_back(E->get()); } @@ -876,7 +831,7 @@ Array EditorSelection::_get_selected_nodes() { Array ret; - for (Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { ret.push_back(E->key()); } @@ -886,14 +841,13 @@ Array EditorSelection::_get_selected_nodes() { void EditorSelection::_bind_methods() { - ClassDB::bind_method(D_METHOD("_node_removed"),&EditorSelection::_node_removed); - ClassDB::bind_method(D_METHOD("clear"),&EditorSelection::clear); - ClassDB::bind_method(D_METHOD("add_node","node:Node"),&EditorSelection::add_node); - ClassDB::bind_method(D_METHOD("remove_node","node:Node"),&EditorSelection::remove_node); - 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); - ADD_SIGNAL( MethodInfo("selection_changed") ); - + ClassDB::bind_method(D_METHOD("_node_removed"), &EditorSelection::_node_removed); + ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear); + ClassDB::bind_method(D_METHOD("add_node", "node:Node"), &EditorSelection::add_node); + ClassDB::bind_method(D_METHOD("remove_node", "node:Node"), &EditorSelection::remove_node); + 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); + ADD_SIGNAL(MethodInfo("selection_changed")); } void EditorSelection::add_editor_plugin(Object *p_object) { @@ -908,18 +862,17 @@ void EditorSelection::_update_nl() { selected_node_list.clear(); - for (Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { - + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { Node *parent = E->key(); - parent=parent->get_parent(); - bool skip=false; + parent = parent->get_parent(); + bool skip = false; while (parent) { if (selection.has(parent)) { - skip=true; + skip = true; break; } - parent=parent->get_parent(); + parent = parent->get_parent(); } if (skip) @@ -927,7 +880,7 @@ void EditorSelection::_update_nl() { selected_node_list.push_back(E->key()); } - nl_changed=true; + nl_changed = true; } void EditorSelection::update() { @@ -937,12 +890,10 @@ void EditorSelection::update() { if (!changed) return; emit_signal("selection_changed"); - changed=false; - - + changed = false; } -List<Node*>& EditorSelection::get_selected_node_list() { +List<Node *> &EditorSelection::get_selected_node_list() { if (changed) update(); @@ -951,26 +902,20 @@ List<Node*>& EditorSelection::get_selected_node_list() { return selected_node_list; } - - - void EditorSelection::clear() { - while( !selection.empty() ) { + while (!selection.empty()) { remove_node(selection.front()->key()); } - - changed=true; - nl_changed=true; - + changed = true; + nl_changed = true; } EditorSelection::EditorSelection() { - changed=false; - nl_changed=false; - + changed = false; + nl_changed = false; } EditorSelection::~EditorSelection() { |