/*************************************************************************/ /* editor_data.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* 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. */ /*************************************************************************/ #include "editor_data.h" #include "globals.h" #include "editor_settings.h" #include "os/dir_access.h" #include "io/resource_loader.h" void EditorHistory::_cleanup_history() { for(int i=0;i=history.size()) current=history.size()-1; } 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(); Obj o; if (r) o.ref=REF(r); o.object=p_object; o.property=p_property; History h; bool has_prev = current>=0 && current0) current--; else return false; return true; } ObjectID EditorHistory::get_current() { if (current<0 || current >=history.size()) return 0; History &h=history[current]; Object *obj = ObjectDB::get_instance(h.path[h.level].object); if (!obj) return 0; return obj->get_instance_ID(); } int EditorHistory::get_path_size() const { if (current<0 || current >=history.size()) return 0; const History &h=history[current]; return h.path.size(); } ObjectID EditorHistory::get_path_object(int p_index) const { if (current<0 || current >=history.size()) return 0; const History &h=history[current]; ERR_FAIL_INDEX_V(p_index,h.path.size(),0); Object *obj = ObjectDB::get_instance(h.path[p_index].object); if (!obj) return 0; return obj->get_instance_ID(); } String EditorHistory::get_path_property(int p_index) const { if (current<0 || current >=history.size()) return ""; const History &h=history[current]; ERR_FAIL_INDEX_V(p_index,h.path.size(),""); return h.path[p_index].property; } void EditorHistory::clear() { history.clear(); current=-1; } EditorHistory::EditorHistory() { current=-1; } EditorPlugin* EditorData::get_editor(Object *p_object) { for (int i=0;ihas_main_screen() && editor_plugins[i]->handles(p_object)) return editor_plugins[i]; } return NULL; } EditorPlugin* EditorData::get_subeditor(Object *p_object) { for (int i=0;ihas_main_screen() && editor_plugins[i]->handles(p_object)) return editor_plugins[i]; } return NULL; } EditorPlugin* EditorData::get_editor(String p_name) { for(int i=0;iget_name()==p_name) return editor_plugins[i]; } return NULL; } void EditorData::copy_object_params(Object *p_object) { clipboard.clear(); List pinfo; p_object->get_property_list(&pinfo); for( List::Element *E=pinfo.front();E;E=E->next()) { if (!(E->get().usage&PROPERTY_USAGE_EDITOR)) continue; PropertyData pd; pd.name=E->get().name; pd.value=p_object->get(pd.name); clipboard.push_back(pd); } } void EditorData::get_editor_breakpoints(List *p_breakpoints) { for(int i=0;iget_breakpoints(p_breakpoints); } } Dictionary EditorData::get_editor_states() const { Dictionary metadata; for(int i=0;iget_state(); if (state.empty()) continue; metadata[editor_plugins[i]->get_name()]=state; } return metadata; } void EditorData::set_editor_states(const Dictionary& p_states) { List keys; p_states.get_key_list(&keys); List::Element *E=keys.front(); for(;E;E=E->next()) { String name = E->get(); int idx=-1; for(int i=0;iget_name()==name) { idx=i; break; } } if (idx==-1) continue; editor_plugins[idx]->set_state(p_states[name]); } } void EditorData::clear_editor_states() { for(int i=0;iclear(); } } void EditorData::save_editor_external_data() { for(int i=0;isave_external_data(); } } void EditorData::apply_changes_in_editors() { for(int i=0;iapply_changes(); } } void EditorData::save_editor_global_states() { for(int i=0;isave_global_state(); } } void EditorData::restore_editor_global_states(){ for(int i=0;irestore_global_state(); } } void EditorData::paste_object_params(Object *p_object) { for( List::Element *E=clipboard.front();E;E=E->next()) { p_object->set( E->get().name, E->get().value); } } UndoRedo &EditorData::get_undo_redo() { return undo_redo; } void EditorData::remove_editor_plugin(EditorPlugin *p_plugin) { p_plugin->undo_redo=NULL; editor_plugins.erase(p_plugin); } void EditorData::add_editor_plugin(EditorPlugin *p_plugin) { p_plugin->undo_redo=&undo_redo; editor_plugins.push_back(p_plugin); } void EditorData::add_custom_type(const String& p_type, const String& p_inherits,const Ref