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

add manual reticle night switch keybind #1141

Merged
merged 2 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions addons/accessory/XEH_preInitClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "XEH_PREP.sqf"

["CBA Accessory Functions", "MRT_SwitchItemNextClass_R", [LSTRING(railNext), LSTRING(railNext_tooltip)], {[1, "next"] call FUNC(switchAttachment)}, {}, [38, [false, true, false]]] call CBA_fnc_addKeybind; //default ctrl + L
["CBA Accessory Functions", "MRT_SwitchItemPrevClass_R", [LSTRING(railPrev), LSTRING(railPrev_tooltip)], {[1, "prev"] call FUNC(switchAttachment)}, {}, [38, [true, false, false]]] call CBA_fnc_addKeybind; //default shift + L
["CBA Accessory Functions", "MRT_SwitchItemNextClass_O", [LSTRING(opticNext), LSTRING(opticNext_tooltip)], {[2, "next"] call FUNC(switchAttachment)}, {}, [181, [false, true, false]]] call CBA_fnc_addKeybind; //default ctlr + NUM-/
["CBA Accessory Functions", "MRT_SwitchItemPrevClass_O", [LSTRING(opticPrev), LSTRING(opticPrev_tooltip)], {[2, "prev"] call FUNC(switchAttachment)}, {}, [181, [true, false, false]]] call CBA_fnc_addKeybind; //default shift + NUM-/
[ELSTRING(common,WeaponsCategory), "MRT_SwitchItemNextClass_R", [LSTRING(railNext), LSTRING(railNext_tooltip)], {[1, "next"] call FUNC(switchAttachment)}, {}, [38, [false, true, false]]] call CBA_fnc_addKeybind; //default ctrl + L
[ELSTRING(common,WeaponsCategory), "MRT_SwitchItemPrevClass_R", [LSTRING(railPrev), LSTRING(railPrev_tooltip)], {[1, "prev"] call FUNC(switchAttachment)}, {}, [38, [true, false, false]]] call CBA_fnc_addKeybind; //default shift + L
[ELSTRING(common,WeaponsCategory), "MRT_SwitchItemNextClass_O", [LSTRING(opticNext), LSTRING(opticNext_tooltip)], {[2, "next"] call FUNC(switchAttachment)}, {}, [181, [false, true, false]]] call CBA_fnc_addKeybind; //default ctlr + NUM-/
[ELSTRING(common,WeaponsCategory), "MRT_SwitchItemPrevClass_O", [LSTRING(opticPrev), LSTRING(opticPrev_tooltip)], {[2, "prev"] call FUNC(switchAttachment)}, {}, [181, [true, false, false]]] call CBA_fnc_addKeybind; //default shift + NUM-/
18 changes: 9 additions & 9 deletions addons/optics/RscInGameUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ class RscInGameUI {
// 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";
x = safezoneXAbs;
y = safezoneY;
w = THIRD_SCREEN_WIDTH;
h = safezoneH;
colorBackground[] = {0,0,0,1};
};

class TrippleHeadRight: TrippleHeadLeft {
idc = IDC_BLACK_RIGHT;
x = "safeZoneXAbs + safeZoneWAbs - (safeZoneX - safeZoneXAbs) * ((getResolution select 4)/(16/3))";
x = safezoneXAbs + safezoneWAbs - THIRD_SCREEN_WIDTH;
};

