diff --git a/addons/chemlights/CfgWeapons.hpp b/addons/chemlights/CfgWeapons.hpp index de6f3920f5..27af9d0f42 100644 --- a/addons/chemlights/CfgWeapons.hpp +++ b/addons/chemlights/CfgWeapons.hpp @@ -65,6 +65,7 @@ class CfgWeapons { ACE_Flashlight_Colour = "green"; ACE_Flashlight_Beam = QPATHTOF(UI\chemlight_shield_beam_green_ca.paa); ACE_Flashlight_Size = 0.8; + ACE_Flashlight_Sound = 0; }; }; }; @@ -74,12 +75,10 @@ class CfgWeapons { displayName = CSTRING(Shield_Red_DisplayName); descriptionShort = CSTRING(Shield_Red_DescriptionShort); picture = QPATHTOF(UI\ace_chemlight_shield_red_x_ca.paa); - class ItemInfo: CBA_MiscItem_ItemInfo { - mass = 1; - class FlashLight { + class ItemInfo: ItemInfo { + class FlashLight: FlashLight { ACE_Flashlight_Colour = "red"; ACE_Flashlight_Beam = QPATHTOF(UI\chemlight_shield_beam_red_ca.paa); - ACE_Flashlight_Size = 0.8; }; }; }; @@ -89,12 +88,10 @@ class CfgWeapons { displayName = CSTRING(Shield_Blue_DisplayName); descriptionShort = CSTRING(Shield_Blue_DescriptionShort); picture = QPATHTOF(UI\ace_chemlight_shield_blue_x_ca.paa); - class ItemInfo: CBA_MiscItem_ItemInfo { - mass = 1; - class FlashLight { + class ItemInfo: ItemInfo { + class FlashLight: FlashLight { ACE_Flashlight_Colour = "blue"; ACE_Flashlight_Beam = QPATHTOF(UI\chemlight_shield_beam_blue_ca.paa); - ACE_Flashlight_Size = 0.8; }; }; }; @@ -104,12 +101,10 @@ class CfgWeapons { displayName = CSTRING(Shield_Yellow_DisplayName); descriptionShort = CSTRING(Shield_Yellow_DescriptionShort); picture = QPATHTOF(UI\ace_chemlight_shield_yellow_x_ca.paa); - class ItemInfo: CBA_MiscItem_ItemInfo { - mass = 1; - class FlashLight { + class ItemInfo: ItemInfo { + class FlashLight: FlashLight { ACE_Flashlight_Colour = "yellow"; ACE_Flashlight_Beam = QPATHTOF(UI\chemlight_shield_beam_yellow_ca.paa); - ACE_Flashlight_Size = 0.8; }; }; }; @@ -119,12 +114,10 @@ class CfgWeapons { displayName = CSTRING(Shield_Orange_DisplayName); descriptionShort = CSTRING(Shield_Orange_DescriptionShort); picture = QPATHTOF(UI\ace_chemlight_shield_orange_x_ca.paa); - class ItemInfo: CBA_MiscItem_ItemInfo { - mass = 1; - class FlashLight { + class ItemInfo: ItemInfo { + class FlashLight: FlashLight { ACE_Flashlight_Colour = "orange"; ACE_Flashlight_Beam = QPATHTOF(UI\chemlight_shield_beam_orange_ca.paa); - ACE_Flashlight_Size = 0.8; }; }; }; @@ -134,12 +127,10 @@ class CfgWeapons { displayName = CSTRING(Shield_White_DisplayName); descriptionShort = CSTRING(Shield_White_DescriptionShort); picture = QPATHTOF(UI\ace_chemlight_shield_white_x_ca.paa); - class ItemInfo: CBA_MiscItem_ItemInfo { - mass = 1; - class FlashLight { + class ItemInfo: ItemInfo { + class FlashLight: FlashLight { ACE_Flashlight_Colour = "white"; ACE_Flashlight_Beam = QPATHTOF(UI\chemlight_shield_beam_white_ca.paa); - ACE_Flashlight_Size = 0.8; }; }; }; diff --git a/addons/flashlights/CfgWeapons.hpp b/addons/flashlights/CfgWeapons.hpp index 9623b4d069..41bfd4a8bb 100644 --- a/addons/flashlights/CfgWeapons.hpp +++ b/addons/flashlights/CfgWeapons.hpp @@ -16,7 +16,6 @@ class CfgWeapons { ACE_Flashlight_Colour = "red"; ACE_Flashlight_Beam = QPATHTOF(UI\Flashlight_beam_red_ca.paa); ACE_Flashlight_Size = 1.75; - ACE_Flashlight_Sound = 1; }; }; }; @@ -34,7 +33,6 @@ class CfgWeapons { ACE_Flashlight_Colour = "red"; ACE_Flashlight_Beam = QPATHTOF(UI\Flashlight_beam_red_ca.paa); ACE_Flashlight_Size = 1.5; - ACE_Flashlight_Sound = 1; }; }; }; @@ -52,7 +50,6 @@ class CfgWeapons { ACE_Flashlight_Colour = "white"; ACE_Flashlight_Beam = QPATHTOF(UI\Flashlight_beam_white_ca.paa); ACE_Flashlight_Size = 2.15; - ACE_Flashlight_Sound = 1; }; }; }; diff --git a/addons/map/CfgVehicles.hpp b/addons/map/CfgVehicles.hpp index 16c03bd225..3da69a1216 100644 --- a/addons/map/CfgVehicles.hpp +++ b/addons/map/CfgVehicles.hpp @@ -5,7 +5,7 @@ class CfgVehicles { class ACE_MapFlashlight { displayName = CSTRING(Action_Flashlights); icon = QUOTE(\a3\ui_f\data\IGUI\Cfg\VehicleToggles\lightsiconon_ca.paa); - condition = QUOTE(GVAR(mapIllumination) && visibleMap && {count ([ACE_player] call FUNC(getUnitFlashlights)) > 0}); + condition = QUOTE(GVAR(mapIllumination) && visibleMap && {!([] isEqualTo (_player call FUNC(getUnitFlashlights)))}); statement = "true"; exceptions[] = {"isNotDragging", "notOnMap", "isNotInside", "isNotSitting"}; insertChildren = QUOTE(_this call DFUNC(compileFlashlightMenu)); diff --git a/addons/map/CfgWeapons.hpp b/addons/map/CfgWeapons.hpp index 5831428c6c..a9188159a3 100644 --- a/addons/map/CfgWeapons.hpp +++ b/addons/map/CfgWeapons.hpp @@ -8,7 +8,7 @@ class CfgWeapons { class FlashLight { ACE_Flashlight_Colour = "white"; ACE_Flashlight_Beam = QPATHTOF(UI\Flashlight_beam_white_ca.paa); - ACE_Flashlight_Size = 2.75; + ACE_Flashlight_Size = DEFAULT_FLASHLIGHT_SIZE; ACE_Flashlight_Sound = 1; }; }; @@ -18,7 +18,7 @@ class CfgWeapons { class FlashLight { ACE_Flashlight_Colour = "white"; ACE_Flashlight_Beam = QPATHTOF(UI\Flashlight_beam_white_ca.paa); - ACE_Flashlight_Size = 2.75; + ACE_Flashlight_Size = DEFAULT_FLASHLIGHT_SIZE; ACE_Flashlight_Sound = 1; }; }; diff --git a/addons/map/XEH_PREP.hpp b/addons/map/XEH_PREP.hpp index b6d1fbcf4a..af6e815fd7 100644 --- a/addons/map/XEH_PREP.hpp +++ b/addons/map/XEH_PREP.hpp @@ -7,6 +7,7 @@ PREP(determineZoom); PREP(flashlightGlow); PREP(getUnitFlashlights); PREP(moduleMap); +PREP(needPlaySound); PREP(onDrawMap); PREP(simulateMapLight); PREP(switchFlashlight); diff --git a/addons/map/XEH_postInitClient.sqf b/addons/map/XEH_postInitClient.sqf index ff93951bbe..f439c4db55 100644 --- a/addons/map/XEH_postInitClient.sqf +++ b/addons/map/XEH_postInitClient.sqf @@ -50,15 +50,15 @@ call FUNC(determineZoom); params ["_player", "_mapOn"]; private _unitLight = _player getVariable [QGVAR(flashlight), ["", objNull]]; _unitLight params ["_flashlight", "_glow"]; - private _flashlightOn = !(_flashlight isEqualTo ""); if (_mapOn) then { - if (_flashlightOn && {isNull _glow}) then { + if (!(_flashlight isEqualTo "") && {isNull _glow}) then { [_player, _flashlight] call FUNC(flashlightGlow); - playSound QGVAR(flashlightClick); + if ([_player, _flashlight] call FUNC(needPlaySound)) then {playSound QGVAR(flashlightClick)}; }; } else { if (!isNull _glow) then { [_player, ""] call FUNC(flashlightGlow); + if ([_player, _flashlight] call FUNC(needPlaySound)) then {playSound QGVAR(flashlightClick)}; }; }; }] call CBA_fnc_addPlayerEventHandler; diff --git a/addons/map/functions/fnc_getUnitFlashlights.sqf b/addons/map/functions/fnc_getUnitFlashlights.sqf index 0bbd8b7af9..d8f537380d 100644 --- a/addons/map/functions/fnc_getUnitFlashlights.sqf +++ b/addons/map/functions/fnc_getUnitFlashlights.sqf @@ -10,7 +10,7 @@ * Flashlight classnames (empty for none) * * Example: - * [unit] call ace_map_fnc_getUnitFlashlights; + * player call ace_map_fnc_getUnitFlashlights * * Public: No */ @@ -18,11 +18,21 @@ params ["_unit"]; private _flashlights = []; +private _cfgWeapons = configFile >> "CfgWeapons"; { - if (isText (configFile >> "CfgWeapons" >> _x >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Colour")) then { - _flashlights pushBackUnique _x; + private _weaponConfig = _cfgWeapons >> _x; + if ( + -1 < [ + _weaponConfig >> "ItemInfo" >> "FlashLight", + _weaponConfig >> "FlashLight" + ] findIf { + isText (_x >> "ACE_Flashlight_Colour") + || {!(getArray (_x >> "ambient") in [[], [0,0,0]])} + } + ) then { + _flashlights pushBack _x; }; -} forEach (_unit call EFUNC(common,uniqueItems)); +} forEach ([_unit, true] call CBA_fnc_uniqueUnitItems); _flashlights diff --git a/addons/map/functions/fnc_needPlaySound.sqf b/addons/map/functions/fnc_needPlaySound.sqf new file mode 100644 index 0000000000..0c0d34f42e --- /dev/null +++ b/addons/map/functions/fnc_needPlaySound.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* + * Author: Dystopian + * Checks if sound needs to be played when flashlight is toggled. + * + * Arguments: + * 0: Unit + * 1: Flashlight + * + * Return Value: + * Need to play sound + * + * Example: + * [player, "acc_flashlight"] call ace_map_fnc_needPlaySound + * + * Public: No + */ + +params ["_unit", "_flashlight"]; + +if (_flashlight isEqualTo "") exitWith { + LOG("empty flashlight"); + false +}; + +private _currentWeapon = currentWeapon _unit; +if ( + _unit isFlashlightOn _currentWeapon + // _currentWeapon==_flashlight should be checked here but it's not supported by isFlashlightOn + && {_flashlight isEqualTo ((weaponsItems _unit select {(_x select 0) isEqualTo _currentWeapon}) select 0 select 2)} +) exitWith { + TRACE_1("weapon flashlight is on",_flashlight); + false +}; + +private _config = configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight"; +if (!isClass _config) exitWith { + TRACE_1("weapon with unmountable flashlight",_flashlight); + true +}; + +0 < [_config >> "ACE_Flashlight_Sound", "number", 1] call CBA_fnc_getConfigEntry diff --git a/addons/map/functions/fnc_simulateMapLight.sqf b/addons/map/functions/fnc_simulateMapLight.sqf index 236914820f..7ec9d573a2 100644 --- a/addons/map/functions/fnc_simulateMapLight.sqf +++ b/addons/map/functions/fnc_simulateMapLight.sqf @@ -55,9 +55,9 @@ if (_flashlight == "") then { private _mousePos = GVAR(mousePos); //flashlight settings - private _cfg = (configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight"); - private _size = getNumber (_cfg >> "ACE_Flashlight_Size"); - private _flashTex = getText (_cfg >> "ACE_Flashlight_Beam"); + private _cfg = configFile >> "CfgWeapons" >> _flashlight >> "ItemInfo" >> "FlashLight"; + private _size = [_cfg >> "ACE_Flashlight_Size", "number", DEFAULT_FLASHLIGHT_SIZE] call CBA_fnc_getConfigEntry; + private _flashTex = [_cfg >> "ACE_Flashlight_Beam", "text", QPATHTOF(UI\Flashlight_beam_white_ca.paa)] call CBA_fnc_getConfigEntry; private _beamSize = (safeZoneW/safeZoneWAbs) * _screenSize / _size; //after 5x zoom, it's simulated to be fixed (it actually gets bigger relative to zoom) diff --git a/addons/map/functions/fnc_switchFlashlight.sqf b/addons/map/functions/fnc_switchFlashlight.sqf index 4fc1c75356..5d4ed9de0a 100644 --- a/addons/map/functions/fnc_switchFlashlight.sqf +++ b/addons/map/functions/fnc_switchFlashlight.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" /* - * Author: voioper + * Author: voiper * Switch flashlight on/off. * * Arguments: @@ -26,12 +26,7 @@ if (GVAR(mapGlow)) then { _glow = [_unit, _newFlashlight, false] call FUNC(flashlightGlow); }; -private _config = (configFile >> "CfgWeapons"); - -if ( - (getNumber (_config >> _newFlashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0) || - {getNumber (_config >> _flashlight >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Sound") > 0} -) then { +if (-1 < [_newFlashlight, _flashlight] findIf {[_unit, _x] call FUNC(needPlaySound)}) then { playSound QGVAR(flashlightClick); }; diff --git a/addons/map/script_component.hpp b/addons/map/script_component.hpp index 12d9c0e5fe..432622f632 100644 --- a/addons/map/script_component.hpp +++ b/addons/map/script_component.hpp @@ -19,3 +19,5 @@ #define MARKERNAME_MAPTOOL_FIXED "ACE_MapToolFixed" #define MARKERNAME_MAPTOOL_ROTATINGNORMAL "ACE_MapToolRotatingNormal" #define MARKERNAME_MAPTOOL_ROTATINGSMALL "ACE_MapToolRotatingSmall" + +#define DEFAULT_FLASHLIGHT_SIZE 2.75 diff --git a/optionals/compat_rh_acc/CfgWeapons.hpp b/optionals/compat_rh_acc/CfgWeapons.hpp index df63559f06..001506ce8d 100644 --- a/optionals/compat_rh_acc/CfgWeapons.hpp +++ b/optionals/compat_rh_acc/CfgWeapons.hpp @@ -158,18 +158,4 @@ class CfgWeapons { }; }; }; - - /* Flashlights */ - class InventoryFlashLightItem_Base_F; - - class RH_SFM952V: ItemCore { - class ItemInfo: InventoryFlashLightItem_Base_F { - class FlashLight { - ACE_Flashlight_Colour = "white"; - ACE_Flashlight_Beam = QPATHTOEF(map,UI\Flashlight_beam_white_ca.paa); - ACE_Flashlight_Size = 2.75; - ACE_Flashlight_Sound = 1; - }; - }; - }; };