From e8c8021fd55df107aeea066f9c2599858af58ab5 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 13 Jan 2023 09:54:16 -0600 Subject: [PATCH 1/5] Added failed status bar to indicate if a progress has failed. --- .../Editor/Modules/ProgressReportingModule.cs | 7 +++ Source/Editor/Modules/UIModule.cs | 45 +++++++++++++++++++ .../Handlers/CompileScriptsProgress.cs | 2 +- Source/Editor/Progress/ProgressHandler.cs | 19 ++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Modules/ProgressReportingModule.cs b/Source/Editor/Modules/ProgressReportingModule.cs index 713292657..b038d9a4c 100644 --- a/Source/Editor/Modules/ProgressReportingModule.cs +++ b/Source/Editor/Modules/ProgressReportingModule.cs @@ -96,6 +96,7 @@ namespace FlaxEditor.Modules handler.ProgressStart += HandlerOnProgressStart; handler.ProgressChanged += HandlerOnProgressChanged; handler.ProgressEnd += HandlerOnProgressEnd; + handler.ProgressFailed += HandlerOnProgressFail; } /// @@ -113,6 +114,7 @@ namespace FlaxEditor.Modules handler.ProgressStart -= HandlerOnProgressStart; handler.ProgressChanged -= HandlerOnProgressChanged; handler.ProgressEnd -= HandlerOnProgressEnd; + handler.ProgressFailed -= HandlerOnProgressFail; } private void UpdateProgress() @@ -150,5 +152,10 @@ namespace FlaxEditor.Modules Editor.Windows.FlashMainWindow(); } } + + private void HandlerOnProgressFail(ProgressHandler handler) + { + Editor.UI.ProgressFailed(); + } } } diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index a3bdf8ee0..d261ba33a 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -31,6 +31,7 @@ namespace FlaxEditor.Modules { private Label _progressLabel; private ProgressBar _progressBar; + private Button _outputLogButton; private List> _statusMessages; private ContentStats _contentStats; @@ -303,7 +304,25 @@ namespace FlaxEditor.Modules if (_progressLabel != null) _progressLabel.Text = text; if (_progressBar != null) + { + if (_outputLogButton.Visible) + { + _progressBar.BarColor = Style.Current.ProgressNormal; + var scale = _progressBar.SmoothingScale; + _progressBar.SmoothingScale = 0; + _progressBar.Value = 0; + _progressBar.SmoothingScale = scale; + _outputLogButton.Visible = false; + } _progressBar.Value = progress * 100.0f; + } + } + + internal void ProgressFailed() + { + _progressBar.BarColor = Color.Red; + _progressLabel.Text = "Failed"; + _outputLogButton.Visible = true; } /// @@ -600,6 +619,32 @@ 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/CompileScriptsProgress.cs b/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs index ef814a0fb..085a0fddf 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 += OnEnd; + ScriptsBuilder.CompilationFailed += OnFail; ScriptsBuilder.CompilationStarted += () => OnUpdate(0.2f, "Compiling scripts..."); ScriptsBuilder.ScriptsReloadCalled += () => OnUpdate(0.8f, "Reloading scripts..."); ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin; diff --git a/Source/Editor/Progress/ProgressHandler.cs b/Source/Editor/Progress/ProgressHandler.cs index 74b31ff1f..71e8a1a20 100644 --- a/Source/Editor/Progress/ProgressHandler.cs +++ b/Source/Editor/Progress/ProgressHandler.cs @@ -51,6 +51,11 @@ namespace FlaxEditor.Progress /// public event ProgressDelegate ProgressEnd; + /// + /// Occurs when the progress fails + /// + public event ProgressDelegate ProgressFailed; + /// /// Gets a value indicating whether this handler action can be cancelled. /// @@ -109,5 +114,19 @@ namespace FlaxEditor.Progress ProgressChanged?.Invoke(this); ProgressEnd?.Invoke(this); } + + /// + /// Called when progress action fails + /// + protected virtual void OnFail() + { + if (!_isActive) + throw new InvalidOperationException("Already ended."); + + _isActive = false; + _progress = 0; + _infoText = string.Empty; + ProgressFailed?.Invoke(this); + } } } From 595d2235d3e75c9c1486c5785dfcd8e9960ec90a Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 13 Jan 2023 10:28:58 -0600 Subject: [PATCH 2/5] Hide progress bar on click --- Source/Editor/Modules/UIModule.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index d261ba33a..6520f02ee 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -640,10 +640,10 @@ namespace FlaxEditor.Modules _outputLogButton.Clicked += () => { Editor.Windows.OutputLogWin.FocusOrShow(); - //_progressBar.BarColor = Style.Current.ProgressNormal; - //_progressBar.Value = 0; - //ProgressVisible = false; - //_outputLogButton.Visible = false; + _progressBar.BarColor = Style.Current.ProgressNormal; + _progressBar.Value = 0; + ProgressVisible = false; + _outputLogButton.Visible = false; }; _progressLabel = new Label { From 5c1d89b1456b8776dca911cb572cdacffdcc8322 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 13 Jan 2023 10:37:06 -0600 Subject: [PATCH 3/5] Added fail progress bar to building game failure. --- Source/Editor/Progress/Handlers/BuildingGameProgress.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Progress/Handlers/BuildingGameProgress.cs b/Source/Editor/Progress/Handlers/BuildingGameProgress.cs index f5152d11c..4f116be11 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: - OnEnd(); + OnFail(); break; case GameCooker.EventType.BuildDone: OnEnd(); From 87e69ca56466cf46065821d3eb54c64bf106fb31 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 13 Jan 2023 18:02:10 -0600 Subject: [PATCH 4/5] 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); } } } From 1421e63aa8843fccdcdecdacf7c3609d5127c77b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 15 Jan 2023 13:33:07 +0100 Subject: [PATCH 5/5] Minor cleanup #891 --- .../Progress/Handlers/CompileScriptsProgress.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs b/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs index 811a2b73f..59d40463e 100644 --- a/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs +++ b/Source/Editor/Progress/Handlers/CompileScriptsProgress.cs @@ -1,6 +1,5 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. -using FlaxEngine; using FlaxEditor.Utilities; namespace FlaxEditor.Progress.Handlers @@ -21,7 +20,7 @@ namespace FlaxEditor.Progress.Handlers // Link for events ScriptsBuilder.CompilationBegin += OnStart; ScriptsBuilder.CompilationSuccess += OnEnd; - ScriptsBuilder.CompilationFailed += OnCompilationFail; + ScriptsBuilder.CompilationFailed += OnCompilationFailed; ScriptsBuilder.CompilationStarted += () => OnUpdate(0.2f, "Compiling scripts..."); ScriptsBuilder.ScriptsReloadCalled += () => OnUpdate(0.8f, "Reloading scripts..."); ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin; @@ -45,6 +44,11 @@ namespace FlaxEditor.Progress.Handlers Newtonsoft.Json.JsonSerializer.ClearCache(); } + private void OnCompilationFailed() + { + OnFail("Scripts compilation failed"); + } + private void OnScriptsReloadEnd() { _selectionCache.Restore(); @@ -57,13 +61,5 @@ namespace FlaxEditor.Progress.Handlers OnUpdate(0, "Starting scripts compilation..."); } - - /// - /// Called when scripts compilation fails - /// - private void OnCompilationFail() - { - OnFail("Scripts Compilation Failed"); - } } }