Cleanup code

#1437
This commit is contained in:
Wojtek Figat
2025-02-23 20:29:58 +01:00
parent 1c3f7fcec0
commit bae381430a
2 changed files with 21 additions and 37 deletions

View File

@@ -95,15 +95,15 @@ namespace FlaxEditor.Windows
{ {
case LogType.Warning: case LogType.Warning:
Group = LogGroup.Warning; Group = LogGroup.Warning;
Icon = _window.IconWarning; Icon = _window._iconWarning;
break; break;
case LogType.Info: case LogType.Info:
Group = LogGroup.Info; Group = LogGroup.Info;
Icon = _window.IconInfo; Icon = _window._iconInfo;
break; break;
default: default:
Group = LogGroup.Error; Group = LogGroup.Error;
Icon = _window.IconError; Icon = _window._iconError;
break; break;
} }
} }
@@ -131,7 +131,7 @@ namespace FlaxEditor.Windows
else if (index % 2 == 0) else if (index % 2 == 0)
Render2D.FillRectangle(clientRect, style.Background * 0.9f); Render2D.FillRectangle(clientRect, style.Background * 0.9f);
var color = Group == LogGroup.Error ? _window.ErrorColor : (Group == LogGroup.Warning ? _window.WarningColor : _window.InfoColor); var color = Group == LogGroup.Error ? _window._colorError : (Group == LogGroup.Warning ? _window._colorWarning : _window._colorInfo);
// Icon // Icon
Render2D.DrawSprite(Icon, new Rectangle(5, 0, 32, 32), color); Render2D.DrawSprite(Icon, new Rectangle(5, 0, 32, 32), color);
@@ -305,14 +305,12 @@ namespace FlaxEditor.Windows
private readonly ToolStripButton[] _groupButtons = new ToolStripButton[3]; private readonly ToolStripButton[] _groupButtons = new ToolStripButton[3];
private LogType _iconType = LogType.Info; private LogType _iconType = LogType.Info;
private SpriteHandle _iconInfo;
internal SpriteHandle IconInfo; private SpriteHandle _iconWarning;
internal Color InfoColor; private SpriteHandle _iconError;
internal SpriteHandle IconWarning; private Color _colorInfo;
internal Color WarningColor; private Color _colorWarning;
internal SpriteHandle IconError; private Color _colorError;
internal Color ErrorColor;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DebugLogWindow"/> class. /// Initializes a new instance of the <see cref="DebugLogWindow"/> class.
@@ -322,7 +320,7 @@ namespace FlaxEditor.Windows
: base(editor, true, ScrollBars.None) : base(editor, true, ScrollBars.None)
{ {
Title = "Debug Log"; Title = "Debug Log";
Icon = IconInfo; Icon = _iconInfo;
FlaxEditor.Utilities.Utils.SetupCommonInputActions(this); FlaxEditor.Utilities.Utils.SetupCommonInputActions(this);
// Toolstrip // Toolstrip
@@ -366,7 +364,6 @@ namespace FlaxEditor.Windows
editor.Options.Apply(editor.Options.Options); editor.Options.Apply(editor.Options.Options);
}).SetAutoCheck(true).LinkTooltip("Shows/hides info messages"); }).SetAutoCheck(true).LinkTooltip("Shows/hides info messages");
UpdateCount(); UpdateCount();
OnEditorOptionsChanged(Editor.Options.Options);
// Split panel // Split panel
_split = new SplitPanel(Orientation.Vertical, ScrollBars.Vertical, ScrollBars.Both) _split = new SplitPanel(Orientation.Vertical, ScrollBars.Vertical, ScrollBars.Both)
@@ -399,32 +396,21 @@ namespace FlaxEditor.Windows
}; };
// Cache entries icons // Cache entries icons
IconInfo = Editor.Icons.Info64; _iconInfo = Editor.Icons.Info64;
IconWarning = Editor.Icons.Warning64; _iconWarning = Editor.Icons.Warning64;
IconError = Editor.Icons.Error64; _iconError = Editor.Icons.Error64;
//Cache entries color
var interfaceOptions = Editor.Options.Options.Interface;
InfoColor = interfaceOptions.OutputLogTextColor;
WarningColor = interfaceOptions.OutputLogWarningTextColor;
ErrorColor = interfaceOptions.OutputLogErrorTextColor;
// Bind events // Bind events
Editor.Options.OptionsChanged += OnEditorOptionsChanged; Editor.Options.OptionsChanged += OnEditorOptionsChanged;
OnEditorOptionsChanged(Editor.Options.Options);
Debug.Logger.LogHandler.SendLog += LogHandlerOnSendLog; Debug.Logger.LogHandler.SendLog += LogHandlerOnSendLog;
Debug.Logger.LogHandler.SendExceptionLog += LogHandlerOnSendExceptionLog; Debug.Logger.LogHandler.SendExceptionLog += LogHandlerOnSendExceptionLog;
// Init editor options
OnEditorOptionsChanged(Editor.Options.Options);
} }
private void OnEditorOptionsChanged(EditorOptions options) private void OnEditorOptionsChanged(EditorOptions options)
{ {
if (_timestampsFormats == options.Interface.DebugLogTimestampsFormat &&
InfoColor == options.Interface.OutputLogTextColor &&
WarningColor == options.Interface.OutputLogWarningTextColor &&
ErrorColor == options.Interface.OutputLogErrorTextColor)
return;
_timestampsFormats = options.Interface.DebugLogTimestampsFormat; _timestampsFormats = options.Interface.DebugLogTimestampsFormat;
_clearOnPlayButton.Checked = options.Interface.DebugLogClearOnPlay; _clearOnPlayButton.Checked = options.Interface.DebugLogClearOnPlay;
_collapseLogsButton.Checked = options.Interface.DebugLogCollapse; _collapseLogsButton.Checked = options.Interface.DebugLogCollapse;
@@ -432,10 +418,9 @@ namespace FlaxEditor.Windows
_groupButtons[0].Checked = options.Interface.DebugLogShowErrorMessages; _groupButtons[0].Checked = options.Interface.DebugLogShowErrorMessages;
_groupButtons[1].Checked = options.Interface.DebugLogShowWarningMessages; _groupButtons[1].Checked = options.Interface.DebugLogShowWarningMessages;
_groupButtons[2].Checked = options.Interface.DebugLogShowInfoMessages; _groupButtons[2].Checked = options.Interface.DebugLogShowInfoMessages;
_colorInfo = options.Interface.OutputLogTextColor;
InfoColor = options.Interface.OutputLogTextColor; _colorWarning = options.Interface.OutputLogWarningTextColor;
WarningColor = options.Interface.OutputLogWarningTextColor; _colorError = options.Interface.OutputLogErrorTextColor;
ErrorColor = options.Interface.OutputLogErrorTextColor;
} }
/// <summary> /// <summary>
@@ -445,7 +430,6 @@ namespace FlaxEditor.Windows
{ {
if (_entriesPanel == null) if (_entriesPanel == null)
return; return;
RemoveEntries(); RemoveEntries();
} }

View File

@@ -604,7 +604,7 @@ namespace FlaxEditor.Windows
var cachedScrollValue = _vScroll.Value; var cachedScrollValue = _vScroll.Value;
var cachedSelection = _output.SelectionRange; var cachedSelection = _output.SelectionRange;
var cachedOutputTargetViewOffset = _output.TargetViewOffset; var cachedOutputTargetViewOffset = _output.TargetViewOffset;
var isBottomScroll = _vScroll.Value >= _vScroll.Maximum - (_scrollSize*2) || wasEmpty; var isBottomScroll = _vScroll.Value >= _vScroll.Maximum - (_scrollSize * 2) || wasEmpty;
_output.Text = _textBuffer.ToString(); _output.Text = _textBuffer.ToString();
_output.TargetViewOffset = cachedOutputTargetViewOffset; _output.TargetViewOffset = cachedOutputTargetViewOffset;
_textBufferCount = _entries.Count; _textBufferCount = _entries.Count;