From 88b9d0899ffd1142308a5ab4e109492da9673ff8 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 3 Apr 2015 00:03:08 +0200 Subject: [PATCH] shortdot scope onDraw --- addons/common/XEH_preInit.sqf | 1 + addons/common/functions/fnc_getZoom.sqf | 14 +++++++++++ addons/scopes/XEH_postInit.sqf | 25 +++++++++++++++---- addons/scopes/XEH_preInit.sqf | 1 - .../scopes/functions/fnc_onDrawShortdot.sqf | 17 +++---------- .../scopes/functions/fnc_onShowShortdot.sqf | 18 ------------- 6 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 addons/common/functions/fnc_getZoom.sqf delete mode 100644 addons/scopes/functions/fnc_onShowShortdot.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 895535233d..345bc7873c 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -81,6 +81,7 @@ PREP(getWeaponAzimuthAndInclination); PREP(getWeaponIndex); PREP(getWeaponState); PREP(getWindDirection); +PREP(getZoom); PREP(goKneeling); PREP(hadamardProduct); PREP(hasItem); diff --git a/addons/common/functions/fnc_getZoom.sqf b/addons/common/functions/fnc_getZoom.sqf new file mode 100644 index 0000000000..1f319ac768 --- /dev/null +++ b/addons/common/functions/fnc_getZoom.sqf @@ -0,0 +1,14 @@ +/* + * Author: commy2 + * + * Returns a value depending on current zoom level. + * + * Argument: + * None. + * + * Return value: + * Zoom. (Number) + */ +#include "script_component.hpp" + +(0.5 - ((worldToScreen positionCameraToWorld [0,1,1]) select 1)) * (getResolution select 5) diff --git a/addons/scopes/XEH_postInit.sqf b/addons/scopes/XEH_postInit.sqf index 3f5bfe920c..dba4fd42cf 100644 --- a/addons/scopes/XEH_postInit.sqf +++ b/addons/scopes/XEH_postInit.sqf @@ -94,11 +94,26 @@ if !(hasInterface) exitWith {}; [201, [false, true, false]], false] call cba_fnc_addKeybind; // init shortdot -["playerInventoryChanged", { - private "_optic"; - _optic = _this select 1 select 9 select 2; +GVAR(showShortdot) = false; - if (_optic == "ACE_optic_DMS" && {!(GETGVAR(shownShortdot,false))}) then { - [_optic] call FUNC(onShowShortdot); +["playerInventoryChanged", { + private "_showShortdot"; + _showShortdot = _this select 1 select 9 select 2 == "ACE_optic_DMS"; + + if (GVAR(showShortdot)) then { + if (!_showShortdot) then { + // hide control and turn onDraw handler off + (uiNamespace getVariable ["ACE_ctrlShortdotReticle", controlNull]) ctrlShow false; + GVAR(showShortdot) = false; + }; + } else { + if (_showShortdot) then { + // create control and turn onDraw handler on + ([QGVAR(reticle)] call BIS_fnc_rscLayer) cutRsc ["ACE_Shortdot_Reticle", "PLAIN", 0, false]; + (uiNamespace getVariable "ACE_ctrlShortdotReticle") ctrlSetText QUOTE(PATHTOF(data\reticles\ace_shortdot_reticle_1.paa)); + GVAR(showShortdot) = true; + }; }; }] call EFUNC(common,addEventHandler); + +addMissionEventHandler ["Draw3D", {if (GVAR(showShortdot)) then {call FUNC(onDrawShortdot)};}]; diff --git a/addons/scopes/XEH_preInit.sqf b/addons/scopes/XEH_preInit.sqf index 2d6174ac24..d33801a510 100644 --- a/addons/scopes/XEH_preInit.sqf +++ b/addons/scopes/XEH_preInit.sqf @@ -8,7 +8,6 @@ PREP(firedEH); PREP(getOptics); PREP(inventoryCheck); PREP(onDrawShortdot); -PREP(onShowShortdot); PREP(showZeroing); GVAR(fadeScript) = scriptNull; diff --git a/addons/scopes/functions/fnc_onDrawShortdot.sqf b/addons/scopes/functions/fnc_onDrawShortdot.sqf index 87ddf02476..78ff0b0f50 100644 --- a/addons/scopes/functions/fnc_onDrawShortdot.sqf +++ b/addons/scopes/functions/fnc_onDrawShortdot.sqf @@ -1,25 +1,16 @@ // by commy2 #include "script_component.hpp" -private ["_control", "_scope"]; +private "_control"; +_control = uiNamespace getVariable ["ACE_ctrlShortdotReticle", controlNull]; -_control = _this select 0 select 0; -_scope = _this select 0 select 1; - -if (currentWeapon ACE_player != primaryWeapon ACE_player || {_scope != primaryWeaponItems ACE_player select 2}) exitWith { - _control ctrlShow false; - - GVAR(shownShortdot) = false; - [_this select 1] call CBA_fnc_removePerFrameHandler; -}; - -if (cameraView != "GUNNER") exitWith { +if (cameraView != "GUNNER" || {currentWeapon ACE_player != primaryWeapon ACE_player}) exitWith { _control ctrlShow false; }; private ["_size", "_sizeX", "_sizeY"]; -_size = ([0.5,0.5] distance worldToScreen positionCameraToWorld [0,1,1]) * (getResolution select 5); +_size = call EFUNC(common,getZoom); _sizeX = _size/4; _sizeY = _sizeX*safezoneW/safezoneH; diff --git a/addons/scopes/functions/fnc_onShowShortdot.sqf b/addons/scopes/functions/fnc_onShowShortdot.sqf deleted file mode 100644 index 079af8fa21..0000000000 --- a/addons/scopes/functions/fnc_onShowShortdot.sqf +++ /dev/null @@ -1,18 +0,0 @@ -// by commy2 - -disableSerialization; -#include "script_component.hpp" - -private ["_scope", "_control"]; - -_scope = _this select 0; - -([QGVAR(reticle)] call BIS_fnc_rscLayer) cutRsc ["ACE_Shortdot_Reticle", "PLAIN", 0, false]; - -_control = uiNamespace getVariable "ACE_ctrlShortdotReticle"; - -_control ctrlSetText QUOTE(PATHTOF(data\reticles\ace_shortdot_reticle_1.paa)); - -GVAR(shownShortdot) = true; - -[FUNC(onDrawShortdot), 0, [_control, _scope]] call CBA_fnc_addPerFrameHandler;