diff options
-rw-r--r-- | core/script_language.h | 1 | ||||
-rw-r--r-- | main/main.cpp | 15 | ||||
-rw-r--r-- | modules/gdscript/gd_script.cpp | 6 | ||||
-rw-r--r-- | modules/gdscript/gd_script.h | 1 | ||||
-rw-r--r-- | scene/main/node.cpp | 5 | ||||
-rw-r--r-- | tools/editor/project_settings.cpp | 119 | ||||
-rw-r--r-- | tools/editor/project_settings.h | 2 |
7 files changed, 137 insertions, 12 deletions
diff --git a/core/script_language.h b/core/script_language.h index 9660f141c7..52ae4e488f 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -165,6 +165,7 @@ public: virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const=0; virtual Error complete_code(const String& p_code, const String& p_base_path, Object*p_owner,List<String>* r_options,String& r_call_hint) { return ERR_UNAVAILABLE; } virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const=0; + virtual void add_global_constant(const StringName& p_variable,const Variant& p_value)=0; /* DEBUGGER FUNCTIONS */ diff --git a/main/main.cpp b/main/main.cpp index 66391ffa7e..8127bba3e9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1330,6 +1330,12 @@ bool Main::start() { continue; String name = s.get_slicec('/',1); String path = Globals::get_singleton()->get(s); + bool global_var=false; + if (path.begins_with("*")) { + global_var=true; + path=path.substr(1,path.length()-1); + } + RES res = ResourceLoader::load(path); ERR_EXPLAIN("Can't autoload: "+path); ERR_CONTINUE(res.is_null()); @@ -1355,7 +1361,16 @@ bool Main::start() { ERR_EXPLAIN("Path in autoload not a node or script: "+path); ERR_CONTINUE(!n); n->set_name(name); + sml->get_root()->add_child(n); + + if (global_var) { + for(int i=0;i<ScriptServer::get_language_count();i++) { + ScriptServer::get_language(i)->add_global_constant(name,n); + } + } + + } } diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 62006cf18b..ef53dcfe71 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -2570,6 +2570,12 @@ void GDScriptLanguage::_add_global(const StringName& p_name,const Variant& p_val _global_array=global_array.ptr(); } +void GDScriptLanguage::add_global_constant(const StringName& p_variable,const Variant& p_value) { + + _add_global(p_variable,p_value); +} + + void GDScriptLanguage::init() { diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 3d16b59065..952a28bdb5 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -529,6 +529,7 @@ public: virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const; virtual Error complete_code(const String& p_code, const String& p_base_path, Object*p_owner,List<String>* r_options,String& r_call_hint); virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const; + virtual void add_global_constant(const StringName& p_variable,const Variant& p_value); /* DEBUGGER FUNCTIONS */ diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 027e9ace65..2b2a188e76 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -856,7 +856,10 @@ Node *Node::_get_child_by_name(const StringName& p_name) const { Node *Node::_get_node(const NodePath& p_path) const { - ERR_FAIL_COND_V( !data.inside_tree && p_path.is_absolute(), NULL ); + if (!data.inside_tree && p_path.is_absolute()) { + ERR_EXPLAIN("Can't use get_node() with absolute paths from outside the active scene tree."); + ERR_FAIL_V(NULL); + } Node *current=NULL; Node *root=NULL; diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index dd3c7552de..98d96f711d 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -33,6 +33,7 @@ #include "editor_node.h" #include "scene/gui/margin_container.h" #include "translation.h" +#include "global_constants.h" ProjectSettings *ProjectSettings::singleton=NULL; @@ -777,10 +778,11 @@ void ProjectSettings::_translation_file_open() { void ProjectSettings::_autoload_file_callback(const String& p_path) { autoload_add_path->set_text(p_path); - if (autoload_add_name->get_text().strip_edges()==String()) { + //if (autoload_add_name->get_text().strip_edges()==String()) { autoload_add_name->set_text( p_path.get_file().basename() ); - } + //} + //_translation_add(p_translation); } @@ -789,6 +791,40 @@ void ProjectSettings::_autoload_file_open() { autoload_file_open->popup_centered_ratio(); } +void ProjectSettings::_autoload_edited() { + + if (updating_autoload) + return; + + TreeItem *ti = autoload_list->get_edited(); + if (!ti || autoload_list->get_edited_column()!=2) + return; + + updating_autoload=true; + bool checked=ti->is_checked(2); + + String base="autoload/"+ti->get_text(0); + + String path = Globals::get_singleton()->get(base); + + if (path.begins_with("*")) + path=path.substr(1,path.length()); + + if (checked) + path="*"+path; + + undo_redo->create_action("Toggle Autoload GlobalVar"); + undo_redo->add_do_property(Globals::get_singleton(),base,path); + undo_redo->add_undo_property(Globals::get_singleton(),base,Globals::get_singleton()->get(base)); + undo_redo->add_do_method(this,"_update_autoload"); + undo_redo->add_undo_method(this,"_update_autoload"); + undo_redo->add_do_method(this,"_settings_changed"); + undo_redo->add_undo_method(this,"_settings_changed"); + undo_redo->commit_action(); + updating_autoload=false; + +} + void ProjectSettings::_autoload_add() { String name = autoload_add_name->get_text(); @@ -799,6 +835,35 @@ void ProjectSettings::_autoload_add() { } + if (ObjectTypeDB::type_exists(name)) { + + message->set_text("Invalid Name.Must not collide with an existing engine class name."); + message->popup_centered(Size2(300,100)); + return; + + } + + for(int i=0;i<Variant::VARIANT_MAX;i++) { + if (Variant::get_type_name(Variant::Type(i))==name) { + + message->set_text("Invalid Name.Must not collide with an existing buit-in type name."); + message->popup_centered(Size2(300,100)); + return; + + } + } + + for(int i=0;i<GlobalConstants::get_global_constant_count();i++) { + + if (GlobalConstants::get_global_constant_name(i)==name) { + + message->set_text("Invalid Name.Must not collide with an existing global constant name."); + message->popup_centered(Size2(300,100)); + return; + } + + } + String path = autoload_add_path->get_text(); if (!FileAccess::exists(path)) { message->set_text("Invalid Path.\nFile does not exist."); @@ -815,7 +880,7 @@ void ProjectSettings::_autoload_add() { undo_redo->create_action("Add Autoload"); name = "autoload/"+name; - undo_redo->add_do_property(Globals::get_singleton(),name,path); + undo_redo->add_do_property(Globals::get_singleton(),name,"*"+path); if (Globals::get_singleton()->has(name)) undo_redo->add_undo_property(Globals::get_singleton(),name,Globals::get_singleton()->get(name)); else @@ -1208,6 +1273,11 @@ void ProjectSettings::_update_translations() { void ProjectSettings::_update_autoload() { + if (updating_autoload) + return; + + updating_autoload=true; + autoload_list->clear(); TreeItem *root = autoload_list->create_item(); autoload_list->set_hide_root(true); @@ -1222,18 +1292,31 @@ void ProjectSettings::_update_autoload() { continue; String name = pi.name.get_slice("/",1); + String path = Globals::get_singleton()->get(pi.name); + if (name=="") continue; - + bool global=false; + if (path.begins_with("*")) { + path=path.substr(1,path.length()); + global=true; + } TreeItem *t = autoload_list->create_item(root); t->set_text(0,name); - t->set_text(1,Globals::get_singleton()->get(pi.name)); - t->add_button(1,get_icon("MoveUp","EditorIcons"),1); - t->add_button(1,get_icon("MoveDown","EditorIcons"),2); - t->add_button(1,get_icon("Del","EditorIcons"),0); + t->set_text(1,path); + t->set_cell_mode(2,TreeItem::CELL_MODE_CHECK); + t->set_editable(2,true); + t->set_text(2,"Enable"); + t->set_checked(2,global); + t->add_button(3,get_icon("MoveUp","EditorIcons"),1); + t->add_button(3,get_icon("MoveDown","EditorIcons"),2); + t->add_button(3,get_icon("Del","EditorIcons"),0); + } + updating_autoload=false; + } void ProjectSettings::_toggle_search_bar(bool p_pressed) { @@ -1302,6 +1385,7 @@ void ProjectSettings::_bind_methods() { ObjectTypeDB::bind_method(_MD("_autoload_file_callback"),&ProjectSettings::_autoload_file_callback); ObjectTypeDB::bind_method(_MD("_update_autoload"),&ProjectSettings::_update_autoload); ObjectTypeDB::bind_method(_MD("_autoload_delete"),&ProjectSettings::_autoload_delete); + ObjectTypeDB::bind_method(_MD("_autoload_edited"),&ProjectSettings::_autoload_edited); ObjectTypeDB::bind_method(_MD("_clear_search_box"),&ProjectSettings::_clear_search_box); ObjectTypeDB::bind_method(_MD("_toggle_search_bar"),&ProjectSettings::_toggle_search_bar); @@ -1694,11 +1778,24 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { autoload_file_open->set_mode(EditorFileDialog::MODE_OPEN_FILE); autoload_file_open->connect("file_selected",this,"_autoload_file_callback"); - autoload_list->set_columns(2); + autoload_list->set_columns(4); autoload_list->set_column_titles_visible(true); - autoload_list->set_column_title(0,"name"); - autoload_list->set_column_title(1,"path"); + autoload_list->set_column_title(0,"Name"); + autoload_list->set_column_expand(0,true); + autoload_list->set_column_min_width(0,100); + autoload_list->set_column_title(1,"Path"); + autoload_list->set_column_expand(1,true); + autoload_list->set_column_min_width(1,100); + autoload_list->set_column_title(2,"GlobalVar"); + autoload_list->set_column_expand(2,false); + autoload_list->set_column_min_width(2,80); + autoload_list->set_column_expand(3,false); + autoload_list->set_column_min_width(3,80); + autoload_list->connect("button_pressed",this,"_autoload_delete"); + autoload_list->connect("item_edited",this,"_autoload_edited"); + + updating_autoload=false; } diff --git a/tools/editor/project_settings.h b/tools/editor/project_settings.h index f201f5c48f..0148c4a2f1 100644 --- a/tools/editor/project_settings.h +++ b/tools/editor/project_settings.h @@ -95,8 +95,10 @@ class ProjectSettings : public AcceptDialog { void _update_autoload(); void _autoload_file_callback(const String& p_path); void _autoload_add(); + void _autoload_edited(); void _autoload_file_open(); void _autoload_delete(Object *p_item,int p_column, int p_button); + bool updating_autoload; void _item_selected(); |