|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using System.Windows.Forms; |
| 5 | +using ScriptFUSION.WarframeAlertTracker.Controls; |
| 6 | +using ScriptFUSION.WarframeAlertTracker.Forms; |
| 7 | +using ScriptFUSION.WarframeAlertTracker.Warframe; |
| 8 | + |
| 9 | +namespace ScriptFUSION.WarframeAlertTracker { |
| 10 | + internal sealed class Notifier { |
| 11 | + private readonly Queue<Control> queue = new Queue<Control>(); |
| 12 | + |
| 13 | + private WatApplication Application { get; } |
| 14 | + |
| 15 | + private NotificationForm Notification { get; set; } |
| 16 | + |
| 17 | + public Notifier(WatApplication application) { |
| 18 | + Application = application; |
| 19 | + application.CurrentWorldState.NewObject += OnNewWorldStateObject; |
| 20 | + } |
| 21 | + |
| 22 | + private void Notify(Control control) { |
| 23 | + if (Notification != null) { |
| 24 | + Queue(control); |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + Notification = new NotificationForm(control); |
| 29 | + Notification.Closed += delegate { |
| 30 | + Notification = null; |
| 31 | + Next(); |
| 32 | + }; |
| 33 | + |
| 34 | + Notification.Show(Application.MainForm); |
| 35 | + } |
| 36 | + |
| 37 | + private void Queue(Control control) { |
| 38 | + queue.Enqueue(control); |
| 39 | + } |
| 40 | + |
| 41 | + private void Next() { |
| 42 | + if (queue.Count > 0) { |
| 43 | + Notify(queue.Dequeue()); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + private async void OnNewWorldStateObject(IWorldStateObject worldStateObject) { |
| 48 | + if (!Application.AlertCollection.Matches(worldStateObject)) { |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + Notify(await ControlFromWorldStateObject(worldStateObject)); |
| 53 | + } |
| 54 | + |
| 55 | + private async Task<Control> ControlFromWorldStateObject(IWorldStateObject worldStateObject) { |
| 56 | + switch (worldStateObject) { |
| 57 | + case Fissure fissure: |
| 58 | + var fissureControl = new FissureControl { |
| 59 | + ImageRepository = Application.ImageRepository, |
| 60 | + Active = true, |
| 61 | + }; |
| 62 | + fissureControl.Update(fissure, await Application.SolNodes); |
| 63 | + |
| 64 | + return fissureControl; |
| 65 | + } |
| 66 | + |
| 67 | + throw new ApplicationException("Unrecognized world state object type."); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments