-
Notifications
You must be signed in to change notification settings - Fork 244
/
Notifications.cs
223 lines (196 loc) · 7.45 KB
/
Notifications.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
namespace LeagueSharp.Common
{
using System;
using System.Collections.Concurrent;
public class Notifications
{
#region Static Fields
/// <summary>
/// The notifications list
/// </summary>
private static readonly ConcurrentDictionary<string, INotification> NotificationsList =
new ConcurrentDictionary<string, INotification>();
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes static members of the <see cref="Notifications" /> class.
/// </summary>
static Notifications()
{
Game.OnUpdate += Game_OnGameUpdate;
Drawing.OnDraw += Drawing_OnDraw;
Drawing.OnPostReset += Drawing_OnPostReset;
Drawing.OnPreReset += Drawing_OnPreReset;
AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
Game.OnWndProc += Game_OnWndProc;
}
#endregion
#region Public Methods and Operators
/// <summary>
/// Adds a notification to the notification list
/// </summary>
/// <param name="notification">Notification Instance</param>
/// <returns>Boolean</returns>
public static bool AddNotification(INotification notification)
{
return (notification != null) && NotificationsList.TryAdd(notification.GetId(), notification);
}
/// <summary>
/// Adds a simple notification to the notification list
/// </summary>
/// <param name="text">Display Text</param>
/// <param name="duration">Duration (-1 for infinite)</param>
/// <param name="dispose">Dispose upon ending</param>
/// <returns>Notification.</returns>
public static Notification AddNotification(string text, int duration = -0x1, bool dispose = true)
{
var notification = new Notification(text, duration, dispose);
NotificationsList.TryAdd(notification.GetId(), notification);
return notification;
}
/// <summary>
/// Returns the next free location
/// </summary>
/// <returns>Location</returns>
public static int GetLocation()
{
return 0x55 + 0x1E * NotificationsList.Count;
}
/// <summary>
/// Returns the location free location
/// </summary>
/// <returns>Location</returns>
public static int GetLocation(INotification notification)
{
var i = 0;
var guid = notification.GetId();
foreach (var notification_ in NotificationsList)
{
if (notification_.Key == guid)
{
return 0x55 + 0x1E * i;
}
i++;
}
return 0x55 + 0x1E * i;
}
/// <summary>
/// Validates if a notification currently exists inside the list.
/// </summary>
/// <param name="notification">Notification Instance</param>
/// <returns>Boolean</returns>
public static bool IsValidNotification(INotification notification)
{
return NotificationsList.ContainsKey(notification.GetId());
}
/// <summary>
/// Validates if a notification currently exists inside the list.
/// </summary>
/// <param name="id">Notification GUID</param>
/// <returns><c>true</c> if the specified identifier is a valid notification; otherwise, <c>false</c>.</returns>
public static bool IsValidNotification(string id)
{
return NotificationsList.ContainsKey(id);
}
/// <summary>
/// Removes a notification from the notification list
/// </summary>
/// <param name="notification">Notification Instance</param>
/// <returns>Boolean</returns>
public static bool RemoveNotification(INotification notification)
{
INotification dump;
return NotificationsList.TryRemove(notification.GetId(), out dump);
}
/// <summary>
/// Removes a notification from the notification list
/// </summary>
/// <param name="id">Notification GUID</param>
/// <param name="notification">Notification Instance</param>
/// <returns>Boolean</returns>
public static bool RemoveNotification(string id, out INotification notification)
{
return NotificationsList.TryRemove(id, out notification);
}
/// <summary>
/// Removes a notification from the notification list
/// </summary>
/// <param name="id">Notification GUID</param>
/// <returns>Boolean</returns>
public static bool RemoveNotification(string id)
{
INotification dump;
return NotificationsList.TryRemove(id, out dump);
}
#endregion
#region Methods
/// <summary>
/// Fired when the current domain unloads
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void CurrentDomain_DomainUnload(object sender, EventArgs e)
{
foreach (var notification in NotificationsList)
{
notification.Value.OnDomainUnload();
}
}
/// <summary>
/// Fired when the game is drawn.
/// </summary>
/// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void Drawing_OnDraw(EventArgs args)
{
foreach (var notification in NotificationsList)
{
notification.Value.OnDraw();
}
}
/// <summary>
/// Fired when the DirectX device is reset.
/// </summary>
/// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void Drawing_OnPostReset(EventArgs args)
{
foreach (var notification in NotificationsList)
{
notification.Value.OnPostReset();
}
}
/// <summary>
/// Fired before the DirectX device is reset.
/// </summary>
/// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void Drawing_OnPreReset(EventArgs args)
{
foreach (var notification in NotificationsList)
{
notification.Value.OnPreReset();
}
}
/// <summary>
/// Fired when the game updates.
/// </summary>
/// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void Game_OnGameUpdate(EventArgs args)
{
foreach (var notification in NotificationsList)
{
notification.Value.OnUpdate();
}
}
/// <summary>
/// Fired when the game recieves a window event.
/// </summary>
/// <param name="args">The <see cref="WndEventArgs" /> instance containing the event data.</param>
private static void Game_OnWndProc(WndEventArgs args)
{
foreach (var notification in NotificationsList)
{
notification.Value.OnWndProc(args);
}
}
#endregion
}
}