You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
Inspector ⚠️ when C# props might be out of date
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user