Skip to content

Commit

Permalink
feat: adding filter to log settings
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Dec 16, 2022
1 parent 42d5368 commit d50e754
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions Assets/Mirage/Editor/Logging/LogLevelsGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class LogLevelsGUI
{
private static LogLevelsGUI _drawer;

// -1 => no type, will show as empty dropdown
private const LogType NO_LEVEL = (LogType)(-1);

public static void DrawSettings(LogSettingsSO settings)
{
if (_drawer == null)
Expand Down Expand Up @@ -43,6 +46,7 @@ public static LogSettingsSO DrawCreateNewButton()
/// Keep track of gui changed. If it has changed then we need to update <see cref="LogFactory"/> and save the new levels to file
/// </summary>
private bool guiChanged;
private LogType? _filter;

public LogLevelsGUI(LogSettingsSO settings)
{
Expand All @@ -61,11 +65,16 @@ public void Draw()
using (new LogGUIScope())
{
EditorGUILayout.HelpBox("You may need to run your game a few times for this list to properly populate!", MessageType.Info);
DrawAllLevelDropdown();

DrawSetAllDropDown();

EditorGUILayout.Space();

DrawFilterByDropDown();

EditorGUILayout.Space();

foreach (var group in settings.LogLevels.GroupBy(x => x.Namespace).OrderBy(x => x.Key))
foreach (var group in GetGroups())
{
DrawGroup(group);
}
Expand All @@ -81,7 +90,19 @@ public void Draw()
}
}

private void DrawAllLevelDropdown()
private IOrderedEnumerable<IGrouping<string, LogSettingsSO.LoggerSettings>> GetGroups()
{
IEnumerable<LogSettingsSO.LoggerSettings> levels = settings.LogLevels;
if (_filter.HasValue)
{
var filter = _filter.Value;
levels = levels.Where(x => x.logLevel == filter);
}

return levels.GroupBy(x => x.Namespace).OrderBy(x => x.Key);
}

private void DrawSetAllDropDown()
{
using (var scope = new EditorGUI.ChangeCheckScope())
{
Expand All @@ -93,6 +114,20 @@ private void DrawAllLevelDropdown()
}
}
}
private void DrawFilterByDropDown()
{
var result = (LogType)EditorGUILayout.EnumPopup("filter by level", _filter ?? NO_LEVEL);

if (result == NO_LEVEL)
_filter = null;
else
_filter = result;

if (GUILayout.Button("Clear filter", GUILayout.Width(100)))
{
_filter = null;
}
}

private void DrawGroup(IGrouping<string, LogSettingsSO.LoggerSettings> group)
{
Expand Down Expand Up @@ -209,8 +244,7 @@ private LogType GetGroupLevel(IEnumerable<LogSettingsSO.LoggerSettings> group)
}
else
{
// -1 => no type, will show as empty dropdown
return (LogType)(-1);
return NO_LEVEL;
}
}
private void SetGroupLevel(IEnumerable<LogSettingsSO.LoggerSettings> group, LogType level)
Expand Down

0 comments on commit d50e754

Please sign in to comment.