shortdot scope onDraw

This commit is contained in:
commy2 2015-04-03 00:03:08 +02:00
parent 646a4b5bd1
commit 88b9d0899f
6 changed files with 39 additions and 37 deletions

View File

@ -81,6 +81,7 @@ PREP(getWeaponAzimuthAndInclination);
PREP(getWeaponIndex);
PREP(getWeaponState);
PREP(getWindDirection);
PREP(getZoom);
PREP(goKneeling);
PREP(hadamardProduct);
PREP(hasItem);

View File

@ -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)

View File

@ -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)};}];

View File

@ -8,7 +8,6 @@ PREP(firedEH);
PREP(getOptics);
PREP(inventoryCheck);
PREP(onDrawShortdot);
PREP(onShowShortdot);
PREP(showZeroing);
GVAR(fadeScript) = scriptNull;

View File

@ -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;

View File

@ -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;