using Qwilight.Utilities; using Qwilight.ViewModel; namespace Qwilight { public sealed class NotifySystem { public const int ModeComponentID = -1; public const int SetFavoritesID = -2; public const int LoadUIID = -3; public const int SaveLevelID = -4; public const int SaveQwilightID = -5; public const int SaveBundleID = -6; public const int SaveAsBundleID = -7; public const int SaveNoteFileID = -8; public const int SaveUIID = -9; public enum NotifyVariety { OK, Fault, Warning, Info, Handling, Cancelled, Closed } public enum NotifyConfigure { Default, Save, NotSave } public static readonly NotifySystem Instance = new(); int _defaultNotifyID; public void NotifyPendingDefaultNotify() => UIHandler.Instance.HandleParallel(() => { var defaultNotifyCount = ViewModels.Instance.NotifyValue.DefaultNotifyItemCollection.Count(defaultNotifyItem => { var isNew = defaultNotifyItem.IsNew; defaultNotifyItem.IsNew = false; return isNew; }); if (defaultNotifyCount > 0) { Notify(NotifyVariety.Info, NotifyConfigure.NotSave, string.Format(LanguageSystem.Instance.WaitingDefaultNotifyContents, defaultNotifyCount), false, null, () => { ViewModels.Instance.NotifyValue.TabPosition = 0; ViewModels.Instance.NotifyValue.Open(); }); } }); public void NotifyPendingPassNotify() => UIHandler.Instance.HandleParallel(() => { var passNotifyCount = ViewModels.Instance.NotifyValue.PassNotifyItemCollection.Count(passNotifyItem => { var isNew = passNotifyItem.IsNew; passNotifyItem.IsNew = false; return isNew; }); if (passNotifyCount > 0) { Notify(NotifyVariety.Info, NotifyConfigure.NotSave, string.Format(LanguageSystem.Instance.WaitingPassNotifyContents, passNotifyCount), false, null, () => { ViewModels.Instance.NotifyValue.TabPosition = 2; ViewModels.Instance.NotifyValue.Open(); }); } }); public void Notify(NotifyVariety toNotifyVariety, NotifyConfigure toNotifyConfigure, string toNotify, bool isUrgent = false, string audioAlt = null, Action onHandle = null, int? toNotifyID = null) { UIHandler.Instance.HandleParallel(() => { switch (toNotifyConfigure) { case NotifyConfigure.Default: Save(toNotifyVariety, toNotify, !Notify()); break; case NotifyConfigure.Save: Save(toNotifyVariety, toNotify, true); break; case NotifyConfigure.NotSave: Notify(); break; } }); bool Notify() { if (isUrgent || !ViewModels.Instance.MainValue.IsPragmatic) { if (audioAlt == null || audioAlt.Length > 0) { switch (toNotifyVariety) { case NotifyVariety.OK: Utility.HandleUIAudio(audioAlt ?? "Notify OK", "Notify"); break; case NotifyVariety.Info: Utility.HandleUIAudio(audioAlt ?? "Notify", "Notify"); break; case NotifyVariety.Fault: Utility.HandleUIAudio(audioAlt ?? "Notify Fault", "Notify"); break; case NotifyVariety.Warning: Utility.HandleUIAudio(audioAlt ?? "Notify Warning", "Notify"); break; } } ViewModels.Instance.NotifyXamlValue.NewNotify(new() { Variety = toNotifyVariety, Paint = toNotifyVariety switch { NotifyVariety.OK => Paints.PaintOK, NotifyVariety.Info => Paints.PaintInfo, NotifyVariety.Fault => Paints.PaintFault, NotifyVariety.Warning => Paints.PaintWarning, _ => throw new ArgumentException(toNotifyVariety.ToString()) }, Color = toNotifyVariety switch { NotifyVariety.OK => Paints.ColorOK, NotifyVariety.Info => Paints.ColorInfo, NotifyVariety.Fault => Paints.ColorFault, NotifyVariety.Warning => Paints.ColorWarning, _ => throw new ArgumentException(toNotifyVariety.ToString()) }, Contents = toNotify, OnHandle = onHandle, ID = toNotifyID ?? ++_defaultNotifyID }); return true; } return false; } void Save(NotifyVariety toNotifyVariety, string toNotify, bool isNew) { ViewModels.Instance.NotifyValue.DefaultNotifyItemCollection.Insert(0, new() { Variety = toNotifyVariety, Text = toNotify, IsNew = isNew, OnHandle = onHandle }); } } } }