player_init.sqf 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. // cTab - Commander's Tablet with FBCB2 Blue Force Tracking
  2. // Battlefield tablet to access real time intel and blue force tracker.
  3. // By - Riouken
  4. // http://forums.bistudio.com/member.php?64032-Riouken
  5. // You may re-use any of this work as long as you provide credit back to me.
  6. // keys.sqf parses the userconfig
  7. #include "functions\keys.sqf"
  8. #include "\ClonecTab\shared\cTab_gui_macros.hpp"
  9. // Exit if this is machine has no interface, i.e. is a headless client (HC)
  10. if (!hasInterface) exitWith {};
  11. // Get a rsc layer for for our displays
  12. cTabRscLayer = ["cTab"] call BIS_fnc_rscLayer;
  13. cTabRscLayerMailNotification = ["cTab_mailNotification"] call BIS_fnc_rscLayer;
  14. // Set up user markers
  15. cTab_userMarkerTransactionId = -1;
  16. cTab_userMarkerLists = [];
  17. [] call cTab_fnc_getUserMarkerList;
  18. // Set up side specific encryption keys
  19. if (isNil "cTab_encryptionKey_west") then {
  20. cTab_encryptionKey_west = "b";
  21. };
  22. if (isNil "cTab_encryptionKey_east") then {
  23. cTab_encryptionKey_east = "o";
  24. };
  25. if (isNil "cTab_encryptionKey_guer") then {
  26. cTab_encryptionKey_guer = call {
  27. if (([west,resistance] call BIS_fnc_areFriendly) and {!([east,resistance] call BIS_fnc_areFriendly)}) exitWith {
  28. "b"
  29. };
  30. if (([east,resistance] call BIS_fnc_areFriendly) and {!([west,resistance] call BIS_fnc_areFriendly)}) exitWith {
  31. "o"
  32. };
  33. "i"
  34. };
  35. };
  36. if (isNil "cTab_encryptionKey_civ") then {
  37. cTab_encryptionKey_civ = "c";
  38. };
  39. // Set up empty lists
  40. cTabBFTmembers = [];
  41. cTabBFTgroups = [];
  42. cTabBFTvehicles = [];
  43. cTabUAVlist = [];
  44. cTabHcamlist = [];
  45. cTabNotificationCache = [];
  46. // set current player object in cTab_player and run a check on every frame to see if there is a change
  47. cTab_player = objNull;
  48. ["cTab_checkForPlayerChange", "onEachFrame", {
  49. if !(cTab_player isEqualTo (missionNamespace getVariable ["BIS_fnc_moduleRemoteControl_unit",player])) then {
  50. cTab_player = missionNamespace getVariable ["BIS_fnc_moduleRemoteControl_unit",player];
  51. // close any interface that might still be open
  52. call cTab_fnc_close;
  53. //prep the arrays that will hold ctab data
  54. cTabBFTmembers = [];
  55. cTabBFTgroups = [];
  56. cTabBFTvehicles = [];
  57. cTabUAVlist = [];
  58. cTabHcamlist = [];
  59. call cTab_fnc_updateLists;
  60. call cTab_fnc_updateUserMarkerList;
  61. // remove msg notification
  62. cTabRscLayerMailNotification cutText ["", "PLAIN"];
  63. };
  64. }] call BIS_fnc_addStackedEventHandler;
  65. /*
  66. Figure out the scaling factor based on the current map (island) being played
  67. Requires the scale of the map control to be at 0.001
  68. */
  69. call {
  70. private ["_displayName","_display","_mapCtrl","_mapScreenPos","_mapScreenX_left","_mapScreenH","_mapScreenY_top","_mapScreenY_middle","_mapWorldY_top","_mapWorldY_middle"];
  71. _displayName = "cTab_mapSize_dsp";
  72. cTabRscLayer cutRsc [_displayName,"PLAIN",0, false];
  73. while {isNull (uiNamespace getVariable _displayName)} do {};
  74. _display = uiNamespace getVariable _displayName;
  75. _mapCtrl = _display displayCtrl 1110;
  76. // get the screen postition of _mapCtrl as [x, y, w, h]
  77. _mapScreenPos = ctrlPosition _mapCtrl;
  78. // Find the screen coordinate for the left side
  79. _mapScreenX_left = _mapScreenPos select 0;
  80. // Find the screen height
  81. _mapScreenH = _mapScreenPos select 3;
  82. // Find the screen coordinate for top Y
  83. _mapScreenY_top = _mapScreenPos select 1;
  84. // Find the screen coordinate for middle Y
  85. _mapScreenY_middle = _mapScreenY_top + _mapScreenH / 2;
  86. // Get world coordinate for top Y in meters
  87. _mapWorldY_top = (_mapCtrl ctrlMapScreenToWorld [_mapScreenX_left,_mapScreenY_top]) select 1;
  88. // Get world coordinate for middle Y in meters
  89. _mapWorldY_middle = (_mapCtrl ctrlMapScreenToWorld [_mapScreenX_left,_mapScreenY_middle]) select 1;
  90. // calculate the difference between top and middle world coordinates, devide by the screen height and return
  91. cTabMapScaleFactor = (abs(_mapWorldY_middle - _mapWorldY_top)) / _mapScreenH;
  92. _display closeDisplay 0;
  93. uiNamespace setVariable [_displayName, displayNull];
  94. };
  95. cTabMapScaleUAV = 0.8 / cTabMapScaleFactor;
  96. cTabMapScaleHCam = 0.3 / cTabMapScaleFactor;
  97. cTabDisplayPropertyGroups = [
  98. ["cTab_Tablet_dlg","Tablet"],
  99. ];
  100. cTabSettings = [];
  101. [cTabSettings,"COMMON",[
  102. ["mode","BFT"],
  103. ["mapScaleMin",0.1],
  104. ["mapScaleMax",2 ^ round(sqrt(2666 * cTabMapScaleFactor / 1024))]
  105. ]] call BIS_fnc_setToPairs;
  106. [cTabSettings,"Main",[
  107. ]] call BIS_fnc_setToPairs;
  108. [cTabSettings,"Tablet",[
  109. ["dlgIfPosition",[]],
  110. ["mode","DESKTOP"],
  111. ["showIconText",true],
  112. ["mapWorldPos",[]],
  113. ["mapScaleDsp",2],
  114. ["mapScaleDlg",2],
  115. ["mapTypes",[["SAT",IDC_CTAB_SCREEN],["TOPO",IDC_CTAB_SCREEN_TOPO]]],
  116. ["mapType","SAT"],
  117. ["uavCam",""],
  118. ["hCam",""],
  119. ["mapTools",true],
  120. ["nightMode",2],
  121. ["brightness",0.9]
  122. ]] call BIS_fnc_setToPairs;
  123. ]] call BIS_fnc_setToPairs;
  124. ]] call BIS_fnc_setToPairs;
  125. // set base colors from BI -- Helps keep colors matching if user changes colors in options.
  126. _r = profilenamespace getvariable ['Map_BLUFOR_R',0];
  127. _g = profilenamespace getvariable ['Map_BLUFOR_G',0.8];
  128. _b = profilenamespace getvariable ['Map_BLUFOR_B',1];
  129. _a = profilenamespace getvariable ['Map_BLUFOR_A',0.8];
  130. cTabColorBlue = [_r,_g,_b,_a];
  131. _r = profilenamespace getvariable ['Map_OPFOR_R',0];
  132. _g = profilenamespace getvariable ['Map_OPFOR_G',1];
  133. _b = profilenamespace getvariable ['Map_OPFOR_B',1];
  134. _a = profilenamespace getvariable ['Map_OPFOR_A',0.8];
  135. cTabColorRed = [_r,_g,_b,_a];
  136. _r = profilenamespace getvariable ['Map_Independent_R',0];
  137. _g = profilenamespace getvariable ['Map_Independent_G',1];
  138. _b = profilenamespace getvariable ['Map_Independent_B',1];
  139. _a = profilenamespace getvariable ['Map_OPFOR_A',0.8];
  140. cTabColorGreen = [_r,_g,_b,_a];
  141. // Define Fire-Team colors
  142. // MAIN,RED,GREEN,BLUE,YELLOW
  143. cTabColorTeam = [cTabColorBlue,[200/255,0,0,0.8],[0,199/255,0,0.8],[0,0,200/255,0.8],[225/255,225/255,0,0.8]];
  144. // define items that enable head cam
  145. if (isNil "cTab_helmetClass_has_HCam") then {
  146. if (!isNil "cTab_helmetClass_has_HCam_server") then {
  147. cTab_helmetClass_has_HCam = cTab_helmetClass_has_HCam_server;
  148. } else {
  149. cTab_helmetClass_has_HCam = ["H_HelmetB_light","H_Helmet_Kerry","H_HelmetSpecB","H_HelmetO_ocamo","BWA3_OpsCore_Fleck_Camera","BWA3_OpsCore_Schwarz_Camera","BWA3_OpsCore_Tropen_Camera"];
  150. };
  151. };
  152. // strip list of invalid config names and duplicates to save time checking through them later
  153. _classNames = [];
  154. {
  155. if (isClass (configfile >> "CfgWeapons" >> _x) && _classNames find _x == -1) then {
  156. 0 = _classNames pushBack _x;
  157. };
  158. } count cTab_helmetClass_has_HCam;
  159. // iterate through all class names and add child classes, so we end up with a list of helmet classes that have the defined helmet classes as parents
  160. {
  161. _childClasses = "inheritsFrom _x == (configfile >> 'CfgWeapons' >> '" + _x + "')" configClasses (configfile >> "CfgWeapons");
  162. {
  163. _childClassName = configName _x;
  164. if (_classNames find _childClassName == -1) then {
  165. 0 = _classNames pushBack configName _x;
  166. };
  167. } count _childClasses;
  168. } forEach _classNames;
  169. cTab_helmetClass_has_HCam = [] + _classNames;
  170. // add cTab_updatePulse event handler triggered periodically by the server
  171. ["cTab_updatePulse",cTab_fnc_updateLists] call CBA_fnc_addEventHandler;
  172. // fnc to set various text and icon sizes
  173. cTab_fnc_update_txt_size = {
  174. cTabIconSize = cTabTxtFctr * 2;
  175. cTabIconManSize = cTabIconSize * 0.75;
  176. cTabGroupOverlayIconSize = cTabIconSize * 1.625;
  177. cTabUserMarkerArrowSize = cTabTxtFctr * 8 * cTabMapScaleFactor;
  178. cTabTxtSize = cTabTxtFctr / 12 * 0.035;
  179. cTabAirContactGroupTxtSize = cTabTxtFctr / 12 * 0.060;
  180. cTabAirContactSize = cTabTxtFctr / 12 * 32;
  181. cTabAirContactDummySize = cTabTxtFctr / 12 * 20;
  182. };
  183. // Beginning text and icon size
  184. cTabTxtFctr = 12;
  185. call cTab_fnc_update_txt_size;
  186. cTabBFTtxt = true;
  187. // Draw Map Tolls (Hook)
  188. cTabDrawMapTools = false;
  189. // Base defines.
  190. cTabUavViewActive = false;
  191. cTabUAVcams = [];
  192. cTabCursorOnMap = false;
  193. cTabMapCursorPos = [0,0];
  194. cTabMapWorldPos = [];
  195. cTabMapScale = 0.5;
  196. // Initialize all uiNamespace variables
  197. uiNamespace setVariable ["cTab_Tablet_dlg", displayNull];
  198. // Set up the array that will hold text messages.
  199. player setVariable ["ctab_messages",[]];
  200. // cTabIfOpenStart will be set to true while interface is starting and prevent further open attempts
  201. cTabIfOpenStart = false;
  202. /*
  203. Function handling IF_Main keydown event
  204. Based on player equipment and the vehicle type he might be in, open or close a cTab device as Main interface.
  205. No Parameters
  206. Returns TRUE when action was taken (interface opened or closed)
  207. Returns FALSE when no action was taken (i.e. player has no cTab device / is not in cTab enabled vehicle)
  208. */
  209. cTab_fnc_onIfMainPressed = {
  210. if (cTabIfOpenStart) exitWith {false};
  211. _previousInterface = "";
  212. if (cTabUavViewActive) exitWith {
  213. objNull remoteControl (gunner cTabActUav);
  214. vehicle cTab_player switchCamera 'internal';
  215. cTabUavViewActive = false;
  216. call cTab_fnc_onIfTertiaryPressed;
  217. true
  218. };
  219. if (!isNil "cTabIfOpen" && {cTabIfOpen select 0 == 0}) exitWith {
  220. // close Main
  221. call cTab_fnc_close;
  222. true
  223. };
  224. if !(isNil "cTabIfOpen") then {
  225. _previousInterface = cTabIfOpen select 1;
  226. // close Secondary / Tertiary
  227. call cTab_fnc_close;
  228. };
  229. _player = cTab_player;
  230. _vehicle = vehicle _player;
  231. _interfaceName = call {
  232. if ([_player,["ItemcTab"]] call cTab_fnc_checkGear) exitWith {"cTab_Tablet_dlg"};
  233. // default
  234. ""
  235. };
  236. if (_interfaceName != "" && _interfaceName != _previousInterface) exitWith {
  237. // queue the start up of the interface as we might still have one closing down
  238. [{
  239. if (isNil "cTabIfOpen") then {
  240. [_this select 1] call CBA_fnc_removePerFrameHandler;
  241. (_this select 0) call cTab_fnc_open;
  242. };
  243. },0,[0,_interfaceName,_player,_vehicle]] call CBA_fnc_addPerFrameHandler;
  244. true
  245. };
  246. false
  247. };
  248. /*
  249. Function handling IF_Secondary keydown event
  250. Based on player equipment and the vehicle type he might be in, open or close a cTab device as Secondary interface.
  251. No Parameters
  252. Returns TRUE when action was taken (interface opened or closed)
  253. Returns FALSE when no action was taken (i.e. player has no cTab device / is not in cTab enabled vehicle)
  254. */
  255. cTab_fnc_onIfSecondaryPressed = {
  256. if (cTabIfOpenStart) exitWith {false};
  257. _previousInterface = "";
  258. if (cTabUavViewActive) exitWith {
  259. objNull remoteControl (gunner cTabActUav);
  260. vehicle cTab_player switchCamera 'internal';
  261. cTabUavViewActive = false;
  262. call cTab_fnc_onIfTertiaryPressed;
  263. true
  264. };
  265. if (!isNil "cTabIfOpen" && {cTabIfOpen select 0 == 1}) exitWith {
  266. // close Secondary
  267. call cTab_fnc_close;
  268. true
  269. };
  270. if !(isNil "cTabIfOpen") then {
  271. _previousInterface = cTabIfOpen select 1;
  272. // close Main / Tertiary
  273. call cTab_fnc_close;
  274. };
  275. _player = cTab_player;
  276. _vehicle = vehicle _player;
  277. _interfaceName = call {
  278. if ([_player,["ItemcTab"]] call cTab_fnc_checkGear) exitWith {"cTab_Tablet_dlg"};
  279. // default
  280. ""
  281. };
  282. if (_interfaceName != "" && _interfaceName != _previousInterface) exitWith {
  283. // queue the start up of the interface as we might still have one closing down
  284. [{
  285. if (isNil "cTabIfOpen") then {
  286. [_this select 1] call CBA_fnc_removePerFrameHandler;
  287. (_this select 0) call cTab_fnc_open;
  288. };
  289. },0,[1,_interfaceName,_player,_vehicle]] call CBA_fnc_addPerFrameHandler;
  290. true
  291. };
  292. false
  293. };
  294. /*
  295. Function handling IF_Tertiary keydown event
  296. Based on player equipment and the vehicle type he might be in, open or close a cTab device as Tertiary interface.
  297. No Parameters
  298. Returns TRUE when action was taken (interface opened or closed)
  299. Returns FALSE when no action was taken (i.e. player has no cTab device / is not in cTab enabled vehicle)
  300. */
  301. cTab_fnc_onIfTertiaryPressed = {
  302. if (cTabIfOpenStart) exitWith {false};
  303. _previousInterface = "";
  304. if (cTabUavViewActive) then {
  305. objNull remoteControl (gunner cTabActUav);
  306. vehicle cTab_player switchCamera 'internal';
  307. cTabUavViewActive = false;
  308. true
  309. };
  310. if (!isNil "cTabIfOpen" && {cTabIfOpen select 0 == 2}) exitWith {
  311. // close Tertiary
  312. call cTab_fnc_close;
  313. true
  314. };
  315. if !(isNil "cTabIfOpen") then {
  316. _previousInterface = cTabIfOpen select 1;
  317. // close Main / Secondary
  318. call cTab_fnc_close;
  319. };
  320. _player = cTab_player;
  321. _vehicle = vehicle _player;
  322. _interfaceName = call {
  323. if ([_player,["ItemcTab"]] call cTab_fnc_checkGear) exitWith {"cTab_Tablet_dlg"};
  324. // default
  325. ""
  326. };
  327. if (_interfaceName != "" && _interfaceName != _previousInterface) exitWith {
  328. // queue the start up of the interface as we might still have one closing down
  329. [{
  330. if (isNil "cTabIfOpen") then {
  331. [_this select 1] call CBA_fnc_removePerFrameHandler;
  332. (_this select 0) call cTab_fnc_open;
  333. };
  334. },0,[2,_interfaceName,_player,_vehicle]] call CBA_fnc_addPerFrameHandler;
  335. true
  336. };
  337. false
  338. };
  339. /*
  340. Function handling Zoom_In keydown event
  341. If supported cTab interface is visible, decrease map scale
  342. Returns TRUE when action was taken
  343. Returns FALSE when no action was taken (i.e. no interface open, or unsupported interface)
  344. */
  345. cTab_fnc_onZoomInPressed = {
  346. if (cTabIfOpenStart || (isNil "cTabIfOpen")) exitWith {false};
  347. _displayName = cTabIfOpen select 1;
  348. if !([_displayName] call cTab_fnc_isDialog) exitWith {
  349. _mapScale = ([_displayName,"mapScaleDsp"] call cTab_fnc_getSettings) / 2;
  350. _mapScaleMin = [_displayName,"mapScaleMin"] call cTab_fnc_getSettings;
  351. if (_mapScale < _mapScaleMin) then {
  352. _mapScale = _mapScaleMin;
  353. };
  354. _mapScale = [_displayName,[["mapScaleDsp",_mapScale]]] call cTab_fnc_setSettings;
  355. true
  356. };
  357. false
  358. };
  359. /*
  360. Function handling Zoom_Out keydown event
  361. If supported cTab interface is visible, increase map scale
  362. Returns TRUE when action was taken
  363. Returns FALSE when no action was taken (i.e. no interface open, or unsupported interface)
  364. */
  365. cTab_fnc_onZoomOutPressed = {
  366. if (cTabIfOpenStart || (isNil "cTabIfOpen")) exitWith {false};
  367. _displayName = cTabIfOpen select 1;
  368. if !([_displayName] call cTab_fnc_isDialog) exitWith {
  369. _mapScale = ([_displayName,"mapScaleDsp"] call cTab_fnc_getSettings) * 2;
  370. _mapScaleMax = [_displayName,"mapScaleMax"] call cTab_fnc_getSettings;
  371. if (_mapScale > _mapScaleMax) then {
  372. _mapScale = _mapScaleMax;
  373. };
  374. _mapScale = [_displayName,[["mapScaleDsp",_mapScale]]] call cTab_fnc_setSettings;
  375. true
  376. };
  377. false
  378. };
  379. /*
  380. Function to toggle text next to BFT icons
  381. Parameter 0: String of uiNamespace variable for which to toggle showIconText for
  382. Returns TRUE
  383. */
  384. cTab_fnc_iconText_toggle = {
  385. _displayName = _this select 0;
  386. if (cTabBFTtxt) then {cTabBFTtxt = false} else {cTabBFTtxt = true};
  387. [_displayName,[["showIconText",cTabBFTtxt]]] call cTab_fnc_setSettings;
  388. true
  389. };
  390. /*
  391. Function to toggle mapType to the next one in the list of available map types
  392. Parameter 0: String of uiNamespace variable for which to toggle to mapType for
  393. Returns TRUE
  394. */
  395. cTab_fnc_mapType_toggle = {
  396. _displayName = _this select 0;
  397. _mapTypes = [_displayName,"mapTypes"] call cTab_fnc_getSettings;
  398. _currentMapType = [_displayName,"mapType"] call cTab_fnc_getSettings;
  399. _currentMapTypeIndex = [_mapTypes,_currentMapType] call BIS_fnc_findInPairs;
  400. if (_currentMapTypeIndex == count _mapTypes - 1) then {
  401. [_displayName,[["mapType",_mapTypes select 0 select 0]]] call cTab_fnc_setSettings;
  402. } else {
  403. [_displayName,[["mapType",_mapTypes select (_currentMapTypeIndex + 1) select 0]]] call cTab_fnc_setSettings;
  404. };
  405. true
  406. };
  407. /*
  408. Function to toggle showMenu
  409. Parameter 0: String of uiNamespace variable for which to toggle showMenu for
  410. Returns TRUE
  411. */
  412. cTab_fnc_showMenu_toggle = {
  413. _displayName = _this select 0;
  414. _showMenu = [_displayName,"showMenu"] call cTab_fnc_getSettings;
  415. _showMenu = !_showMenu;
  416. [_displayName,[["showMenu",_showMenu]]] call cTab_fnc_setSettings;
  417. true
  418. };
  419. /*
  420. Function to toggle night mode
  421. Parameter 0: String of uiNamespace variable for which to toggle nightMode for
  422. Returns TRUE
  423. */
  424. cTab_fnc_toggleNightMode = {
  425. _displayName = _this select 0;
  426. _nightMode = [_displayName,"nightMode"] call cTab_fnc_getSettings;
  427. if (_nightMode != 2) then {
  428. if (_nightMode == 0) then {_nightMode = 1} else {_nightMode = 0};
  429. [_displayName,[["nightMode",_nightMode]]] call cTab_fnc_setSettings;
  430. };
  431. true
  432. };
  433. /*
  434. Function to increase brightness
  435. Parameter 0: String of uiNamespace variable for which to increase brightness for
  436. Returns TRUE
  437. */
  438. cTab_fnc_incBrightness = {
  439. _displayName = _this select 0;
  440. _brightness = [_displayName,"brightness"] call cTab_fnc_getSettings;
  441. _brightness = _brightness + 0.1;
  442. // make sure brightness is not larger than 1
  443. if (_brightness > 1) then {_brightness = 1};
  444. [_displayName,[["brightness",_brightness]]] call cTab_fnc_setSettings;
  445. true
  446. };
  447. /*
  448. Function to decrease brightness
  449. Parameter 0: String of uiNamespace variable for which to decreas brightness for
  450. Returns TRUE
  451. */
  452. cTab_fnc_decBrightness = {
  453. _displayName = _this select 0;
  454. _brightness = [_displayName,"brightness"] call cTab_fnc_getSettings;
  455. _brightness = _brightness - 0.1;
  456. // make sure brightness is not larger than 0.5
  457. if (_brightness < 0.5) then {_brightness = 0.5};
  458. [_displayName,[["brightness",_brightness]]] call cTab_fnc_setSettings;
  459. true
  460. };
  461. // fnc to increase icon and text size
  462. cTab_fnc_txt_size_inc = {
  463. cTabTxtFctr = cTabTxtFctr + 1;
  464. call cTab_fnc_update_txt_size;
  465. };
  466. // fnc to decrease icon and text size
  467. cTab_fnc_txt_size_dec = {
  468. if (cTabTxtFctr > 1) then {cTabTxtFctr = cTabTxtFctr - 1};
  469. call cTab_fnc_update_txt_size;
  470. };
  471. // This is drawn every frame on the tablet. fnc
  472. cTabOnDrawbft = {
  473. _cntrlScreen = _this select 0;
  474. _display = ctrlParent _cntrlScreen;
  475. cTabMapWorldPos = [_cntrlScreen] call cTab_fnc_ctrlMapCenter;
  476. cTabMapScale = ctrlMapScale _cntrlScreen;
  477. [_cntrlScreen,true] call cTab_fnc_drawUserMarkers;
  478. [_cntrlScreen,0] call cTab_fnc_drawBftMarkers;
  479. // draw directional arrow at own location
  480. _veh = vehicle cTab_player;
  481. _playerPos = getPosASL _veh;
  482. _heading = direction _veh;
  483. _cntrlScreen drawIcon ["\A3\ui_f\data\map\VehicleIcons\iconmanvirtual_ca.paa"_playerPos,_heading,"", 1,cTabTxtSize,"TahomaB","right"];
  484. // update hook information
  485. if (cTabDrawMapTools) then {
  486. [_display,_cntrlScreen,_playerPos,cTabMapCursorPos,0,false] call cTab_fnc_drawHook;
  487. };
  488. true
  489. };
  490. // This is drawn every frame on the vehicle display. fnc
  491. cTabOnDrawbftVeh = {
  492. _cntrlScreen = _this select 0;
  493. _display = ctrlParent _cntrlScreen;
  494. cTabMapWorldPos = [_cntrlScreen] call cTab_fnc_ctrlMapCenter;
  495. cTabMapScale = ctrlMapScale _cntrlScreen;
  496. [_cntrlScreen,true] call cTab_fnc_drawUserMarkers;
  497. [_cntrlScreen,0] call cTab_fnc_drawBftMarkers;
  498. // draw directional arrow at own location
  499. _veh = vehicle cTab_player;
  500. _playerPos = getPosASL _veh;
  501. _heading = direction _veh;
  502. _cntrlScreen drawIcon ["\A3\ui_f\data\map\VehicleIcons\iconmanvirtual_ca.paa",_playerPos,_heading,"", 1,cTabTxtSize,"TahomaB","right"];
  503. // update hook information
  504. if (cTabDrawMapTools) then {
  505. [_display,_cntrlScreen,_playerPos,cTabMapCursorPos,0,false] call cTab_fnc_drawHook;
  506. };
  507. true
  508. };
  509. // This is drawn every frame on the tablet uav screen. fnc
  510. cTabOnDrawUAV = {
  511. if (isNil 'cTabActUav') exitWith {};
  512. if (cTabActUav == player) exitWith {};
  513. _cntrlScreen = _this select 0;
  514. _display = ctrlParent _cntrlScreen;
  515. _pos = getPosASL cTabActUav;
  516. [_cntrlScreen,false] call cTab_fnc_drawUserMarkers;
  517. [_cntrlScreen,0] call cTab_fnc_drawBftMarkers;
  518. // draw icon at own location
  519. _veh = vehicle cTab_player;
  520. _cntrlScreen drawIcon ["\A3\ui_f\data\map\VehicleIcons\iconmanvirtual_ca.paa",getPosASL _veh,direction _veh,"", 1,cTabTxtSize,"TahomaB","right"];
  521. // draw icon at UAV location
  522. _cntrlScreen drawIcon ["\A3\ui_f\data\map\VehicleIcons\iconmanvirtual_ca.paa",_pos,direction cTabActUav,"",0,cTabTxtSize,"TahomaB","right"];
  523. _cntrlScreen ctrlMapAnimAdd [0,cTabMapScaleUAV,_pos];
  524. ctrlMapAnimCommit _cntrlScreen;
  525. true
  526. };
  527. // This is drawn every frame on the tablet helmet cam screen. fnc
  528. cTabOnDrawHCam = {
  529. if (isNil 'cTabHcams') exitWith {};
  530. _camHost = cTabHcams select 2;
  531. _cntrlScreen = _this select 0;
  532. _display = ctrlParent _cntrlScreen;
  533. _pos = getPosASL _camHost;
  534. [_cntrlScreen,false] call cTab_fnc_drawUserMarkers;
  535. [_cntrlScreen,0] call cTab_fnc_drawBftMarkers;
  536. // draw icon at own location
  537. _veh = vehicle cTab_player;
  538. _cntrlScreen drawIcon ["\A3\ui_f\data\map\VehicleIcons\iconmanvirtual_ca.paa",getPosASL _veh,direction _veh,"", 1,cTabTxtSize,"TahomaB","right"];
  539. // draw icon at helmet cam location
  540. _cntrlScreen drawIcon ["\A3\ui_f\data\map\VehicleIcons\iconmanvirtual_ca.paa",direction _camHost,"",0,cTabTxtSize,"TahomaB","right"];
  541. _cntrlScreen ctrlMapAnimAdd [0,cTabMapScaleHCam,_pos];
  542. ctrlMapAnimCommit _cntrlScreen;
  543. true
  544. };
  545. //Main loop to add the key handler to the unit.
  546. [] spawn {
  547. waitUntil {sleep 0.1;!(IsNull (findDisplay 46))};
  548. ["cTab","ifMain",["Toggle Main Interface","Open cTab device in small overlay mode if available"],{call cTab_fnc_onIfMainPressed},"",[cTab_key_if_main_scancode,cTab_key_if_main_modifiers],false] call cba_fnc_addKeybind;
  549. ["cTab","ifSecondary",["Toggle Secondary Interface","Open cTab device in interactable mode"],{call cTab_fnc_onIfSecondaryPressed},"",[cTab_key_if_secondary_scancode,cTab_key_if_secondary_modifiers],false] call cba_fnc_addKeybind;
  550. ["cTab","zoomIn",["Zoom In","Zoom In on map while cTab is in small overlay mode"],{call cTab_fnc_onZoomInPressed},"",[cTab_key_zoom_in_scancode,cTab_key_zoom_in_modifiers],false] call cba_fnc_addKeybind;
  551. ["cTab","zoomOut",["Zoom Out","Zoom Out on map while cTab is in small overlay mode"],{call cTab_fnc_onZoomOutPressed},"",[cTab_key_zoom_out_scancode,cTab_key_zoom_out_modifiers],false] call cba_fnc_addKeybind;
  552. ["cTab","toggleIfPosition",["Toggle Interface Position","Toggle overlay mode interface position from left to right or reset interactive mode interface position to default"],{[] call cTab_fnc_toggleIfPosition},"",[cTab_key_toggleIfPosition_scancode,cTab_key_toggleIfPosition_modifiers],false] call cba_fnc_addKeybind;
  553. // if player is curator (ZEUS), setup key handlers
  554. waitUntil {sleep 0.1;!(isNull player)};
  555. sleep 2;
  556. if (player in (call BIS_fnc_listCuratorPlayers)) then {
  557. [] spawn {
  558. while {true} do {
  559. waitUntil {sleep 0.1;!(isNull (findDisplay 312))};
  560. (findDisplay 312) displayAddEventHandler ["KeyDown","[_this,'keydown'] call cTab_fnc_processCuratorKey"];
  561. (findDisplay 312) displayAddEventHandler ["KeyUp","[_this,'keyup'] call cTab_fnc_processCuratorKey"];
  562. waitUntil {sleep 0.1;isNull (findDisplay 312)};
  563. };
  564. };
  565. };
  566. };
  567. cTab_msg_gui_load = {
  568. disableSerialization;
  569. _return = true;
  570. _display = uiNamespace getVariable (cTabIfOpen select 1);
  571. _playerEncryptionKey = call cTab_fnc_getPlayerEncryptionKey;
  572. _msgArray = cTab_player getVariable [format ["cTab_messages_%1",_playerEncryptionKey],[]];
  573. _msgControl = _display displayCtrl IDC_CTAB_MSG_LIST;
  574. _plrlistControl = _display displayCtrl IDC_CTAB_MSG_RECIPIENTS;
  575. lbClear _msgControl;
  576. lbClear _plrlistControl;
  577. _plrList = playableUnits;
  578. // since playableUnits will return an empty array in single player, add the player if array is empty
  579. if (_plrList isEqualTo []) then {_plrList pushBack cTab_player};
  580. _validSides = call cTab_fnc_getPlayerSides;
  581. // turn this on for testing, otherwise not really usefull, since sending to an AI controlled, but switchable unit will send the message to the player himself
  582. /*if (count _plrList < 1) then { _plrList = switchableUnits;};*/
  583. uiNamespace setVariable ['cTab_msg_playerList', _plrList];
  584. // Messages
  585. {
  586. _title = _x select 0;
  587. _msgState = _x select 2;
  588. _img = call {
  589. if (_msgState == 0) exitWith {"\ClonecTab\img\icoUnopenedmail.paa"};
  590. if (_msgState == 1) exitWith {"\ClonecTab\img\icoOpenmail.paa"};
  591. if (_msgState == 2) exitWith {"\ClonecTab\img\icon_sentMail_ca.paa"};
  592. };
  593. _index = _msgControl lbAdd _title;
  594. _msgControl lbSetPicture [_index,_img];
  595. _msgControl lbSetTooltip [_index,_title];
  596. } count _msgArray;
  597. lbSort [_plrlistControl, "ASC"];
  598. _return;
  599. };
  600. cTab_msg_get_mailTxt = {
  601. disableSerialization;
  602. _return = true;
  603. _index = _this select 1;
  604. _display = uiNamespace getVariable (cTabIfOpen select 1);
  605. _playerEncryptionKey = call cTab_fnc_getPlayerEncryptionKey;
  606. _msgArray = cTab_player getVariable [format ["cTab_messages_%1",_playerEncryptionKey],[]];
  607. _msgName = (_msgArray select _index) select 0;
  608. _msgtxt = (_msgArray select _index) select 1;
  609. _msgState = (_msgArray select _index) select 2;
  610. if (_msgState == 0) then {
  611. _msgArray set [_index,[_msgName,_msgtxt,1]];
  612. cTab_player setVariable [format ["cTab_messages_%1",_playerEncryptionKey],_msgArray];
  613. };
  614. _nop = [] call cTab_msg_gui_load;
  615. _txtControl = _display displayCtrl IDC_CTAB_MSG_CONTENT;
  616. _nul = _txtControl ctrlSetText _msgtxt;
  617. _return;
  618. };
  619. cTab_msg_Send = {
  620. private ["_return","_display","_plrLBctrl","_msgBodyctrl","_plrList","_indices","_time","_msgTitle","_msgBody","_recip","_recipientNames","_msgArray","_playerEncryptionKey"];
  621. disableSerialization;
  622. _return = true;
  623. _display = uiNamespace getVariable (cTabIfOpen select 1);
  624. _playerEncryptionKey = call cTab_fnc_getPlayerEncryptionKey;
  625. _plrLBctrl = _display displayCtrl IDC_CTAB_MSG_RECIPIENTS;
  626. _msgBodyctrl = _display displayCtrl IDC_CTAB_MSG_COMPOSE;
  627. _plrList = (uiNamespace getVariable "cTab_msg_playerList");
  628. _indices = lbSelection _plrLBctrl;
  629. if (_indices isEqualTo []) exitWith {false};
  630. _time = call cTab_fnc_currentTime;
  631. _msgTitle = format ["%1 - %2:%3 (%4)",_time,groupId group cTab_player,[cTab_player] call CBA_fnc_getGroupIndex,name cTab_player];
  632. _msgBody = ctrlText _msgBodyctrl;
  633. if (_msgBody isEqualTo "") exitWith {false};
  634. _recipientNames = "";
  635. {
  636. _data = _plrLBctrl lbData _x;
  637. _recip = objNull;
  638. {
  639. if (_data == str _x) exitWith {_recip = _x;};
  640. } count _plrList;
  641. if !(IsNull _recip) then {
  642. if (_recipientNames isEqualTo "") then {
  643. _recipientNames = format ["%1:%2 (%3)",groupId group _recip,[_recip] call CBA_fnc_getGroupIndex,name _recip];
  644. } else {
  645. _recipientNames = format ["%1; %2",_recipientNames,name _recip];
  646. };
  647. ["cTab_msg_receive",[_recip,_msgTitle,_msgBody,_playerEncryptionKey,cTab_player]] call CBA_fnc_whereLocalEvent;
  648. };
  649. } forEach _indices;
  650. // If the message was sent
  651. if (_recipientNames != "") then {
  652. _msgArray = cTab_player getVariable [format ["cTab_messages_%1",_playerEncryptionKey],[]];
  653. _msgArray pushBack [format ["%1 - %2",_time,_recipientNames],_msgBody,2];
  654. cTab_player setVariable [format ["cTab_messages_%1",_playerEncryptionKey],_msgArray];
  655. if (!isNil "cTabIfOpen" && {[cTabIfOpen select 1,"mode"] call cTab_fnc_getSettings == "MESSAGE"}) then {
  656. call cTab_msg_gui_load;
  657. };
  658. // add a notification
  659. ["MSG","Message sent successfully",3] call cTab_fnc_addNotification;
  660. playSound "cTab_mailSent";
  661. // remove message body
  662. _msgBodyctrl ctrlSetText "";
  663. // clear selected recipients
  664. _plrLBctrl lbSetCurSel -1;
  665. };
  666. _return;
  667. };
  668. ["cTab_msg_receive",
  669. {
  670. _msgRecipient = _this select 0;
  671. _msgTitle = _this select 1;
  672. _msgBody = _this select 2;
  673. _msgEncryptionKey = _this select 3;
  674. _sender = _this select 4;
  675. _playerEncryptionKey = call cTab_fnc_getPlayerEncryptionKey;
  676. _msgArray = _msgRecipient getVariable [format ["cTab_messages_%1",_msgEncryptionKey],[]];
  677. _msgArray pushBack [_msgTitle,_msgBody,0];
  678. _msgRecipient setVariable [format ["cTab_messages_%1",_msgEncryptionKey],_msgArray];
  679. if (_msgRecipient == cTab_player && _sender != cTab_player && {_playerEncryptionKey == _msgEncryptionKey} && {[cTab_player,["ItemcTab"]] call cTab_fnc_checkGear}) then {
  680. playSound "cTab_phoneVibrate";
  681. if (!isNil "cTabIfOpen" && {[cTabIfOpen select 1,"mode"] call cTab_fnc_getSettings == "MESSAGE"}) then {
  682. _nop = [] call cTab_msg_gui_load;
  683. // add a notification
  684. ["MSG",format ["New message from %1",name _sender],6] call cTab_fnc_addNotification;
  685. } else {
  686. cTabRscLayerMailNotification cutRsc ["cTab_Mail_ico_disp", "PLAIN"]; //show
  687. };
  688. };
  689. }
  690. ] call CBA_fnc_addLocalEventHandler;
  691. cTab_msg_delete_all = {
  692. _playerEncryptionKey = call cTab_fnc_getPlayerEncryptionKey;
  693. cTab_player setVariable [format ["cTab_messages_%1",_playerEncryptionKey],[]];
  694. };
  695. /*
  696. Function to execute the correct action when btnACT is pressed on Tablet
  697. No Parameters
  698. Returns TRUE
  699. */
  700. cTab_Tablet_btnACT = {
  701. _mode = ["cTab_Tablet_dlg","mode"] call cTab_fnc_getSettings;
  702. call {
  703. if (_mode == "UAV") exitWith {[] call cTab_fnc_remoteControlUav;};
  704. if (_mode == "HCAM") exitWith {["cTab_Tablet_dlg",[["mode","HCAM_FULL"]]] call cTab_fnc_setSettings;};
  705. if (_mode == "HCAM_FULL") exitWith {["cTab_Tablet_dlg",[["mode","HCAM"]]] call cTab_fnc_setSettings;};
  706. };
  707. true
  708. };
  709. /*
  710. Function called when DELETE button is pressed in messaging mode
  711. Parameter 0: Name of uiNameSpace variable of display
  712. Returns false if nothing was selected for deletion, else returns true
  713. */
  714. cTab_fnc_onMsgBtnDelete = {
  715. _displayName = _this select 0;
  716. _display = uiNamespace getVariable _displayName;
  717. _msgLbCtrl = _display displayCtrl IDC_CTAB_MSG_LIST;
  718. _msgLbSelection = lbSelection _msgLbCtrl;
  719. if (count _msgLbSelection == 0) exitWith {false};
  720. _playerEncryptionKey = call cTab_fnc_getPlayerEncryptionKey;
  721. _msgArray = cTab_player getVariable [format ["cTab_messages_%1",_playerEncryptionKey],[]];
  722. // run through the selection backwards as otherwise the indices won't match anymore
  723. for "_i" from (count _msgLbSelection) to 0 step -1 do {
  724. _msgArray deleteAt (_msgLbSelection select _i);
  725. };
  726. cTab_player setVariable [format ["cTab_messages_%1",_playerEncryptionKey],_msgArray];
  727. _msgTextCtrl = _display displayCtrl IDC_CTAB_MSG_CONTENT;
  728. _msgTextCtrl ctrlSetText "No Message Selected";
  729. _nop = [] call cTab_msg_gui_load;
  730. true
  731. };