Changed interface for script compliation error

This commit is contained in:
Chandler Cox
2023-01-13 18:02:10 -06:00
parent 5c1d89b145
commit 87e69ca564
6 changed files with 71 additions and 44 deletions

View File

@@ -30,6 +30,11 @@ namespace FlaxEditor.GUI
/// </summary>
public string Text { get; set; }
/// <summary>
/// Gets or sets the status text color
/// </summary>
public Color TextColor { get; set; } = Style.Current.Foreground;
/// <summary>
/// Initializes a new instance of the <see cref="StatusBar"/> class.
/// </summary>
@@ -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);
}
}
}

View File

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

View File

@@ -34,6 +34,7 @@ namespace FlaxEditor.Modules
private Button _outputLogButton;
private List<KeyValuePair<string, DateTime>> _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();
}
/// <inheritdoc />
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,

View File

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

View File

@@ -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...");
}
/// <summary>
/// Called when scripts compilation fails
/// </summary>
private void OnCompilationFail()
{
OnFail("Scripts Compilation Failed");
}
}
}

View File

@@ -16,6 +16,11 @@ namespace FlaxEditor.Progress
/// </summary>
/// <param name="handler">The calling handler.</param>
public delegate void ProgressDelegate(ProgressHandler handler);
/// <summary>
/// Progress failed handler event delegate
/// </summary>
public delegate void ProgressFailedDelegate(ProgressHandler handler, string message);
private float _progress;
private bool _isActive;
@@ -54,7 +59,7 @@ namespace FlaxEditor.Progress
/// <summary>
/// Occurs when the progress fails
/// </summary>
public event ProgressDelegate ProgressFailed;
public event ProgressFailedDelegate ProgressFailed;
/// <summary>
/// Gets a value indicating whether this handler action can be cancelled.
@@ -118,7 +123,7 @@ namespace FlaxEditor.Progress
/// <summary>
/// Called when progress action fails
/// </summary>
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);
}
}
}