Advertisement
Guest User

Furlong_FNC_Reticles3

a guest
Mar 5th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. #include "script_component.hpp"
  2. 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"];
  3.  
  4. disableSerialization;
  5. __dsp = uiNameSpace getVariable "ACE_RscOpticsReticle";
  6. _wpn = ((player weaponAccessories currentWeapon player) select 2);
  7. __ctrl = __dsp displayCtrl 1;
  8. __ctrlRing = __dsp displayCtrl 2;
  9. __wcfg = configfile>>"cfgweapons">>_wpn;
  10. _currentoptic = "";
  11. call fnc_opticfg;
  12. _minfov = getNumber (__wcfg>>"iteminfo">>"OpticsModes">>"Snip">>"OpticsZoomMin");
  13. _maxfov = getNumber (__wcfg>>"iteminfo">>"OpticsModes">>"Snip">>"OpticsZoomMax");
  14. _initfov = getNumber (__wcfg>>"iteminfo">>"OpticsModes">>"Snip">>"OpticsZoomInit");
  15. fov = (((call cba_fnc_getfov) select 0) * 0.669556852268466);
  16. _exit = false;
  17.  
  18. _doUpdateAllLayers = false;
  19. if (_currentOptic != _wpn) then
  20. {
  21. _currentOptic = _wpn;
  22. _doUpdateAllLayers = true;
  23. };
  24. if (ctrlText (__ctrlRing) == "") then
  25. {
  26. _doUpdateAllLayers = true;
  27. };
  28. sleep 0.001;
  29. call rsc;
  30. if (_doUpdateAllLayers) then {
  31. __ctrl ctrlSetText getText(__wcfg>>"ace_sys_reticles_texreticle");
  32. diag_log "RingDrawTest";
  33. __ctrlRing ctrlSetText getText(__wcfg>>"ace_sys_reticles_texring");
  34. };
  35. // scaling ze reticle
  36.  
  37. if(_minfov != _maxfov && {(getNumber(__wcfg>>"ace_sys_reticles_scalereticle")==1)}) then
  38. {
  39. //spawn reticle-adjusting loop
  40. sleep 0.1;
  41. fov = (((call cba_fnc_getfov) select 0) * 0.669556852268466);
  42. if (abs(1-fov/_maxfov)<0.01) then {fov = _maxfov}; //cba func has 0.5-1% margin of error
  43. diag_log "ScaleLaunchTest";
  44. [__ctrl, __ctrlRing] spawn {
  45. disableSerialization;
  46. __ctrl = _this select 0;
  47. __ctrlRing = _this select 1;
  48. private ["_curfov" ];
  49. while {sightup} do
  50. {
  51. waituntil
  52. {
  53. //CBA FOV is off by .669556852268466 from FOV listed in config. Probably a change from A2 to A3, will investigate later
  54. curfov = (((call cba_fnc_getfov) select 0) * 0.669556852268466);
  55. diag_log "ScaleLaunchTest1";
  56. call fnc_scale;
  57. diag_log "ScaleLaunchTest2";
  58. //hint format ["%1",_curfov];
  59. (abs(curfov - fov)/fov > 0.01) || {!sightup}
  60. };
  61. if !(sightup) exitwith
  62. {
  63. __ctrl ctrlSetText "";
  64. __ctrlRing ctrlSetText "";
  65. };
  66. fov = curfov;
  67. call fnc_scale;
  68. sleep 0.01;
  69. };
  70. };
  71. _fov0 = getNumber(__wcfg>>"ace_sys_reticles_fov0"); //FOV at which the reticle is scaled correctly
  72. } else {
  73. fov = _maxfov;
  74. _fov0 = _maxfov;
  75. };
  76.  
  77.  
  78. //reset reticle if different rifle
  79. if (getNumber(__wcfg>>"ace_sys_reticles_enable_sa") == 1) then {
  80. if (ACE_SYS_SA_RFL select 2 != _wpn) then {
  81. _wpn call ace_sys_sight_adjustment_rifle_fnc_newweap;
  82. };
  83. } else {
  84. el = 0;
  85. wnd = 0;
  86. };
  87.  
  88. if (getNumber(__wcfg>>"ace_sys_reticles_illum")==1) then {
  89. if !(illum) then
  90. {__ctrl ctrlSetTextColor [0,0,0,1];
  91. diag_log "RingDrawIllumTest1";
  92. __ctrlRing ctrlSetTextColor [1,1,1,1];
  93. }
  94. else
  95. {__ctrl ctrlsetTextColor (getArray(__wcfg>>"ace_sys_reticles_illumcolor"));
  96. __ctrlRing ctrlSetTextColor [1,1,1,1];
  97. };
  98. } else {
  99. __ctrl ctrlSetTextColor [1,1,1,1];
  100. diag_log "RingDrawIllumTest";
  101. __ctrlRing ctrlSetTextColor [1,1,1,1];
  102. };
  103.  
  104.  
  105. _pos = ctrlposition __ctrl;
  106. _res = getresolution;
  107. _resX = _res select 0;
  108. _resY = _res select 1;
  109. _viewportX = _res select 2;
  110. _viewportY = _res select 3;
  111. _kmap = getNumber(__wcfg>>"ace_sys_reticles_texmap");//reticle texture mapping (1-whole surface of model, 0.5 - half etc)
  112. _kpxpermil = getNumber(__wcfg>>"ace_sys_reticles_pxmil"); //pxels per mil in optics texture
  113. _texsize = getNumber(__wcfg>>"ace_sys_reticles_texsize"); //optics texture size
  114. _kup = 1.36*_kmap; //upscale coefficient
  115. _kres = _resY/_texsize;
  116. _kring = getNumber(__wcfg>>"ace_sys_reticles_ringscale");
  117. _ratio = _fov0/fov;
  118. _mil = _kpxpermil*_kres*_kup;
  119.  
  120. //GVAR(milx) = _mil/_viewportX;
  121. milx = _mil*0.749351/_viewportY;
  122. mily = _mil/_viewportY;
  123. _milX = _ratio*milx; //size of one mil in screen coords
  124. _milY = _ratio*mily;
  125.  
  126. //diag_log format ["ratio %1 kup %2 vpY %3 vpX %4 fov0 %5",_ratio,_kup,_viewportY,_viewportX,_fov0];
  127.  
  128. //takes the min dimension when 'keep aspect ratio' type
  129. _w = _ratio*_kup*safezoneH*0.749351;
  130. //_w = _ratio*_kup*_viewportY*safezoneH/_viewportX;//this is to always keep it 1:1
  131. _h = _ratio*_kup*SafeZoneH;
  132. _xoff = _w/2;
  133. _yoff = _h/2;
  134. furlong_retpos = [0.5-_xoff-wnd*_milX,0.5-_yoff+el*_milY,_w,_h];
  135. //diag_log GVAR(retpos);
  136.  
  137. _w = _kring*_kup*safezoneH*0.749351/_kmap;
  138. //_w = _kring*_kup*_viewportY*safezoneH/(_viewportX*_kmap);
  139. _h = _kring*_kup*SafeZoneH/_kmap;
  140. _xoff = _w/2;
  141. _yoff = _h/2;
  142. furlong_ringpos = [0.5-_xoff,0.5-_yoff,_w,_h];
  143.  
  144. if (ctrlCommitted __ctrl && {ctrlCommitted __ctrlRing}) then {
  145. __ctrl ctrlsetposition furlong_retpos;
  146. __ctrlRing ctrlsetposition furlong_ringpos;
  147.  
  148. __ctrl ctrlcommit 0;
  149. __ctrlRing ctrlcommit 0;
  150. };
  151.  
  152. sleep 0.1;
  153. call deh_add; //add DEH to switch the reticle off as soon as the key is pressed
  154. waituntil {player != player || {player != vehicle player} || {cameraview != "GUNNER"} || {visibleMap} };
  155. sightup = false;
  156. __ctrl ctrlSetText "";
  157. __ctrlRing ctrlSetText "";
  158. call deh_remove;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement