Advertisement
X39

VehicleCrewDisplay

X39
Jun 22nd, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.16 KB | None | 0 0
  1. /**
  2.  *  @Param 1 - ACTION:
  3.  *      STRING - String containing the action name, possible actions:
  4.  *                  - init
  5.  *                  - EH_KeyUp
  6.  *                  - EH_KeyDown
  7.  *                  - CreateDisplay
  8.  *                  - DestroyDisplay
  9.  *  @Param 2 - PARAMETERS:
  10.  *      ARRAY, see:
  11.  *          @Action "init":
  12.  *              [
  13.  *                  ARRAY   - Array containing all valid KeysArrays for this action (KeyArray: [NIL, KeyToPress:SCALAR, ShiftState:BOOLEAN, CtrlState:BOOLEAN, AltState:BOOLEAN])
  14.  *                  OBJECT  - Object whichs vehicle partners are watches (most of the time should be player)
  15.  *              ]
  16.  *          @Action "EH_KeyUp", "EH_KeyDown":
  17.  *              [
  18.  *                  ANY     - Just added for simple compatibility with the displayEventHandlers (best to pass displayNull)
  19.  *                  SCALAR  - Key pressed
  20.  *                  BOOLEAN - SHIFT state
  21.  *                  BOOLEAN - CTRL state
  22.  *                  BOOLEAN - ALT state
  23.  *              ]
  24.  *          @Action "CreateDisplay", "DestroyDisplay":
  25.  *              []
  26.  */
  27.  
  28. //Error Defines
  29. #define ERROR_COULD_NOT_CREATE_DISPLAY "Could not create display"
  30. #define ERROR_UNKNOWN_ACTION "Unknown action"
  31. //UI Defines
  32. #define uiPositionX 0.408837 * safezoneW + safezoneX
  33. #define uiPositionY 0.3834 * safezoneH + safezoneY
  34. #define uiPositionW 0.154687 * safezoneW
  35. #define uiPositionH 0.231 * safezoneH
  36. #define uiPosition [uiPositionX, uiPositionY, uiPositionW, uiPositionH]
  37. #define uiIDC 32001
  38. #define uiPictureColor [1, 1, 1, 1]
  39. //Macros
  40. #define uiVariable(VAR) (uiNamespace getVariable ["X39_XLib_var_VehicleDisplay", displayNull])
  41.  
  42.  
  43. private["_action"];
  44.  
  45. _action = _this select 0;
  46. _this = _this select 1;
  47. switch(_action) do
  48. {
  49.     case "init": {
  50.         //Make sure the KeyArray passed has nil at first spot
  51.         (_this select 0) set[0, nil];
  52.        
  53.         //Assign the different variables of this script
  54.         X39_XLib_var_VehicleDisplay_ActionKeys = _this select 0;
  55.         X39_XLib_var_VehicleDisplay_WatchedUnit = _this select 1;
  56.         X39_XLib_var_VehicleDisplay_LastUnitsInVehicle = [];
  57.         X39_XLib_var_VehicleDisplay_KeyEventHandler = [
  58.             (findDisplay 46) displayAddEventHandler["KeyDown", {["EH_KeyDown", _this] call _fnc_scriptName;}],
  59.             (findDisplay 46) displayAddEventHandler["KeyUp", {["EH_KeyUp", _this] call _fnc_scriptName;}]
  60.         ];
  61.        
  62.         //Create the display element
  63.         ["CreateDisplay", nil] call _fnc_scriptName;
  64.     };
  65.     case "EH_KeyUp": {
  66.         //Clear display element and after that exit this function if it is not in our key list
  67.         _this set[0, nil];
  68.         if(!(_this in X39_XLib_var_VehicleDisplay_ActionKeys)) exitWith {};
  69.        
  70.         //Check if the vehicleDisplayUI has to be hidden
  71.         if(ctrlShown uiVariable("X39_XLib_var_VehicleDisplay_UI")) then
  72.         {
  73.             uiVariable("X39_XLib_var_VehicleDisplay_UI") ctrlShow false;
  74.         };
  75.     };
  76.     case "EH_KeyDown": {
  77.         //Clear display element and after that exit this function if it is not in our key list
  78.         _this set[0, nil];
  79.         if(!(_this in X39_XLib_var_VehicleDisplay_ActionKeys)) exitWith {};
  80.        
  81.         private["_crew", "_index"];
  82.         //check if we are currently in a vehicle and leave the script if we are not
  83.         if(vehicle X39_XLib_var_VehicleDisplay_WatchedUnit == X39_XLib_var_VehicleDisplay_WatchedUnit) exitWith
  84.         {
  85.             if(ctrlShown uiVariable("X39_XLib_var_VehicleDisplay_UI")) then
  86.             {
  87.                 uiVariable("X39_XLib_var_VehicleDisplay_UI") ctrlShow false;
  88.             };
  89.         };
  90.        
  91.         //get current crew of the vehicle and compare it to the last
  92.         _crew = fullCrew vehicle X39_XLib_var_VehicleDisplay_WatchedUnit;
  93.         if(!(X39_XLib_var_VehicleDisplay_LastUnitsInVehicle isEqualTo _crew)) then
  94.         {
  95.             //last crew differs from current crew, clear the listbox and update every crew entry
  96.             X39_XLib_var_VehicleDisplay_LastUnitsInVehicle = _crew;
  97.             lbClear uiVariable("X39_XLib_var_VehicleDisplay_UI");
  98.             {
  99.                
  100.                 _index = uiVariable("X39_XLib_var_VehicleDisplay_UI") lbAdd name (_x select 0);
  101.                 switch(toLower (_x select 1)) do
  102.                 {
  103.                     case "driver": {
  104.                         uiVariable("X39_XLib_var_VehicleDisplay_UI") lbSetPicture  [_index, "a3\ui_f\data\IGUI\Cfg\Actions\getindriver_ca.paa"];
  105.                     };
  106.                     case "gunner"; case "turret": {
  107.                         uiVariable("X39_XLib_var_VehicleDisplay_UI") lbSetPicture  [_index, "a3\ui_f\data\IGUI\Cfg\Actions\getingunner_ca.paa"];
  108.                     };
  109.                     case "commander": {
  110.                         uiVariable("X39_XLib_var_VehicleDisplay_UI") lbSetPicture  [_index, "a3\ui_f\data\IGUI\Cfg\Actions\getincommander_ca.paa"];
  111.                     };
  112.                     default {
  113.                         uiVariable("X39_XLib_var_VehicleDisplay_UI") lbSetPicture  [_index, "a3\ui_f\data\IGUI\Cfg\Actions\getincargo_ca.paa"];
  114.                     };
  115.                 };
  116.                 uiVariable("X39_XLib_var_VehicleDisplay_UI") lbSetPictureColor [_index, uiPictureColor];
  117.                 false
  118.             }count _crew;
  119.         };
  120.     };
  121.     case "CreateDisplay": {
  122.         uiNamespace setVariable ["X39_XLib_var_VehicleDisplay_UI", (findDisplay 46) ctrlCreate ["RscListBox", uiIDC]];
  123.         if(isNull uiVariable("X39_XLib_var_VehicleDisplay_UI")) then
  124.         {
  125.             throw ERROR_COULD_NOT_CREATE_DISPLAY;
  126.         };
  127.         uiVariable("X39_XLib_var_VehicleDisplay_UI") ctrlShow false;
  128.         uiVariable("X39_XLib_var_VehicleDisplay_UI") ctrlSetPosition uiPosition;
  129.         uiVariable("X39_XLib_var_VehicleDisplay_UI") ctrlCommit 0;
  130.     };
  131.     case "DestroyDisplay": {
  132.         ctrlDelete uiVariable("X39_XLib_var_VehicleDisplay_UI");
  133.         uiNamespace setVariable ["X39_XLib_var_VehicleDisplay_UI", nil];
  134.     }:
  135.     default {
  136.         throw ERROR_UNKNOWN_ACTION;
  137.     };
  138. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement