DayZ 1.24
Loading...
Searching...
No Matches
NotificationSystem.c
Go to the documentation of this file.
1const static float NOTIFICATION_FADE_TIME = 3.0;
2
14
16{
18
22
24 {
28
29 if (detail_text != "")
31 else
32 m_DetailText = m_StaticData.m_DescriptionText;
33 }
34
35 float GetTime()
36 {
37 return m_NotificationTime;
38 }
39
41 {
42 return m_TimeRemaining;
43 }
44
45 string GetIcon()
46 {
47 return m_StaticData.m_Icon;
48 }
49
50 string GetTitleText()
51 {
52 return m_StaticData.m_TitleText;
53 }
54
56 {
57 return m_DetailText;
58 }
59
64
66 void SetTime(float time);
67}
68
70{
71 const int DEFAULT_TIME_DISPLAYED = 10;
72 const float NOTIFICATION_FADE_TIME = 3.0;
73
74 protected static const string JSON_FILE_PATH = "scripts/data/notifications.json";
75 protected static const int MAX_NOTIFICATIONS = 5;
76
77 private static const float UPDATE_INTERVAL_THRESHOLD = 1.0;
78
80
84
85 protected float m_TimeElapsed;
86
89
90 static void InitInstance()
91 {
92 if (!m_Instance)
93 {
95 m_Instance.LoadNotificationData();
96 }
97 }
98
99 static void CleanupInstance()
100 {
102 }
103
105 {
106 return m_Instance;
107 }
108
116
125 static void SendNotificationToPlayerExtended(Man player, float show_time, string title_text, string detail_text = "", string icon = "")
126 {
127 if (player)
129 }
130
140 {
141 ScriptRPC rpc = new ScriptRPC();
142
143 rpc.Write(show_time);
144 rpc.Write(title_text);
145 rpc.Write(detail_text);
146 rpc.Write(icon);
147
148 rpc.Send(null, ERPCs.RPC_SEND_NOTIFICATION_EXTENDED, true, player);
149 }
150
158 static void SendNotificationToPlayer(Man player, NotificationType type, float show_time, string detail_text = "")
159 {
160 if (player)
162 }
163
172 {
173 ScriptRPC rpc = new ScriptRPC();
174
175 rpc.Write(type);
176 rpc.Write(show_time);
177 rpc.Write(detail_text);
178
179 rpc.Send(null, ERPCs.RPC_SEND_NOTIFICATION, true, player);
180 }
181
188 static void AddNotification(NotificationType type, float show_time, string detail_text = "")
189 {
190 if (m_Instance.m_TimeArray.Count() < MAX_NOTIFICATIONS)
191 {
193
194 m_Instance.m_TimeArray.Insert(data);
195 m_Instance.m_OnNotificationAdded.Invoke(data);
196 }
197 else
198 {
200 m_Instance.m_DeferredArray.Insert(dataDeferred);
201 }
202 }
203
211 static void AddNotificationExtended(float show_time, string title_text, string detail_text = "", string icon = "")
212 {
213 if (m_Instance.m_TimeArray.Count() < MAX_NOTIFICATIONS)
214 {
217
218 m_Instance.m_TimeArray.Insert(data);
219 m_Instance.m_OnNotificationAdded.Invoke(data);
220 }
221 else
222 {
225 m_Instance.m_DeferredArray.Insert(dataDeferred);
226 }
227 }
228
229 static void Update(float timeslice)
230 {
231 if (m_Instance)
232 {
233 if (g_Game.GetGameState() != DayZGameState.IN_GAME && g_Game.GetGameState() != DayZGameState.MAIN_MENU)
234 return;
235
236 m_Instance.m_TimeElapsed += timeslice;
237 if (m_Instance.m_TimeElapsed >= UPDATE_INTERVAL_THRESHOLD)
238 {
241 {
242 if (visibleNotificationData.GetRemainingTime() <= 0.0)
244 else
246 }
247
249 {
250 m_Instance.m_OnNotificationRemoved.Invoke(expiredNotificationData);
251 m_Instance.m_TimeArray.RemoveItem(expiredNotificationData);
252
253 if (m_Instance.m_DeferredArray.Count() > 0)
254 {
255 int count = m_Instance.m_DeferredArray.Count();
257 m_Instance.m_TimeArray.Insert(deferredNotificationData);
258 m_Instance.m_OnNotificationAdded.Invoke(deferredNotificationData);
259 m_Instance.m_DeferredArray.Remove(count - 1);
260 }
261 }
262
263 m_Instance.m_TimeElapsed = 0;
264 }
265 }
266 }
267
269 {
270 if (m_DataArray.Contains(type))
271 return m_DataArray.Get(type);
272
273 return null;
274 }
275
277 {
280 string errorMessage;
283
284 m_Instance.m_DataArray.Copy(dataArray);
285
288 while (notificationType != NotificationType.NOTIFICATIONS_END)
289 {
292 }
293
294 for (int i = 0; i < m_Instance.m_DataArray.Count(); ++i)
295 notificationTypes.RemoveItem(m_Instance.m_DataArray.GetKey(i));
296
297 if (notificationTypes.Count() > 0)
298 {
300 {
302 "please_add_an_icon",
303 "please_add_a_title",
304 "optional_description",
305 );
306
307 m_Instance.m_DataArray.Insert(notificationType2, notificationData);
308 }
309
312 }
313 }
314}
DayZGame g_Game
Definition DayZGame.c:3528
ERPCs
Definition ERPCs.c:2
float m_TimeRemaining
NotificationType
DEPRECATED (moved into NotificationSystem)
@ CONNECT_FAIL_GENERIC
@ NOTIFICATIONS_END
@ GENERIC_ERROR
@ INVITE_FAIL_SAME_SERVER
@ DISCONNECTED
@ FRIEND_CONNECTED
@ JOIN_FAIL_GET_SESSION
static const float NOTIFICATION_FADE_TIME
void NotificationRuntimeData(float time, NotificationData data, string detail_text)
float GetRemainingTime()
void SetTime(float time)
DEPRECATED.
float m_NotificationTime
string m_DetailText
string GetIcon()
string GetTitleText()
float GetTime()
string GetDetailText()
void UpdateRemainingTime(float updateInterval)
enum NotificationType m_StaticData
ref ScriptInvoker m_OnNotificationAdded
static const string JSON_FILE_PATH
static void LoadNotificationData()
ref ScriptInvoker m_OnNotificationRemoved
NotificationData GetNotificationData(NotificationType type)
static void SendNotificationToPlayer(Man player, NotificationType type, float show_time, string detail_text="")
Send notification from default types to player from server.
ref map< NotificationType, ref NotificationData > m_DataArray
const float NOTIFICATION_FADE_TIME
static void SendNotificationToPlayerExtended(Man player, float show_time, string title_text, string detail_text="", string icon="")
Send custom notification to player from server.
ref array< ref NotificationRuntimeData > m_DeferredArray
static const float UPDATE_INTERVAL_THRESHOLD
static void AddNotificationExtended(float show_time, string title_text, string detail_text="", string icon="")
Send custom notification from to local player.
static ref NotificationSystem m_Instance
static void InitInstance()
static NotificationSystem GetInstance()
static void CleanupInstance()
ref array< ref NotificationRuntimeData > m_TimeArray
static const int MAX_NOTIFICATIONS
static void SendNotificationToPlayerIdentity(PlayerIdentity player, NotificationType type, float show_time, string detail_text="")
Send notification from default types to player identity from server.
static void AddNotification(NotificationType type, float show_time, string detail_text="")
Send notification from default types to local player.
static void SendNotificationToPlayerIdentityExtended(PlayerIdentity player, float show_time, string title_text, string detail_text="", string icon="")
Send custom notification to player identity from server.
static void Update(float timeslice)
The class that will be instanced (moddable)
Definition gameplay.c:376
ScriptInvoker Class provide list of callbacks usage:
Definition tools.c:116
enum ShapeType ErrorEx