Move Godot events to instance

This commit is contained in:
Matt Parker
2025-09-30 19:43:49 +10:00
parent 51817f580e
commit eb88897a2a
9 changed files with 43 additions and 36 deletions

View File

@@ -42,12 +42,12 @@ public partial class BottomPanelManager : Panel
{ BottomPanelType.IdeDiagnostics, _ideDiagnosticsPanel }
};
GodotGlobalEvents.BottomPanelTabSelected += OnBottomPanelTabSelected;
GodotGlobalEvents.Instance.BottomPanelTabSelected += OnBottomPanelTabSelected;
}
public override void _ExitTree()
{
GodotGlobalEvents.BottomPanelTabSelected -= OnBottomPanelTabSelected;
GodotGlobalEvents.Instance.BottomPanelTabSelected -= OnBottomPanelTabSelected;
}
private async Task OnBottomPanelTabSelected(BottomPanelType? type)
@@ -56,11 +56,11 @@ public partial class BottomPanelManager : Panel
{
if (type == null)
{
GodotGlobalEvents.InvokeBottomPanelVisibilityChangeRequested(false);
GodotGlobalEvents.Instance.InvokeBottomPanelVisibilityChangeRequested(false);
}
else
{
GodotGlobalEvents.InvokeBottomPanelVisibilityChangeRequested(true);
GodotGlobalEvents.Instance.InvokeBottomPanelVisibilityChangeRequested(true);
}
foreach (var kvp in _panelTypeMap)
{

View File

@@ -39,7 +39,7 @@ public partial class CodeEditorPanel : MarginContainer
private void OnTabClicked(long tab)
{
var sharpIdeFile = _tabContainer.GetChild<SharpIdeCodeEdit>((int)tab).SharpIdeFile;
GodotGlobalEvents.InvokeFileExternallySelected(sharpIdeFile);
GodotGlobalEvents.Instance.InvokeFileExternallySelected(sharpIdeFile);
}
private void OnTabClosePressed(long tabIndex)
@@ -87,7 +87,7 @@ public partial class CodeEditorPanel : MarginContainer
if (executionStopInfo.FilePath != currentSharpIdeFile?.Path)
{
var file = Solution.AllFiles.Single(s => s.Path == executionStopInfo.FilePath);
await GodotGlobalEvents.InvokeFileExternallySelectedAndWait(file).ConfigureAwait(false);
await GodotGlobalEvents.Instance.InvokeFileExternallySelectedAndWait(file).ConfigureAwait(false);
}
var lineInt = executionStopInfo.Line - 1; // Debugging is 1-indexed, Godot is 0-indexed
Guard.Against.Negative(lineInt, nameof(lineInt));

View File

@@ -21,12 +21,12 @@ public partial class LeftSideBar : Panel
_debugButton = GetNode<Button>("%DebugButton");
_ideDiagnosticsButton = GetNode<Button>("%IdeDiagnosticsButton");
_problemsButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Problems : null);
_runButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Run : null);
_buildButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Build : null);
_debugButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Debug : null);
_ideDiagnosticsButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.IdeDiagnostics : null);
GodotGlobalEvents.BottomPanelTabExternallySelected += OnBottomPanelTabExternallySelected;
_problemsButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Problems : null);
_runButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Run : null);
_buildButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Build : null);
_debugButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Debug : null);
_ideDiagnosticsButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.IdeDiagnostics : null);
GodotGlobalEvents.Instance.BottomPanelTabExternallySelected += OnBottomPanelTabExternallySelected;
}
private async Task OnBottomPanelTabExternallySelected(BottomPanelType arg)

View File

@@ -124,6 +124,6 @@ public partial class ProblemsPanel : Control
var file = projectModel.Files
.Concat(projectModel.Folders.SelectMany(f => f.GetAllFiles()))
.Single(s => s.Path == diagnostic.Location.SourceTree?.GetMappedLineSpan(diagnostic.Location.SourceSpan).Path);
GodotGlobalEvents.InvokeFileExternallySelected(file);
GodotGlobalEvents.Instance.InvokeFileExternallySelected(file);
}
}

View File

@@ -51,13 +51,13 @@ public partial class RunMenuItem : HBoxContainer
private async void OnRunButtonPressed()
{
GodotGlobalEvents.InvokeBottomPanelTabExternallySelected(BottomPanelType.Run);
GodotGlobalEvents.Instance.InvokeBottomPanelTabExternallySelected(BottomPanelType.Run);
await Singletons.RunService.RunProject(Project).ConfigureAwait(false);
}
private async void OnDebugButtonPressed()
{
GodotGlobalEvents.InvokeBottomPanelTabExternallySelected(BottomPanelType.Debug);
GodotGlobalEvents.Instance.InvokeBottomPanelTabExternallySelected(BottomPanelType.Debug);
await Singletons.RunService.RunProject(Project, true).ConfigureAwait(false);
}
}

View File

@@ -27,7 +27,7 @@ public partial class SearchResultComponent : MarginContainer
private void OnButtonPressed()
{
var fileLinePosition = new SharpIdeFileLinePosition { Line = Result.Line, Column = Result.StartColumn };
GodotGlobalEvents.InvokeFileExternallySelected(Result.File, fileLinePosition);
GodotGlobalEvents.Instance.InvokeFileExternallySelected(Result.File, fileLinePosition);
ParentSearchWindow.Hide();
}

View File

@@ -25,7 +25,7 @@ public partial class SolutionExplorerPanel : MarginContainer
{
_tree = GetNode<Tree>("Tree");
_tree.ItemMouseSelected += TreeOnItemMouseSelected;
GodotGlobalEvents.FileExternallySelected += OnFileExternallySelected;
GodotGlobalEvents.Instance.FileExternallySelected += OnFileExternallySelected;
}
private void TreeOnItemMouseSelected(Vector2 mousePosition, long mouseButtonIndex)
@@ -36,13 +36,13 @@ public partial class SolutionExplorerPanel : MarginContainer
if (sharpIdeFileContainer is null) return;
var sharpIdeFile = sharpIdeFileContainer.File;
Guard.Against.Null(sharpIdeFile, nameof(sharpIdeFile));
GodotGlobalEvents.InvokeFileSelected(sharpIdeFile);
GodotGlobalEvents.Instance.InvokeFileSelected(sharpIdeFile);
}
private async Task OnFileExternallySelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition)
{
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
var task = GodotGlobalEvents.InvokeFileSelectedAndWait(file, fileLinePosition);
var task = GodotGlobalEvents.Instance.InvokeFileSelectedAndWait(file, fileLinePosition);
var item = FindItemRecursive(_tree.GetRoot(), file);
if (item is not null)
{