DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
NotificationSystem.c
Go to the documentation of this file.
1const static float NOTIFICATION_FADE_TIME = 3.0;
2
4{
10 //Please add types before this item
13
15{
17
20
21 void NotificationRuntimeData( float time, NotificationData data, string detail_text )
22 {
24 m_StaticData = data;
25 if ( detail_text != "" )
26 m_DetailText = detail_text;
27 else
28 m_DetailText = m_StaticData.m_DescriptionText;
29 }
30
31 void SetTime( float time )
32 {
33 m_NotificationTime = time;
34 }
35
36 float GetTime()
37 {
38 return m_NotificationTime;
39 }
40
41 string GetIcon()
42 {
43 return m_StaticData.m_Icon;
44 }
45
46 string GetTitleText()
47 {
48 return m_StaticData.m_TitleText;
49 }
50
52 {
53 return m_DetailText;
54 }
55}
56
58{
59 protected static const string JSON_FILE_PATH = "Scripts/Data/notifications.json";
60 protected static const int MAX_NOTIFICATIONS = 5;
61
62 protected static ref NotificationSystem m_Instance;
63
67
70
71 static void InitInstance()
72 {
73 if (!m_Instance)
74 {
77 }
78 }
79
80 static void CleanupInstance()
81 {
82 m_Instance = null;
83 }
84
86 {
87 return m_Instance;
88 }
89
91 {
92 #ifndef WORKBENCH
95 #endif
96 }
97
106 static void SendNotificationToPlayerExtended( Man player, float show_time, string title_text, string detail_text = "", string icon = "" )
107 {
108 if ( player )
109 {
110 SendNotificationToPlayerIdentityExtended( player.GetIdentity(), show_time, title_text, detail_text, icon );
111 }
112 }
113
122 static void SendNotificationToPlayerIdentityExtended( PlayerIdentity player, float show_time, string title_text, string detail_text = "", string icon = "" )
123 {
124 ScriptRPC rpc = new ScriptRPC();
125
126 rpc.Write(show_time);
127 rpc.Write(title_text);
128 rpc.Write(detail_text);
129 rpc.Write(icon);
130
131 rpc.Send(null, ERPCs.RPC_SEND_NOTIFICATION_EXTENDED, true, player);
132 }
133
141 static void SendNotificationToPlayer( Man player, NotificationType type, float show_time, string detail_text = "" )
142 {
143 if ( player )
144 {
145 SendNotificationToPlayerIdentity( player.GetIdentity(), type, show_time, detail_text );
146 }
147 }
148
156 static void SendNotificationToPlayerIdentity( PlayerIdentity player, NotificationType type, float show_time, string detail_text = "" )
157 {
158 ScriptRPC rpc = new ScriptRPC();
159
160 rpc.Write(type);
161 rpc.Write(show_time);
162 rpc.Write(detail_text);
163
164 rpc.Send(null, ERPCs.RPC_SEND_NOTIFICATION, true, player);
165 }
166
173 static void AddNotification( NotificationType type, float show_time, string detail_text = "" )
174 {
176 {
177 float time = GetGame().GetTickTime() + show_time;
179
180 m_Instance.m_TimeArray.Insert( data );
182 }
183 else
184 {
185 NotificationRuntimeData data_def = new NotificationRuntimeData(show_time, m_Instance.GetNotificationData( type ), detail_text);
186 m_Instance.m_DeferredArray.Insert( data_def );
187 }
188 }
189
197 static void AddNotificationExtended( float show_time, string title_text, string detail_text = "", string icon = "" )
198 {
200 {
201 float time = GetGame().GetTickTime() + show_time;
202
203 NotificationData temp_data = new NotificationData( icon, title_text );
204 NotificationRuntimeData data = new NotificationRuntimeData(time, temp_data, detail_text);
205
206 m_Instance.m_TimeArray.Insert( data );
208 }
209 else
210 {
211 NotificationData temp_data_def = new NotificationData( icon, title_text );
212 NotificationRuntimeData data_def = new NotificationRuntimeData(show_time, temp_data_def, detail_text);
213 m_Instance.m_DeferredArray.Insert( data_def );
214 }
215 }
216
217 static void Update(float timeslice)
218 {
219 if ( m_Instance )
220 {
223 {
224 if ( data.GetTime() < GetGame().GetTickTime() )
225 {
226 to_remove.Insert( data );
227 }
228 }
229
230 foreach ( NotificationRuntimeData data2 : to_remove )
231 {
232 m_Instance.m_TimeArray.RemoveItem( data2 );
234
235 if ( m_Instance.m_DeferredArray.Count() > 0 )
236 {
238 float time = GetGame().GetTickTime() + data_def.GetTime();
239 data_def.SetTime( time );
240 m_Instance.m_TimeArray.Insert( data_def );
243 }
244 }
245 }
246 }
247
249 {
250 if ( m_DataArray.Contains(type) )
251 {
252 return m_DataArray.Get( type );
253 }
254
255 return null;
256 }
257
259 {
262 JsonFileLoader<map<NotificationType, NotificationData>>.JsonLoadFile( JSON_FILE_PATH, data_array );
263
264 m_Instance.m_DataArray.Copy( data_array );
265
266 array<int> types = new array<int>;
267 NotificationType type_curr = 0;
268 while ( type_curr != NotificationType.NOTIFICATIONS_END )
269 {
270 types.Insert( type_curr );
271 type_curr++;
272 }
273
274 for ( int i = 0; i < m_Instance.m_DataArray.Count(); i++ )
275 {
276 types.RemoveItem( m_Instance.m_DataArray.GetKey( i ) );
277 }
278
279 if ( types.Count() > 0 )
280 {
281 foreach ( NotificationType type2 : types )
282 {
283 NotificationData data2 = new NotificationData( "please_add_an_icon", "please_add_a_title", "optional_description" );
284 m_Instance.m_DataArray.Insert( type2, data2 );
285 }
286 JsonFileLoader<map<NotificationType, ref NotificationData>>.JsonSaveFile( JSON_FILE_PATH, m_Instance.m_DataArray );
287 }
288 }
289}
ERPCs
Definition ERPCs.c:2
NotificationType
@ CONNECT_FAIL_GENERIC
@ NOTIFICATIONS_END
@ 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)
void SetTime(float time)
float m_NotificationTime
string m_DetailText
string GetIcon()
string GetTitleText()
float GetTime()
string GetDetailText()
enum NotificationType m_StaticData
proto native float GetTickTime()
Returns current time from start of the game.
static void InitInstance()
static protected ref NotificationSystem m_Instance
protected ref array< ref NotificationRuntimeData > m_DeferredArray
ref ScriptInvoker m_OnNotificationAdded
static void SendNotificationToPlayer(Man player, NotificationType type, float show_time, string detail_text="")
Send notification from default types to player from server.
static void CleanupInstance()
static protected const string JSON_FILE_PATH
static NotificationSystem GetInstance()
static void Update(float timeslice)
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 SendNotificationToPlayerExtended(Man player, float show_time, string title_text, string detail_text="", string icon="")
Send custom notification to player from server.
static protected const int MAX_NOTIFICATIONS
protected ref array< ref NotificationRuntimeData > m_TimeArray
static void LoadNotificationData()
protected ref map< NotificationType, ref NotificationData > m_DataArray
static void AddNotificationExtended(float show_time, string title_text, string detail_text="", string icon="")
Send custom notification from to local player.
static void AddNotification(NotificationType type, float show_time, string detail_text="")
Send notification from default types to local player.
ref ScriptInvoker m_OnNotificationRemoved
static void SendNotificationToPlayerIdentity(PlayerIdentity player, NotificationType type, float show_time, string detail_text="")
Send notification from default types to player identity from server.
protected NotificationData GetNotificationData(NotificationType type)
The class that will be instanced (moddable)
Definition gameplay.c:378
ScriptInvoker Class provide list of callbacks usage:
Definition tools.c:116
proto void Invoke(void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
invoke call on all inserted methods with given arguments
proto native void Send(Object target, int rpc_type, bool guaranteed, PlayerIdentity recipient=NULL)
Initiate remote procedure call. When called on client, RPC is evaluated on server; When called on ser...
proto bool Write(void value_out)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()