fn_processNotifications.sqf 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Author: Gundy
  3. *
  4. * Description:
  5. * Process cached notifications
  6. *
  7. * Arguments:
  8. * NONE
  9. *
  10. * Return Value:
  11. * TRUE <BOOL>
  12. *
  13. * Example:
  14. * [] call cTab_devices_processNotifications;
  15. *
  16. * Public: No
  17. */
  18. #include "\ClonecTab\shared\cTab_gui_macros.hpp"
  19. private ["_displayName","_display","_ctrl","_currentTime","_text","_notification","_decayTime"];
  20. disableSerialization;
  21. // make sure there is no PFH already, the interface is open and notifications are available
  22. if (isNil "cTabProcessNotificationsPFH" && !(isNil "cTabIfOpen") && count cTabNotificationCache != 0) then {
  23. _displayName = cTabIfOpen select 1;
  24. _display = uiNamespace getVariable _displayName;
  25. _ctrl = _display displayCtrl IDC_CTAB_NOTIFICATION;
  26. // only proceed if there is a notification control
  27. if (!isNull _ctrl) then {
  28. // run every 4 seconds
  29. cTabProcessNotificationsPFH = [{
  30. private ["_ctrl","_notification","_currentTime","_text"];
  31. if !(isNil "cTabIfOpen") then {
  32. if (count cTabNotificationCache != 0) then {
  33. // grab and delete the oldest notification
  34. _notification = cTabNotificationCache deleteAt 0;
  35. _decayTime = _notification select 3;
  36. _currentTime = [] call cTab_fnc_currentTime;
  37. // see if notification was issued in the same minute, if so, omit showing the time
  38. _text = if (_currentTime isEqualTo (_notification select 1)) then {
  39. format ["%1",_notification select 2];
  40. } else {
  41. format ["%1: %2",_notification select 1,_notification select 2];
  42. };
  43. // if the counter on the notification is greater than 1, append the counter to the notification text
  44. if ((_notification select 4) > 1) then {
  45. _text = format ["%1 (x%2)",_text,_notification select 4];
  46. };
  47. // show the notification
  48. _ctrl = _this select 0 select 0;
  49. _ctrl ctrlSetText _text;
  50. // make the control visible (it might have had its fade set to 1 before)
  51. _ctrl ctrlSetFade 0;
  52. _ctrl ctrlCommit 0;
  53. _ctrl ctrlShow true;
  54. // bring the control to the front. Enable is required before focus can be set
  55. _ctrl ctrlEnable true;
  56. ctrlSetFocus _ctrl;
  57. _ctrl ctrlEnable false;
  58. // make the control fade out
  59. _ctrl ctrlSetFade 1;
  60. _ctrl ctrlCommit _decayTime;
  61. } else {
  62. [_this select 1] call CBA_fnc_removePerFrameHandler;
  63. _ctrl ctrlShow false;
  64. cTabProcessNotificationsPFH = nil;
  65. };
  66. } else {
  67. [_this select 1] call CBA_fnc_removePerFrameHandler;
  68. cTabProcessNotificationsPFH = nil;
  69. };
  70. },4,[_ctrl]] call CBA_fnc_addPerFrameHandler;
  71. };
  72. };
  73. true