diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 0dc00182244..fb45136575f 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -721,8 +721,10 @@ void CSharpLanguage::reload_assemblies_if_needed(bool p_soft_reload) { for (Map, Map > > >::Element *E = to_reload.front(); E; E = E->next()) { Ref scr = E->key(); + scr->signals_invalidated = true; scr->exports_invalidated = true; scr->reload(p_soft_reload); + scr->update_signals(); scr->update_exports(); //restore state if saved @@ -755,8 +757,10 @@ void CSharpLanguage::reload_assemblies_if_needed(bool p_soft_reload) { //if instance states were saved, set them! } - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { EditorNode::get_singleton()->get_property_editor()->update_tree(); + NodeDock::singleton->update_lists(); + } } #endif @@ -1545,6 +1549,77 @@ bool CSharpScript::_update_exports() { return false; } +bool CSharpScript::_update_signals() { +#ifdef TOOLS_ENABLED + if (!valid) + return false; + + bool changed = false; + + if (signals_invalidated) { + signals_invalidated = false; + + GDMonoClass *top = script_class; + + _signals.clear(); + changed = true; // TODO Do a real check for change + + while (top && top != native) { + const Vector &delegates = top->get_all_delegates(); + for (int i = delegates.size() - 1; i >= 0; --i) { + Vector parameters; + + GDMonoClass *delegate = delegates[i]; + + if (_get_signal(top, delegate, parameters)) { + _signals[delegate->get_name()] = parameters; + } + } + + top = top->get_parent_class(); + } + } + + return changed; +#endif + return false; +} + +bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Vector ¶ms) { + if (p_delegate->has_attribute(CACHED_CLASS(SignalAttribute))) { + MonoType *raw_type = GDMonoClass::get_raw_type(p_delegate); + + if (mono_type_get_type(raw_type) == MONO_TYPE_CLASS) { + // Arguments are accessibles as arguments of .Invoke method + GDMonoMethod *invoke = p_delegate->get_method("Invoke", -1); + + Vector names; + Vector types; + invoke->get_parameter_names(names); + invoke->get_parameter_types(types); + + if (names.size() == types.size()) { + for (int i = 0; i < names.size(); ++i) { + Argument arg; + arg.name = names[i]; + arg.type = GDMonoMarshal::managed_to_variant_type(types[i]); + + if (arg.type == Variant::NIL) { + ERR_PRINTS("Unknown type of signal parameter: " + arg.name + " in " + p_class->get_full_name()); + return false; + } + + params.push_back(arg); + } + + return true; + } + } + } + + return false; +} + #ifdef TOOLS_ENABLED bool CSharpScript::_get_member_export(GDMonoClass *p_class, GDMonoClassMember *p_member, PropertyInfo &r_prop_info, bool &r_exported) { @@ -1866,12 +1941,15 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { PlaceHolderScriptInstance *si = memnew(PlaceHolderScriptInstance(CSharpLanguage::get_singleton(), Ref