Merge pull request #505 from acemod/muteunit

Muteunit framework, fix #473
This commit is contained in:
commy2 2015-04-13 19:18:45 +02:00
commit fa64225e55
10 changed files with 84 additions and 30 deletions

View File

@ -26,6 +26,9 @@ class Extended_InitPost_EventHandlers {
class GVAR(forceWalk) {
init = QUOTE(if (local (_this select 0)) then {_this call FUNC(applyForceWalkStatus);};);
};
class GVAR(muteUnit) {
init = QUOTE(_this call FUNC(muteUnitHandleInitPost));
};
};
};
@ -41,4 +44,9 @@ class Extended_Respawn_EventHandlers {
respawn = QUOTE(_this call FUNC(resetAllDefaults));
};
};
class CAManBase {
class GVAR(muteUnit) {
respawn = QUOTE(_this call FUNC(muteUnitHandleRespawn));
};
};
};

View File

@ -35,6 +35,7 @@ if (hasInterface) then {
["setDir", {(_this select 0) setDir (_this select 1)}] call FUNC(addEventhandler);
["setFuel", {(_this select 0) setFuel (_this select 1)}] call FUNC(addEventhandler);
["setSpeaker", {(_this select 0) setSpeaker (_this select 1)}] call FUNC(addEventhandler);
// hack to get PFH to work in briefing
[QGVAR(onBriefingPFH), "onEachFrame", {

View File

@ -124,6 +124,8 @@ PREP(moduleCheckPBOs);
PREP(moduleLSDVehicles);
PREP(moveToTempGroup);
PREP(muteUnit);
PREP(muteUnitHandleInitPost);
PREP(muteUnitHandleRespawn);
PREP(numberToDigits);
PREP(numberToDigitsString);
PREP(numberToString);

View File

@ -5,21 +5,34 @@
*
* Argument:
* 0: Unit (Object)
* 1: Reason to mute the unit (String)
*
* Return value:
* Nothing
*/
#include "script_component.hpp"
private ["_unit", "_speaker"];
private ["_unit", "_reason"];
_unit = _this select 0;
_reason = _this select 1;
if (isNull _unit) exitWith {};
// add reason to mute to the unit
private "_muteUnitReasons";
_muteUnitReasons = _unit getVariable [QGVAR(muteUnitReasons), []];
if !(_reason in _muteUnitReasons) then {
_muteUnitReasons pushBack _reason;
_unit setVariable [QGVAR(muteUnitReasons), _muteUnitReasons, true];
};
private "_speaker";
_speaker = speaker _unit;
if (_speaker == "ACE_NoVoice") exitWith {};
[0, "{(_this select 1) setSpeaker 'ACE_NoVoice'}", _unit, "ACE_Speaker"] call FUNC(execPersistentFnc);
["setSpeaker", [_unit, "ACE_NoVoice"]] call FUNC(globalEvent);
_unit setVariable ["ACE_OriginalSpeaker", _speaker, true];

View File

@ -0,0 +1,11 @@
// by commy2
#include "script_component.hpp"
private "_unit";
_unit = _this select 0;
// setSpeaker gets overwritten after init on remote units; if unit is muted, setSpeaker again
if (count (_unit getVariable [QGVAR(muteUnitReasons), []]) > 0) then {
["setSpeaker", [_unit, "ACE_NoVoice"]] call FUNC(localEvent);
};

View File

@ -0,0 +1,12 @@
// by commy2
#include "script_component.hpp"
private "_unit";
_unit = _this select 0;
// setVariable is broken on JIP after respawn
_unit setVariable [QGVAR(muteUnitReasons), _unit getVariable [QGVAR(muteUnitReasons), []], true];
// fix mp issues with respawning and the speaker
["setSpeaker", [_unit, speaker _unit]] call FUNC(globalEvent);

View File

@ -23,6 +23,3 @@ _respawnVariables pushBack "ACE_PersistentFunctions";
{
_unit setVariable [_x, _unit getVariable _x, true];
} forEach _respawnVariables;
// fix speaker after respawn
[_unit, format ["{_this setSpeaker '%1'}", speaker _unit], 2] call FUNC(execRemoteFnc);

View File

@ -1,23 +1,39 @@
/*
* Author: commy2
*
* Unmutes the unit.
* Unmutes the unit. Only unmutes if the last reason was removed.
*
* Argument:
* 0: Unit (Object)
* 1: Reason to unmute the unit. (String)
*
* Return value:
* Nothing
*/
#include "script_component.hpp"
private ["_unit", "_speaker"];
private ["_unit", "_reason"];
_unit = _this select 0;
_reason = _this select 1;
if (isNull _unit) exitWith {};
// remove reason to mute to the unit
private "_muteUnitReasons";
_muteUnitReasons = _unit getVariable [QGVAR(muteUnitReasons), []];
if (_reason in _muteUnitReasons) then {
_muteUnitReasons deleteAt (_muteUnitReasons find _reason);
_unit setVariable [QGVAR(muteUnitReasons), _muteUnitReasons, true];
};
// don't unmute if there is another mute reason!
if (count _muteUnitReasons > 0) exitWith {};
private "_speaker";
_speaker = _unit getVariable ["ACE_OriginalSpeaker", ""];
if (_speaker == "") exitWith {};
[0, format ["{(_this select 1) setSpeaker '%1'}", _speaker], _unit, "ACE_Speaker"] call FUNC(execPersistentFnc);
["setSpeaker", _unit, [_unit, _speaker]] call FUNC(targetEvent);

View File

@ -1,31 +1,29 @@
// by commy2
#include "script_component.hpp"
/*
_setupPlayer = {
if (!isNull ACE_player) then {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
if (!isNull ACE_player) then {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
[ACE_player] call EFUNC(common,muteUnit);
ACE_player setVariable [QGVAR(isMuted), true, true];
};
[ACE_player, "isPlayer"] call EFUNC(common,muteUnit);
};
};
[_setupPlayer, 0, []] call CBA_fnc_addPerFrameHandler;
*/
if (!hasInterface) exitWith {};
// Mutes/unmutes units when the player changes
["playerChanged", {
EXPLODE_2_PVT(_this,_newPlayer,_oldPlayer);
EXPLODE_2_PVT(_this,_newPlayer,_oldPlayer);
// On player change mute the new player
[_newPlayer] call EFUNC(common,muteUnit);
_newPlayer setVariable [QGVAR(isMuted), true, true];
// Unmute the old player
//@todo: sort interaction with medical system
if (!(_oldPlayer getVariable ["ACE_isUnconscious", false]) && {alive _oldPlayer}) then {
[_oldPlayer] call EFUNC(common,unMuteUnit);
};
_oldPlayer setVariable [QGVAR(isMuted), false, true];
// On player change mute the new player
[_newPlayer, "isPlayer"] call EFUNC(common,muteUnit);
// Unmute the old player
if (alive _oldPlayer) then {
[_oldPlayer, "isPlayer"] call EFUNC(common,unmuteUnit);
};
}] call EFUNC(common,addEventhandler);

View File

@ -1,10 +1,6 @@
// by commy2
#include "script_component.hpp"
addMissionEventHandler ["HandleDisconnect", {
if !((_this select 0) getVariable ["ACE_isUnconscious", false]) then { //@ToDo: ai waking up will be silent?
_this call EFUNC(common,unMuteUnit);
};
(_this select 0) setVariable [QGVAR(isMuted), false, true];
[_this select 0, "isPlayer"] call EFUNC(common,unmuteUnit);
}];