Map - Improve flashlight support (#6608)

* Improve flashlight support

* Speed up items check loop

* Speed up more

* Remove useless var
This commit is contained in:
Dystopian 2018-10-25 18:39:27 +02:00 committed by PabstMirror
parent 8580cb250a
commit 1fe7c5c29c
12 changed files with 81 additions and 57 deletions

View File

@ -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;
};
};
};

View File

@ -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;
};
};
};

View File

@ -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));

View File

@ -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;
};
};

View File

@ -7,6 +7,7 @@ PREP(determineZoom);
PREP(flashlightGlow);
PREP(getUnitFlashlights);
PREP(moduleMap);
PREP(needPlaySound);
PREP(onDrawMap);
PREP(simulateMapLight);
PREP(switchFlashlight);

View File

@ -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;

View File

@ -10,7 +10,7 @@
* Flashlight classnames (empty for none) <ARRAY>
*
* 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

View File

@ -0,0 +1,42 @@
#include "script_component.hpp"
/*
* Author: Dystopian
* Checks if sound needs to be played when flashlight is toggled.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Flashlight <STRING>
*
* Return Value:
* Need to play sound <BOOL>
*
* 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

View File

@ -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)

View File

@ -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);
};

View File

@ -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

View File

@ -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;
};
};
};
};