From b3538c972fe85795e9b233be4de1ec5ce62b454a Mon Sep 17 00:00:00 2001 From: ulteq Date: Thu, 11 Jun 2015 11:56:25 +0200 Subject: [PATCH] Finished the DAGR port: * Added keybinds * Shortened the function names * Made use of the GVAR macro for all global variable names --- addons/dagr/CfgVehicles.hpp | 4 +- addons/dagr/Dialog.hpp | 24 +++---- addons/dagr/XEH_postInit.sqf | 5 +- addons/dagr/XEH_preInit.sqf | 12 ++-- ...CTOR.sqf => fnc_handleRangeFinderData.sqf} | 2 +- ...nc_DAGR_MENU_INIT.sqf => fnc_menuInit.sqf} | 69 ++++++++++--------- ...AGR_OUTPUT_DATA.sqf => fnc_outputData.sqf} | 0 ...OUTPUT_VECTOR.sqf => fnc_outputVector.sqf} | 0 ...nc_DAGR_OUTPUT_WP.sqf => fnc_outputWP.sqf} | 0 ...c_DAGR_START.sqf => fnc_toggleOverlay.sqf} | 6 +- addons/dagr/initKeybinds.sqf | 30 ++++++++ 11 files changed, 93 insertions(+), 59 deletions(-) rename addons/dagr/functions/{fnc_DAGR_VECTOR.sqf => fnc_handleRangeFinderData.sqf} (92%) rename addons/dagr/functions/{fnc_DAGR_MENU_INIT.sqf => fnc_menuInit.sqf} (96%) rename addons/dagr/functions/{fnc_DAGR_OUTPUT_DATA.sqf => fnc_outputData.sqf} (100%) rename addons/dagr/functions/{fnc_DAGR_OUTPUT_VECTOR.sqf => fnc_outputVector.sqf} (100%) rename addons/dagr/functions/{fnc_DAGR_OUTPUT_WP.sqf => fnc_outputWP.sqf} (100%) rename addons/dagr/functions/{fnc_DAGR_START.sqf => fnc_toggleOverlay.sqf} (86%) create mode 100644 addons/dagr/initKeybinds.sqf diff --git a/addons/dagr/CfgVehicles.hpp b/addons/dagr/CfgVehicles.hpp index 9e2eee1e8e..96b81c15b6 100644 --- a/addons/dagr/CfgVehicles.hpp +++ b/addons/dagr/CfgVehicles.hpp @@ -6,7 +6,7 @@ class CfgVehicles { class GVAR(menu) { displayName = "Configure DAGR"; condition = QUOTE([ARR_2(_player,'ACE_DAGR')] call EFUNC(common,hasItem)); - statement = QUOTE(call FUNC(DAGR_MENU_INIT)); + statement = QUOTE(call FUNC(menuInit)); showDisabled = 0; priority = 0.1; icon = QUOTE(PATHTOF(UI\DAGR_Icon.paa)); @@ -14,7 +14,7 @@ class CfgVehicles { class GVAR(toggle) { displayName = "Toggle DAGR"; condition = QUOTE([ARR_2(_player,'ACE_DAGR')] call EFUNC(common,hasItem)); - statement = QUOTE(call FUNC(DAGR_START)); + statement = QUOTE(call FUNC(toggleOverlay)); showDisabled = 0; priority = 0.2; icon = QUOTE(PATHTOF(UI\DAGR_Icon.paa)); diff --git a/addons/dagr/Dialog.hpp b/addons/dagr/Dialog.hpp index 4f42a12db0..2faeb03879 100644 --- a/addons/dagr/Dialog.hpp +++ b/addons/dagr/Dialog.hpp @@ -145,7 +145,7 @@ class DAGR_Menu { fadeout = 0; name = "Dagr_Menu"; onLoad = "uiNamespace setVariable ['DAGR_Menu', _this select 0]"; - onUnload = "DAGR_PWR = true"; + onUnload = QUOTE(GVAR(PWR) = true); // Simulate pressing the power button controls[] = {"DAGR_MENU_UI", "DAGR_PWR_Button", "DAGR_UP_Button", "DAGR_DOWN_Button", "DAGR_LEFT_Button", "DAGR_RIGHT_Button", "DAGR_NEXT_Button", "DAGR_SEL_Button", "DAGR_MENU_Button", "DAGR_F1_Button", "DAGR_F2_Button", "DAGR_F3_Button", "DAGR_F1_Text", "DAGR_F2_Text", "DAGR_F3_Text", "DAGR_MENU_OPTION0", "DAGR_MENU_OPTION1", "DAGR_MENU_OPTION2", "DAGR_MENU_OPTION3", "DAGR_MENU_OPTION4", "DAGR_MENU_SELECTION0", "DAGR_MENU_SELECTION1", "DAGR_MENU_SELECTION2", @@ -162,28 +162,28 @@ class DAGR_Menu { class DAGR_PWR_Button : DAGR_Button { idc = 266863; - action = "DAGR_PWR = true"; + action = QUOTE(GVAR(PWR) = true); x = 0.40; y = 0.65; }; class DAGR_UP_Button : DAGR_Button { idc = 266864; - action = "DAGR_UP = true"; + action = QUOTE(GVAR(UP) = true); x = 0.50; y = 0.675; }; class DAGR_DOWN_Button : DAGR_Button { idc = 266865; - action = "DAGR_Down = true"; + action = QUOTE(GVAR(DOWN) = true); x = 0.50; y = 0.81; }; class DAGR_LEFT_Button : DAGR_Button { idc = 266866; - action = "DAGR_LEFT = true"; + action = QUOTE(GVAR(LEFT) = true); x = 0.40; y = 0.735; w = 0.05; @@ -192,7 +192,7 @@ class DAGR_Menu { class DAGR_RIGHT_Button : DAGR_Button { idc = 266867; - action = "DAGR_RIGHT = true"; + action = QUOTE(GVAR(RIGHT) = true); x = 0.62; y = 0.735; w = 0.05; @@ -201,14 +201,14 @@ class DAGR_Menu { class DAGR_NEXT_Button : DAGR_Button { idc = 266868; - action = "DAGR_NEXT = true"; + action = QUOTE(DAGR_NEXT = true); x = 0.60; y = 0.65; }; class DAGR_SEL_Button : DAGR_Button { idc = 266869; - action = "DAGR_SEL = true"; + action = QUOTE(GVAR(SEL) = true); x = 0.54; y = 0.735; w = 0.06; @@ -217,7 +217,7 @@ class DAGR_Menu { class DAGR_MENU_Button : DAGR_Button { idc = 266870; - action = "DAGR_MENU_B = true"; + action = QUOTE(GVAR(MENU_B) = true); x = 0.46; y = 0.735; w = 0.06; @@ -226,21 +226,21 @@ class DAGR_Menu { class DAGR_F1_Button : DAGR_Button { idc = 266871; - action = "DAGR_F1 = true"; + action = QUOTE(GVAR(F1) = true); x = 0.40; y = 0.575; }; class DAGR_F2_Button : DAGR_Button { idc = 266872; - action = "DAGR_F2 = true"; + action = QUOTE(GVAR(F2) = true); x = 0.495; y = 0.575; }; class DAGR_F3_Button : DAGR_Button { idc = 266873; - action = "DAGR_F3 = true"; + action = QUOTE(GVAR(F3) = true); x = 0.59; y = 0.575; }; diff --git a/addons/dagr/XEH_postInit.sqf b/addons/dagr/XEH_postInit.sqf index 5ce826a938..b788d85411 100644 --- a/addons/dagr/XEH_postInit.sqf +++ b/addons/dagr/XEH_postInit.sqf @@ -1,6 +1,9 @@ #include "script_component.hpp" +#include "initKeybinds.sqf" + GVAR(run) = false; +GVAR(menuRun) = false; GVAR(useDegrees) = true; GVAR(updateInterval) = 0.5; @@ -22,4 +25,4 @@ GVAR(vectorConnected) = false; GVAR(noVectorData) = true; GVAR(vectorGrid) = "00000000"; -["RangerfinderData", {_this call FUNC(DAGR_VECTOR)}] call EFUNC(common,addEventHandler); +["RangerfinderData", {_this call FUNC(handleRangeFinderData)}] call EFUNC(common,addEventHandler); diff --git a/addons/dagr/XEH_preInit.sqf b/addons/dagr/XEH_preInit.sqf index c1b252bb4e..7c61d71775 100644 --- a/addons/dagr/XEH_preInit.sqf +++ b/addons/dagr/XEH_preInit.sqf @@ -2,11 +2,11 @@ ADDON = false; -PREP(DAGR_MENU_INIT); -PREP(DAGR_OUTPUT_DATA); -PREP(DAGR_OUTPUT_VECTOR); -PREP(DAGR_OUTPUT_WP); -PREP(DAGR_START); -PREP(DAGR_VECTOR); +PREP(handleRangeFinderData); +PREP(menuInit); +PREP(outputData); +PREP(outputVector); +PREP(outputWP); +PREP(toggleOverlay); ADDON = true; diff --git a/addons/dagr/functions/fnc_DAGR_VECTOR.sqf b/addons/dagr/functions/fnc_handleRangeFinderData.sqf similarity index 92% rename from addons/dagr/functions/fnc_DAGR_VECTOR.sqf rename to addons/dagr/functions/fnc_handleRangeFinderData.sqf index 165e5537dd..59e10a1711 100644 --- a/addons/dagr/functions/fnc_DAGR_VECTOR.sqf +++ b/addons/dagr/functions/fnc_handleRangeFinderData.sqf @@ -11,7 +11,7 @@ * Nothing * * Example: - * [1000, 45, 1] call ace_dagr_fnc_DAGR_VECTOR + * [1000, 45, 1] call ace_dagr_fnc_handleRangeFinderData * * Public: No */ diff --git a/addons/dagr/functions/fnc_DAGR_MENU_INIT.sqf b/addons/dagr/functions/fnc_menuInit.sqf similarity index 96% rename from addons/dagr/functions/fnc_DAGR_MENU_INIT.sqf rename to addons/dagr/functions/fnc_menuInit.sqf index eeb0626431..ae1eed9a2b 100644 --- a/addons/dagr/functions/fnc_DAGR_MENU_INIT.sqf +++ b/addons/dagr/functions/fnc_menuInit.sqf @@ -66,34 +66,35 @@ GVAR(showInfoUpdatin) = false; GVAR(showDeleting) = false; GVAR(showOutOfSpace) = false; -DAGR_PWR = false; +GVAR(PWR) = false; +GVAR(menuRun) = true; [{ - if (!dialog || DAGR_PWR) exitWith { + if (!dialog || GVAR(PWR)) exitWith { closeDialog 266860; - DAGR_MENU_RUN = false; + GVAR(menuRun) = false; [_this select 1] call CBA_fnc_removePerFrameHandler; }; - if (DAGR_MENU_B) then { + if (GVAR(MENU_B)) then { GVAR(menu) = "main"; GVAR(selection) = 0; GVAR(numSelections) = 5; }; if (!GVAR(add) && !GVAR(edit)) then { - if (DAGR_DOWN) then { + if (GVAR(DOWN)) then { GVAR(selection) = (GVAR(numSelections) + GVAR(selection) + 1); }; - if (DAGR_UP) then { + if (GVAR(UP)) then { GVAR(selection) = (GVAR(numSelections) + GVAR(selection) - 1); }; GVAR(selection) = if (GVAR(numSelections) > 0) then { GVAR(selection) % GVAR(numSelections) } else { 0 }; }; - if (DAGR_LEFT) then { + if (GVAR(LEFT)) then { GVAR(pointer) = (8 + GVAR(pointer) - 1); }; - if (DAGR_RIGHT) then { + if (GVAR(RIGHT)) then { GVAR(pointer) = (8 + GVAR(pointer) + 1); }; GVAR(pointer) = GVAR(pointer) % 8; @@ -126,7 +127,7 @@ DAGR_PWR = false; switch (GVAR(menu)) do { case "main": { - if (DAGR_SEL) then { + if (GVAR(SEL)) then { switch (GVAR(selection)) do { case 0: { GVAR(displaySelection) = "DATA"; @@ -192,7 +193,7 @@ DAGR_PWR = false; (__dsp displayCtrl (__Selection0 + GVAR(selection))) ctrlSetText QUOTE(PATHTOF(UI\DAGR_Selection.paa)); }; }; - if (DAGR_SEL) then { + if (GVAR(SEL)) then { GVAR(vectorConnected) = false; GVAR(displaySelection) = "WP"; switch (GVAR(selection)) do { @@ -240,7 +241,7 @@ DAGR_PWR = false; (__dsp displayCtrl (__Selection0 + GVAR(selection))) ctrlSetText QUOTE(PATHTOF(UI\DAGR_Selection.paa)); }; }; - if (DAGR_F3 && GVAR(numWaypoints) > 0) then { + if (GVAR(F3) && GVAR(numWaypoints) > 0) then { if (!GVAR(busy)) then { switch (GVAR(selection)) do { case 0: { @@ -307,7 +308,7 @@ DAGR_PWR = false; GVAR(busy) = false; }; }; - if (DAGR_F1) then { + if (GVAR(F1)) then { if (GVAR(numWaypoints) == 5) then { if (!GVAR(busy)) then { GVAR(showOutOfSpace) = true; @@ -334,7 +335,7 @@ DAGR_PWR = false; GVAR(busy) = false; }; }; - if (DAGR_F2 && GVAR(numWaypoints) > 0) then { + if (GVAR(F2) && GVAR(numWaypoints) > 0) then { GVAR(pointer) = 0; GVAR(edit) = true; GVAR(add) = false; @@ -400,7 +401,7 @@ DAGR_PWR = false; (__dsp displayCtrl __mainText) ctrlSetText GVAR(output); (__dsp displayCtrl __PSelection1 + GVAR(pointer)) ctrlSetText QUOTE(PATHTOF(UI\DAGR_PSelection.paa)); }; - if (DAGR_F1) then { + if (GVAR(F1)) then { if (!GVAR(busy)) then { if (GVAR(add)) then { switch (GVAR(numWaypoints)) do { @@ -445,7 +446,7 @@ DAGR_PWR = false; GVAR(busy) = false; }; }; - if (DAGR_F2) then { + if (GVAR(F2)) then { private ["_grid", "_gridVector"]; _grid = toArray GVAR(vectorGrid); _grid deleteAt 4; @@ -460,7 +461,7 @@ DAGR_PWR = false; GVAR(digit7) = floor(_gridVector / 10- GVAR(digit6) * 10 - GVAR(digit5) * 100 - GVAR(digit4) * 1000 - GVAR(digit3) * 10000 - GVAR(digit2) * 100000 - GVAR(digit1) * 1000000); GVAR(digit8) = floor(_gridVector - GVAR(digit7) * 10 - GVAR(digit6) * 100 - GVAR(digit5) * 1000 - GVAR(digit4) * 10000 - GVAR(digit3) * 100000 - GVAR(digit2) * 1000000 - GVAR(digit1) * 10000000); }; - if (DAGR_F3) then { + if (GVAR(F3)) then { if (!GVAR(busy)) then { GVAR(busy) = true; GVAR(busyTimer) = ACE_time; @@ -477,7 +478,7 @@ DAGR_PWR = false; GVAR(busy) = false; }; }; - if (DAGR_UP) then { + if (GVAR(UP)) then { switch (GVAR(pointer) + 1) do { case 1: { GVAR(digit1) = (10 + GVAR(digit1) + 1) % 10 }; case 2: { GVAR(digit2) = (10 + GVAR(digit2) + 1) % 10 }; @@ -489,7 +490,7 @@ DAGR_PWR = false; case 8: { GVAR(digit8) = (10 + GVAR(digit8) + 1) % 10 }; }; }; - if (DAGR_DOWN) then { + if (GVAR(DOWN)) then { switch (GVAR(pointer) + 1) do { case 1: { GVAR(digit1) = (10 + GVAR(digit1) - 1) % 10 }; case 2: { GVAR(digit2) = (10 + GVAR(digit2) - 1) % 10 }; @@ -508,7 +509,7 @@ DAGR_PWR = false; (__dsp displayCtrl __Option0) ctrlSetText "Vector 21"; (__dsp displayCtrl __Selection0) ctrlSetText QUOTE(PATHTOF(UI\DAGR_Selection.paa)); }; - if (DAGR_SEL) then { + if (GVAR(SEL)) then { if (!GVAR(busy)) then { GVAR(busy) = true; GVAR(busyTimer) = ACE_time; @@ -542,7 +543,7 @@ DAGR_PWR = false; (__dsp displayCtrl __Option0) ctrlSetText "Signal Delay"; (__dsp displayCtrl __Option1) ctrlSetText (if (GVAR(useDegrees)) then { "Direction: Deg" } else { "Direction: MIL" }); (__dsp displayCtrl (__Selection0 + GVAR(selection))) ctrlSetText QUOTE(PATHTOF(UI\DAGR_Selection.paa)); - if (DAGR_SEL) then { + if (GVAR(SEL)) then { GVAR(vectorConnected) = false; switch (GVAR(selection)) do { case 0: { GVAR(menu) = "update_rate"; GVAR(numSelections) = 1; GVAR(tmpUpdateRate) = GVAR(updateInterval); }; @@ -551,7 +552,7 @@ DAGR_PWR = false; } }; case "update_rate": { - if (DAGR_F1) then { + if (GVAR(F1)) then { GVAR(updateInterval) = GVAR(tmpUpdateRate); if (!GVAR(busy)) then { GVAR(busy) = true; @@ -572,13 +573,13 @@ DAGR_PWR = false; GVAR(menu) = "options"; GVAR(numSelections) = 2; }; }; - if (DAGR_F3) then { + if (GVAR(F3)) then { GVAR(menu) = "options"; GVAR(numSelections) = 2; }; - if (DAGR_DOWN) then { + if (GVAR(DOWN)) then { GVAR(tmpUpdateRate) = GVAR(tmpUpdateRate) - 0.1; }; - if (DAGR_UP) then { + if (GVAR(UP)) then { GVAR(tmpUpdateRate) = GVAR(tmpUpdateRate) + 0.1; }; GVAR(tmpUpdateRate) = 0.1 max GVAR(tmpUpdateRate) min 2.0; @@ -591,16 +592,16 @@ DAGR_PWR = false; }; if (!GVAR(busy)) then { - DAGR_F3 = false; - DAGR_F2 = false; - DAGR_F1 = false; - DAGR_MENU_B = false; - DAGR_SEL = false; + GVAR(F3) = false; + GVAR(F2) = false; + GVAR(F1) = false; + GVAR(MENU_B) = false; + GVAR(SEL) = false; DAGR_NEXT = false; - DAGR_RIGHT = false; - DAGR_LEFT = false; - DAGR_UP = false; - DAGR_Down = false; - DAGR_PWR = false; + GVAR(RIGHT) = false; + GVAR(LEFT) = false; + GVAR(UP) = false; + GVAR(DOWN) = false; + GVAR(PWR) = false; }; }, 0, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/dagr/functions/fnc_DAGR_OUTPUT_DATA.sqf b/addons/dagr/functions/fnc_outputData.sqf similarity index 100% rename from addons/dagr/functions/fnc_DAGR_OUTPUT_DATA.sqf rename to addons/dagr/functions/fnc_outputData.sqf diff --git a/addons/dagr/functions/fnc_DAGR_OUTPUT_VECTOR.sqf b/addons/dagr/functions/fnc_outputVector.sqf similarity index 100% rename from addons/dagr/functions/fnc_DAGR_OUTPUT_VECTOR.sqf rename to addons/dagr/functions/fnc_outputVector.sqf diff --git a/addons/dagr/functions/fnc_DAGR_OUTPUT_WP.sqf b/addons/dagr/functions/fnc_outputWP.sqf similarity index 100% rename from addons/dagr/functions/fnc_DAGR_OUTPUT_WP.sqf rename to addons/dagr/functions/fnc_outputWP.sqf diff --git a/addons/dagr/functions/fnc_DAGR_START.sqf b/addons/dagr/functions/fnc_toggleOverlay.sqf similarity index 86% rename from addons/dagr/functions/fnc_DAGR_START.sqf rename to addons/dagr/functions/fnc_toggleOverlay.sqf index 7d096bd63b..981dfb5fbe 100644 --- a/addons/dagr/functions/fnc_DAGR_START.sqf +++ b/addons/dagr/functions/fnc_toggleOverlay.sqf @@ -21,13 +21,13 @@ GVAR(run) = !GVAR(run); if (GVAR(run)) then { switch (toUpper GVAR(displaySelection)) do { case "WP" : { - call FUNC(DAGR_OUTPUT_WP); + call FUNC(outputWP); }; case "VECTOR" : { - call FUNC(DAGR_OUTPUT_VECTOR); + call FUNC(outputVector); }; case "DATA" : { - call FUNC(DAGR_OUTPUT_DATA); + call FUNC(outputData); }; }; [{ diff --git a/addons/dagr/initKeybinds.sqf b/addons/dagr/initKeybinds.sqf new file mode 100644 index 0000000000..db7ae0a8af --- /dev/null +++ b/addons/dagr/initKeybinds.sqf @@ -0,0 +1,30 @@ + +["ACE3 Equipment", QGVAR(MenuKey), "Configure DAGR", +{ + // Conditions: canInteract + if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false}; + if !([_player, "ACE_DAGR"] call EFUNC(common,hasItem)) exitWith {false}; + + // Statement + if (!GVAR(menuRun)) then { + [] call FUNC(menuInit); + } else { + GVAR(PWR) = true; // Simulate pressing the power button + }; + true +}, +{false}, +[199, [false, true, false]], false] call cba_fnc_addKeybind; // (CTRL + Home) + +["ACE3 Equipment", QGVAR(ToggleKey), "Toggle DAGR", +{ + // Conditions: canInteract + if !([ACE_player, objNull, ["notOnMap", "isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false}; + if !([_player, "ACE_DAGR"] call EFUNC(common,hasItem)) exitWith {false}; + + // Statement + [] call FUNC(toggleOverlay); + true +}, +{false}, +[199, [false, false, false]], false] call cba_fnc_addKeybind; // (Home)