summaryrefslogtreecommitdiff
path: root/tools/editor
diff options
context:
space:
mode:
authorhurikhan <m4r10.5ch14ck@gmail.com>2015-02-12 15:58:29 +0100
committerhurikhan <m4r10.5ch14ck@gmail.com>2015-02-12 15:58:29 +0100
commita13e180052d2e17275498a2fa78185cc299ace11 (patch)
tree6f9051d0b3d2444ac09c1bbf78f9e395af1782e9 /tools/editor
parentdf7d26ff5b89ce9852813abd370d1357aab1501b (diff)
parentb3a6cc097d5bc60ee6e7ba30b177bed3a8aadc71 (diff)
Merge remote-tracking branch 'upstream/master' into x11-window-management
Diffstat (limited to 'tools/editor')
-rw-r--r--tools/editor/editor_import_export.cpp26
-rw-r--r--tools/editor/editor_import_export.h1
-rw-r--r--tools/editor/editor_node.cpp63
-rw-r--r--tools/editor/editor_node.h6
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp6
-rw-r--r--tools/editor/scene_tree_dock.cpp33
-rw-r--r--tools/editor/scene_tree_dock.h1
7 files changed, 123 insertions, 13 deletions
diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp
index 58f9afaa5d..6399d0f909 100644
--- a/tools/editor/editor_import_export.cpp
+++ b/tools/editor/editor_import_export.cpp
@@ -1141,10 +1141,36 @@ EditorImportExport* EditorImportExport::singleton=NULL;
void EditorImportExport::add_import_plugin(const Ref<EditorImportPlugin>& p_plugin) {
+ // Need to make sure the name is unique if we are going to lookup by it
+ ERR_FAIL_COND(by_idx.has(p_plugin->get_name()));
+
by_idx[ p_plugin->get_name() ]=plugins.size();
plugins.push_back(p_plugin);
}
+void EditorImportExport::remove_import_plugin(const Ref<EditorImportPlugin>& p_plugin) {
+
+ String plugin_name = p_plugin->get_name();
+
+ // Keep the indices the same
+ // Find the index of the target plugin
+ ERR_FAIL_COND(!by_idx.has(plugin_name));
+ int idx = by_idx[plugin_name];
+ int last_idx = plugins.size() - 1;
+
+ // Swap the last plugin and the target one
+ SWAP(plugins[idx], plugins[last_idx]);
+
+ // Update the index of the old last one
+ by_idx[plugins[idx]->get_name()] = idx;
+
+ // Remove the target plugin's by_idx entry
+ by_idx.erase(plugin_name);
+
+ // Erase the plugin
+ plugins.remove(last_idx);
+}
+
int EditorImportExport::get_import_plugin_count() const{
return plugins.size();
diff --git a/tools/editor/editor_import_export.h b/tools/editor/editor_import_export.h
index 8305e3c88c..cd24fa076b 100644
--- a/tools/editor/editor_import_export.h
+++ b/tools/editor/editor_import_export.h
@@ -270,6 +270,7 @@ public:
static EditorImportExport* get_singleton() { return singleton; }
void add_import_plugin(const Ref<EditorImportPlugin>& p_plugin);
+ void remove_import_plugin(const Ref<EditorImportPlugin>& p_plugin);
int get_import_plugin_count() const;
Ref<EditorImportPlugin> get_import_plugin(int p_idx) const;
Ref<EditorImportPlugin> get_import_plugin_by_name(const String& p_string) const;
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 6ff16e661c..58c1cac12c 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -336,6 +336,19 @@ void EditorNode::_vp_resized() {
}
+void EditorNode::_rebuild_import_menu()
+{
+ PopupMenu* p = import_menu->get_popup();
+ p->clear();
+ p->add_item("Sub-Scene", FILE_IMPORT_SUBSCENE);
+ p->add_separator();
+ for (int i = 0; i < editor_import_export->get_import_plugin_count(); i++) {
+ p->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(), IMPORT_PLUGIN_BASE + i);
+ }
+ p->add_separator();
+ p->add_item("Re-Import..", SETTINGS_IMPORT);
+}
+
void EditorNode::_node_renamed() {
if (property_editor)
@@ -1967,6 +1980,25 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
log->add_message("REDO: "+action);
} break;
+
+ case EDIT_REVERT: {
+
+ Node *scene = get_edited_scene();
+
+ if (!scene)
+ break;
+
+ if (unsaved_cache && !p_confirmed) {
+ confirmation->get_ok()->set_text("Revert");
+ confirmation->set_text("This action cannot be undone. Revert anyway?");
+ confirmation->popup_centered(Size2(300,70));
+ break;
+ }
+
+ Error err = load_scene(scene->get_filename());
+
+ } break;
+
#if 0
case NODE_EXTERNAL_INSTANCE: {
@@ -2388,6 +2420,19 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) {
}
+void EditorNode::add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) {
+
+ editor_import_export->add_import_plugin(p_editor_import);
+ _rebuild_import_menu();
+}
+
+void EditorNode::remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) {
+
+ editor_import_export->remove_import_plugin(p_editor_import);
+ _rebuild_import_menu();
+}
+
+
void EditorNode::set_edited_scene(Node *p_scene) {
if (edited_scene) {
@@ -3152,6 +3197,9 @@ void EditorNode::_bind_methods() {
ObjectTypeDB::bind_method("_sources_changed",&EditorNode::_sources_changed);
ObjectTypeDB::bind_method("_fs_changed",&EditorNode::_fs_changed);
+ ObjectTypeDB::bind_method(_MD("add_editor_import_plugin", "plugin"), &EditorNode::add_editor_import_plugin);
+ ObjectTypeDB::bind_method(_MD("remove_editor_import_plugin", "plugin"), &EditorNode::remove_editor_import_plugin);
+ ObjectTypeDB::bind_method(_MD("get_gui_base"), &EditorNode::get_gui_base);
ADD_SIGNAL( MethodInfo("play_pressed") );
ADD_SIGNAL( MethodInfo("pause_pressed") );
@@ -3469,6 +3517,8 @@ EditorNode::EditorNode() {
p->add_separator();
p->add_item("Project Settings",RUN_SETTINGS);
p->add_separator();
+ p->add_item("Revert Scene",EDIT_REVERT);
+ p->add_separator();
p->add_item("Quit to Project List",RUN_PROJECT_MANAGER,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_Q);
p->add_item("Quit",FILE_QUIT,KEY_MASK_CMD+KEY_Q);
@@ -3513,8 +3563,6 @@ EditorNode::EditorNode() {
left_menu_hb->add_child( import_menu );
p=import_menu->get_popup();
- p->add_item("Sub-Scene",FILE_IMPORT_SUBSCENE);
- p->add_separator();
p->connect("item_pressed",this,"_menu_option");
export_button = memnew( ToolButton );
@@ -3552,7 +3600,7 @@ EditorNode::EditorNode() {
play_button->set_icon(gui_base->get_icon("MainPlay","EditorIcons"));
play_button->set_focus_mode(Control::FOCUS_NONE);
play_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY));
- play_button->set_tooltip("Start the scene (F5).");
+ play_button->set_tooltip("Play the project (F5).");
@@ -4023,11 +4071,6 @@ EditorNode::EditorNode() {
editor_import_export->add_import_plugin( Ref<EditorSampleImportPlugin>( memnew(EditorSampleImportPlugin(this))));
editor_import_export->add_import_plugin( Ref<EditorTranslationImportPlugin>( memnew(EditorTranslationImportPlugin(this))));
-
- for(int i=0;i<editor_import_export->get_import_plugin_count();i++) {
- import_menu->get_popup()->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(),IMPORT_PLUGIN_BASE+i);
- }
-
editor_import_export->add_export_plugin( Ref<EditorTextureExportPlugin>( memnew(EditorTextureExportPlugin)));
add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) );
@@ -4072,9 +4115,7 @@ EditorNode::EditorNode() {
circle_step_frame=OS::get_singleton()->get_frames_drawn();;
circle_step=0;
-
- import_menu->get_popup()->add_separator();
- import_menu->get_popup()->add_item("Re-Import..",SETTINGS_IMPORT);
+ _rebuild_import_menu();
editor_plugin_screen=NULL;
editor_plugin_over=NULL;
diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h
index 7560c2b149..c7c3bde4cb 100644
--- a/tools/editor/editor_node.h
+++ b/tools/editor/editor_node.h
@@ -127,6 +127,7 @@ class EditorNode : public Node {
FILE_EXTERNAL_OPEN_SCENE,
EDIT_UNDO,
EDIT_REDO,
+ EDIT_REVERT,
RESOURCE_NEW,
RESOURCE_LOAD,
RESOURCE_SAVE,
@@ -339,6 +340,8 @@ class EditorNode : public Node {
void _show_messages();
void _vp_resized();
+ void _rebuild_import_menu();
+
void _save_scene(String p_file);
@@ -420,6 +423,9 @@ public:
static void add_editor_plugin(EditorPlugin *p_editor);
static void remove_editor_plugin(EditorPlugin *p_editor);
+ void add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import);
+ void remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import);
+
void edit_node(Node *p_node);
void edit_resource(const Ref<Resource>& p_resource);
diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp
index 4b7d1cf0e0..1349d5ccab 100644
--- a/tools/editor/plugins/script_editor_plugin.cpp
+++ b/tools/editor/plugins/script_editor_plugin.cpp
@@ -631,7 +631,10 @@ bool ScriptEditor::_test_script_times_on_disk() {
if (!all_ok)
- disk_changed->call_deferred("popup_centered_ratio",0.5);
+ if (bool(EDITOR_DEF("text_editor/auto_reload_changed_scripts",false)))
+ script_editor->_reload_scripts();
+ else
+ disk_changed->call_deferred("popup_centered_ratio",0.5);
return all_ok;
}
@@ -1806,6 +1809,7 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) {
script_editor->hide();
+ EDITOR_DEF("text_editor/auto_reload_changed_scripts",false);
EDITOR_DEF("external_editor/use_external_editor",false);
EDITOR_DEF("external_editor/exec_path","");
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"external_editor/exec_path",PROPERTY_HINT_GLOBAL_FILE));
diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp
index cff3913579..6f33d4b3d1 100644
--- a/tools/editor/scene_tree_dock.cpp
+++ b/tools/editor/scene_tree_dock.cpp
@@ -79,10 +79,22 @@ Node* SceneTreeDock::instance(const String& p_file) {
//accept->get_cancel()->hide();
accept->get_ok()->set_text("Ugh");
accept->set_text(String("Error loading scene from ")+p_file);
- accept->popup_centered(Size2(300,70));;
+ accept->popup_centered(Size2(300,70));
return NULL;
}
+ // If the scene hasn't been saved yet a cyclical dependency cannot exist.
+ if (edited_scene->get_filename()!="") {
+
+ if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) {
+
+ accept->get_ok()->set_text("Ok");
+ accept->set_text(String("Cannot instance the scene '")+p_file+String("' because the current scene exists within one of its' nodes."));
+ accept->popup_centered(Size2(300,90));
+ return NULL;
+ }
+ }
+
instanced_scene->generate_instance_state();
instanced_scene->set_filename( Globals::get_singleton()->localize_path(p_file) );
@@ -100,6 +112,25 @@ Node* SceneTreeDock::instance(const String& p_file) {
}
+bool SceneTreeDock::_cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node) {
+ int childCount = p_desired_node->get_child_count();
+
+ if (p_desired_node->get_filename()==p_target_scene_path) {
+ return true;
+ }
+
+ for (int i=0;i<childCount;i++) {
+ Node* child=p_desired_node->get_child(i);
+
+ if(_cyclical_dependency_exists(p_target_scene_path,child)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
static String _get_name_num_separator() {
switch(EditorSettings::get_singleton()->get("scenetree_editor/duplicate_node_name_num_separator").operator int()) {
case 0: return "";
diff --git a/tools/editor/scene_tree_dock.h b/tools/editor/scene_tree_dock.h
index ac5391f3b9..92ebfc5bee 100644
--- a/tools/editor/scene_tree_dock.h
+++ b/tools/editor/scene_tree_dock.h
@@ -102,6 +102,7 @@ class SceneTreeDock : public VBoxContainer {
void _load_request(const String& p_path);
void _script_open_request(const Ref<Script>& p_script);
+ bool _cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node);
void _node_selected();
void _node_renamed();