Editor: Improve signal callback generation

This commit is contained in:
Danil Alexeev 2023-08-18 07:35:58 +03:00
parent 221884e6bc
commit 4b5daf06ef
No known key found for this signature in database
GPG Key ID: 124453E157DA8DC7
3 changed files with 38 additions and 8 deletions

View File

@ -517,16 +517,41 @@ String ConnectDialog::get_signature(const MethodInfo &p_method, PackedStringArra
} }
const PropertyInfo &pi = p_method.arguments[i]; const PropertyInfo &pi = p_method.arguments[i];
String tname = "var"; String type_name;
if (pi.type == Variant::OBJECT && pi.class_name != StringName()) { switch (pi.type) {
tname = pi.class_name.operator String(); case Variant::NIL:
} else if (pi.type != Variant::NIL) { type_name = "Variant";
tname = Variant::get_type_name(pi.type); break;
case Variant::INT:
if ((pi.usage & PROPERTY_USAGE_CLASS_IS_ENUM) && pi.class_name != StringName() && !String(pi.class_name).begins_with("res://")) {
type_name = pi.class_name;
} else {
type_name = "int";
}
break;
case Variant::ARRAY:
if (pi.hint == PROPERTY_HINT_ARRAY_TYPE && !pi.hint_string.is_empty() && !pi.hint_string.begins_with("res://")) {
type_name = "Array[" + pi.hint_string + "]";
} else {
type_name = "Array";
}
break;
case Variant::OBJECT:
if (pi.class_name != StringName()) {
type_name = pi.class_name;
} else {
type_name = "Object";
}
break;
default:
type_name = Variant::get_type_name(pi.type);
break;
} }
signature.append((pi.name.is_empty() ? String("arg " + itos(i)) : pi.name) + ": " + tname); String arg_name = pi.name.is_empty() ? "arg" + itos(i) : pi.name;
signature.append(arg_name + ": " + type_name);
if (r_arg_names) { if (r_arg_names) {
r_arg_names->push_back(pi.name + ":" + tname); r_arg_names->push_back(arg_name + ":" + type_name);
} }
} }

View File

@ -500,7 +500,7 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na
s += p_args[i].get_slice(":", 0); s += p_args[i].get_slice(":", 0);
if (th) { if (th) {
String type = p_args[i].get_slice(":", 1); String type = p_args[i].get_slice(":", 1);
if (!type.is_empty() && type != "var") { if (!type.is_empty()) {
s += ": " + type; s += ": " + type;
} }
} }

View File

@ -435,6 +435,11 @@ static String variant_type_to_managed_name(const String &p_var_type_name) {
return "Collections.Dictionary"; return "Collections.Dictionary";
} }
if (p_var_type_name.begins_with(Variant::get_type_name(Variant::ARRAY) + "[")) {
String element_type = p_var_type_name.trim_prefix(Variant::get_type_name(Variant::ARRAY) + "[").trim_suffix("]");
return "Collections.Array<" + variant_type_to_managed_name(element_type) + ">";
}
if (p_var_type_name == Variant::get_type_name(Variant::ARRAY)) { if (p_var_type_name == Variant::get_type_name(Variant::ARRAY)) {
return "Collections.Array"; return "Collections.Array";
} }