diff options
author | Paul Joannon <hello@pauljoannon.com> | 2023-12-22 23:27:13 +0100 |
---|---|---|
committer | Paul Joannon <hello@pauljoannon.com> | 2023-12-22 23:27:13 +0100 |
commit | 0818d015db720491684b70cd64ae971bd02cb81c (patch) | |
tree | f5f137b8e83f81a267032ca2384f7e202bdd9577 /modules | |
parent | 2d0ee20ff30461b6b10f6fdfba87511a0ebc6642 (diff) | |
download | redot-engine-0818d015db720491684b70cd64ae971bd02cb81c.tar.gz |
Inspector :warning: when C# props might be out of date
Diffstat (limited to 'modules')
4 files changed, 131 insertions, 0 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 8e1587997b..175e213579 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -2246,6 +2246,17 @@ bool CSharpScript::_update_exports(PlaceHolderScriptInstance *p_instance_to_upda } else { p_instance_to_update->update(propnames, values); } + } else if (placeholders.size()) { + uint64_t script_modified_time = FileAccess::get_modified_time(get_path()); + uint64_t last_valid_build_time = GDMono::get_singleton()->get_project_assembly_modified_time(); + if (script_modified_time > last_valid_build_time) { + for (PlaceHolderScriptInstance *instance : placeholders) { + Object *owner = instance->get_owner(); + if (owner->get_script_instance() == instance) { + owner->notify_property_list_changed(); + } + } + } } } #endif diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index 650afb4cdf..5408b9b13e 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -9,6 +9,7 @@ using System.Linq; using GodotTools.Build; using GodotTools.Ides; using GodotTools.Ides.Rider; +using GodotTools.Inspector; using GodotTools.Internals; using GodotTools.ProjectEditor; using JetBrains.Annotations; @@ -45,6 +46,7 @@ namespace GodotTools // TODO Use WeakReference once we have proper serialization. private WeakRef _exportPluginWeak; + private WeakRef _inspectorPluginWeak; public GodotIdeManager GodotIdeManager { get; private set; } @@ -52,6 +54,8 @@ namespace GodotTools public bool SkipBuildBeforePlaying { get; set; } = false; + public DateTime LastValidBuildDateTime { get; private set; } + [UsedImplicitly] private bool CreateProjectSolutionIfNeeded() { @@ -437,6 +441,21 @@ namespace GodotTools } } + private void UpdateLastValidBuildDateTime() + { + var dllName = $"{GodotSharpDirs.ProjectAssemblyName}.dll"; + var path = Path.Combine(GodotSharpDirs.ProjectBaseOutputPath, "Debug", dllName); + LastValidBuildDateTime = File.GetLastWriteTime(path); + } + + private void BuildFinished(BuildResult buildResult) + { + if (buildResult == BuildResult.Success) + { + UpdateLastValidBuildDateTime(); + } + } + private void BuildStateChanged() { if (_bottomPanelBtn != null) @@ -447,6 +466,8 @@ namespace GodotTools { base._EnablePlugin(); + UpdateLastValidBuildDateTime(); + ProjectSettings.SettingsChanged += GodotSharpDirs.DetermineProjectLocation; if (Instance != null) @@ -615,6 +636,12 @@ namespace GodotTools AddExportPlugin(exportPlugin); _exportPluginWeak = WeakRef(exportPlugin); + // Inspector plugin + var inspectorPlugin = new InspectorPlugin(); + AddInspectorPlugin(inspectorPlugin); + _inspectorPluginWeak = WeakRef(inspectorPlugin); + BuildManager.BuildFinished += BuildFinished; + BuildManager.Initialize(); RiderPathManager.Initialize(); @@ -627,6 +654,10 @@ namespace GodotTools base._DisablePlugin(); _editorSettings.SettingsChanged -= OnSettingsChanged; + + // Custom signals aren't automatically disconnected currently. + MSBuildPanel.BuildStateChanged -= BuildStateChanged; + BuildManager.BuildFinished -= BuildFinished; } public override void _ExitTree() @@ -661,6 +692,13 @@ namespace GodotTools _exportPluginWeak.Dispose(); } + if (IsInstanceValid(_inspectorPluginWeak)) + { + (_inspectorPluginWeak.GetRef().AsGodotObject() as InspectorPlugin)?.Dispose(); + + _inspectorPluginWeak.Dispose(); + } + GodotIdeManager?.Dispose(); } diff --git a/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorOutOfSyncWarning.cs b/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorOutOfSyncWarning.cs new file mode 100644 index 0000000000..c5c451f143 --- /dev/null +++ b/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorOutOfSyncWarning.cs @@ -0,0 +1,37 @@ +using Godot; +using GodotTools.Internals; + +namespace GodotTools.Inspector +{ + public partial class InspectorOutOfSyncWarning : HBoxContainer + { + public override void _Ready() + { + SetAnchorsPreset(LayoutPreset.TopWide); + + var iconTexture = GetThemeIcon("StatusWarning", "EditorIcons"); + + var icon = new TextureRect() + { + Texture = iconTexture, + ExpandMode = TextureRect.ExpandModeEnum.FitWidthProportional, + CustomMinimumSize = iconTexture.GetSize(), + }; + + icon.SizeFlagsVertical = SizeFlags.ShrinkCenter; + + var label = new Label() + { + Text = "This inspector might be out of date. Please build the C# project.".TTR(), + AutowrapMode = TextServer.AutowrapMode.WordSmart, + CustomMinimumSize = new Vector2(100f, 0f), + }; + + label.AddThemeColorOverride("font_color", GetThemeColor("warning_color", "Editor")); + label.SizeFlagsHorizontal = SizeFlags.Fill | SizeFlags.Expand; + + AddChild(icon); + AddChild(label); + } + } +} diff --git a/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorPlugin.cs new file mode 100644 index 0000000000..8282ca6ea6 --- /dev/null +++ b/modules/mono/editor/GodotTools/GodotTools/Inspector/InspectorPlugin.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using Godot; +using GodotTools.Utils; + +namespace GodotTools.Inspector +{ + public partial class InspectorPlugin : EditorInspectorPlugin + { + public override bool _CanHandle(GodotObject godotObject) + { + foreach (var script in EnumerateScripts(godotObject)) + { + if (script is CSharpScript) + { + return true; + } + } + return false; + } + + public override void _ParseBegin(GodotObject godotObject) + { + foreach (var script in EnumerateScripts(godotObject)) + { + if (script is not CSharpScript) continue; + + if (File.GetLastWriteTime(script.ResourcePath) > GodotSharpEditor.Instance.LastValidBuildDateTime) + { + AddCustomControl(new InspectorOutOfSyncWarning()); + break; + } + } + } + + private static IEnumerable<Script> EnumerateScripts(GodotObject godotObject) + { + var script = godotObject.GetScript().As<Script>(); + while (script != null) + { + yield return script; + script = script.GetBaseScript(); + } + } + } +} |