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 1 commit
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
6 changes: 6 additions & 0 deletions addons/2doptics/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

class Extended_DisplayLoad_EventHandlers {
class RscDisplayInterrupt {
ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayInterrupt)'));
};
};
7 changes: 4 additions & 3 deletions addons/2doptics/RscInGameUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RscInGameUI {
onLoad = QUOTE(call FUNC(loadScriptedOptic));
controls[] = {"CA_FOVMode","ScopeBlack","Reticle","BodyNight","BodyDay","TrippleHeadLeft","TrippleHeadRight","CA_Zeroing","Magnification"};

// Idea by Taosenai. This control can be used to determine whether the scope or the kolimator is used.
commy2 marked this conversation as resolved.
Show resolved Hide resolved
class CA_FOVMode: RscOpticsValue {
idc = 154;
w = 0;
Expand Down Expand Up @@ -44,8 +45,8 @@ class RscInGameUI {
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
// 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";
Expand Down Expand Up @@ -90,7 +91,7 @@ class RscInGameUI {
};
};

class EnableAutoZoom: RscText { // idea by Taosenai. Apparently this can be used via isNil check to determine wheter the scope or the kolimator is used
class EnableAutoZoom: RscText {
idc = IDC_ENABLE_ZOOM;
w = 0;
h = 0;
Expand Down
3 changes: 1 addition & 2 deletions addons/2doptics/XEH_PREP.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ PREP(updateOpticInfo);
PREP(restartCamera);
PREP(loadScriptedOptic);
PREP(animateScriptedOptic);
PREP(animateOpticRecoil);
PREP(animateScriptedOpticRecoil);
PREP(changePIPOpticClass);
PREP(changeCarryHandleOpticClass);

PREP(setOpticMagnification);
PREP(setOpticMagnificationHelper);
14 changes: 9 additions & 5 deletions addons/2doptics/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ 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(ReticleAdjust) = [1,1,nil,1,1];
GVAR(HideRedDotMagnification) = 1e+11;
GVAR(FadeReticleInterval) = [0,0,nil,0,0];
Expand All @@ -35,19 +38,20 @@ GVAR(OpticBodyTextureNight) = "";
}] call CBA_fnc_addPlayerEventHandler;

// Switch to pip class.
["cameraView", {
params ["_unit", "_view"];
if (_view isEqualTo "GUNNER") then {
[QGVAR(UsingOptic), {
params ["_display", "_isUsingOptic"];
if (_isUsingOptic) then {
private _unit = call CBA_fnc_currentUnit;
_unit call FUNC(changePIPOpticClass);
};
}] call CBA_fnc_addPlayerEventHandler;
}] call CBA_fnc_addEventHandler;

["featureCamera", {
params ["_unit", "_camera"];
[_unit, _camera isEqualTo ""] call FUNC(restartCamera);
}] call CBA_fnc_addPlayerEventHandler;

["CAManBase", "Fired", FUNC(animateOpticRecoil)] call CBA_fnc_addClassEventHandler;
["CAManBase", "Fired", FUNC(animateScriptedOpticRecoil)] call CBA_fnc_addClassEventHandler;

// Handle Arsenal: Switch back to normal classes.
GVAR(inArsenal) = false;
Expand Down
4 changes: 4 additions & 0 deletions addons/2doptics/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#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 {};

Expand Down
5 changes: 5 additions & 0 deletions addons/2doptics/fnc_animateScriptedOptic.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ _ctrlBlackRight ctrlShow _isUsingOptic;
//_ctrlZeroing ctrlShow _isUsingOptic;
_ctrlMagnification ctrlShow _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];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Internal Function: cba_2doptics_fnc_animateOpticRecoil
Internal Function: cba_2doptics_fnc_animateScriptedOpticRecoil

Description:
Animates the 2D optic when firing.
Expand All @@ -14,7 +14,7 @@ Returns:

Examples:
(begin example)
[player, currentWeapon player] call cba_2doptics_fnc_animateOpticRecoil;
[player, currentWeapon player] call cba_2doptics_fnc_animateScriptedOpticRecoil;
(end)

Author:
Expand All @@ -26,7 +26,6 @@ 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;
Expand Down
58 changes: 58 additions & 0 deletions addons/2doptics/fnc_initDisplayInterrupt.sqf
Original file line number Diff line number Diff line change
@@ -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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like forgotten debug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not debug, but doesn't belong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (isNull (uiNamespace getVariable ["RscDisplayInterrupt", displayNull])) then {
{
QGVAR(pauseOpticLayer) cutText ["", "PLAIN"];
} call CBA_fnc_execNextFrame;
};
}];
9 changes: 4 additions & 5 deletions addons/2doptics/fnc_loadScriptedOptic.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ Author:
commy2
---------------------------------------------------------------------------- */

if (isNil QGVAR(OpticReticleDetailTextures) || {GVAR(OpticReticleDetailTextures) isEqualTo []}) then {
WARNING("No scripted reticle info found.");
private _unit = call CBA_fnc_currentUnit;
_unit call FUNC(updateOpticInfo);
};
private _unit = call CBA_fnc_currentUnit;
_unit call FUNC(updateOpticInfo);

params ["_display"];

Expand Down Expand Up @@ -80,4 +77,6 @@ _ctrlBodyNight ctrlCommit 0;
_thisArgs call FUNC(animateScriptedOptic);
}, _display] call CBA_fnc_addBISEventHandler;

//INFO("Scripted optic weapon info display loaded.");

nil
2 changes: 1 addition & 1 deletion addons/2doptics/fnc_updateOpticInfo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ if (GVAR(OpticBodyTextureNight) isEqualTo "") then {
GVAR(OpticBodyTextureNight) = GVAR(OpticBodyTexture);
};

INFO_1("Updated optic info %1.",_optic);
//INFO_1("Updated optic info %1.",_optic);

nil
18 changes: 9 additions & 9 deletions addons/2doptics/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#define AMBIENT_BRIGHTNESS (sunOrMoon * sunOrMoon * (1 - overcast * 0.25) + moonIntensity / 5 * (1 - overcast) min 1) // idea by Falke

// control ids
#define IDC_RETICLE 1000
#define IDC_BODY 1001
#define IDC_BODY_NIGHT 1002
#define IDC_RETICLE_SAFEZONE 1010
#define IDC_BLACK_SCOPE 1020
#define IDC_BLACK_LEFT 1021
#define IDC_BLACK_RIGHT 1022
#define IDC_RED_DOT 1030
#define IDC_MAGNIFICATION 1040
#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_ENABLE_ZOOM 9999

// control positions
Expand Down