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 ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit) );
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
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);
//@todo addEventHandler infoDisplayChanged with select 1 == "Soldier"
// Add keybinds
// add keybinds
["ACE3 Weapons", QGVAR(safeMode), localize LSTRING(SafeMode),
{
// Conditions: canInteract
@ -21,4 +20,4 @@ if (!hasInterface) exitWith {};
true
},
{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
if (inputAction "nextWeapon" > 0) exitWith {};
private ["_safedWeapons", "_condition", "_statement", "_id", "_picture"];
params ["_unit", "_weapon", "_muzzle"];
private ["_safedWeapons", "_picture"];
_safedWeapons = _unit getVariable [QGVAR(safedWeapons), []];
if (_weapon in _safedWeapons) exitWith {
@ -35,47 +35,39 @@ _safedWeapons pushBack _weapon;
_unit setVariable [QGVAR(safedWeapons), _safedWeapons];
if (_unit getVariable [QGVAR(actionID), -1] == -1) then {
_condition = {
params ["", "_caller"];
if (
[_caller] call EFUNC(common,canUseWeapon)
&& {
if (currentMuzzle _caller in (_caller getVariable [QGVAR(safedWeapons), []])) then {
if (inputAction "nextWeapon" > 0) exitWith {
[_this select 1, currentWeapon _caller, currentMuzzle _caller] call FUNC(unlockSafety);
false
};
true
} else {false}
}
) then {
// player hud
[false] call FUNC(setSafeModeVisual);
true
} else {
// player hud
[true] call FUNC(setSafeModeVisual);
false
}
};
_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];
_unit setVariable [QGVAR(actionID), [
_unit, "DefaultAction", {
if (
[_this select 1] call EFUNC(common,canUseWeapon)
&& {
if (currentMuzzle (_this select 1) in ((_this select 1) getVariable [QGVAR(safedWeapons), []])) then {
if (inputAction "nextWeapon" > 0) exitWith {
[_this select 1, currentWeapon (_this select 1), currentMuzzle (_this select 1)] call FUNC(unlockSafety);
false
};
true
} else {false}
}
) then {
// player hud
[false] call FUNC(setSafeModeVisual);
true
} else {
// player hud
[true] call FUNC(setSafeModeVisual);
false
};
}, {}
] call EFUNC(common,addActionEventHandler)];
};
if ((typeName _muzzle) == (typeName "")) then {
_unit selectWeapon _muzzle; //_weapon
if (typeName _muzzle == "STRING") then {
_unit selectWeapon _muzzle;
};
// play fire mode selector sound
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
// show info box
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
[localize LSTRING(PutOnSafety), _picture] call EFUNC(common,displayTextPicture);

View File

@ -16,23 +16,28 @@
*/
#include "script_component.hpp"
private ["_sound", "_position"];
params ["_unit", "_weapon"];
private ["_sound", "_position"];
_sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound");
if (count _sound == 0) exitWith {
if (_sound isEqualTo []) exitWith {
playSound "ACE_Sound_Click";
};
// add file extension
if ({(toLower (_sound select 0) find _x == (count toArray (_sound select 0) - count toArray _x) - 1)} count [".wav", ".ogg", ".wss"] == 0) then {
_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)];
// get position where to play the sound (position of the weapon)
_position = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "RightHand"));
_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];

View File

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

View File

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