Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripted 2D optics component #1105

Merged
merged 42 commits into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
55170f6
add 2d optics component
commy2 Mar 30, 2019
f0f9629
assets
commy2 Mar 30, 2019
02129b2
port some functions
commy2 Mar 31, 2019
99e2f9b
add component to main requiredAddons, fix currentOptic for null
commy2 Apr 1, 2019
5997a9c
port CBA_fnc_restartCamera, some macros
commy2 Apr 1, 2019
c67b6a8
port updateOpticInfo, global variable names, setting
commy2 Apr 1, 2019
e19ca59
punctuation
commy2 Apr 1, 2019
1c6fd86
some global variables
commy2 Apr 1, 2019
ce40420
loadScriptedOptic and animateScriptedOptic functions
commy2 Apr 2, 2019
529755a
work on changePIP/CarryHandleOpticClass functions
commy2 Apr 2, 2019
e2a2b84
work on changePIP/CarryHandleOpticClass functions
commy2 Apr 3, 2019
e33ba6e
fix bugs
commy2 Apr 3, 2019
6090a6e
Update addons/2doptics/reticles/pip.rvmat
dedmen Apr 3, 2019
d3b7b60
fix a function description
commy2 Apr 3, 2019
f7bbe43
move stuff to ace
commy2 Apr 3, 2019
9a598d1
Thanks Travis
commy2 Apr 3, 2019
287ff93
optimize, don't create camera if pip disabled
commy2 Apr 3, 2019
4ad92d1
optimize
commy2 Apr 3, 2019
4ceb9a1
delete empty file
commy2 Apr 3, 2019
bbe75f1
new configs
commy2 Apr 5, 2019
fd7921b
Merge remote-tracking branch 'origin' into scripted_optics_component
commy2 Apr 5, 2019
d763fac
multiple carry handle types support
commy2 Apr 5, 2019
80df2d2
manual merge
commy2 Apr 5, 2019
26a4887
fix a classname in config
commy2 Apr 5, 2019
e098697
shortened classnames
commy2 Apr 5, 2019
1e1272f
delete unused macros
commy2 Apr 5, 2019
4259970
fix a bug
commy2 Apr 5, 2019
3343240
add dummy classes to force magnification
commy2 Apr 7, 2019
c113243
2D Optics polish translation (#1113)
veteran29 Apr 7, 2019
42f546f
setOpticMagnification function
commy2 Apr 8, 2019
9e87f1f
fix various bugs and quirks
commy2 Apr 10, 2019
9d7d038
restore optic magnification after optic mode toggle wip
commy2 Apr 12, 2019
6b90efc
Merge remote-tracking branch 'origin' into scripted_optics_component
commy2 Apr 12, 2019
bd94e36
Merge branch 'scripted_optics_component' of https://github.com/CBATea…
commy2 Apr 12, 2019
13f57fe
restore magnification and zeroing
commy2 Apr 12, 2019
2749274
pip support for launchers and pistols
commy2 Apr 12, 2019
8c8d7b8
restore magnification for pistol and launcher optics
commy2 Apr 12, 2019
20f0db4
spelling "collimator"
commy2 Apr 12, 2019
032e7e0
cache zeroing distances array on optic switch
commy2 Apr 13, 2019
c6b50cc
add support for scripted optics mode pp effects
commy2 Apr 13, 2019
1623f77
fix flickering of current zeroing in ui when switching modes
commy2 Apr 13, 2019
04be06a
delete dead code
commy2 Apr 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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