Code Cleanup SafetyMode

This commit is contained in:
commy2 2015-09-27 08:28:55 +02:00
parent f77242fce3
commit 50046decf3
6 changed files with 59 additions and 67 deletions

View File

@ -1,12 +1,12 @@
class Extended_PreInit_EventHandlers { class Extended_PreInit_EventHandlers {
class ADDON { class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit) ); init = QUOTE(call COMPILE_FILE(XEH_preInit));
}; };
}; };
class Extended_PostInit_EventHandlers { class Extended_PostInit_EventHandlers {
class ADDON { class ADDON {
clientInit = QUOTE( call COMPILE_FILE(XEH_postInit) ); init = QUOTE(call COMPILE_FILE(XEH_postInit));
}; };
}; };

View File

@ -7,8 +7,7 @@ if (!hasInterface) exitWith {};
//["Soldier", {_player = ACE_player; if (currentWeapon _player in (_player getVariable [QGVAR(safedWeapons), []])) then {[false] call FUNC(setSafeModeVisual)}] call EFUNC(common,addInfoDisplayEventHandler); //["Soldier", {_player = ACE_player; if (currentWeapon _player in (_player getVariable [QGVAR(safedWeapons), []])) then {[false] call FUNC(setSafeModeVisual)}] call EFUNC(common,addInfoDisplayEventHandler);
//@todo addEventHandler infoDisplayChanged with select 1 == "Soldier" //@todo addEventHandler infoDisplayChanged with select 1 == "Soldier"
// add keybinds
// Add keybinds
["ACE3 Weapons", QGVAR(safeMode), localize LSTRING(SafeMode), ["ACE3 Weapons", QGVAR(safeMode), localize LSTRING(SafeMode),
{ {
// Conditions: canInteract // Conditions: canInteract
@ -21,4 +20,4 @@ if (!hasInterface) exitWith {};
true true
}, },
{false}, {false},
[41, [false, true, false]], false] call cba_fnc_addKeybind; [41, [false, true, false]], false] call CBA_fnc_addKeybind;

View File

@ -20,10 +20,10 @@
// don't immediately switch back // don't immediately switch back
if (inputAction "nextWeapon" > 0) exitWith {}; if (inputAction "nextWeapon" > 0) exitWith {};
private ["_safedWeapons", "_condition", "_statement", "_id", "_picture"];
params ["_unit", "_weapon", "_muzzle"]; params ["_unit", "_weapon", "_muzzle"];
private ["_safedWeapons", "_picture"];
_safedWeapons = _unit getVariable [QGVAR(safedWeapons), []]; _safedWeapons = _unit getVariable [QGVAR(safedWeapons), []];
if (_weapon in _safedWeapons) exitWith { if (_weapon in _safedWeapons) exitWith {
@ -35,47 +35,39 @@ _safedWeapons pushBack _weapon;
_unit setVariable [QGVAR(safedWeapons), _safedWeapons]; _unit setVariable [QGVAR(safedWeapons), _safedWeapons];
if (_unit getVariable [QGVAR(actionID), -1] == -1) then { if (_unit getVariable [QGVAR(actionID), -1] == -1) then {
_condition = { _unit setVariable [QGVAR(actionID), [
params ["", "_caller"]; _unit, "DefaultAction", {
if ( if (
[_caller] call EFUNC(common,canUseWeapon) [_this select 1] call EFUNC(common,canUseWeapon)
&& { && {
if (currentMuzzle _caller in (_caller getVariable [QGVAR(safedWeapons), []])) then { if (currentMuzzle (_this select 1) in ((_this select 1) getVariable [QGVAR(safedWeapons), []])) then {
if (inputAction "nextWeapon" > 0) exitWith { if (inputAction "nextWeapon" > 0) exitWith {
[_this select 1, currentWeapon _caller, currentMuzzle _caller] call FUNC(unlockSafety); [_this select 1, currentWeapon (_this select 1), currentMuzzle (_this select 1)] call FUNC(unlockSafety);
false false
}; };
true true
} else {false} } else {false}
} }
) then { ) then {
// player hud // player hud
[false] call FUNC(setSafeModeVisual); [false] call FUNC(setSafeModeVisual);
true true
} else { } else {
// player hud // player hud
[true] call FUNC(setSafeModeVisual); [true] call FUNC(setSafeModeVisual);
false false
} };
}; }, {}
] call EFUNC(common,addActionEventHandler)];
_statement = {
params ["", "_caller"];
[_caller, currentWeapon _caller, currentMuzzle _caller] call FUNC(unlockSafety);
};
//_id = [_unit, format ["<t color=""#FFFF00"" >%1</t>", localize LSTRING(TakeOffSafety)], "DefaultAction", _condition, {}, {true}, _statement, 10] call EFUNC(common,addActionMenuEventHandler);
_id = [_unit, "DefaultAction", _condition, {}] call EFUNC(common,addActionEventHandler);
_unit setVariable [QGVAR(actionID), _id];
}; };
if ((typeName _muzzle) == (typeName "")) then { if (typeName _muzzle == "STRING") then {
_unit selectWeapon _muzzle; //_weapon _unit selectWeapon _muzzle;
}; };
// play fire mode selector sound // play fire mode selector sound
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound); [_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
// show info box
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture"); _picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
[localize LSTRING(PutOnSafety), _picture] call EFUNC(common,displayTextPicture); [localize LSTRING(PutOnSafety), _picture] call EFUNC(common,displayTextPicture);

View File

@ -16,23 +16,28 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_sound", "_position"];
params ["_unit", "_weapon"]; params ["_unit", "_weapon"];
private ["_sound", "_position"];
_sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound"); _sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound");
if (count _sound == 0) exitWith { if (_sound isEqualTo []) exitWith {
playSound "ACE_Sound_Click"; playSound "ACE_Sound_Click";
}; };
// add file extension // get position where to play the sound (position of the weapon)
if ({(toLower (_sound select 0) find _x == (count toArray (_sound select 0) - count toArray _x) - 1)} count [".wav", ".ogg", ".wss"] == 0) then { _position = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "RightHand"));
_sound set [0, (_sound select 0) + ".wss"];
};
_position = _unit modelToWorldVisual (_unit selectionPosition "RightHand");
_position set [2, (_position select 2) + ((getPosASLW _unit select 2) - (getPosATL _unit select 2) max 0)];
_sound params ["_filename", ["_volume", 1], ["_soundPitch", 1], ["_distance", 0]]; _sound params ["_filename", ["_volume", 1], ["_soundPitch", 1], ["_distance", 0]];
if (_filename == "") exitWith {
playSound "ACE_Sound_Click";
};
// add file extension .wss as default
if !(toLower (_filename select [count _filename - 4]) in [".wav", ".ogg", ".wss"]) then {
_filename = format ["%1.wss", _filename];
};
playSound3D [_filename, objNull, false, _position, _volume, _soundPitch, _distance]; playSound3D [_filename, objNull, false, _position, _volume, _soundPitch, _distance];

