backlit.c 13 KB

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