From efd52cd1725145dc9c8038477dbe133b23868e99 Mon Sep 17 00:00:00 2001 From: Paul Joannon Date: Thu, 18 Jan 2018 18:17:29 +0100 Subject: [PATCH 1/2] add a [Signal] attribute to CSharpScripts --- modules/mono/csharp_script.cpp | 50 ++++++++++++++++++- modules/mono/csharp_script.h | 5 ++ modules/mono/glue/cs_files/SignalAttribute.cs | 12 +++++ modules/mono/mono_gd/gd_mono_class.cpp | 28 +++++++++++ modules/mono/mono_gd/gd_mono_class.h | 6 +++ modules/mono/mono_gd/gd_mono_utils.cpp | 2 + modules/mono/mono_gd/gd_mono_utils.h | 1 + 7 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 modules/mono/glue/cs_files/SignalAttribute.cs diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 0dc00182244..609cb1c0139 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,42 @@ 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--) { + GDMonoClass *delegate = delegates[i]; + + if (delegate->has_attribute(CACHED_CLASS(SignalAttribute))) { + StringName name = delegate->get_name(); + + _signals[name] = Vector(); // TODO Retrieve arguments + } + } + + top = top->get_parent_class(); + } + } + + return changed; +#endif + return false; +} + #ifdef TOOLS_ENABLED bool CSharpScript::_get_member_export(GDMonoClass *p_class, GDMonoClassMember *p_member, PropertyInfo &r_prop_info, bool &r_exported) { @@ -1866,6 +1906,7 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { PlaceHolderScriptInstance *si = memnew(PlaceHolderScriptInstance(CSharpLanguage::get_singleton(), Ref