Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
backlit.c
Go to the documentation of this file.
1
2// Purpose of this file is to encapsulate Backlit Effects
3// Basic implementatoin is for Razer Chroma devices, but API is made to remain universal for future purposes
4//
5// for specific method - watch UAInputAPI/ UAInput class
6//
7//
8
9
10//-----------------------------------------------------------------------------
12const int EUABLAYER_ALL = 0; // all layers
13const int EUABLAYER_HINTKEY = 1; // showing hints
14const int EUABLAYER_VISKEY = 2; // visualisation
15const int EUABLAYER_3 = 3; //
16const int EUABLAYER_CAR = 4; //
17const int EUABLAYER_HUMAN = 5; //
18const int EUABLAYER_6 = 6; //
19const int EUABLAYER_CUSTOM = 7; // custom
20const int EUABLAYER_LOADING = 8; // keys during loading sequence
21const int EUABLAYER_MENU = 9; // keys during menu
22
23
24//-----------------------------------------------------------------------------
26const int EUABACKLIT_NONE = 0; // turn off
27const int EUABACKLIT_ON = 1; // permanent ilumination
28const int EUABACKLIT_2 = 2;
29const int EUABACKLIT_3 = 3;
30const int EUABACKLIT_FADEOUT_SLOW = 4; // slow fadeout
31const int EUABACKLIT_FADEOUT_FAST = 5; // fast fadeout
32const int EUABACKLIT_FADEIN_SLOW = 6; // slow in -> then stay on
33const int EUABACKLIT_FADEIN_FAST = 7; // fast in -> then stay on
34
35
36// note: there should be states like:
37//
38//
39// LOADING/ MAIN MENU/ CONNECTING/ KEYBINDING/ OPTIONS - continuous
40// CHARACTER/ CAR/ "HELI"/ SPECTATOR/ INFECTED - continuous BASE
41// SWIMMING/ CRAWLING/ SPRINTING/ FIGHTING/ FLARE/ FLASHLIGHT - continuous CHARACTER
42//
43// DoorOpen/ HitTaken/ CarCrashed/ etc. - event based
44//
45
46
47const int EUAB_OFF = 0; // all off
48
49// logos :: anims
50const int EUAB_LOGO_DAYZ = 10;
51const int EUAB_LOGO_CONNECTING = 11;
52
53// menus :: anims
54const int EUAB_MENU_BROWSER = 20;
55const int EUAB_MENU_MAIN = 21;
56const int EUAB_MENU_KEYBINDING = 22;
57const int EUAB_MENU_OPTIONS = 23;
58
59// car :: basic background colour + overlay + transition anims
60const int EUAB_CAR_OFF = 100; // sitting in car with engine off
61const int EUAB_CAR_ON_NOLIGHTS = 101; // driving w/o lights (day)
62const int EUAB_CAR_ON_LIGHTS = 102; // driving with headlights (night)
63const int EUAB_CAR_STARTING = 103; // short starting animation
64const int EUAB_CAR_ENTER = 104; // entering car
65const int EUAB_CAR_LEAVE = 105; // leaving car
66const int EUAB_CAR_CRASH = 106; // crashed
67
68// character :: basic background colour + overlay + transition anims
69const int EUAB_PLR_WALK = 200;
70const int EUAB_PLR_RUN = 201;
71const int EUAB_PLR_SPRINT = 202;
72const int EUAB_PLR_SWIM = 203;
73const int EUAB_PLR_HITBY = 204;
74const int EUAB_PLR_CONSUME = 205;
75const int EUAB_PLR_CRAFTING = 206;
76const int EUAB_PLR_EMOTE = 207; // playing emote
77const int EUAB_PLR_UNCONSCIOUS = 208;
78const int EUAB_PLR_DEAD = 209;
79
80// modes :: these are set of background colours
81const int EUAB_MODE_NIGHT = 300;
82const int EUAB_MODE_MORNING_BAD = 301;
83const int EUAB_MODE_MORNING_GOOD = 302;
84const int EUAB_MODE_DAY_FOGGY = 303;
85const int EUAB_MODE_DAY_OVERCAST = 304;
86const int EUAB_MODE_DAY_NICE = 305;
87const int EUAB_MODE_EVENING_BAD = 306;
88const int EUAB_MODE_EVENING_GOOD = 307;
89
90const int EUAB_MODE_FLASHLIGHT = 320;
91const int EUAB_MODE_CHEMLIGHT = 321;
92
93
94// overlay types
95const int EUAB_OVERLAY_NONE = 400; // no overlay
96const int EUAB_OVERLAY_CONTROLS = 401; // highlighted controls
97const int EUAB_OVERLAY_STATUS = 402; // numpad + mouse used for health/ blood level visualisation
98const int EUAB_OVERLAY_VON = 403; // VON status
99
100
101//-----------------------------------------------------------------------------
103
105{
106// private void ~Backlit(); // raist todo: turn lights off there?
107
108 bool m_BacklitActive;
109
110 void OnInit( DayZGame game )
111 {
112 // enable only on client/ standalone!
113 if( game.IsClient() || !game.IsMultiplayer() )
114 m_BacklitActive = true;
115
116 if( m_BacklitActive )
117 Print("... Backlit Effects Enabled");
118 }
119
120 // start infinite loading animation
121 void LoadingAnim()
122 {
123 if( !m_BacklitActive )
124 return; // always return when backlit not present!
125
126 // lighten up your desktop
127 GetUApi().Backlit_KeyByName("kD",EUABLAYER_LOADING,EUABACKLIT_ON,0xffff0000);
128 GetUApi().Backlit_KeyByName("kA",EUABLAYER_LOADING,EUABACKLIT_ON,0xffcf0000);
129 GetUApi().Backlit_KeyByName("kY",EUABLAYER_LOADING,EUABACKLIT_ON,0xffaf0000);
130 GetUApi().Backlit_KeyByName("kZ",EUABLAYER_LOADING,EUABACKLIT_ON,0xff8f0000);
131 GetUApi().Backlit_Animation("Loading/",2,0xffc8c8c8,0xff080808);
132 GetUApi().Backlit_ForceUpdate();
133 }
134
135 // ...
136 void MainMenu_OnShow()
137 {
138 if( !m_BacklitActive )
139 return; // always return when backlit not present!
140
141 // lighten up your desktop
142 GetUApi().Backlit_Remove(EUABLAYER_ALL);
143 GetUApi().Backlit_Animation("MainMenu/",2,0xffff0000,0xff080000);
144 GetUApi().Backlit_ForceUpdate();
145 }
146
147 // ...
148 void MainMenu_OnHide()
149 {
150 if( !m_BacklitActive )
151 return; // always return when backlit not present!
152
153 GetUApi().Backlit_Remove(EUABLAYER_ALL);
154 GetUApi().Backlit_Background(0,0xff220000,0xff222222);
155 }
156
157 // ...
158 void OnEnterCar()
159 {
160 if( !m_BacklitActive )
161 return; // always return when backlit not present!
162
163 GetUApi().Backlit_Remove(EUABLAYER_ALL);
164 GetUApi().Backlit_Background(0,0xff211202,0xff110800);
165 }
166
167 // ...
168 void OnLeaveCar()
169 {
170 if( !m_BacklitActive )
171 return; // always return when backlit not present!
172
173 // force update player
174 if( GetGame().GetMission().GetHud() )
175 {
176 GetUApi().Backlit_Remove(EUABLAYER_ALL);
177 GetUApi().Backlit_Background(0,0xff220000,0xff222222);
178
179 UpdatePlayer(true);
180 }
181 }
182
183 // ...
184 void OnSwimmingStart()
185 {
186 if( !m_BacklitActive )
187 return; // always return when backlit not present!
188
189 // reset queue
190 GetUApi().Backlit_EmptyQueue();
191 // play hit animation
192 GetUApi().Backlit_Animation("Water/",0,0xff00ffff,0xffffffff);
193 }
194
195 // ...
196 void OnSwimmingStop()
197 {
198 if( !m_BacklitActive )
199 return; // always return when backlit not present!
200
201 if( GetGame().GetMission().GetHud() )
202 {
203 // enqueue background
204 GetUApi().Backlit_Background(0,0xff220000,0xff222222);
205 // force update player
206 UpdatePlayer(true);
207 }
208 }
209
210 // clear tutorial/ hint keys
211 void HintClear()
212 {
213 if( !m_BacklitActive )
214 return; // always return when backlit not present!
215
216 // remove previous backlit
217 GetUApi().Backlit_Remove(EUABLAYER_HINTKEY);
218 }
219
220 // highlight tutorial/ hint keys
221 void HintShow( UAInput action )
222 {
223 if( !m_BacklitActive )
224 return; // always return when backlit not present!
225
226 action.Backlit_Override(EUABLAYER_HINTKEY,0xffafafff);
227 }
228
229 // clear keybinding keys
230 void KeybindingClear( )
231 {
232 if( !m_BacklitActive )
233 return; // always return when backlit not present!
234
235 GetUApi().Backlit_Remove(EUABLAYER_ALL);
236 }
237
238 // clear keybinding keys
239 void KeybindingShow( int keyHash )
240 {
241 if( !m_BacklitActive )
242 return; // always return when backlit not present!
243
244 GetUApi().Backlit_KeyByHash(keyHash,EUABLAYER_VISKEY,EUABACKLIT_FADEOUT_SLOW,0xff0000ff);
245 }
246
247
248 void VisualiseHealth( int iLevel )
249 {
250 UAInputAPI ua_api = GetUApi();
251
252 int aColor = 0xff1fff1f;
253 int dColor = 0xff001f00;
254
255 if( iLevel > 0 )
256 ua_api.Backlit_KeyByName("kF1",EUABLAYER_HUMAN,EUABACKLIT_ON,aColor);
257 else
258 ua_api.Backlit_KeyByName("kF1",EUABLAYER_HUMAN,EUABACKLIT_ON,dColor );
259 if( iLevel > 1 )
260 ua_api.Backlit_KeyByName("kF2",EUABLAYER_HUMAN,EUABACKLIT_ON,aColor);
261 else
262 ua_api.Backlit_KeyByName("kF2",EUABLAYER_HUMAN,EUABACKLIT_ON,dColor );
263 if( iLevel> 2 )
264 ua_api.Backlit_KeyByName("kF3",EUABLAYER_HUMAN,EUABACKLIT_ON,aColor);
265 else
266 ua_api.Backlit_KeyByName("kF3",EUABLAYER_HUMAN,EUABACKLIT_ON,dColor );
267 if( iLevel > 3 )
268 ua_api.Backlit_KeyByName("kF4",EUABLAYER_HUMAN,EUABACKLIT_ON,aColor);
269 else
270 ua_api.Backlit_KeyByName("kF4",EUABLAYER_HUMAN,EUABACKLIT_ON,dColor );
271
272/* int lc = 0xff001f00;
273 if( iLevel > 0 )
274 lc = 0xff003f00;
275 else if( iLevel > 1 )
276 lc = 0xff007f00;
277 else if( iLevel > 2 )
278 lc = 0xff00af00;
279 else if( iLevel > 3 )
280 lc = 0xff00ff00;
281
282 ua_api.Backlit_KeyByName("mBMiddle",EUABLAYER_HUMAN,EUABACKLIT_ON,lc);*/
283
284 }
285
286 void VisualiseBlood( int iLevel )
287 {
288 UAInputAPI ua_api = GetUApi();
289
290 int aColor = 0xffff1f1f;
291 int dColor = 0xff1f0000;
292
293 if( iLevel > 0 )
294 ua_api.Backlit_KeyByName("kF5",EUABLAYER_HUMAN,EUABACKLIT_ON,aColor);
295 else
296 ua_api.Backlit_KeyByName("kF5",EUABLAYER_HUMAN,EUABACKLIT_ON,dColor );
297 if( iLevel > 1 )
298 ua_api.Backlit_KeyByName("kF6",EUABLAYER_HUMAN,EUABACKLIT_ON,aColor);
299 else
300 ua_api.Backlit_KeyByName("kF6",EUABLAYER_HUMAN,EUABACKLIT_ON,dColor );
301 if( iLevel > 2 )
302 ua_api.Backlit_KeyByName("kF7",EUABLAYER_HUMAN,EUABACKLIT_ON,aColor);
303 else
304 ua_api.Backlit_KeyByName("kF7",EUABLAYER_HUMAN,EUABACKLIT_ON,dColor );
305 if( iLevel > 3 )
306 ua_api.Backlit_KeyByName("kF8",EUABLAYER_HUMAN,EUABACKLIT_ON,aColor);
307 else
308 ua_api.Backlit_KeyByName("kF8",EUABLAYER_HUMAN,EUABACKLIT_ON,dColor );
309
310/* int lc = 0xff1f0000;
311 if( iLevel > 0 )
312 lc = 0xff3f0000;
313 else if( iLevel > 1 )
314 lc = 0xff7f0000;
315 else if( iLevel > 2 )
316 lc = 0xffaf0000;
317 else if( iLevel > 3 )
318 lc = iLevel;
319
320 ua_api.Backlit_KeyByName("mBRight",EUABLAYER_HUMAN,EUABACKLIT_ON,lc);*/
321
322 }
323
324 int m_HealthBefore = -1;
325 int m_BloodBefore = -1;
326
327 int m_HealthNew = 0;
328 int m_BloodNew = 0;
329
330 void SetHealth( float fHealth ) // range 0 .. 100
331 {
332 float health = fHealth * 0.01; // div 100
333 m_HealthNew = health*4; // 4 stages
334 }
335
336 void SetBlood( float fBlood ) // range 0 .. 5000
337 {
338 float blood = fBlood * 0.0002; // div 5000
339 m_BloodNew = blood*4; // 4 stages
340 }
341
342 void UpdatePlayer( bool bForce )
343 {
344 if( !m_BacklitActive )
345 return; // always return when backlit not present!
346
347 // force update
348 if( bForce )
349 {
350 m_HealthBefore = -1;
351 m_BloodBefore = -1;
352 }
353
354 // do not update
355 if( m_HealthNew == m_HealthBefore && m_BloodNew == m_BloodBefore )
356 return;
357
358 // remove previous layers
359 GetUApi().Backlit_Remove(EUABLAYER_ALL);
360
361 // set keys to layer CUSTOM
362 GetUApi().Backlit_KeyByName("kW",EUABLAYER_CUSTOM,EUABACKLIT_ON,0xff0000ff);
363 GetUApi().Backlit_KeyByName("kA",EUABLAYER_CUSTOM,EUABACKLIT_ON,0xff0000cf);
364 GetUApi().Backlit_KeyByName("kS",EUABLAYER_CUSTOM,EUABACKLIT_ON,0xff0000af);
365 GetUApi().Backlit_KeyByName("kD",EUABLAYER_CUSTOM,EUABACKLIT_ON,0xff00008f);
366
367 GetUApi().Backlit_KeyByName("kX",EUABLAYER_CUSTOM,EUABACKLIT_ON,0xff3f3f3f);
368 GetUApi().Backlit_KeyByName("kC",EUABLAYER_CUSTOM,EUABACKLIT_ON,0xff3f3f3f);
369
370 GetUApi().Backlit_KeyByName("kQ",EUABLAYER_CUSTOM,EUABACKLIT_ON,0xff7f7f0f);
371 GetUApi().Backlit_KeyByName("kE",EUABLAYER_CUSTOM,EUABACKLIT_ON,0xff7f7f0f);
372
373 // health
374 VisualiseHealth(m_HealthNew);
375 // blood
376 VisualiseBlood(m_BloodNew);
377
378 // animation
379 GetUApi().Backlit_Background(0,0xff220000,0xff222222);
380
381 // save level
382 m_BloodBefore = m_BloodNew;
383 m_HealthBefore = m_HealthNew;
384 }
385
386
387 int m_GearBefore = 0;
388 bool m_CELBefore = false;
389
390 void RefreshVehicleLayout( int iGear, bool bCEL )
391 {
392 if( !m_BacklitActive )
393 return; // always return when backlit not present!
394
395 UAInputAPI ua_api = GetUApi();
396
397 if( m_GearBefore != iGear )
398 {
399 m_GearBefore = iGear;
400
401 int activeColor = 0xff3fff3f;
402 int dimmColor = 0xff0f3f0f;
403
404 if( iGear == CarGear.REVERSE )
405 ua_api.Backlit_KeyByName("kR",EUABLAYER_CAR,EUABACKLIT_ON,activeColor);
406 else
407 ua_api.Backlit_KeyByName("kR",EUABLAYER_CAR,EUABACKLIT_ON,dimmColor);
408
409 if( iGear == CarGear.NEUTRAL )
410 ua_api.Backlit_KeyByName("kN",EUABLAYER_CAR,EUABACKLIT_ON,activeColor);
411 else
412 ua_api.Backlit_KeyByName("kN",EUABLAYER_CAR,EUABACKLIT_ON,dimmColor);
413
414 if( iGear == CarGear.FIRST )
415 ua_api.Backlit_KeyByName("k1",EUABLAYER_CAR,EUABACKLIT_ON,activeColor);
416 else
417 ua_api.Backlit_KeyByName("k1",EUABLAYER_CAR,EUABACKLIT_ON,dimmColor);
418
419 if( iGear == CarGear.SECOND )
420 ua_api.Backlit_KeyByName("k2",EUABLAYER_CAR,EUABACKLIT_ON,activeColor);
421 else
422 ua_api.Backlit_KeyByName("k2",EUABLAYER_CAR,EUABACKLIT_ON,dimmColor);
423
424 if( iGear == CarGear.THIRD )
425 ua_api.Backlit_KeyByName("k3",EUABLAYER_CAR,EUABACKLIT_ON,activeColor);
426 else
427 ua_api.Backlit_KeyByName("k3",EUABLAYER_CAR,EUABACKLIT_ON,dimmColor);
428
429 if( iGear == CarGear.FOURTH )
430 ua_api.Backlit_KeyByName("k4",EUABLAYER_CAR,EUABACKLIT_ON,activeColor);
431 else
432 ua_api.Backlit_KeyByName("k4",EUABLAYER_CAR,EUABACKLIT_ON,dimmColor);
433
434 if( iGear == CarGear.FIFTH )
435 ua_api.Backlit_KeyByName("k5",EUABLAYER_CAR,EUABACKLIT_ON,activeColor);
436 else
437 ua_api.Backlit_KeyByName("k5",EUABLAYER_CAR,EUABACKLIT_ON,dimmColor);
438
439 }
440
441 if( bCEL != m_CELBefore )
442 {
443 m_CELBefore = bCEL;
444
445 if( bCEL )
446 ua_api.Backlit_KeyByName("kC",EUABLAYER_CAR,EUABACKLIT_ON,0xffff0f0f);
447 else
448 ua_api.Backlit_KeyByName("kC",EUABLAYER_CAR,EUABACKLIT_NONE,0xff000000);
449 }
450
451 }
452
453};
454
455
456
const int EUAB_PLR_DEAD
Definition backlit.c:78
const int EUABLAYER_CUSTOM
Definition backlit.c:19
const int EUABACKLIT_NONE
Input backlit type.
Definition backlit.c:26
const int EUABLAYER_6
Definition backlit.c:18
const int EUABACKLIT_3
Definition backlit.c:29
const int EUAB_MODE_DAY_OVERCAST
Definition backlit.c:85
const int EUAB_MENU_BROWSER
Definition backlit.c:54
const int EUAB_PLR_HITBY
Definition backlit.c:73
const int EUAB_MODE_DAY_NICE
Definition backlit.c:86
const int EUABLAYER_HUMAN
Definition backlit.c:17
const int EUABLAYER_VISKEY
Definition backlit.c:14
const int EUAB_PLR_CONSUME
Definition backlit.c:74
const int EUAB_MODE_EVENING_GOOD
Definition backlit.c:88
const int EUAB_PLR_SPRINT
Definition backlit.c:71
const int EUAB_OVERLAY_STATUS
Definition backlit.c:97
const int EUAB_CAR_OFF
Definition backlit.c:60
const int EUABLAYER_CAR
Definition backlit.c:16
const int EUAB_MODE_NIGHT
Definition backlit.c:81
const int EUAB_CAR_ON_LIGHTS
Definition backlit.c:62
const int EUABACKLIT_FADEOUT_SLOW
Definition backlit.c:30
const int EUAB_CAR_CRASH
Definition backlit.c:66
const int EUAB_OFF
Definition backlit.c:47
const int EUAB_MODE_CHEMLIGHT
Definition backlit.c:91
const int EUAB_OVERLAY_CONTROLS
Definition backlit.c:96
const int EUAB_PLR_UNCONSCIOUS
Definition backlit.c:77
const int EUABACKLIT_FADEOUT_FAST
Definition backlit.c:31
const int EUABLAYER_MENU
Definition backlit.c:21
const int EUABLAYER_LOADING
Definition backlit.c:20
const int EUAB_MODE_FLASHLIGHT
Definition backlit.c:90
const int EUAB_PLR_RUN
Definition backlit.c:70
const int EUAB_MENU_KEYBINDING
Definition backlit.c:56
const int EUAB_PLR_EMOTE
Definition backlit.c:76
const int EUAB_MODE_MORNING_GOOD
Definition backlit.c:83
const int EUAB_MODE_DAY_FOGGY
Definition backlit.c:84
const int EUAB_PLR_CRAFTING
Definition backlit.c:75
const int EUAB_PLR_WALK
Definition backlit.c:69
const int EUAB_CAR_ENTER
Definition backlit.c:64
const int EUAB_CAR_ON_NOLIGHTS
Definition backlit.c:61
const int EUAB_MENU_MAIN
Definition backlit.c:55
const int EUABACKLIT_FADEIN_SLOW
Definition backlit.c:32
const int EUABACKLIT_ON
Definition backlit.c:27
const int EUAB_LOGO_DAYZ
Definition backlit.c:50
const int EUABLAYER_ALL
Input layer type.
Definition backlit.c:12
const int EUABLAYER_3
Definition backlit.c:15
const int EUAB_CAR_LEAVE
Definition backlit.c:65
const int EUAB_MENU_OPTIONS
Definition backlit.c:57
const int EUAB_MODE_EVENING_BAD
Definition backlit.c:87
const int EUAB_MODE_MORNING_BAD
Definition backlit.c:82
const int EUABACKLIT_2
Definition backlit.c:28
const int EUAB_OVERLAY_VON
Definition backlit.c:98
const int EUABACKLIT_FADEIN_FAST
Definition backlit.c:33
const int EUAB_PLR_SWIM
Definition backlit.c:72
const int EUAB_LOGO_CONNECTING
Definition backlit.c:51
const int EUABLAYER_HINTKEY
Definition backlit.c:13
const int EUAB_OVERLAY_NONE
Definition backlit.c:95
const int EUAB_CAR_STARTING
Definition backlit.c:63
Backlit effect class.
Definition backlit.c:105
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
void OnInit()
Callback for user defined initialization. Called for all suites during TestHarness....
Definition freezestate.c:81
proto native UAInputAPI GetUApi()