From 87e69ca56466cf46065821d3eb54c64bf106fb31 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 13 Jan 2023 18:02:10 -0600 Subject: [PATCH] Changed interface for script compliation error --- Source/Editor/GUI/StatusBar.cs | 7 +- .../Editor/Modules/ProgressReportingModule.cs | 5 +- Source/Editor/Modules/UIModule.cs | 80 ++++++++++--------- .../Progress/Handlers/BuildingGameProgress.cs | 2 +- .../Handlers/CompileScriptsProgress.cs | 10 ++- Source/Editor/Progress/ProgressHandler.cs | 11 ++- 6 files changed, 71 insertions(+), 44 deletions(-) diff --git a/Source/Editor/GUI/StatusBar.cs b/Source/Editor/GUI/StatusBar.cs index 80a500236..f8f7ae839 100644 --- a/Source/Editor/GUI/StatusBar.cs +++ b/Source/Editor/GUI/StatusBar.cs @@ -30,6 +30,11 @@ namespace FlaxEditor.GUI /// public string Text { get; set; } + /// + /// Gets or sets the status text color + /// + public Color TextColor { get; set; } = Style.Current.Foreground; + /// /// Initializes a new instance of the class. /// @@ -51,7 +56,7 @@ namespace FlaxEditor.GUI Render2D.DrawSprite(style.StatusBarSizeGrip, new Rectangle(Width - 12, 10, 12, 12), style.Foreground); // Draw status text - Render2D.DrawText(style.FontSmall, Text, new Rectangle(4, 0, Width - 20, Height), style.Foreground, TextAlignment.Near, TextAlignment.Center); + Render2D.DrawText(style.FontSmall, Text, new Rectangle(4, 0, Width - 20, Height), TextColor, TextAlignment.Near, TextAlignment.Center); } } } diff --git a/Source/Editor/Modules/ProgressReportingModule.cs b/Source/Editor/Modules/ProgressReportingModule.cs index b038d9a4c..16acd7f8b 100644 --- a/Source/Editor/Modules/ProgressReportingModule.cs +++ b/Source/Editor/Modules/ProgressReportingModule.cs @@ -153,9 +153,10 @@ namespace FlaxEditor.Modules } } - private void HandlerOnProgressFail(ProgressHandler handler) + private void HandlerOnProgressFail(ProgressHandler handler, string message) { - Editor.UI.ProgressFailed(); + UpdateProgress(); + Editor.UI.ProgressFailed(message); } } } diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index 6520f02ee..c72e07c6c 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -34,6 +34,7 @@ namespace FlaxEditor.Modules private Button _outputLogButton; private List> _statusMessages; private ContentStats _contentStats; + private bool _progressFailed; private ContextMenuButton _menuFileSaveScenes; private ContextMenuButton _menuFileCloseScenes; @@ -253,6 +254,12 @@ namespace FlaxEditor.Modules { if (StatusBar == null) return; + + if (ScriptsBuilder.LastCompilationFailed) + { + ProgressFailed("Scripts Compilation Failed"); + return; + } var contentStats = FlaxEngine.Content.Stats; Color color; @@ -305,26 +312,29 @@ namespace FlaxEditor.Modules _progressLabel.Text = text; if (_progressBar != null) { - if (_outputLogButton.Visible) + if (_progressFailed) { - _progressBar.BarColor = Style.Current.ProgressNormal; - var scale = _progressBar.SmoothingScale; - _progressBar.SmoothingScale = 0; - _progressBar.Value = 0; - _progressBar.SmoothingScale = scale; - _outputLogButton.Visible = false; + ResetProgressFailure(); } _progressBar.Value = progress * 100.0f; } } - internal void ProgressFailed() + internal void ProgressFailed(string message) { - _progressBar.BarColor = Color.Red; - _progressLabel.Text = "Failed"; + _progressFailed = true; + StatusBar.StatusColor = Color.Red; + StatusBar.Text = message; _outputLogButton.Visible = true; } + internal void ResetProgressFailure() + { + _outputLogButton.Visible = false; + _progressFailed = false; + UpdateStatusBar(); + } + /// public override void OnInit() { @@ -600,6 +610,30 @@ namespace FlaxEditor.Modules Parent = mainWindow, Offsets = new Margin(0, 0, -StatusBar.DefaultHeight, StatusBar.DefaultHeight), }; + // Output log button + _outputLogButton = new Button() + { + AnchorPreset = AnchorPresets.TopLeft, + Parent = StatusBar, + Visible = false, + Text = "", + Width = 200, + TooltipText = "Opens or shows the output log window.", + BackgroundColor = Color.Transparent, + BorderColor = Color.Transparent, + BackgroundColorHighlighted = Color.Transparent, + BackgroundColorSelected = Color.Transparent, + BorderColorHighlighted = Color.Transparent, + BorderColorSelected = Color.Transparent, + }; + _outputLogButton.LocalY -= 2; + var defaultTextColor = StatusBar.TextColor; + _outputLogButton.HoverBegin += () => StatusBar.TextColor = Style.Current.BackgroundSelected; + _outputLogButton.HoverEnd += () => StatusBar.TextColor = defaultTextColor; + _outputLogButton.Clicked += () => + { + Editor.Windows.OutputLogWin.FocusOrShow(); + }; // Progress bar with label const float progressBarWidth = 120.0f; @@ -619,32 +653,6 @@ namespace FlaxEditor.Modules Parent = progressPanel, Offsets = new Margin(-progressBarWidth - progressBarRightMargin, progressBarWidth, progressBarHeight * -0.5f, progressBarHeight), }; - _outputLogButton = new Button() - { - AnchorPreset = AnchorPresets.TopLeft, - Parent = _progressBar, - Visible = false, - Text = "Output Log", - TooltipText = "Opens or shows the output log window.", - BackgroundColor = Color.Transparent, - BorderColor = Color.Transparent, - BackgroundColorHighlighted = Color.Transparent, - BackgroundColorSelected = Color.Transparent, - BorderColorHighlighted = Color.Transparent, - BorderColorSelected = Color.Transparent, - }; - _outputLogButton.LocalY -= 2; - var defaultTextColor = _outputLogButton.TextColor; - _outputLogButton.HoverBegin += () => _outputLogButton.TextColor = Style.Current.BackgroundSelected; - _outputLogButton.HoverEnd += () => _outputLogButton.TextColor = defaultTextColor; - _outputLogButton.Clicked += () => - { - Editor.Windows.OutputLogWin.FocusOrShow(); - _progressBar.BarColor = Style.Current.ProgressNormal; - _progressBar.Value = 0; - ProgressVisible = false; - _outputLogButton.Visible = false; - }; _progressLabel = new Label { HorizontalAlignment = TextAlignment.Far, diff --git a/Source/Editor/Progress/Handlers/BuildingGameProgress.cs b/Source/Editor/Progress/Handlers/BuildingGameProgress.cs index 4f116be11..f5152d11c 100644 --- a/Source/Editor/Progress/Handlers/BuildingGameProgress.cs +++ b/Source/Editor/Progress/Handlers/BuildingGameProgress.cs @@ -39,7 +39,7 @@ namespace FlaxEditor.Progress.Handlers OnUpdate(0, "Starting building game.."); break; case GameCooker.EventType.BuildFailed: - OnFail(); + OnEnd(); break; case GameCooker.EventType.BuildDone: OnEnd(); diff --git a/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs b/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs index 085a0fddf..811a2b73f 100644 --- a/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs +++ b/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs @@ -21,7 +21,7 @@ namespace FlaxEditor.Progress.Handlers // Link for events ScriptsBuilder.CompilationBegin += OnStart; ScriptsBuilder.CompilationSuccess += OnEnd; - ScriptsBuilder.CompilationFailed += OnFail; + ScriptsBuilder.CompilationFailed += OnCompilationFail; ScriptsBuilder.CompilationStarted += () => OnUpdate(0.2f, "Compiling scripts..."); ScriptsBuilder.ScriptsReloadCalled += () => OnUpdate(0.8f, "Reloading scripts..."); ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin; @@ -57,5 +57,13 @@ namespace FlaxEditor.Progress.Handlers OnUpdate(0, "Starting scripts compilation..."); } + + /// + /// Called when scripts compilation fails + /// + private void OnCompilationFail() + { + OnFail("Scripts Compilation Failed"); + } } } diff --git a/Source/Editor/Progress/ProgressHandler.cs b/Source/Editor/Progress/ProgressHandler.cs index 71e8a1a20..2738b7c57 100644 --- a/Source/Editor/Progress/ProgressHandler.cs +++ b/Source/Editor/Progress/ProgressHandler.cs @@ -16,6 +16,11 @@ namespace FlaxEditor.Progress /// /// The calling handler. public delegate void ProgressDelegate(ProgressHandler handler); + + /// + /// Progress failed handler event delegate + /// + public delegate void ProgressFailedDelegate(ProgressHandler handler, string message); private float _progress; private bool _isActive; @@ -54,7 +59,7 @@ namespace FlaxEditor.Progress /// /// Occurs when the progress fails /// - public event ProgressDelegate ProgressFailed; + public event ProgressFailedDelegate ProgressFailed; /// /// Gets a value indicating whether this handler action can be cancelled. @@ -118,7 +123,7 @@ namespace FlaxEditor.Progress /// /// Called when progress action fails /// - protected virtual void OnFail() + protected virtual void OnFail(string message) { if (!_isActive) throw new InvalidOperationException("Already ended."); @@ -126,7 +131,7 @@ namespace FlaxEditor.Progress _isActive = false; _progress = 0; _infoText = string.Empty; - ProgressFailed?.Invoke(this); + ProgressFailed?.Invoke(this, message); } } }