1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-25 15:20:10 +00:00
msfs-popout-panel-manager/Shared/StatusMessageWriter.cs

66 lines
2.1 KiB
C#
Raw Normal View History

2022-07-23 19:23:32 +00:00
using System;
2023-07-12 22:41:31 +00:00
using System.Collections.Generic;
2022-07-23 19:23:32 +00:00
namespace MSFSPopoutPanelManager.Shared
{
public class StatusMessageWriter
{
2024-02-28 02:44:21 +00:00
private static readonly List<StatusMessage> Messages = new();
2023-07-12 22:41:31 +00:00
2023-08-16 03:41:14 +00:00
public static event EventHandler<List<StatusMessage>> OnStatusMessage;
2022-07-23 19:23:32 +00:00
2023-08-16 03:41:14 +00:00
public static void WriteMessage(string message, StatusMessageType statusMessageType)
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
Messages.Add(new StatusMessage { Message = message, StatusMessageType = statusMessageType });
2023-07-12 22:41:31 +00:00
if (IsEnabled)
2024-02-28 02:44:21 +00:00
OnStatusMessage?.Invoke(null, Messages);
2023-07-12 22:41:31 +00:00
}
2023-08-16 03:41:14 +00:00
public static void WriteMessageWithNewLine(string message, StatusMessageType statusMessageType)
2022-07-23 19:23:32 +00:00
{
2024-02-28 02:44:21 +00:00
Messages.Add(new StatusMessage { Message = message, StatusMessageType = statusMessageType, NewLine = true });
2023-07-12 22:41:31 +00:00
if (IsEnabled)
2024-02-28 02:44:21 +00:00
OnStatusMessage?.Invoke(null, Messages);
2022-07-23 19:23:32 +00:00
}
2023-08-16 03:41:14 +00:00
public static void WriteExecutingStatusMessage()
{
2024-02-28 02:44:21 +00:00
Messages.Add(new StatusMessage { Message = " (Executing)", StatusMessageType = StatusMessageType.Executing, NewLine = false });
2023-08-16 03:41:14 +00:00
if (IsEnabled)
2024-02-28 02:44:21 +00:00
OnStatusMessage?.Invoke(null, Messages);
2023-08-16 03:41:14 +00:00
}
public static void WriteOkStatusMessage()
2022-07-23 19:23:32 +00:00
{
2024-02-28 02:44:21 +00:00
Messages.Add(new StatusMessage { Message = " (OK)", StatusMessageType = StatusMessageType.Success, NewLine = true });
2023-07-12 22:41:31 +00:00
if (IsEnabled)
2024-02-28 02:44:21 +00:00
OnStatusMessage?.Invoke(null, Messages);
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
2023-08-16 03:41:14 +00:00
public static void WriteFailureStatusMessage()
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
Messages.Add(new StatusMessage { Message = " (FAILED)", StatusMessageType = StatusMessageType.Failure, NewLine = true });
2023-07-12 22:41:31 +00:00
if (IsEnabled)
2024-02-28 02:44:21 +00:00
OnStatusMessage?.Invoke(null, Messages);
2023-08-16 03:41:14 +00:00
}
public static void RemoveLastMessage()
{
2024-02-28 02:44:21 +00:00
Messages.RemoveAt(Messages.Count - 1);
2023-07-12 22:41:31 +00:00
}
public static void ClearMessage()
{
2024-02-28 02:44:21 +00:00
Messages.Clear();
2023-08-16 03:41:14 +00:00
OnStatusMessage?.Invoke(null, new List<StatusMessage>());
2023-07-12 22:41:31 +00:00
}
public static bool IsEnabled { get; set; }
2022-07-23 19:23:32 +00:00
}
}