Kaynağa Gözat

-Added proper code completion for singletons

reduz 9 yıl önce
ebeveyn
işleme
110de2ccac

+ 64 - 0
modules/gdscript/gd_editor.cpp

@@ -1147,8 +1147,54 @@ static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const
 		}
 	}
 
+	//autoloads as singletons
+	List<PropertyInfo> props;
+	Globals::get_singleton()->get_property_list(&props);
 
+	for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
 
+		String s = E->get().name;
+		if (!s.begins_with("autoload/"))
+			continue;
+		String name = s.get_slice("/",1);
+		if (name==String(p_identifier)) {
+
+			String path = Globals::get_singleton()->get(s);
+			if (path.begins_with("*")) {
+				String script =path.substr(1,path.length());
+
+				if (!script.ends_with(".gd")) {
+					//not a script, try find the script anyway,
+					//may have some success
+					script=script.basename()+".gd";
+				}
+
+				if (FileAccess::exists(script)) {
+
+					//print_line("is a script");
+
+
+					Ref<Script> scr;
+					if (ScriptCodeCompletionCache::get_sigleton())
+						scr = ScriptCodeCompletionCache::get_sigleton()->get_cached_resource(script);
+					else
+						scr = ResourceLoader::load(script);
+
+
+					r_type.obj_type="Node";
+					r_type.type=Variant::OBJECT;
+					r_type.script=scr;
+					r_type.value=Variant();
+
+					return true;
+
+				}
+			}
+		}
+
+	}
+
+	//global
 	for(Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
 		if (E->key()==p_identifier) {
 
@@ -1336,6 +1382,24 @@ static void _find_identifiers(GDCompletionContext& context,int p_line,bool p_onl
 		result.insert(_type_names[i]);
 	}
 
+	//autoload singletons
+	List<PropertyInfo> props;
+	Globals::get_singleton()->get_property_list(&props);
+
+	for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+
+		String s = E->get().name;
+		if (!s.begins_with("autoload/"))
+			continue;
+		String name = s.get_slice("/",1);
+		String path = Globals::get_singleton()->get(s);
+		if (path.begins_with("*")) {
+			result.insert(name);
+		}
+
+	}
+
+
 	for(const Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
 		result.insert(E->key().operator String());
 	}

+ 1 - 1
tools/editor/project_settings.cpp

@@ -1786,7 +1786,7 @@ ProjectSettings::ProjectSettings(EditorData *p_data) {
 		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_title(2,"Singleton");
 		autoload_list->set_column_expand(2,false);
 		autoload_list->set_column_min_width(2,80);
 		autoload_list->set_column_expand(3,false);