class Magnification: CA_Zeroing {
Expand Down Expand Up @@ -87,10 +87,10 @@ class RscInGameUI {

class ReticleSafeZone: RscControlsGroupNoScrollbars {
idc = IDC_RETICLE_SAFEZONE;
x = RETICLE_SAFEZONE_LEFT;
y = RETICLE_SAFEZONE_TOP;
w = RETICLE_SAFEZONE_WIDTH;
h = RETICLE_SAFEZONE_HEIGHT;
x = RETICLE_SAFEZONE_DEFAULT_LEFT;
y = RETICLE_SAFEZONE_DEFAULT_TOP;
w = RETICLE_SAFEZONE_DEFAULT_WIDTH;
h = RETICLE_SAFEZONE_DEFAULT_HEIGHT;

class controls {
class Reticle: Reticle {};
Expand Down
6 changes: 6 additions & 0 deletions addons/optics/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if (configProperties [configFile >> "CBA_PIPItems"] isEqualTo [] && {

if (!hasInterface) exitWith {};

#include "initKeybinds.sqf"

QGVAR(pauseOpticLayer) cutText ["", "PLAIN"];

GVAR(camera) = objNull;
Expand All @@ -28,6 +30,10 @@ GVAR(OpticReticleDetailTextures) = [];
GVAR(OpticBodyTexture) = "";
GVAR(OpticBodyTextureNight) = "";
GVAR(ppEffects) = [];
GVAR(manualReticleNightSwitch) = false;
GVAR(useReticleNight) = false;
GVAR(reticleSafezoneSize) = RETICLE_SAFEZONE_DEFAULT_SIZE;
GVAR(hidePeripheralVision) = false;

// Update optic info.
["weapon", {
Expand Down
15 changes: 11 additions & 4 deletions addons/optics/fnc_animateScriptedOptic.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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 _ctrlReticleSafezone = _display displayCtrl IDC_RETICLE_SAFEZONE;
private _ctrlZeroing = _display displayCtrl 168;
private _ctrlMagnification = _display displayCtrl IDC_MAGNIFICATION;

Expand Down Expand Up @@ -89,6 +90,12 @@ _ctrlMagnification ctrlCommit 0;
private _dayOpacity = AMBIENT_BRIGHTNESS;
private _nightOpacity = [1,0] select (_dayOpacity == 1);

private _useReticleNight = GVAR(useReticleNight);

if (!GVAR(manualReticleNightSwitch)) then {
_useReticleNight = _dayOpacity < 0.5;
};

// Apply lighting and make layers visible.
private _texture = "";
private _detailScaleFactor = 1;
Expand All @@ -97,7 +104,7 @@ private _detailScaleFactor = 1;
_x params ["_zoomX", "_textureX", "_detailScaleFactorX", "_textureXNight"];

if (_zoom > _zoomX) then {
_texture = [_textureX, _textureXNight] select (_dayOpacity < 0.5);
_texture = [_textureX, _textureXNight] select _useReticleNight;
_detailScaleFactor = _detailScaleFactorX;
};
} forEach GVAR(OpticReticleDetailTextures);
Expand All @@ -118,12 +125,12 @@ if (_zoom >= 1) then {

GVAR(ReticleAdjust) set [2, _zoom];
private _reticleAdjust = linearConversion GVAR(ReticleAdjust);

private _sizeReticle = _reticleAdjust * _detailScaleFactor;
ctrlPosition _ctrlReticleSafezone params ["_reticleSafeZonePositionLeft", "_reticleSafeZonePositionTop"];

private _positionReticle = [
POS_X(_sizeReticle) - RETICLE_SAFEZONE_LEFT,
POS_Y(_sizeReticle) - RETICLE_SAFEZONE_TOP,
POS_X(_sizeReticle) - _reticleSafeZonePositionLeft,
POS_Y(_sizeReticle) - _reticleSafeZonePositionTop,
POS_W(_sizeReticle),
POS_H(_sizeReticle)
];
Expand Down
16 changes: 7 additions & 9 deletions addons/optics/fnc_animateScriptedOpticRecoil.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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 _ctrlReticleSafezone = _display displayCtrl IDC_RETICLE_SAFEZONE;

// Reduce the reticle movement as the player drops into lower, supported stances.
private _recoilCoef = SCOPE_RECOIL_COEF;
Expand All @@ -60,21 +61,18 @@ private _sizeBody = GVAR(OpticBodyTextureSize);

// Create and commit recoil effect.
private _reticleAdjust = 1;
private _reticleSafeZoneOffsetLeft = 0;
private _reticleSafeZoneOffsetTop = 0;
ctrlPosition _ctrlReticleSafezone params ["_reticleSafeZonePositionLeft", "_reticleSafeZonePositionTop"];

if (!isNull (_display displayCtrl IDC_RETICLE_SAFEZONE)) then {
if (!isNull _ctrlReticleSafezone) 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_X(_size + _reticleShiftX) - _reticleSafeZonePositionLeft,
POS_Y(_size + _reticleShiftY) - _reticleSafeZonePositionTop,
POS_W(_size),
POS_H(_size)
];
Expand All @@ -101,8 +99,8 @@ _ctrlBodyNight ctrlCommit 0;
private _sizeReticle = _reticleAdjust * _detailScaleFactor;

_positionReticle = [
POS_X(_sizeReticle) + _reticleSafeZoneOffsetLeft,
POS_Y(_sizeReticle) + _reticleSafeZoneOffsetTop,
POS_X(_sizeReticle) - _reticleSafeZonePositionLeft,
POS_Y(_sizeReticle) - _reticleSafeZonePositionTop,
POS_W(_sizeReticle),
POS_H(_sizeReticle)
];
Expand Down
29 changes: 26 additions & 3 deletions addons/optics/fnc_loadScriptedOptic.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Description:

Parameters:
_display - CBA weapon info display <DISPLAY>
_init - Begin draw script, true when called from onLoad event <BOOLEAN>

Returns:
Nothing.
Expand All @@ -20,9 +21,9 @@ Author:
commy2
---------------------------------------------------------------------------- */

params [["_display", displayNull], ["_initDisplay", false]];
params [["_display", displayNull], ["_init", false]];

if (_initDisplay) then {
if (_init) then {
private _unit = call CBA_fnc_currentUnit;

_unit call FUNC(updateOpticInfo);
Expand All @@ -35,6 +36,7 @@ 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 _ctrlReticleSafezone = _display displayCtrl IDC_RETICLE_SAFEZONE;
private _ctrlMagnification = _display displayCtrl IDC_MAGNIFICATION;

_ctrlRedDot ctrlShow false;
Expand Down Expand Up @@ -72,7 +74,28 @@ _ctrlBodyNight ctrlSetText GVAR(OpticBodyTextureNight);
_ctrlBodyNight ctrlSetPosition _bodyPosition;
_ctrlBodyNight ctrlCommit 0;

if (_initDisplay) then {
_ctrlReticleSafezone ctrlSetPosition [
POS_X(GVAR(reticleSafezoneSize)),
POS_Y(GVAR(reticleSafezoneSize)),
POS_W(GVAR(reticleSafezoneSize)),
POS_H(GVAR(reticleSafezoneSize))
];
_ctrlReticleSafezone ctrlCommit 0;

private _width = THIRD_SCREEN_WIDTH;

if (GVAR(hidePeripheralVision)) then {
_width = 0.5 - (_bodyPosition select 2)/2 - safezoneXAbs;
};

_ctrlBlackLeft ctrlSetPositionW _width;
_ctrlBlackLeft ctrlCommit 0;

_ctrlBlackRight ctrlSetPositionW _width;
_ctrlBlackRight ctrlSetPositionX (safezoneXAbs + safezoneWAbs - _width);
_ctrlBlackRight ctrlCommit 0;

if (_init) then {
[missionNamespace, "Draw3D", {
if (isNull _thisArgs) exitWith {
removeMissionEventHandler ["Draw3D", _thisId];
Expand Down
10 changes: 10 additions & 0 deletions addons/optics/fnc_updateOpticInfo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ if (GVAR(OpticBodyTextureNight) isEqualTo "") then {
GVAR(OpticBodyTextureNight) = GVAR(OpticBodyTexture);
};

GVAR(manualReticleNightSwitch) = getNumber (_config >> "manualReticleNightSwitch") != 0;

GVAR(reticleSafezoneSize) = RETICLE_SAFEZONE_DEFAULT_SIZE;

if (isNumber (_config >> "reticleSafezoneSize")) then {
GVAR(reticleSafezoneSize) = getNumber (_config >> "reticleSafezoneSize");
};

GVAR(hidePeripheralVision) = getNumber (_config >> "hidePeripheralVision") != 0;

// zeroing distances
configProperties [configFile >> "CfgWeapons" >> _optic >> "ItemInfo" >> "OpticsModes"] findIf {
GVAR(ZeroingDistances) = getArray (_x >> "discreteDistance");
Expand Down
27 changes: 27 additions & 0 deletions addons/optics/initKeybinds.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
ELSTRING(common,WeaponsCategory),
QGVAR(ManualReticleNightSwitch),
[LSTRING(manual_reticle_switch), LSTRING(manual_reticle_switch_tooltip)],
{
if (GVAR(manualReticleNightSwitch)) then {
GVAR(useReticleNight) = !GVAR(useReticleNight);

// play sound
private _unit = call CBA_fnc_currentUnit;
private _position = _unit modelToWorldVisualWorld (_unit selectionPosition "RightHand");

SOUND_RETICLE_SWITCH params ["_filename", ["_volume", 1], ["_soundPitch", 1], ["_distance", 0]];

// add file extension .wss as default
if !(toLower (_filename select [count _filename - 4]) in [".wav", ".ogg", ".wss"]) then {
_filename = format ["%1.wss", _filename];
};

playSound3D [_filename, objNull, false, _position, _volume, _soundPitch, _distance];

true
} else {false};
},
{},
[DIK_NUMPAD0, [false, false, false]]
] call CBA_fnc_addKeybind;
15 changes: 10 additions & 5 deletions addons/optics/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
#define DEBUG_SYNCHRONOUS
#include "\x\cba\addons\main\script_macros.hpp"

#include "\a3\ui_f\hpp\defineDIKCodes.inc"

#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
#define WEAPON_MAGAZINES(unit,weapon) (weaponsItems (unit) select {_x select 0 == (weapon)} param [0, []] select {_x isEqualType []})

#define SOUND_RETICLE_SWITCH ["A3\Sounds_F\arsenal\weapons\UGL\Firemode_ugl",0.31622776,1,5]
#define THIRD_SCREEN_WIDTH ((safezoneX - safezoneXAbs) * ((getResolution select 4)/(16/3)))

// control ids
#define IDC_RETICLE 4000
#define IDC_BODY 4001
Expand All @@ -40,11 +45,11 @@
#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)
#define RETICLE_SAFEZONE_DEFAULT_SIZE 0.84
#define RETICLE_SAFEZONE_DEFAULT_WIDTH POS_W(RETICLE_SAFEZONE_DEFAULT_SIZE)
#define RETICLE_SAFEZONE_DEFAULT_HEIGHT POS_H(RETICLE_SAFEZONE_DEFAULT_SIZE)
#define RETICLE_SAFEZONE_DEFAULT_LEFT POS_X(RETICLE_SAFEZONE_DEFAULT_SIZE)
#define RETICLE_SAFEZONE_DEFAULT_TOP POS_Y(RETICLE_SAFEZONE_DEFAULT_SIZE)

// scope animation config
#define SCOPE_RECOIL_COEF 1
Expand Down
8 changes: 8 additions & 0 deletions addons/optics/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
<Polish>Używaj optyki typu Obraz w obrazie (PIP)</Polish>
<Italian>Usa ottiche on Picture-in-Picture</Italian>
</Key>
<Key ID="STR_cba_optics_manual_reticle_switch">
<English>Toggle Reticle</English>
<German>Absehen umschalten</German>
</Key>
<Key ID="STR_cba_optics_manual_reticle_switch_tooltip">
<English>Manually switch the reticle of the optic.</English>
<German>Absehen der Optik manuell umschalten.</German>
</Key>
</Package>
</Project>