diff --git a/addons/nametags/XEH_postInit.sqf b/addons/nametags/XEH_postInit.sqf index ab3cd03391..1df20e45e7 100644 --- a/addons/nametags/XEH_postInit.sqf +++ b/addons/nametags/XEH_postInit.sqf @@ -5,6 +5,7 @@ if (!hasInterface) exitWith {}; +GVAR(ShowNamesTime) = -10; // Add keybinds ["ACE3", QGVAR(showNameTags), localize "STR_ACE_NameTags_ShowNames", diff --git a/addons/nametags/XEH_preInit.sqf b/addons/nametags/XEH_preInit.sqf index 80c06cff1f..f3c9a97cba 100644 --- a/addons/nametags/XEH_preInit.sqf +++ b/addons/nametags/XEH_preInit.sqf @@ -9,9 +9,6 @@ PREP(getVehicleData); PREP(initIsSpeaking); PREP(moduleNameTags); PREP(onDraw3d); -PREP(onMouseZChanged); PREP(setText); -GVAR(ShowNamesTime) = -10; - ADDON = true; diff --git a/addons/nametags/functions/fnc_initIsSpeaking.sqf b/addons/nametags/functions/fnc_initIsSpeaking.sqf index 56c5cfc2f1..d8ffda756c 100644 --- a/addons/nametags/functions/fnc_initIsSpeaking.sqf +++ b/addons/nametags/functions/fnc_initIsSpeaking.sqf @@ -20,8 +20,8 @@ if (isServer) then { //If someone disconnects while speaking, reset their variable addMissionEventHandler ["HandleDisconnect", { PARAMS_1(_disconnectedPlayer); - if (_disconnectedPlayer getVariable [QGVAR(isSpeaking), false]) then { - _disconnectedPlayer setVariable [QGVAR(isSpeaking), false, true]; + if (_disconnectedPlayer getVariable [QGVAR(isSpeakingInGame), false]) then { + _disconnectedPlayer setVariable [QGVAR(isSpeakingInGame), false, true]; }; }]; }; @@ -31,46 +31,40 @@ if (!hasInterface) exitWith {}; ["playerChanged", { //When player changes, make sure to reset old unit's variable PARAMS_2(_newUnit,_oldUnit); - if (_oldUnit getVariable [QGVAR(isSpeaking), false]) then { - _oldUnit setVariable [QGVAR(isSpeaking), false, true]; + if ((!isNull _oldUnit) && {_oldUnit getVariable [QGVAR(isSpeakingInGame), false]}) then { + _oldUnit setVariable [QGVAR(isSpeakingInGame), false, true]; }; }] call EFUNC(common,addEventHandler); -//For performance, chose different code paths at mission start based on installed mods (once, instead of checking each time) -_pfEHCode = switch (true) do { -case (isClass (configFile >> "cfgPatches" >> "acre_api")): { - { - _oldSetting = ACE_player getVariable [QGVAR(isSpeaking), false]; - _newSetting = ([ACE_player] call acre_api_fnc_isSpeaking) || ([ACE_player] call acre_api_fnc_isBroadcasting) || {!(isNull findDisplay 55)}; - if (!(_oldSetting isEqualTo _newSetting)) then { - ACE_player setVariable [QGVAR(isSpeaking), _newSetting, true]; - }; - }; +if (isClass (configFile >> "cfgPatches" >> "acre_api")) then { + diag_log text format ["[ACE_nametags] - ACRE Detected"]; + DFUNC(isSpeaking) = { + PARAMS_1(_unit); + ([_unit] call acre_api_fnc_isSpeaking) || ([ACE_player] call acre_api_fnc_isBroadcasting) }; -case (isClass (configFile >> "cfgPatches" >> "task_force_radio")): { - //Note: TFAR has a TFAR_fnc_isSpeaking function, but it has a fairly costly `callExtension` - //I think it's much faster to use the internal "tf_isSpeaking" variable - //If we don't care about the built-in VON, we could switch this to a pure event driven system - { - _oldSetting = ACE_player getVariable [QGVAR(isSpeaking), false]; - _newSetting = (ACE_player getVariable ["tf_isSpeaking", false]) || {!(isNull findDisplay 55)}; - if (!(_oldSetting isEqualTo _newSetting)) then { - ACE_player setVariable [QGVAR(isSpeaking), _newSetting, true]; - }; +} else { + if (isClass (configFile >> "cfgPatches" >> "task_force_radio")) then { + diag_log text format ["[ACE_nametags] - TFR Detected"]; + DFUNC(isSpeaking) = { + PARAMS_1(_unit); + (_unit getVariable ["tf_isSpeaking", false]) }; - }; - default { - //Note: class RscDisplayVoiceChat {idd = 55}; //only present when talking - { - _oldSetting = ACE_player getVariable [QGVAR(isSpeaking), false]; + } else { + //No Radio Mod - Start a PFEH to watch the internal VON icon + //Note: class RscDisplayVoiceChat {idd = 55} - only present when talking + + [{ + _oldSetting = ACE_player getVariable [QGVAR(isSpeakingInGame), false]; _newSetting = (!(isNull findDisplay 55)); if (!(_oldSetting isEqualTo _newSetting)) then { - ACE_player setVariable [QGVAR(isSpeaking), _newSetting, true]; + ACE_player setVariable [QGVAR(isSpeakingInGame), _newSetting, true]; }; + } , 0.1, []] call CBA_fnc_addPerFrameHandler; + + DFUNC(isSpeaking) = { + PARAMS_1(_unit); + (_unit getVariable [QGVAR(isSpeakingInGame), false]) }; }; }; - -//Is 0.05sec precision enough?? -[_pfEHCode, 0.05, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/nametags/functions/fnc_onDraw3d.sqf b/addons/nametags/functions/fnc_onDraw3d.sqf index 8aa503d377..d35cef0d67 100644 --- a/addons/nametags/functions/fnc_onDraw3d.sqf +++ b/addons/nametags/functions/fnc_onDraw3d.sqf @@ -50,9 +50,9 @@ if ((GVAR(showPlayerNames) in [2,4]) && {_onKeyPressAlphaMax > 0}) then { _alpha = _alpha min _onKeyPressAlphaMax; _icon = ICON_NONE; if (GVAR(showSoundWaves) == 2) then { //icon will be drawn below, so only show name here - _icon = if ((_target getVariable [QGVAR(isSpeaking), false]) && {(vehicle _target) == _target}) then {ICON_NAME} else {_defaultIcon}; + _icon = if (([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target}) then {ICON_NAME} else {_defaultIcon}; } else { - _icon = if ((_target getVariable [QGVAR(isSpeaking), false]) && {(vehicle _target) == _target} && {GVAR(showSoundWaves) > 0}) then {ICON_NAME_SPEAK} else {_defaultIcon}; + _icon = if (([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target} && {GVAR(showSoundWaves) > 0}) then {ICON_NAME_SPEAK} else {_defaultIcon}; }; [_player, _target, _alpha, _distance * 0.026, _icon] call FUNC(drawNameTagIcon); @@ -77,10 +77,10 @@ if (((GVAR(showPlayerNames) in [1,3]) && {_onKeyPressAlphaMax > 0}) || {GVAR(sho _icon = ICON_NONE; if ((GVAR(showPlayerNames) in [1,3]) && {_onKeyPressAlphaMax > 0}) then { - if ((_target getVariable [QGVAR(isSpeaking), false]) && {(vehicle _target) == _target} && {GVAR(showSoundWaves) > 0}) then {_icon = ICON_NAME_SPEAK;} else {_icon = _defaultIcon}; + if (([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target} && {GVAR(showSoundWaves) > 0}) then {_icon = ICON_NAME_SPEAK;} else {_icon = _defaultIcon}; } else { //showSoundWaves must be 2, only draw speak icon - if ((_target getVariable [QGVAR(isSpeaking), false]) && {(vehicle _target) == _target}) then {_icon = ICON_SPEAK;}; + if (([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target}) then {_icon = ICON_SPEAK;}; }; if ((_icon != ICON_NONE) && @@ -96,7 +96,7 @@ if (((GVAR(showPlayerNames) in [1,3]) && {_onKeyPressAlphaMax > 0}) || {GVAR(sho _alpha = ((1 - 0.2 * (_distance - GVAR(PlayerNamesViewDistance))) min (1 - 0.15 * (_projDist * 5 - _distance - 3)) min 1) * GVAR(PlayerNamesMaxAlpha); - if ((GVAR(showSoundWaves) == 2) && {(_target getVariable [QGVAR(isSpeaking), false]) && {(vehicle _target) == _target}}) then { + if ((GVAR(showSoundWaves) == 2) && {([_target] call FUNC(isSpeaking)) && {(vehicle _target) == _target}}) then { _alpha = 1; } else { _alpha = _alpha min _onKeyPressAlphaMax; diff --git a/addons/nametags/functions/fnc_onMouseZChanged.sqf b/addons/nametags/functions/fnc_onMouseZChanged.sqf deleted file mode 100644 index 8892f201bc..0000000000 --- a/addons/nametags/functions/fnc_onMouseZChanged.sqf +++ /dev/null @@ -1,18 +0,0 @@ -/* - Author: aeroson - - Description: - Callback for mouse wheel change - - Parameters: - None - - Returns: - Nothing -*/ - -#include "script_component.hpp" - -if(call FUNC(canShow)) then { - call FUNC(doShow); -};