From 2fe53431c7a00d0b14782b6c5ce0419eb1424ad9 Mon Sep 17 00:00:00 2001 From: BaerMitUmlaut Date: Thu, 8 Oct 2015 19:29:30 +0200 Subject: [PATCH] Split event handlers --- addons/nightvision/XEH_postInitClient.sqf | 4 +-- addons/nightvision/XEH_preInit.sqf | 3 +- ...leNVGs.sqf => fnc_onCameraViewChanged.sqf} | 11 +++---- .../functions/fnc_onVisionModeChanged.sqf | 29 +++++++++++++++++++ 4 files changed, 39 insertions(+), 8 deletions(-) rename addons/nightvision/functions/{fnc_handleNVGs.sqf => fnc_onCameraViewChanged.sqf} (63%) create mode 100644 addons/nightvision/functions/fnc_onVisionModeChanged.sqf diff --git a/addons/nightvision/XEH_postInitClient.sqf b/addons/nightvision/XEH_postInitClient.sqf index 894fe00ee4..accc1872be 100644 --- a/addons/nightvision/XEH_postInitClient.sqf +++ b/addons/nightvision/XEH_postInitClient.sqf @@ -32,12 +32,12 @@ GVAR(ppEffectMuzzleFlash) ppEffectCommit 0; ["playerInventoryChanged", {_this call FUNC(updatePPEffects)}] call EFUNC(common,addEventHandler); ["playerVisionModeChanged", { _this call FUNC(updatePPEffects); - _this call FUNC(handleNVGs); + _this call FUNC(onVisionModeChanged); }] call EFUNC(common,addEventHandler); ["zeusDisplayChanged", {_this call FUNC(updatePPEffects)}] call EFUNC(common,addEventHandler); ["cameraViewChanged", { _this call FUNC(updatePPEffects); - _this call FUNC(handleNVGs); + _this call FUNC(onCameraViewChanged); }] call EFUNC(common,addEventHandler); ["playerVehicleChanged", {_this call FUNC(updatePPEffects)}] call EFUNC(common,addEventHandler); ["playerTurretChanged", {_this call FUNC(updatePPEffects)}] call EFUNC(common,addEventHandler); diff --git a/addons/nightvision/XEH_preInit.sqf b/addons/nightvision/XEH_preInit.sqf index ab9995c745..ed02b9524e 100644 --- a/addons/nightvision/XEH_preInit.sqf +++ b/addons/nightvision/XEH_preInit.sqf @@ -4,8 +4,9 @@ ADDON = false; PREP(blending); PREP(changeNVGBrightness); -PREP(handleNVGs); PREP(initModule); +PREP(onCameraViewChanged); +PREP(onVisionModeChanged); PREP(updatePPEffects); ADDON = true; diff --git a/addons/nightvision/functions/fnc_handleNVGs.sqf b/addons/nightvision/functions/fnc_onCameraViewChanged.sqf similarity index 63% rename from addons/nightvision/functions/fnc_handleNVGs.sqf rename to addons/nightvision/functions/fnc_onCameraViewChanged.sqf index ca05f5ac94..adc221c06d 100644 --- a/addons/nightvision/functions/fnc_handleNVGs.sqf +++ b/addons/nightvision/functions/fnc_onCameraViewChanged.sqf @@ -1,31 +1,32 @@ /* * Author: BaerMitUmlaut - * Disables NVGs when the player aims down his sight. + * Disables/re-enables NVGs when the player starts/stops aiming down his sight. * * Arguments: * 0: Unit + * 1: New camera view * * Return Value: * None * * Example: - * [player] call ace_nightvision_fnc_disableNVGs + * [player, "GUNNER"] call ace_nightvision_fnc_onCameraViewChanged * * Public: No */ #include "script_component.hpp" -params ["_unit"]; +params ["_unit", "_cameraView"]; if (GVAR(disableNVGsWithSights) && {(hmd _unit) != ""}) then { (assignedVehicleRole _unit) params ["_role", "_turretPath"]; if ((vehicle _unit == _unit) || {isTurnedOut _unit} || {_role == "cargo" && {!(isNil "_turretPath")}}) then { - if ((cameraView == "GUNNER") && {currentVisionMode _unit > 0}) then { + if ((_cameraView == "GUNNER") && {currentVisionMode _unit > 0}) then { _unit action ["NVGogglesOff", _unit]; GVAR(reenableNVGs) = true; } else { - if (GVAR(reenableNVGs) && {cameraView != "GUNNER"}) then { + if (GVAR(reenableNVGs) && {_cameraView != "GUNNER"}) then { _unit action ["NVGoggles", _unit]; GVAR(reenableNVGs) = false; }; diff --git a/addons/nightvision/functions/fnc_onVisionModeChanged.sqf b/addons/nightvision/functions/fnc_onVisionModeChanged.sqf new file mode 100644 index 0000000000..d14e504dc8 --- /dev/null +++ b/addons/nightvision/functions/fnc_onVisionModeChanged.sqf @@ -0,0 +1,29 @@ +/* + * Author: BaerMitUmlaut + * Disables turning on NVGs while the player aims down his sight. + * + * Arguments: + * 0: Unit + * 1: New vision mode + * + * Return Value: + * None + * + * Example: + * [player, 1] call ace_nightvision_fnc_onVisionModeChanged + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_unit", "_visionMode"]; + +if (GVAR(disableNVGsWithSights) && {(hmd _unit) != ""}) then { + (assignedVehicleRole _unit) params ["_role", "_turretPath"]; + if ((vehicle _unit == _unit) || {isTurnedOut _unit} || {_role == "cargo" && {!(isNil "_turretPath")}}) then { + if ((cameraView == "GUNNER") && {_visionMode > 0}) then { + _unit action ["NVGogglesOff", _unit]; + }; + }; +};