diff --git a/addons/2doptics/$PBOPREFIX$ b/addons/2doptics/$PBOPREFIX$ new file mode 100644 index 000000000..81feffa7b --- /dev/null +++ b/addons/2doptics/$PBOPREFIX$ @@ -0,0 +1 @@ +x\cba\addons\2doptics diff --git a/addons/2doptics/CfgCarryHandleTypes.hpp b/addons/2doptics/CfgCarryHandleTypes.hpp new file mode 100644 index 000000000..005078ee9 --- /dev/null +++ b/addons/2doptics/CfgCarryHandleTypes.hpp @@ -0,0 +1 @@ +class CBA_CarryHandleTypes {}; diff --git a/addons/2doptics/CfgEventHandlers.hpp b/addons/2doptics/CfgEventHandlers.hpp new file mode 100644 index 000000000..5dc9f7f00 --- /dev/null +++ b/addons/2doptics/CfgEventHandlers.hpp @@ -0,0 +1,17 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preStart)); + }; +}; + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_DisplayLoad_EventHandlers { + class RscDisplayInterrupt { + ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayInterrupt)')); + }; +}; diff --git a/addons/2doptics/CfgOpticsEffect.hpp b/addons/2doptics/CfgOpticsEffect.hpp new file mode 100644 index 000000000..116c6bf84 --- /dev/null +++ b/addons/2doptics/CfgOpticsEffect.hpp @@ -0,0 +1,7 @@ +class CfgOpticsEffect { + class CBA_OpticsRadBlur1 { + type = "radialblur"; + params[] = {0.015,0,0.14,0.2}; + priority = 950; + }; +}; diff --git a/addons/2doptics/CfgPIPItems.hpp b/addons/2doptics/CfgPIPItems.hpp new file mode 100644 index 000000000..909cd0972 --- /dev/null +++ b/addons/2doptics/CfgPIPItems.hpp @@ -0,0 +1 @@ +class CBA_PIPItems {}; diff --git a/addons/2doptics/RscInGameUI.hpp b/addons/2doptics/RscInGameUI.hpp new file mode 100644 index 000000000..1dbafc4c2 --- /dev/null +++ b/addons/2doptics/RscInGameUI.hpp @@ -0,0 +1,106 @@ +class RscOpticsValue; +class RscPicture; +class RscText; +class RscControlsGroupNoScrollbars; + +class RscInGameUI { + class RscUnitInfo; + class RscWeaponZeroing: RscUnitInfo { + class CA_Zeroing; + }; + + class CBA_ScriptedOptic: RscWeaponZeroing { + onLoad = QUOTE(call FUNC(loadScriptedOptic)); + controls[] = {"CA_FOVMode","ScopeBlack","Reticle","BodyNight","BodyDay","TrippleHeadLeft","TrippleHeadRight","CA_Zeroing","Magnification","ActiveDisplayHelper"}; + + // Idea by Taosenai. This control can be used to determine whether the scope or the collimator is used. + class CA_FOVMode: RscOpticsValue { + idc = 154; + w = 0; + h = 0; + }; + + class Reticle: RscPicture { + idc = IDC_RETICLE; + w = 0; + h = 0; + }; + + class BodyDay: RscPicture { + idc = IDC_BODY; + w = 0; + h = 0; + }; + + class BodyNight: BodyDay { + idc = IDC_BODY_NIGHT; + }; + + class ScopeBlack: RscPicture { + idc = IDC_BLACK_SCOPE; + text = QPATHTOF(reticles\scopeblack_ca.paa); + x = POS_X(2); + y = POS_Y(2); + w = POS_W(2); + h = POS_H(2); + }; + + // These are just black side panels to cover the areas that the optics p3d doesn't cover. + // It will ONLY effect tripple head users, as (safeZoneX == safeZoneXAbs) for everyone else. + class TrippleHeadLeft: RscText { + idc = IDC_BLACK_LEFT; + x = "safeZoneXAbs"; + y = "safeZoneY"; + w = "(safeZoneX - safeZoneXAbs) * ((getResolution select 4)/(16/3))"; + h = "safeZoneH"; + colorBackground[] = {0,0,0,1}; + }; + + class TrippleHeadRight: TrippleHeadLeft { + idc = IDC_BLACK_RIGHT; + x = "safeZoneXAbs + safeZoneWAbs - (safeZoneX - safeZoneXAbs) * ((getResolution select 4)/(16/3))"; + }; + + class Magnification: CA_Zeroing { + idc = IDC_MAGNIFICATION; + text = ""; + }; + + class ActiveDisplayHelper: RscText { + idc = IDC_ACTIVE_DISPLAY; + w = 0; + h = 0; + }; + }; + + class CBA_ScriptedOptic_zooming: CBA_ScriptedOptic { + controls[] = {"CA_FOVMode","ScopeBlack","ReticleSafeZone","RedDot","BodyNight","BodyDay","TrippleHeadLeft","TrippleHeadRight","EnableAutoZoom","CA_Zeroing","Magnification","ActiveDisplayHelper"}; + + class RedDot: RscPicture { + idc = IDC_RED_DOT; + text = "\a3\weapons_f\acc\data\collimdot_red_ca.paa"; // alt: green + x = POS_X(0.025); + y = POS_Y(0.025); + w = POS_W(0.025); + h = POS_H(0.025); + }; + + class ReticleSafeZone: RscControlsGroupNoScrollbars { + idc = IDC_RETICLE_SAFEZONE; + x = RETICLE_SAFEZONE_LEFT; + y = RETICLE_SAFEZONE_TOP; + w = RETICLE_SAFEZONE_WIDTH; + h = RETICLE_SAFEZONE_HEIGHT; + + class controls { + class Reticle: Reticle {}; + }; + }; + + class EnableAutoZoom: RscText { + idc = IDC_ENABLE_ZOOM; + w = 0; + h = 0; + }; + }; +}; diff --git a/addons/2doptics/XEH_PREP.sqf b/addons/2doptics/XEH_PREP.sqf new file mode 100644 index 000000000..d42fb08db --- /dev/null +++ b/addons/2doptics/XEH_PREP.sqf @@ -0,0 +1,11 @@ +PREP(currentOptic); +PREP(updateOpticInfo); +PREP(restartCamera); +PREP(loadScriptedOptic); +PREP(animateScriptedOptic); +PREP(animateScriptedOpticRecoil); +PREP(changePIPOpticClass); +PREP(changeCarryHandleOpticClass); +PREP(setOpticMagnification); +PREP(setOpticMagnificationHelper); +PREP(setOpticMagnificationHelperZeroing); diff --git a/addons/2doptics/XEH_preInit.sqf b/addons/2doptics/XEH_preInit.sqf new file mode 100644 index 000000000..f91013751 --- /dev/null +++ b/addons/2doptics/XEH_preInit.sqf @@ -0,0 +1,125 @@ +#include "script_component.hpp" + +#include "initSettings.sqf" + +if (!hasInterface) exitWith {}; +if (configProperties [configFile >> "CBA_PIPItems"] isEqualTo []) exitWith {}; +if (configProperties [configFile >> "CBA_CarryHandleTypes"] isEqualTo []) exitWith {}; + +ADDON = false; + +#include "XEH_PREP.sqf" + +QGVAR(pauseOpticLayer) cutText ["", "PLAIN"]; + +GVAR(camera) = objNull; +[QGVAR(camera), {!isNull GVAR(camera)}] call CBA_fnc_registerFeatureCamera; + +// scripted optic data cache +GVAR(currentOptic) = ""; +GVAR(IsUsingOptic) = false; +GVAR(magnificationCache) = -1; +GVAR(ReticleAdjust) = [1,1,nil,1,1]; +GVAR(HideRedDotMagnification) = 1e+11; +GVAR(FadeReticleInterval) = [0,0,nil,0,0]; +GVAR(OpticReticleDetailTextures) = []; +GVAR(OpticBodyTexture) = ""; +GVAR(OpticBodyTextureNight) = ""; +GVAR(ppEffects) = []; + +// Update optic info. +["weapon", { + params ["_unit"]; + _unit call FUNC(updateOpticInfo); +}] call CBA_fnc_addPlayerEventHandler; + +["loadout", { + params ["_unit"]; + _unit call FUNC(updateOpticInfo); + _unit call FUNC(changeCarryHandleOpticClass); +}] call CBA_fnc_addPlayerEventHandler; + +[QGVAR(UsingOptic), { + params ["_display", "_isUsingOptic"]; + if (_isUsingOptic) then { + // Switch to pip class. + private _unit = call CBA_fnc_currentUnit; + _unit call FUNC(changePIPOpticClass); + + // Restore previous magnification. + if (GVAR(magnificationCache) > 0) then { + [_unit, GVAR(magnificationCache)] call FUNC(setOpticMagnification); + }; + }; +}] call CBA_fnc_addEventHandler; + +["featureCamera", { + params ["_unit", "_camera"]; + [_unit, _camera isEqualTo ""] call FUNC(restartCamera); +}] call CBA_fnc_addPlayerEventHandler; + +["CAManBase", "Fired", FUNC(animateScriptedOpticRecoil)] call CBA_fnc_addClassEventHandler; + +// Handle Arsenal: Switch back to normal classes. +GVAR(inArsenal) = false; + +[QGVAR(arsenalOpened), { + GVAR(inArsenal) = true; + private _unit = call CBA_fnc_currentUnit; + _unit call FUNC(changePIPOpticClass); + _unit call FUNC(changeCarryHandleOpticClass); +}] call CBA_fnc_addEventHandler; + +[missionNamespace, "arsenalOpened", { + isNil { + QGVAR(arsenalOpened) call CBA_fnc_localEvent; + }; +}] call BIS_fnc_addScriptedEventHandler; + +[QGVAR(arsenalClosed), { + GVAR(inArsenal) = false; + private _unit = call CBA_fnc_currentUnit; + _unit call FUNC(changeCarryHandleOpticClass); + [FUNC(restartCamera), [_unit, true]] call CBA_fnc_execNextFrame; +}] call CBA_fnc_addEventHandler; + +[missionNamespace, "arsenalClosed", { + isNil { + QGVAR(arsenalClosed) call CBA_fnc_localEvent; + }; +}] call BIS_fnc_addScriptedEventHandler; + +// Link classes by config. +GVAR(PIPOptics) = [] call CBA_fnc_createNamespace; +GVAR(NonPIPOptics) = [] call CBA_fnc_createNamespace; + +{ + private _normalOptic = configName _x; + private _pipOptic = getText _x; + + GVAR(PIPOptics) setVariable [_normalOptic, _pipOptic]; + + if (isNil {GVAR(NonPIPOptics) getVariable _pipOptic}) then { + GVAR(NonPIPOptics) setVariable [_pipOptic, _normalOptic]; + }; +} forEach configProperties [configFile >> "CBA_PIPItems", "isText _x"]; + +GVAR(CarryHandleOptics) = [] call CBA_fnc_createNamespace; +GVAR(NonCarryHandleOptics) = [] call CBA_fnc_createNamespace; + +{ + private _carryHandleType = configName _x; + + { + private _normalOptic = configName _x; + private _carryHandleOptic = getText _x; + + GVAR(CarryHandleOptics) setVariable [format ["%1@%2", _normalOptic, _carryHandleType], _carryHandleOptic]; + + if (isNil {GVAR(NonCarryHandleOptics) getVariable _carryHandleOptic}) then { + GVAR(NonCarryHandleOptics) setVariable [_carryHandleOptic, _normalOptic]; + }; + } forEach configProperties [_x, "isText _x"]; +} forEach ("true" configClasses (configFile >> "CBA_CarryHandleTypes")); + +ADDON = true; diff --git a/addons/2doptics/XEH_preStart.sqf b/addons/2doptics/XEH_preStart.sqf new file mode 100644 index 000000000..b84e75bbf --- /dev/null +++ b/addons/2doptics/XEH_preStart.sqf @@ -0,0 +1,11 @@ +#include "script_component.hpp" + +if (!hasInterface) exitWith {}; + +// Do not move this below these checks, or this missing function can be exploited. +PREP(initDisplayInterrupt); + +if (configProperties [configFile >> "CBA_PIPItems"] isEqualTo []) exitWith {}; +if (configProperties [configFile >> "CBA_CarryHandleTypes"] isEqualTo []) exitWith {}; + +#include "XEH_PREP.sqf" diff --git a/addons/2doptics/cba_optic_big_100.p3d b/addons/2doptics/cba_optic_big_100.p3d new file mode 100644 index 000000000..af31d7368 Binary files /dev/null and b/addons/2doptics/cba_optic_big_100.p3d differ diff --git a/addons/2doptics/cba_optic_big_70.p3d b/addons/2doptics/cba_optic_big_70.p3d new file mode 100644 index 000000000..bc2a960b5 Binary files /dev/null and b/addons/2doptics/cba_optic_big_70.p3d differ diff --git a/addons/2doptics/cba_optic_big_80.p3d b/addons/2doptics/cba_optic_big_80.p3d new file mode 100644 index 000000000..fe74097c8 Binary files /dev/null and b/addons/2doptics/cba_optic_big_80.p3d differ diff --git a/addons/2doptics/cba_optic_big_90.p3d b/addons/2doptics/cba_optic_big_90.p3d new file mode 100644 index 000000000..845d73124 Binary files /dev/null and b/addons/2doptics/cba_optic_big_90.p3d differ diff --git a/addons/2doptics/cba_optic_big_pip.p3d b/addons/2doptics/cba_optic_big_pip.p3d new file mode 100644 index 000000000..c03f9a459 Binary files /dev/null and b/addons/2doptics/cba_optic_big_pip.p3d differ diff --git a/addons/2doptics/cba_optic_small_100.p3d b/addons/2doptics/cba_optic_small_100.p3d new file mode 100644 index 000000000..8a49f6a54 Binary files /dev/null and b/addons/2doptics/cba_optic_small_100.p3d differ diff --git a/addons/2doptics/cba_optic_small_70.p3d b/addons/2doptics/cba_optic_small_70.p3d new file mode 100644 index 000000000..8c66292f9 Binary files /dev/null and b/addons/2doptics/cba_optic_small_70.p3d differ diff --git a/addons/2doptics/cba_optic_small_80.p3d b/addons/2doptics/cba_optic_small_80.p3d new file mode 100644 index 000000000..5bfb11f3c Binary files /dev/null and b/addons/2doptics/cba_optic_small_80.p3d differ diff --git a/addons/2doptics/cba_optic_small_90.p3d b/addons/2doptics/cba_optic_small_90.p3d new file mode 100644 index 000000000..6f952af8b Binary files /dev/null and b/addons/2doptics/cba_optic_small_90.p3d differ diff --git a/addons/2doptics/cba_optic_small_pip.p3d b/addons/2doptics/cba_optic_small_pip.p3d new file mode 100644 index 000000000..fb66e8d10 Binary files /dev/null and b/addons/2doptics/cba_optic_small_pip.p3d differ diff --git a/addons/2doptics/config.cpp b/addons/2doptics/config.cpp new file mode 100644 index 000000000..cf90c6170 --- /dev/null +++ b/addons/2doptics/config.cpp @@ -0,0 +1,21 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + author = "$STR_CBA_Author"; + name = CSTRING(component); + url = "$STR_CBA_URL"; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"cba_common","cba_jr"}; + version = VERSION; + authors[] = {"commy2"}; + }; +}; + +#include "CfgEventHandlers.hpp" +#include "CfgPIPItems.hpp" +#include "CfgCarryHandleTypes.hpp" +#include "CfgOpticsEffect.hpp" +#include "RscInGameUI.hpp" diff --git a/addons/2doptics/fnc_animateScriptedOptic.sqf b/addons/2doptics/fnc_animateScriptedOptic.sqf new file mode 100644 index 000000000..dc31f6211 --- /dev/null +++ b/addons/2doptics/fnc_animateScriptedOptic.sqf @@ -0,0 +1,142 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: cba_2doptics_fnc_animateScriptedOptic + +Description: + Executed every draw frame to update the scripted weapon info display. + +Parameters: + _display - CBA weapon info display + +Returns: + Nothing. + +Examples: + (begin example) + _weaponInfoDisplay call cba_2doptics_fnc_animateScriptedOptic; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +params ["_display"]; +if (!ctrlShown (_display displayCtrl IDC_ACTIVE_DISPLAY)) exitWith {}; +uiNamespace setVariable [QGVAR(ScriptedOpticDisplay), _display]; + +private _ctrlRedDot = _display displayCtrl IDC_RED_DOT; +private _ctrlReticle = _display displayCtrl IDC_RETICLE; +private _ctrlBody = _display displayCtrl IDC_BODY; +private _ctrlBodyNight = _display displayCtrl IDC_BODY_NIGHT; +private _ctrlBlackScope = _display displayCtrl IDC_BLACK_SCOPE; +private _ctrlBlackLeft = _display displayCtrl IDC_BLACK_LEFT; +private _ctrlBlackRight = _display displayCtrl IDC_BLACK_RIGHT; +private _ctrlZeroing = _display displayCtrl 168; +private _ctrlMagnification = _display displayCtrl IDC_MAGNIFICATION; + +// Check if optics are used, hide all controls otherwise. +private _isUsingOptic = ctrlShown (_display displayCtrl 154); + +_ctrlRedDot ctrlShow _isUsingOptic; +_ctrlReticle ctrlShow _isUsingOptic; +_ctrlBody ctrlShow _isUsingOptic; +_ctrlBodyNight ctrlShow _isUsingOptic; +_ctrlBlackScope ctrlShow _isUsingOptic; +_ctrlBlackLeft ctrlShow _isUsingOptic; +_ctrlBlackRight ctrlShow _isUsingOptic; +//_ctrlZeroing ctrlShow _isUsingOptic; +_ctrlMagnification ctrlShow _isUsingOptic; + +GVAR(ppEffects) ppEffectEnable _isUsingOptic; + +if !(_isUsingOptic isEqualTo GVAR(IsUsingOptic)) then { + GVAR(IsUsingOptic) = _isUsingOptic; + [QGVAR(UsingOptic), [_display, _isUsingOptic]] call CBA_fnc_localEvent; +}; + +if !(_isUsingOptic) exitWith {}; + +GVAR(camera) setPosASL AGLToASL positionCameraToWorld [0,0,0.4]; +GVAR(camera) camPrepareTarget positionCameraToWorld [0,0,50]; +GVAR(camera) camCommitPrepared 0; + +// @todo, check if that needs to be done at all +if (cameraView == "GUNNER") then { + GVAR(camera) camSetFOV 0.7; + GVAR(camera) camCommit 0; +} else { + GVAR(camera) camSetFOV 0.01; + GVAR(camera) camCommit 0; +}; + +// Add magnification to zeroing control. +private _zoom = 0.25 call CBA_fnc_getFov select 1; + +_ctrlMagnification ctrlSetText format [ + "(%1x)", + [_zoom, 1, 1] call CBA_fnc_formatNumber +]; + +_ctrlMagnification ctrlShow (_zoom >= 1); + +private _positionMagnification = ctrlPosition _ctrlZeroing; +_positionMagnification set [0, _positionMagnification#0 + ctrlTextWidth _ctrlZeroing]; + +_ctrlMagnification ctrlSetPosition _positionMagnification; +_ctrlMagnification ctrlCommit 0; + +// Calculate lighting. +private _dayOpacity = AMBIENT_BRIGHTNESS; +private _nightOpacity = [1,0] select (_dayOpacity == 1); + +// Apply lighting and make layers visible. +private _texture = ""; +private _detailScaleFactor = 1; + +{ + _x params ["_zoomX", "_textureX", "_detailScaleFactorX", "_textureXNight"]; + + if (_zoom > _zoomX) then { + _texture = [_textureX, _textureXNight] select (_dayOpacity < 0.5); + _detailScaleFactor = _detailScaleFactorX; + }; +} forEach GVAR(OpticReticleDetailTextures); + +_display setVariable [QGVAR(DetailScaleFactor), _detailScaleFactor]; + +_ctrlReticle ctrlSetText _texture; +_ctrlBody ctrlSetTextColor [1,1,1,_dayOpacity]; +_ctrlBodyNight ctrlSetTextColor [1,1,1,_nightOpacity]; +_ctrlBlackScope ctrlShow (GVAR(usePipOptics) && !isPipEnabled); + +// zooming reticle +if (isNull (_display displayCtrl IDC_ENABLE_ZOOM)) exitWith {}; + +if (_zoom >= 1) then { + GVAR(magnificationCache) = _zoom; +}; + +GVAR(ReticleAdjust) set [2, _zoom]; +private _reticleAdjust = linearConversion GVAR(ReticleAdjust); + +private _sizeReticle = _reticleAdjust * _detailScaleFactor; + +private _positionReticle = [ + POS_X(_sizeReticle) - RETICLE_SAFEZONE_LEFT, + POS_Y(_sizeReticle) - RETICLE_SAFEZONE_TOP, + POS_W(_sizeReticle), + POS_H(_sizeReticle) +]; + +_ctrlReticle ctrlSetPosition _positionReticle; + +if (ctrlCommitted _ctrlBody) then { + _ctrlReticle ctrlCommit 0; +}; + +if (_zoom > GVAR(HideRedDotMagnification)) then { + _ctrlRedDot ctrlShow false; +}; + +GVAR(FadeReticleInterval) set [2, _zoom]; +_ctrlReticle ctrlSetTextColor [1,1,1,linearConversion GVAR(FadeReticleInterval)]; diff --git a/addons/2doptics/fnc_animateScriptedOpticRecoil.sqf b/addons/2doptics/fnc_animateScriptedOpticRecoil.sqf new file mode 100644 index 000000000..9315a9899 --- /dev/null +++ b/addons/2doptics/fnc_animateScriptedOpticRecoil.sqf @@ -0,0 +1,124 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: cba_2doptics_fnc_animateScriptedOpticRecoil + +Description: + Animates the 2D optic when firing. + +Parameters: + _unit - The avatar + _weapon - Fired weapon + +Returns: + Nothing. + +Examples: + (begin example) + [player, currentWeapon player] call cba_2doptics_fnc_animateScriptedOpticRecoil; + (end) + +Author: + commy2, (Taosenai, KoffeinFlummi) +---------------------------------------------------------------------------- */ + +params ["_unit", "_weapon"]; +if (_unit != call CBA_fnc_currentUnit) exitWith {}; + +// Check if compatible scope is used. +private _display = uiNamespace getVariable [QGVAR(ScriptedOpticDisplay), displayNull]; +if (isNull _display) exitWith {}; + +private _ctrlReticle = _display displayCtrl IDC_RETICLE; +private _ctrlBody = _display displayCtrl IDC_BODY; +private _ctrlBodyNight = _display displayCtrl IDC_BODY_NIGHT; +private _ctrlBlackScope = _display displayCtrl IDC_BLACK_SCOPE; +private _ctrlBlackLeft = _display displayCtrl IDC_BLACK_LEFT; +private _ctrlBlackRight = _display displayCtrl IDC_BLACK_RIGHT; + +// Reduce the reticle movement as the player drops into lower, supported stances. +private _recoilCoef = SCOPE_RECOIL_COEF; + +if (isWeaponDeployed _unit) then { + _recoilCoef = SCOPE_RECOIL_COEF_DEPLOYED; +} else { + if (isWeaponRested _unit) then { + _recoilCoef = SCOPE_RECOIL_COEF_RESTED; + }; +}; + +// Constants which determine how the scope recoils. +private _recoilScope = _recoilCoef * linearConversion [0, 1, random 1, SCOPE_RECOIL_MIN, SCOPE_RECOIL_MAX, false]; + +private _reticleShiftX = _recoilCoef * linearConversion [0, 1, random 1, RETICLE_SHIFT_X_MIN, RETICLE_SHIFT_X_MAX, false]; +private _reticleShiftY = _recoilCoef * linearConversion [0, 1, random 1, RETICLE_SHIFT_Y_MIN, RETICLE_SHIFT_Y_MAX, false]; + +private _scopeShiftX = _recoilCoef * linearConversion [0, 1, random 1, SCOPE_SHIFT_X_MIN, SCOPE_SHIFT_X_MAX, false]; +private _scopeShiftY = _recoilCoef * linearConversion [0, 1, random 1, SCOPE_SHIFT_Y_MIN, SCOPE_SHIFT_Y_MAX, false]; + +// Read default sizes from display. +private _sizeBody = GVAR(OpticBodyTextureSize); + +// Create and commit recoil effect. +private _reticleAdjust = 1; +private _reticleSafeZoneOffsetLeft = 0; +private _reticleSafeZoneOffsetTop = 0; + +if (!isNull (_display displayCtrl IDC_RETICLE_SAFEZONE)) then { + _reticleAdjust = linearConversion GVAR(ReticleAdjust); + _reticleSafeZoneOffsetLeft = - RETICLE_SAFEZONE_LEFT; + _reticleSafeZoneOffsetTop = - RETICLE_SAFEZONE_TOP; +}; + +private _detailScaleFactor = _display getVariable [QGVAR(DetailScaleFactor), 1]; +private _size = _reticleAdjust * _detailScaleFactor + _recoilScope; + +private _positionReticle = [ + POS_X(_size + _reticleShiftX) + _reticleSafeZoneOffsetLeft, + POS_Y(_size + _reticleShiftY) + _reticleSafeZoneOffsetTop, + POS_W(_size), + POS_H(_size) +]; + +_ctrlReticle ctrlSetPosition _positionReticle; + +_size = _sizeBody + _recoilScope; + +private _positionBody = [ + POS_X(_size + _reticleShiftX), + POS_Y(_size + _reticleShiftY), + POS_W(_size), + POS_H(_size) +]; + +_ctrlBody ctrlSetPosition _positionBody; +_ctrlBodyNight ctrlSetPosition _positionBody; + +_ctrlReticle ctrlCommit 0; +_ctrlBody ctrlCommit 0; +_ctrlBodyNight ctrlCommit 0; + +// Bring them all back. +private _sizeReticle = _reticleAdjust * _detailScaleFactor; + +_positionReticle = [ + POS_X(_sizeReticle) + _reticleSafeZoneOffsetLeft, + POS_Y(_sizeReticle) + _reticleSafeZoneOffsetTop, + POS_W(_sizeReticle), + POS_H(_sizeReticle) +]; + +_ctrlReticle ctrlSetPosition _positionReticle; + +_positionBody = [ + POS_X(_sizeBody), + POS_Y(_sizeBody), + POS_W(_sizeBody), + POS_H(_sizeBody) +]; + +_ctrlBody ctrlSetPosition _positionBody; +_ctrlBodyNight ctrlSetPosition _positionBody; + +_ctrlReticle ctrlCommit RECENTER_TIME; +_ctrlBody ctrlCommit RECENTER_TIME; +_ctrlBodyNight ctrlCommit RECENTER_TIME; diff --git a/addons/2doptics/fnc_changeCarryHandleOpticClass.sqf b/addons/2doptics/fnc_changeCarryHandleOpticClass.sqf new file mode 100644 index 000000000..fe2d1cc2c --- /dev/null +++ b/addons/2doptics/fnc_changeCarryHandleOpticClass.sqf @@ -0,0 +1,74 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: cba_2doptics_fnc_changeCarryHandleOpticClass + +Description: + Switch scripted optic class to class with integrated carry handle optic. + +Parameters: + _unit - The avatar + +Returns: + Nothing. + +Examples: + (begin example) + player call cba_2doptics_fnc_changeCarryHandleOpticClass; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +params ["_unit"]; + +private _gun = primaryWeapon _unit; +private _gunOptic = primaryWeaponItems _unit select 2; +private _launcher = secondaryWeapon _unit; +private _launcherOptic = secondaryWeaponItems _unit select 2; +private _pistol = handgunWeapon _unit; +private _pistolOptic = handgunItems _unit select 2; + +private _config = configFile >> "CfgWeapons"; +private _gunCarryHandleType = getText (_config >> _gun >> "CBA_CarryHandleType"); +private _launcherCarryHandleType = getText (_config >> _launcher >> "CBA_CarryHandleType"); +private _pistolCarryHandleType = getText (_config >> _pistol >> "CBA_CarryHandleType"); + +// primary weapon +if (_gunCarryHandleType != "" && {!GVAR(inArsenal)}) then { + _gunOptic = GVAR(NonCarryHandleOptics) getVariable [_gunOptic, _gunOptic]; + _gunOptic = GVAR(CarryHandleOptics) getVariable format ["%1@%2", _gunOptic, _gunCarryHandleType]; +} else { + _gunOptic = GVAR(NonCarryHandleOptics) getVariable _gunOptic; +}; + +if (!isNil "_gunOptic") then { + INFO_1("Switched rifle optic to %1.",_gunOptic); + _unit addPrimaryWeaponItem _gunOptic; +}; + +// secondary weapon +if (_launcherCarryHandleType != "" && {!GVAR(inArsenal)}) then { + _launcherOptic = GVAR(NonCarryHandleOptics) getVariable [_launcherOptic, _launcherOptic]; + _launcherOptic = GVAR(CarryHandleOptics) getVariable format ["%1@%2", _launcherOptic, _launcherCarryHandleType]; +} else { + _launcherOptic = GVAR(NonCarryHandleOptics) getVariable _launcherOptic; +}; + +if (!isNil "_launcherOptic") then { + INFO_1("Switched launcher optic to %1.",_launcherOptic); + _unit addSecondaryWeaponItem _launcherOptic; +}; + +// handgun +if (_pistolCarryHandleType != "" && {!GVAR(inArsenal)}) then { + _pistolOptic = GVAR(NonCarryHandleOptics) getVariable [_pistolOptic, _pistolOptic]; + _pistolOptic = GVAR(CarryHandleOptics) getVariable format ["%1@%2", _pistolOptic, _pistolCarryHandleType]; +} else { + _pistolOptic = GVAR(NonCarryHandleOptics) getVariable _pistolOptic; +}; + +if (!isNil "_pistolOptic") then { + INFO_1("Switched pistol optic to %1.",_pistolOptic); + _unit addHandgunItem _pistolOptic; +}; diff --git a/addons/2doptics/fnc_changePIPOpticClass.sqf b/addons/2doptics/fnc_changePIPOpticClass.sqf new file mode 100644 index 000000000..d7da4ac57 --- /dev/null +++ b/addons/2doptics/fnc_changePIPOpticClass.sqf @@ -0,0 +1,187 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: cba_2doptics_fnc_changePIPOpticClass + +Description: + Switch scripted optic class to PIP class. + +Parameters: + _unit - The avatar + +Returns: + Nothing. + +Examples: + (begin example) + player call cba_2doptics_fnc_changePIPOpticClass; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +params ["_unit"]; + +if (GVAR(usePipOptics) && {!GVAR(inArsenal)}) then { + // Gun, switch to pip weapon. + private _gun = primaryWeapon _unit; + private _gunItems = primaryWeaponItems _unit; + private _gunMagazine = primaryWeaponMagazine _unit; + + private _pipGun = GVAR(PIPOptics) getVariable _gun; + + if (!isNil "_pipGun") then { + private _muzzle = currentMuzzle _unit; + _unit addWeapon _pipGun; + if (_muzzle isEqualType "") then {_unit selectWeapon _muzzle}; + + { + _unit addPrimaryWeaponItem _x; + } forEach _gunItems; + + { + _unit addWeaponItem [_pipGun, _x]; + } forEach _gunMagazine; + + INFO_2("Switched %1 to %2.",_gun,_pipGun); + }; + + // Launcher, switch to pip weapon. + private _launcher = secondaryWeapon _unit; + private _launcherItems = secondaryWeaponItems _unit; + private _launcherMagazine = secondaryWeaponMagazine _unit; + + private _pipLauncher = GVAR(PIPOptics) getVariable _launcher; + + if (!isNil "_pipLauncher") then { + private _muzzle = currentMuzzle _unit; + _unit addWeapon _pipLauncher; + if (_muzzle isEqualType "") then {_unit selectWeapon _muzzle}; + + { + _unit addSecondaryWeaponItem _x; + } forEach _launcherItems; + + { + _unit addWeaponItem [_pipLauncher, _x]; + } forEach _launcherMagazine; + + INFO_2("Switched %1 to %2.",_launcher,_pipLauncher); + }; + + // Pistol, switch to pip weapon. + private _pistol = handgunWeapon _unit; + private _pistolItems = handgunItems _unit; + private _pistolMagazine = handgunMagazine _unit; + + private _pipPistol = GVAR(PIPOptics) getVariable _pistol; + + if (!isNil "_pipPistol") then { + private _muzzle = currentMuzzle _unit; + _unit addWeapon _pipPistol; + if (_muzzle isEqualType "") then {_unit selectWeapon _muzzle}; + + { + _unit addHandgunItem _x; + } forEach _pistolItems; + + { + _unit addWeaponItem [_pipPistol, _x]; + } forEach _pistolMagazine; + + INFO_2("Switched %1 to %2.",_pistol,_pipPistol); + }; + + // Switch to pip optic attchments. + { + _x params ["_weapon", "", "", "_optic"]; // ["_weapon", "_muzzle", "_pointer", "_optic", "_magazine", "_bipod"] + + private _pipOptic = GVAR(PIPOptics) getVariable _optic; + + if (!isNil "_pipOptic") then { + _unit addWeaponItem [_weapon, _pipOptic]; + INFO_2("Switched %1 to %2.",_optic,_pipOptic); + }; + } forEach weaponsItems _unit; +} else { + // Gun, switch to normal weapon. + private _gun = primaryWeapon _unit; + private _gunItems = primaryWeaponItems _unit; + private _gunMagazine = primaryWeaponMagazine _unit; + + private _normalGun = GVAR(NonPIPOptics) getVariable _gun; + + if (!isNil "_normalGun") then { + private _muzzle = currentMuzzle _unit; + _unit addWeapon _normalGun; + if (_muzzle isEqualType "") then {_unit selectWeapon _muzzle}; + + { + _unit addPrimaryWeaponItem _x; + } forEach _gunItems; + + { + _unit addWeaponItem [_normalGun, _x]; + } forEach _gunMagazine; + + INFO_2("Switched %1 to %2.",_gun,_normalGun); + }; + + // Launcher, switch to normal weapon. + private _launcher = secondaryWeapon _unit; + private _launcherItems = secondaryWeaponItems _unit; + private _launcherMagazine = secondaryWeaponMagazine _unit; + + private _normalLauncher = GVAR(NonPIPOptics) getVariable _launcher; + + if (!isNil "_normalLauncher") then { + private _muzzle = currentMuzzle _unit; + _unit addWeapon _normalLauncher; + if (_muzzle isEqualType "") then {_unit selectWeapon _muzzle}; + + { + _unit addSecondaryWeaponItem _x; + } forEach _launcherItems; + + { + _unit addWeaponItem [_normalLauncher, _x]; + } forEach _launcherMagazine; + + INFO_2("Switched %1 to %2.",_launcher,_normalLauncher); + }; + + // Pistol, switch to normal weapon. + private _pistol = handgunWeapon _unit; + private _pistolItems = handgunItems _unit; + private _pistolMagazine = handgunMagazine _unit; + + private _normalPistol = GVAR(NonPIPOptics) getVariable _pistol; + + if (!isNil "_normalPistol") then { + private _muzzle = currentMuzzle _unit; + _unit addWeapon _normalPistol; + if (_muzzle isEqualType "") then {_unit selectWeapon _muzzle}; + + { + _unit addHandgunItem _x; + } forEach _pistolItems; + + { + _unit addWeaponItem [_normalPistol, _x]; + } forEach _pistolMagazine; + + INFO_2("Switched %1 to %2.",_pistol,_normalPistol); + }; + + // Switch to normal / 2d optic attchments. + { + _x params ["_weapon", "", "", "_optic"]; + + private _normalOptic = GVAR(NonPIPOptics) getVariable _optic; + + if (!isNil "_normalOptic") then { + _unit addWeaponItem [_weapon, _normalOptic]; + INFO_2("Switched %1 to %2.",_optic,_normalOptic); + }; + } forEach weaponsItems _unit; +}; diff --git a/addons/2doptics/fnc_currentOptic.sqf b/addons/2doptics/fnc_currentOptic.sqf new file mode 100644 index 000000000..169173802 --- /dev/null +++ b/addons/2doptics/fnc_currentOptic.sqf @@ -0,0 +1,58 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: cba_2doptics_fnc_currentOptic + +Description: + Reports the currently selected optic classname of a person. + +Parameters: + _unit - A unit with weapon + +Returns: + _optic - The optic of the current weapon. + If the weapon has no optic, it reports the current weapon instead. + This never reports a muzzle, but the actual weapon. + Will report the binocular if selected. + If no weapon is equipped or selected, it reports the empty string "". + Reports the empty string "" for vehicles and the null object. + +Examples: + (begin example) + player call cba_2doptics_fnc_currentOptic + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +params ["_unit"]; + +private _weapon = currentWeapon _unit; + +private _gun = primaryWeapon _unit; +if (_weapon isEqualTo _gun) exitWith { + private _optic = [primaryWeaponItems _unit] param [0, [nil, nil, ""]] select 2; + if (_optic != "") exitWith {_optic}; + _gun +}; + +private _launcher = secondaryWeapon _unit; +if (_weapon isEqualTo _launcher) exitWith { + private _optic = [secondaryWeaponItems _unit] param [0, [nil, nil, ""]] select 2; + if (_optic != "") exitWith {_optic}; + _launcher +}; + +private _pistol = handgunWeapon _unit; +if (_weapon isEqualTo _pistol) exitWith { + private _optic = [handgunItems _unit] param [0, [nil, nil, ""]] select 2; + if (_optic != "") exitWith {_optic}; + _pistol +}; + +private _binocular = binocular _unit; +if (_weapon isEqualTo _binocular) exitWith { + _binocular +}; + +"" diff --git a/addons/2doptics/fnc_initDisplayInterrupt.sqf b/addons/2doptics/fnc_initDisplayInterrupt.sqf new file mode 100644 index 000000000..a89c81323 --- /dev/null +++ b/addons/2doptics/fnc_initDisplayInterrupt.sqf @@ -0,0 +1,58 @@ +#include "script_component.hpp" + +// Check if compatible scope is used. +private _display = uiNamespace getVariable [QGVAR(ScriptedOpticDisplay), displayNull]; +if (isNull _display) exitWith {}; + +if (!GVAR(IsUsingOptic)) exitWith {}; + +// Draw reticle and scope body, because they are otherwise hidden when the pause menu is shown. +QGVAR(pauseOpticLayer) cutRsc ["RscTitleDisplayEmpty", "PLAIN", 0, false]; +private _display = uiNamespace getVariable "RscTitleDisplayEmpty"; + +private _vignette = _display displayCtrl 1202; +_vignette ctrlShow false; + +private _ctrlReticle = _display ctrlCreate ["RscPicture", IDC_RETICLE]; + +private _reticleSize = GVAR(OpticReticleDetailTextures)#0#2; +private _reticlePosition = [ + POS_X(_reticleSize), + POS_Y(_reticleSize), + POS_W(_reticleSize), + POS_H(_reticleSize) +]; + +_ctrlReticle ctrlSetText (GVAR(OpticReticleDetailTextures)#0#1); +_ctrlReticle ctrlSetPosition _reticlePosition; +_ctrlReticle ctrlCommit 0; + +private _ctrlBody = _display ctrlCreate ["RscPicture", IDC_BODY]; + +private _bodyPosition = [ + POS_X(GVAR(OpticBodyTextureSize)), + POS_Y(GVAR(OpticBodyTextureSize)), + POS_W(GVAR(OpticBodyTextureSize)), + POS_H(GVAR(OpticBodyTextureSize)) +]; + +_ctrlBody ctrlSetText GVAR(OpticBodyTexture); +_ctrlBody ctrlSetPosition _bodyPosition; +_ctrlBody ctrlCommit 0; + +// Automatically hide when pause menu is closed. +private _script = _display ctrlCreate ["RscMapControl", -1]; + +_script ctrlSetPosition [0,0,0,0]; +_script ctrlCommit 0; + +_script ctrlAddEventHandler ["Draw", { + params ["_script"]; + private _counter = ctrlParent _script getVariable "commy_fpsCounter"; + + if (isNull (uiNamespace getVariable ["RscDisplayInterrupt", displayNull])) then { + { + QGVAR(pauseOpticLayer) cutText ["", "PLAIN"]; + } call CBA_fnc_execNextFrame; + }; +}]; diff --git a/addons/2doptics/fnc_loadScriptedOptic.sqf b/addons/2doptics/fnc_loadScriptedOptic.sqf new file mode 100644 index 000000000..c81178706 --- /dev/null +++ b/addons/2doptics/fnc_loadScriptedOptic.sqf @@ -0,0 +1,82 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: cba_2doptics_fnc_loadScriptedOptic + +Description: + Sets up the CBA_ScriptedOptic weapon info display and adds the draw script. + +Parameters: + _display - CBA weapon info display + +Returns: + Nothing. + +Examples: + (begin example) + _weaponInfoDisplay call cba_2doptics_fnc_loadScriptedOptic; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +private _unit = call CBA_fnc_currentUnit; +_unit call FUNC(updateOpticInfo); + +params ["_display"]; + +private _ctrlRedDot = _display displayCtrl IDC_RED_DOT; +private _ctrlReticle = _display displayCtrl IDC_RETICLE; +private _ctrlBody = _display displayCtrl IDC_BODY; +private _ctrlBodyNight = _display displayCtrl IDC_BODY_NIGHT; +private _ctrlBlackScope = _display displayCtrl IDC_BLACK_SCOPE; +private _ctrlBlackLeft = _display displayCtrl IDC_BLACK_LEFT; +private _ctrlBlackRight = _display displayCtrl IDC_BLACK_RIGHT; +private _ctrlMagnification = _display displayCtrl IDC_MAGNIFICATION; + +_ctrlRedDot ctrlShow false; +_ctrlReticle ctrlShow false; +_ctrlBody ctrlShow false; +_ctrlBodyNight ctrlShow false; +_ctrlBlackScope ctrlShow false; +_ctrlBlackLeft ctrlShow false; +_ctrlBlackRight ctrlShow false; +_ctrlMagnification ctrlShow false; + +private _reticleSize = GVAR(OpticReticleDetailTextures)#0#2; +private _reticlePosition = [ + POS_X(_reticleSize), + POS_Y(_reticleSize), + POS_W(_reticleSize), + POS_H(_reticleSize) +]; + +_ctrlReticle ctrlSetPosition _reticlePosition; +_ctrlReticle ctrlCommit 0; + +private _bodyPosition = [ + POS_X(GVAR(OpticBodyTextureSize)), + POS_Y(GVAR(OpticBodyTextureSize)), + POS_W(GVAR(OpticBodyTextureSize)), + POS_H(GVAR(OpticBodyTextureSize)) +]; + +_ctrlBody ctrlSetText GVAR(OpticBodyTexture); +_ctrlBody ctrlSetPosition _bodyPosition; +_ctrlBody ctrlCommit 0; + +_ctrlBodyNight ctrlSetText GVAR(OpticBodyTextureNight); +_ctrlBodyNight ctrlSetPosition _bodyPosition; +_ctrlBodyNight ctrlCommit 0; + +[missionNamespace, "Draw3D", { + if (isNull _thisArgs) exitWith { + removeMissionEventHandler ["Draw3D", _thisId]; + }; + + _thisArgs call FUNC(animateScriptedOptic); +}, _display] call CBA_fnc_addBISEventHandler; + +//INFO("Scripted optic weapon info display loaded."); + +nil diff --git a/addons/2doptics/fnc_restartCamera.sqf b/addons/2doptics/fnc_restartCamera.sqf new file mode 100644 index 000000000..b4a2a2bf4 --- /dev/null +++ b/addons/2doptics/fnc_restartCamera.sqf @@ -0,0 +1,43 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: cba_2doptics_fnc_restartCamera + +Description: + Restarts the PIP camera for scripted 2D optics. + +Parameters: + _unit - The avatar + _reset - Restart PIP camera if true (optional, default: true) + +Returns: + Nothing. + +Examples: + (begin example) + player call cba_2doptics_fnc_restartCamera; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +if (!GVAR(usePipOptics)) exitWith {}; +if (configProperties [configFile >> "CBA_PIPItems"] isEqualTo []) exitWith {}; + +params ["_unit", ["_reset", true]]; + +if (_reset) then { + GVAR(camera) cameraEffect ["TERMINATE", "BACK"]; + camDestroy GVAR(camera); + + // PIP technique by BadBenson + GVAR(camera) = "camera" camCreate positionCameraToWorld [0,0,0]; + GVAR(camera) camSetFov 0.7; + GVAR(camera) camSetTarget _unit; + GVAR(camera) camCommit 1; + + QGVAR(rendertarget0) setPiPEffect [2, 1.0, 1.0, 1.0, 0.0, [0.0, 1.0, 0.0, 0.25], [1.0, 0.0, 1.0, 1.0], [0.199, 0.587, 0.114, 0.0]]; + GVAR(camera) cameraEffect ["INTERNAL", "BACK", QGVAR(rendertarget0)]; + + INFO("Scripted camera restarted."); +}; diff --git a/addons/2doptics/fnc_setOpticMagnification.sqf b/addons/2doptics/fnc_setOpticMagnification.sqf new file mode 100644 index 000000000..683ebf4fe --- /dev/null +++ b/addons/2doptics/fnc_setOpticMagnification.sqf @@ -0,0 +1,49 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: cba_2doptics_fnc_setOpticMagnification + +Description: + Set magnification of the current optic of the unit. + +Parameters: + _unit - The unit with a weapon + _magnification - Magnification to apply + +Returns: + Nothing. + +Examples: + (begin example) + [player, 3] call cba_2doptics_fnc_setOpticMagnification; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +if (!isNil {parsingNamespace getVariable QGVAR(magnification)}) exitWith {}; + +params ["_unit", "_magnification"]; +private _weapon = currentWeapon _unit; +private _optic = _unit call FUNC(currentOptic); + +// store zeroing +private _zeroing = GVAR(ZeroingDistances) find currentZeroing _unit; + +if (_zeroing isEqualTo -1) then { + _zeroing = nil; +}; + +parsingNamespace setVariable [QGVAR(magnification), _magnification]; +parsingNamespace setVariable [QGVAR(zeroing), _zeroing]; +_unit addWeaponItem [_weapon, _optic]; + +[{ + params ["_unit", "_weapon", "_optic"]; + + parsingNamespace setVariable [QGVAR(magnification), nil]; + _unit addWeaponItem [_weapon, _optic]; + parsingNamespace setVariable [QGVAR(zeroing), nil]; +}, [_unit, _weapon, _optic]] call CBA_fnc_execNextFrame; + +// @todo, rifle, pistol, launcher, plus optics diff --git a/addons/2doptics/fnc_setOpticMagnificationHelper.sqf b/addons/2doptics/fnc_setOpticMagnificationHelper.sqf new file mode 100644 index 000000000..a81367970 --- /dev/null +++ b/addons/2doptics/fnc_setOpticMagnificationHelper.sqf @@ -0,0 +1,25 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: cba_2doptics_fnc_setOpticMagnificationHelper + +Description: + Helper function used in config to set the magnification of a zooming optic. + +Parameters: + _value - Min, max or init optic zoom + +Returns: + Nothing. + +Examples: + (begin example) + 2 call (uiNamespace getVariable 'cba_2doptics_fnc_setOpticMagnificationHelper') + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +if (!isNil QGVAR(magnification)) exitWith {0.25/GVAR(magnification)}; + +0.25/_this diff --git a/addons/2doptics/fnc_setOpticMagnificationHelperZeroing.sqf b/addons/2doptics/fnc_setOpticMagnificationHelperZeroing.sqf new file mode 100644 index 000000000..0e048fb49 --- /dev/null +++ b/addons/2doptics/fnc_setOpticMagnificationHelperZeroing.sqf @@ -0,0 +1,25 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: cba_2doptics_fnc_setOpticMagnificationHelperZeroing + +Description: + Helper function used in config to remember the zeroing of a zooming optic. + +Parameters: + _value - "discreteDistanceInitIndex" + +Returns: + Nothing. + +Examples: + (begin example) + 2 call (uiNamespace getVariable 'cba_2doptics_fnc_setOpticMagnificationHelperZeroing') + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +if (!isNil QGVAR(zeroing)) exitWith {GVAR(zeroing)}; + +_this diff --git a/addons/2doptics/fnc_updateOpticInfo.sqf b/addons/2doptics/fnc_updateOpticInfo.sqf new file mode 100644 index 000000000..457c8d17e --- /dev/null +++ b/addons/2doptics/fnc_updateOpticInfo.sqf @@ -0,0 +1,98 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Internal Function: cba_2doptics_fnc_updateOpticInfo + +Description: + Caches the current optic's parameters in mission namespace variables. + +Parameters: + _unit - The avatar + +Returns: + Nothing. + +Examples: + (begin example) + player call cba_2doptics_fnc_updateOpticInfo; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +params ["_unit"]; + +// Update scripted optic cache. +private _optic = _unit call FUNC(currentOptic); +if (_optic isEqualTo GVAR(currentOptic)) exitWith {}; +GVAR(currentOptic) = _optic; + +private _config = configFile >> "CfgWeapons" >> _optic >> "CBA_ScriptedOptic"; +if (!isClass _config) exitWith {}; + +getArray (_config >> "minMagnificationReticleScale") apply {PARSE(_x)} params [["_minMagnification", 1], ["_minMagnificationReticleScale", 1]]; +getArray (_config >> "maxMagnificationReticleScale") apply {PARSE(_x)} params [["_maxMagnification", 1], ["_maxMagnificationReticleScale", 1]]; + +GVAR(ReticleAdjust) = [ + _minMagnification, _maxMagnification, 1, + _minMagnificationReticleScale, _maxMagnificationReticleScale +]; + +GVAR(HideRedDotMagnification) = getNumber (_config >> "hideRedDotMagnification"); + +getArray (_config >> "fadeReticleInterval") apply {PARSE(_x)} params [["_fadeStart", 0], ["_fadeEnd", 0]]; + +GVAR(FadeReticleInterval) = [ + _fadeStart, _fadeEnd, 1, + 1, 0, true +]; + +GVAR(OpticReticleDetailTextures) = getArray (_config >> "reticleDetailTextures") apply {[PARSE(_x#0), _x#1, PARSE(_x#2), _x param [3, _x#1]]}; + +if (GVAR(OpticReticleDetailTextures) isEqualTo []) then { + private _reticleTexture = getText (_config >> "reticleTexture"); + private _reticleTextureSize = getNumber (_config >> "reticleTextureSize"); + private _reticleTextureeNight = getText (_config >> "reticleTextureNight"); + + if (_reticleTextureeNight isEqualTo "") then { + _reticleTextureeNight = _reticleTexture; + }; + + GVAR(OpticReticleDetailTextures) = [[0, _reticleTexture, _reticleTextureSize, _reticleTextureeNight]]; +}; + +GVAR(OpticBodyTexture) = getText (_config >> "bodyTexture"); +GVAR(OpticBodyTextureSize) = getNumber (_config >> "bodyTextureSize"); +GVAR(OpticBodyTextureNight) = getText (_config >> "bodyTextureNight"); + +if (GVAR(OpticBodyTextureNight) isEqualTo "") then { + GVAR(OpticBodyTextureNight) = GVAR(OpticBodyTexture); +}; + +// zeroing distances +configProperties [configFile >> "CfgWeapons" >> _optic >> "ItemInfo" >> "OpticsModes"] findIf { + GVAR(ZeroingDistances) = getArray (_x >> "discreteDistance"); + !(GVAR(ZeroingDistances) isEqualTo []) +}; + +// pp effects +ppEffectDestroy GVAR(ppEffects); + +GVAR(ppEffects) = getArray (_config >> "opticsPPEffects") apply { + private _config = configFile >> "CfgOpticsEffect" >> _x; + private _type = getText (_config >> "type"); + private _priority = getNumber (_config >> "priority"); + private _params = getArray (_config >> "params"); + + private _ppEffect = ppEffectCreate [_type, _priority]; + _ppEffect ppEffectAdjust _params; + + _ppEffect ppEffectEnable false; + _ppEffect ppEffectForceInNVG true; + _ppEffect ppEffectCommit 0; + _ppEffect +}; + +//INFO_1("Updated optic info %1.",_optic); + +nil diff --git a/addons/2doptics/initSettings.sqf b/addons/2doptics/initSettings.sqf new file mode 100644 index 000000000..3128836ca --- /dev/null +++ b/addons/2doptics/initSettings.sqf @@ -0,0 +1,12 @@ +[ + QGVAR(usePipOptics), + "CHECKBOX", + LSTRING(UsePIP), + LSTRING(Category), + true, // default value + 2, // isGlobal + { + private _unit = call CBA_fnc_currentUnit; + [_unit, true] call FUNC(restartCamera); + } +] call EFUNC(settings,init); diff --git a/addons/2doptics/reticles/pip.rvmat b/addons/2doptics/reticles/pip.rvmat new file mode 100644 index 000000000..6966c7389 --- /dev/null +++ b/addons/2doptics/reticles/pip.rvmat @@ -0,0 +1,20 @@ +ambient[] = {1,1,1,1}; +diffuse[] = {1,1,1,1}; +forcedDiffuse[] = {0,0,0,0}; +emmisive[] = {1,1,1,1}; +specular[] = {1,1,1,1}; +specularPower = 1; +PixelShaderID = "Normal"; +VertexShaderID = "Basic"; + +class Stage1 { + texture = "#(argb,8,8,3)color(0.5,0.5,0.5,0.5,dt)"; + uvSource = "tex"; + + class uvTransform { + aside[] = {1,0,0}; + up[] = {0,1,0}; + dir[] = {0,0,1}; + pos[] = {0,0,0}; + }; +}; diff --git a/addons/2doptics/reticles/scopeblack.rvmat b/addons/2doptics/reticles/scopeblack.rvmat new file mode 100644 index 000000000..319d5f4a9 --- /dev/null +++ b/addons/2doptics/reticles/scopeblack.rvmat @@ -0,0 +1,8 @@ +ambient[] = {0,0,0,0.9}; +diffuse[] = {0,0,0,0.9}; +forcedDiffuse[] = {0,0,0,1}; +emmisive[] = {0,0,0,1}; +specular[] = {0,0,0,0}; +specularPower = 1; +PixelShaderID = "Normal"; +VertexShaderID = "Basic"; diff --git a/addons/2doptics/reticles/scopeblack_big_100_ca.paa b/addons/2doptics/reticles/scopeblack_big_100_ca.paa new file mode 100644 index 000000000..7d45ab818 Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_big_100_ca.paa differ diff --git a/addons/2doptics/reticles/scopeblack_big_70_ca.paa b/addons/2doptics/reticles/scopeblack_big_70_ca.paa new file mode 100644 index 000000000..1453793b5 Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_big_70_ca.paa differ diff --git a/addons/2doptics/reticles/scopeblack_big_80_ca.paa b/addons/2doptics/reticles/scopeblack_big_80_ca.paa new file mode 100644 index 000000000..58013255c Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_big_80_ca.paa differ diff --git a/addons/2doptics/reticles/scopeblack_big_90_ca.paa b/addons/2doptics/reticles/scopeblack_big_90_ca.paa new file mode 100644 index 000000000..281797392 Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_big_90_ca.paa differ diff --git a/addons/2doptics/reticles/scopeblack_ca.paa b/addons/2doptics/reticles/scopeblack_ca.paa new file mode 100644 index 000000000..506f6d612 Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_ca.paa differ diff --git a/addons/2doptics/reticles/scopeblack_small_100_ca.paa b/addons/2doptics/reticles/scopeblack_small_100_ca.paa new file mode 100644 index 000000000..d0232dc0c Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_small_100_ca.paa differ diff --git a/addons/2doptics/reticles/scopeblack_small_70_ca.paa b/addons/2doptics/reticles/scopeblack_small_70_ca.paa new file mode 100644 index 000000000..62b06d7f8 Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_small_70_ca.paa differ diff --git a/addons/2doptics/reticles/scopeblack_small_80_ca.paa b/addons/2doptics/reticles/scopeblack_small_80_ca.paa new file mode 100644 index 000000000..f74e3e41f Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_small_80_ca.paa differ diff --git a/addons/2doptics/reticles/scopeblack_small_90_ca.paa b/addons/2doptics/reticles/scopeblack_small_90_ca.paa new file mode 100644 index 000000000..2240dcc5f Binary files /dev/null and b/addons/2doptics/reticles/scopeblack_small_90_ca.paa differ diff --git a/addons/2doptics/script_component.hpp b/addons/2doptics/script_component.hpp new file mode 100644 index 000000000..daeb716d4 --- /dev/null +++ b/addons/2doptics/script_component.hpp @@ -0,0 +1,66 @@ +#define COMPONENT 2doptics +#include "\x\cba\addons\main\script_mod.hpp" + +//#define DEBUG_MODE_FULL +//#define DISABLE_COMPILE_CACHE +//#define DEBUG_ENABLED_2DOPTICS + +#ifdef DEBUG_ENABLED_2DOPTICS + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_2DOPTICS + #define DEBUG_SETTINGS DEBUG_SETTINGS_2DOPTICS +#endif + +#define DEBUG_MODE_NORMAL +#define DEBUG_SYNCHRONOUS +#include "\x\cba\addons\main\script_macros.hpp" + +#define PARSE(value) (call compile format ["%1", value]) +#define AMBIENT_BRIGHTNESS (sunOrMoon * sunOrMoon * (1 - overcast * 0.25) + moonIntensity / 5 * (1 - overcast) min 1) // idea by Falke + +// control ids +#define IDC_RETICLE 4000 +#define IDC_BODY 4001 +#define IDC_BODY_NIGHT 4002 +#define IDC_RETICLE_SAFEZONE 4010 +#define IDC_BLACK_SCOPE 4020 +#define IDC_BLACK_LEFT 4021 +#define IDC_BLACK_RIGHT 4022 +#define IDC_RED_DOT 4030 +#define IDC_MAGNIFICATION 4040 +#define IDC_ACTIVE_DISPLAY 8888 +#define IDC_ENABLE_ZOOM 9999 + +// control positions +#define POS_W(size) ((size) / (getResolution select 5)) +#define POS_H(size) (POS_W(size) * 4/3) +#define POS_X(size) (0.5 - 0.5 * POS_W(size)) +#define POS_Y(size) (0.5 - 0.5 * POS_H(size)) + +#define RETICLE_SAFEZONE_SIZE 0.84 +#define RETICLE_SAFEZONE_WIDTH POS_W(RETICLE_SAFEZONE_SIZE) +#define RETICLE_SAFEZONE_HEIGHT POS_H(RETICLE_SAFEZONE_SIZE) +#define RETICLE_SAFEZONE_LEFT POS_X(RETICLE_SAFEZONE_SIZE) +#define RETICLE_SAFEZONE_TOP POS_Y(RETICLE_SAFEZONE_SIZE) + +// scope animation config +#define SCOPE_RECOIL_COEF 1 +#define SCOPE_RECOIL_COEF_RESTED 0.4 +#define SCOPE_RECOIL_COEF_DEPLOYED 0.1 + +#define SCOPE_RECOIL_MIN 0.03 +#define SCOPE_RECOIL_MAX 0.032 + +#define SCOPE_SHIFT_X_MIN 0.04 +#define SCOPE_SHIFT_X_MAX 0.05 +#define SCOPE_SHIFT_Y_MIN -0.02 +#define SCOPE_SHIFT_Y_MAX -0.03 + +#define RETICLE_SHIFT_X_MIN 0.006 +#define RETICLE_SHIFT_X_MAX 0.011 +#define RETICLE_SHIFT_Y_MIN -0.009 +#define RETICLE_SHIFT_Y_MAX -0.014 + +#define RECENTER_TIME 0.09 diff --git a/addons/2doptics/stringtable.xml b/addons/2doptics/stringtable.xml new file mode 100644 index 000000000..455157c0c --- /dev/null +++ b/addons/2doptics/stringtable.xml @@ -0,0 +1,21 @@ + + + + + Community Base Addons - 2D Optics + Community Base Addons - 2D-Optiken + Community Base Addons - Optyka 2D + + + CBA 2D Optics + CBA 2D-Optiken + CBA Optyka 2D + + + Use picture in picture optics + Bild in Bild-Optiken verwenden + Picture in Picture 照準器を使う + Używaj optyki typu Obraz w obrazie (PIP) + + + diff --git a/addons/main/config.cpp b/addons/main/config.cpp index dba1fe995..f7957bf3d 100644 --- a/addons/main/config.cpp +++ b/addons/main/config.cpp @@ -31,7 +31,8 @@ class CfgPatches { "cba_jr", "cba_jam", "cba_ui", - "cba_versioning" + "cba_versioning", + "cba_2doptics" }; versionDesc = "C.B.A."; VERSION_CONFIG;