Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "script_component.hpp"
- private ["_ratio", "_mil", "_exit", "_checkfov", "_fovarray", "_maxfov", "_minfov", "_kring", "_kmap", "_kpxpermil", "_fov0", "_texsize", "_kup", "_kres", "_milX", "_milY", "_res", "_resX", "_resY", "_viewportX", "_viewportY", "_k", "_scale", "_wpn", "_xoff", "_yoff", "_pos", "_maxWidth", "_h", "_w"];
- disableSerialization;
- __dsp = uiNameSpace getVariable "ACE_RscOpticsReticle";
- _wpn = ((player weaponAccessories currentWeapon player) select 2);
- __ctrl = __dsp displayCtrl 1;
- __ctrlRing = __dsp displayCtrl 2;
- __wcfg = configfile>>"cfgweapons">>_wpn;
- _currentoptic = "";
- call fnc_opticfg;
- _minfov = getNumber (__wcfg>>"iteminfo">>"OpticsModes">>"Snip">>"OpticsZoomMin");
- _maxfov = getNumber (__wcfg>>"iteminfo">>"OpticsModes">>"Snip">>"OpticsZoomMax");
- _initfov = getNumber (__wcfg>>"iteminfo">>"OpticsModes">>"Snip">>"OpticsZoomInit");
- fov = (((call cba_fnc_getfov) select 0) * 0.669556852268466);
- _exit = false;
- _doUpdateAllLayers = false;
- if (_currentOptic != _wpn) then
- {
- _currentOptic = _wpn;
- _doUpdateAllLayers = true;
- };
- if (ctrlText (__ctrlRing) == "") then
- {
- _doUpdateAllLayers = true;
- };
- sleep 0.001;
- call rsc;
- if (_doUpdateAllLayers) then {
- __ctrl ctrlSetText getText(__wcfg>>"ace_sys_reticles_texreticle");
- diag_log "RingDrawTest";
- __ctrlRing ctrlSetText getText(__wcfg>>"ace_sys_reticles_texring");
- };
- // scaling ze reticle
- if(_minfov != _maxfov && {(getNumber(__wcfg>>"ace_sys_reticles_scalereticle")==1)}) then
- {
- //spawn reticle-adjusting loop
- sleep 0.1;
- fov = (((call cba_fnc_getfov) select 0) * 0.669556852268466);
- if (abs(1-fov/_maxfov)<0.01) then {fov = _maxfov}; //cba func has 0.5-1% margin of error
- diag_log "ScaleLaunchTest";
- [__ctrl, __ctrlRing] spawn {
- disableSerialization;
- __ctrl = _this select 0;
- __ctrlRing = _this select 1;
- private ["_curfov" ];
- while {sightup} do
- {
- waituntil
- {
- //CBA FOV is off by .669556852268466 from FOV listed in config. Probably a change from A2 to A3, will investigate later
- curfov = (((call cba_fnc_getfov) select 0) * 0.669556852268466);
- diag_log "ScaleLaunchTest1";
- call fnc_scale;
- diag_log "ScaleLaunchTest2";
- //hint format ["%1",_curfov];
- (abs(curfov - fov)/fov > 0.01) || {!sightup}
- };
- if !(sightup) exitwith
- {
- __ctrl ctrlSetText "";
- __ctrlRing ctrlSetText "";
- };
- fov = curfov;
- call fnc_scale;
- sleep 0.01;
- };
- };
- _fov0 = getNumber(__wcfg>>"ace_sys_reticles_fov0"); //FOV at which the reticle is scaled correctly
- } else {
- fov = _maxfov;
- _fov0 = _maxfov;
- };
- //reset reticle if different rifle
- if (getNumber(__wcfg>>"ace_sys_reticles_enable_sa") == 1) then {
- if (ACE_SYS_SA_RFL select 2 != _wpn) then {
- _wpn call ace_sys_sight_adjustment_rifle_fnc_newweap;
- };
- } else {
- el = 0;
- wnd = 0;
- };
- if (getNumber(__wcfg>>"ace_sys_reticles_illum")==1) then {
- if !(illum) then
- {__ctrl ctrlSetTextColor [0,0,0,1];
- diag_log "RingDrawIllumTest1";
- __ctrlRing ctrlSetTextColor [1,1,1,1];
- }
- else
- {__ctrl ctrlsetTextColor (getArray(__wcfg>>"ace_sys_reticles_illumcolor"));
- __ctrlRing ctrlSetTextColor [1,1,1,1];
- };
- } else {
- __ctrl ctrlSetTextColor [1,1,1,1];
- diag_log "RingDrawIllumTest";
- __ctrlRing ctrlSetTextColor [1,1,1,1];
- };
- _pos = ctrlposition __ctrl;
- _res = getresolution;
- _resX = _res select 0;
- _resY = _res select 1;
- _viewportX = _res select 2;
- _viewportY = _res select 3;
- _kmap = getNumber(__wcfg>>"ace_sys_reticles_texmap");//reticle texture mapping (1-whole surface of model, 0.5 - half etc)
- _kpxpermil = getNumber(__wcfg>>"ace_sys_reticles_pxmil"); //pxels per mil in optics texture
- _texsize = getNumber(__wcfg>>"ace_sys_reticles_texsize"); //optics texture size
- _kup = 1.36*_kmap; //upscale coefficient
- _kres = _resY/_texsize;
- _kring = getNumber(__wcfg>>"ace_sys_reticles_ringscale");
- _ratio = _fov0/fov;
- _mil = _kpxpermil*_kres*_kup;
- //GVAR(milx) = _mil/_viewportX;
- milx = _mil*0.749351/_viewportY;
- mily = _mil/_viewportY;
- _milX = _ratio*milx; //size of one mil in screen coords
- _milY = _ratio*mily;
- //diag_log format ["ratio %1 kup %2 vpY %3 vpX %4 fov0 %5",_ratio,_kup,_viewportY,_viewportX,_fov0];
- //takes the min dimension when 'keep aspect ratio' type
- _w = _ratio*_kup*safezoneH*0.749351;
- //_w = _ratio*_kup*_viewportY*safezoneH/_viewportX;//this is to always keep it 1:1
- _h = _ratio*_kup*SafeZoneH;
- _xoff = _w/2;
- _yoff = _h/2;
- furlong_retpos = [0.5-_xoff-wnd*_milX,0.5-_yoff+el*_milY,_w,_h];
- //diag_log GVAR(retpos);
- _w = _kring*_kup*safezoneH*0.749351/_kmap;
- //_w = _kring*_kup*_viewportY*safezoneH/(_viewportX*_kmap);
- _h = _kring*_kup*SafeZoneH/_kmap;
- _xoff = _w/2;
- _yoff = _h/2;
- furlong_ringpos = [0.5-_xoff,0.5-_yoff,_w,_h];
- if (ctrlCommitted __ctrl && {ctrlCommitted __ctrlRing}) then {
- __ctrl ctrlsetposition furlong_retpos;
- __ctrlRing ctrlsetposition furlong_ringpos;
- __ctrl ctrlcommit 0;
- __ctrlRing ctrlcommit 0;
- };
- sleep 0.1;
- call deh_add; //add DEH to switch the reticle off as soon as the key is pressed
- waituntil {player != player || {player != vehicle player} || {cameraview != "GUNNER"} || {visibleMap} };
- sightup = false;
- __ctrl ctrlSetText "";
- __ctrlRing ctrlSetText "";
- call deh_remove;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement