Added failed status bar to indicate if a progress has failed.

This commit is contained in:
Chandler Cox
2023-01-13 09:54:16 -06:00
parent da63e843d8
commit e8c8021fd5
4 changed files with 72 additions and 1 deletions

View File

@@ -96,6 +96,7 @@ namespace FlaxEditor.Modules
handler.ProgressStart += HandlerOnProgressStart;
handler.ProgressChanged += HandlerOnProgressChanged;
handler.ProgressEnd += HandlerOnProgressEnd;
handler.ProgressFailed += HandlerOnProgressFail;
}
/// <summary>
@@ -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();
}
}
}

View File

@@ -31,6 +31,7 @@ namespace FlaxEditor.Modules
{
private Label _progressLabel;
private ProgressBar _progressBar;
private Button _outputLogButton;
private List<KeyValuePair<string, DateTime>> _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;
}
/// <inheritdoc />
@@ -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,

View File

@@ -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;

View File

@@ -51,6 +51,11 @@ namespace FlaxEditor.Progress
/// </summary>
public event ProgressDelegate ProgressEnd;
/// <summary>
/// Occurs when the progress fails
/// </summary>
public event ProgressDelegate ProgressFailed;
/// <summary>
/// Gets a value indicating whether this handler action can be cancelled.
/// </summary>
@@ -109,5 +114,19 @@ namespace FlaxEditor.Progress
ProgressChanged?.Invoke(this);
ProgressEnd?.Invoke(this);
}
/// <summary>
/// Called when progress action fails
/// </summary>
protected virtual void OnFail()
{
if (!_isActive)
throw new InvalidOperationException("Already ended.");
_isActive = false;
_progress = 0;
_infoText = string.Empty;
ProgressFailed?.Invoke(this);
}
}
}