Skip to content

Commit 91573d5

Browse files
committed
Added Notifier to queue displaying of matching alerts.
1 parent 4cc1717 commit 91573d5

File tree

11 files changed

+155
-49
lines changed

11 files changed

+155
-49
lines changed

Source/Controls/ControlExtension.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.ComponentModel;
2-
using System.Drawing;
32
using System.Windows.Forms;
43
using Bitmap = System.Drawing.Bitmap;
54

Source/Controls/FissureList.Designer.cs

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Forms/NotificationForm.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ protected override CreateParams CreateParams
3939
/// <summary>
4040
/// Gets or sets the animation time in seconds.
4141
/// </summary>
42-
private double AnimationTime { get; } = .5;
42+
private double AnimationTime { get; } = .45;
4343

44-
private double HoldTime { get; } = 2.5;
44+
private double HoldTime { get; } = 2.75;
4545

4646
public NotificationForm(Control childControl) {
4747
InitializeComponent();
@@ -106,8 +106,9 @@ private async void NotificationForm_Load(object sender, EventArgs e) {
106106
try {
107107
await Animate();
108108
}
109+
// Owning form has been disposed.
109110
catch (ObjectDisposedException) {
110-
// Continue closing the form.
111+
// Abort animation.
111112
}
112113

113114
Close();

Source/Forms/WatForm.Designer.cs

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Forms/WatForm.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ internal WatForm(WatApplication application) {
1616

1717
Application = application;
1818

19-
var solNodes = application.SolNodesDownloader.Download();
2019
application.CurrentWorldState.Update +=
21-
async worldState => OnWorldStateUpdate(worldState.Fissures, await solNodes);
20+
async worldState => OnWorldStateUpdate(worldState.Fissures, await application.SolNodes);
2221

2322
application.AlertsUpdate += OnAlertsUpdate;
2423

Source/Notifier.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
}

Source/Warframe/CurrentWorldState.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using System.Threading.Tasks;
35

46
namespace ScriptFUSION.WarframeAlertTracker.Warframe {
@@ -8,6 +10,8 @@ namespace ScriptFUSION.WarframeAlertTracker.Warframe {
810
internal sealed class CurrentWorldState {
911
public event Action<WorldState> Update;
1012

13+
public event Action<IWorldStateObject> NewObject;
14+
1115
public WorldState CurrentState { get; private set; }
1216

1317
/// <summary>
@@ -40,9 +44,22 @@ private async void Download() {
4044
var worldState = await Downloader.Download();
4145

4246
if (CurrentState == null || worldState?.Time > CurrentState.Time) {
43-
CurrentState = worldState;
44-
Update?.Invoke(worldState);
47+
UpdateWorldState(CurrentState, worldState);
4548
}
4649
}
50+
51+
private void UpdateWorldState(WorldState oldState, WorldState newState) {
52+
CurrentState = newState;
53+
Update?.Invoke(newState);
54+
55+
foreach (var worldStateObject in DetectNewObjects(oldState, newState)) {
56+
NewObject?.Invoke(worldStateObject);
57+
}
58+
}
59+
60+
private static IEnumerable<IWorldStateObject> DetectNewObjects(WorldState oldState, WorldState newState) {
61+
return oldState == null ? Enumerable.Empty<IWorldStateObject>() :
62+
newState.WorldStateObjects.Except(oldState.WorldStateObjects, new WorldStateObjectComparer());
63+
}
4764
}
4865
}

Source/Warframe/IWorldStateObject.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace ScriptFUSION.WarframeAlertTracker.Warframe {
44

55
internal interface IWorldStateObject {
6+
string Id { get; }
7+
68
bool Matches(Alert alert);
79
}
810
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
3+
namespace ScriptFUSION.WarframeAlertTracker.Warframe {
4+
internal class WorldStateObjectComparer : EqualityComparer<IWorldStateObject> {
5+
public override bool Equals(IWorldStateObject x, IWorldStateObject y) {
6+
return x.Id == y.Id;
7+
}
8+
9+
public override int GetHashCode(IWorldStateObject obj) {
10+
return obj.Id.GetHashCode();
11+
}
12+
}
13+
}

Source/WarframeAlertTracker.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
</Reference>
4444
<Reference Include="System" />
4545
<Reference Include="System.Core" />
46+
<Reference Include="System.Web" />
4647
<Reference Include="System.Xml.Linq" />
4748
<Reference Include="System.Data.DataSetExtensions" />
4849
<Reference Include="Microsoft.CSharp" />
@@ -72,6 +73,7 @@
7273
<Compile Include="Forms\NotificationOptionsForm.Designer.cs">
7374
<DependentUpon>NotificationOptionsForm.cs</DependentUpon>
7475
</Compile>
76+
<Compile Include="Notifier.cs" />
7577
<Compile Include="Warframe\FissureTierParser.cs" />
7678
<Compile Include="Warframe\MissionType.cs" />
7779
<Compile Include="Warframe\MissionTypeFormatter.cs" />
@@ -135,6 +137,7 @@
135137
<DependentUpon>WatForm.cs</DependentUpon>
136138
</Compile>
137139
<Compile Include="Warframe\Fissure.cs" />
140+
<Compile Include="Warframe\WorldStateObjectComparer.cs" />
138141
<Compile Include="WatApplication.cs" />
139142
<Compile Include="Downloader.cs" />
140143
<Compile Include="Program.cs" />

0 commit comments

Comments
 (0)