View File

@ -15,17 +15,17 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_control", "_config"];
params ["_show"]; params ["_show"];
disableSerialization; disableSerialization;
private "_control";
_control = (uiNamespace getVariable ["ACE_dlgSoldier", displayNull]) displayCtrl 187; _control = (uiNamespace getVariable ["ACE_dlgSoldier", displayNull]) displayCtrl 187;
if (isNull _control) exitWith {}; if (isNull _control) exitWith {};
if (_show) then { if (_show) then {
private "_config";
_config = configFile >> "RscInGameUI" >> "RscUnitInfoSoldier" >> "WeaponInfoControlsGroupLeft" >> "controls" >> "CA_ModeTexture"; _config = configFile >> "RscInGameUI" >> "RscUnitInfoSoldier" >> "WeaponInfoControlsGroupLeft" >> "controls" >> "CA_ModeTexture";
_control ctrlSetPosition [getNumber (_config >> "x"), getNumber (_config >> "y"), getNumber (_config >> "w"), getNumber (_config >> "h")]; _control ctrlSetPosition [getNumber (_config >> "x"), getNumber (_config >> "y"), getNumber (_config >> "w"), getNumber (_config >> "h")];

View File

@ -17,24 +17,19 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_safedWeapons", "_id", "_picture"];
params ["_unit", "_weapon", "_muzzle"]; params ["_unit", "_weapon", "_muzzle"];
private ["_safedWeapons", "_picture"];
_safedWeapons = _unit getVariable [QGVAR(safedWeapons), []]; _safedWeapons = _unit getVariable [QGVAR(safedWeapons), []];
_safedWeapons deleteAt (_safedWeapons find _weapon);
if (_weapon in _safedWeapons) then { _unit setVariable [QGVAR(safedWeapons), _safedWeapons];
_safedWeapons = _safedWeapons - [_weapon];
_unit setVariable [QGVAR(safedWeapons), _safedWeapons]; // remove action if all weapons have put their safety on
if (_safedWeapons isEqualTo []) then {
if (count _safedWeapons == 0) then { [_unit, "DefaultAction", _unit getVariable [QGVAR(actionID), -1]] call EFUNC(common,removeActionEventHandler);
_id = _unit getVariable [QGVAR(actionID), -1]; _unit setVariable [QGVAR(actionID), -1];
//[_unit, "DefaultAction", _id] call EFUNC(common,removeActionMenuEventHandler);
[_unit, "DefaultAction", _id] call EFUNC(common,removeActionEventHandler);
_unit setVariable [QGVAR(actionID), -1];
};
}; };
_unit selectWeapon _muzzle; _unit selectWeapon _muzzle;
@ -74,5 +69,6 @@ if (inputAction "nextWeapon" > 0) then {
// player hud // player hud
[true] call FUNC(setSafeModeVisual); [true] call FUNC(setSafeModeVisual);
// show info box
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture"); _picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
[localize LSTRING(TookOffSafety), _picture] call EFUNC(common,displayTextPicture); [localize LSTRING(TookOffSafety), _picture] call EFUNC(common,displayTextPicture);