Skip to content

Commit

Permalink
Scripted 2D optics component (#1105)
Browse files Browse the repository at this point in the history
* add 2d optics component

* assets

* port some functions

* add component to main requiredAddons, fix currentOptic for null

* port CBA_fnc_restartCamera, some macros

* port updateOpticInfo, global variable names, setting

* punctuation

* some global variables

* loadScriptedOptic and animateScriptedOptic functions

* work on changePIP/CarryHandleOpticClass functions

* work on changePIP/CarryHandleOpticClass functions

* fix bugs

* Update addons/2doptics/reticles/pip.rvmat

Co-Authored-By: commy2 <commy-2@gmx.de>

* fix a function description

* move stuff to ace

* Thanks Travis

* optimize, don't create camera if pip disabled

* optimize

* delete empty file

* new configs

* multiple carry handle types support

* fix a classname in config

* shortened classnames

* delete unused macros

* fix a bug

* add dummy classes to force magnification

* 2D Optics polish translation (#1113)

* setOpticMagnification function

* fix various bugs and quirks

* restore optic magnification after optic mode toggle wip

* restore magnification and zeroing

* pip support for launchers and pistols

* restore magnification for pistol and launcher optics

* spelling "collimator"

* cache zeroing distances array on optic switch

* add support for scripted optics mode pp effects

* fix flickering of current zeroing in ui when switching modes

* delete dead code
  • Loading branch information
commy2 committed Apr 13, 2019
1 parent 5648bdd commit 1589933
Show file tree
Hide file tree
Showing 47 changed files with 1,395 additions and 1 deletion.
1 change: 1 addition & 0 deletions addons/2doptics/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\cba\addons\2doptics
1 change: 1 addition & 0 deletions addons/2doptics/CfgCarryHandleTypes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class CBA_CarryHandleTypes {};
17 changes: 17 additions & 0 deletions addons/2doptics/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -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)'));
};
};
7 changes: 7 additions & 0 deletions addons/2doptics/CfgOpticsEffect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CfgOpticsEffect {
class CBA_OpticsRadBlur1 {
type = "radialblur";
params[] = {0.015,0,0.14,0.2};
priority = 950;
};
};
1 change: 1 addition & 0 deletions addons/2doptics/CfgPIPItems.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class CBA_PIPItems {};
106 changes: 106 additions & 0 deletions addons/2doptics/RscInGameUI.hpp
Original file line number Diff line number Diff line change
@@ -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;
};
};
};
11 changes: 11 additions & 0 deletions addons/2doptics/XEH_PREP.sqf
Original file line number Diff line number Diff line change
@@ -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);
125 changes: 125 additions & 0 deletions addons/2doptics/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions addons/2doptics/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -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"
Binary file added addons/2doptics/cba_optic_big_100.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_big_70.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_big_80.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_big_90.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_big_pip.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_small_100.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_small_70.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_small_80.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_small_90.p3d
Binary file not shown.
Binary file added addons/2doptics/cba_optic_small_pip.p3d
Binary file not shown.
21 changes: 21 additions & 0 deletions addons/2doptics/config.cpp
Original file line number Diff line number Diff line change
@@ -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"
Loading

0 comments on commit 1589933

Please sign in to comment.