Code cleanup of Safemode module

This commit is contained in:
Michael Braun
2015-08-08 02:26:09 +02:00
parent a9ed1052dd
commit 42e7340b79
6 changed files with 93 additions and 40 deletions

View File

@ -2,7 +2,6 @@
ADDON = false; ADDON = false;
PREP(firstMode);
PREP(lockSafety); PREP(lockSafety);
PREP(playChangeFiremodeSound); PREP(playChangeFiremodeSound);
PREP(setSafeModeVisual); PREP(setSafeModeVisual);

View File

@ -1,9 +0,0 @@
// by commy2
#include "script_component.hpp"
PARAMS_1(_weapon);
private ["_mode"];
_mode = getArray (configFile >> "CfgWeapons" >> _weapon >> "modes") select 0;
[_mode, _weapon] select (_mode == "this")

View File

@ -1,12 +1,29 @@
// by commy2 /*
* Author: commy2
* Put weapon on safety, or take it off safety if safety is already put on.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
* 2: Muzzle <STRING>
*
* Return Value:
* None
*
* Example:
* [ACE_player, currentWeapon ACE_player, currentMuzzle ACE_player] call ace_safemode_fnc_lockSafety
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_unit,_weapon,_muzzle);
// don't immediately switch back // don't immediately switch back
if (inputAction "nextWeapon" > 0) exitWith {}; if (inputAction "nextWeapon" > 0) exitWith {};
private ["_safedWeapons"]; private ["_safedWeapons", "_condition", "_statement", "_id", "_picture"];
params ["_unit", "_weapon", "_muzzle"];
_safedWeapons = _unit getVariable [QGVAR(safedWeapons), []]; _safedWeapons = _unit getVariable [QGVAR(safedWeapons), []];
if (_weapon in _safedWeapons) exitWith { if (_weapon in _safedWeapons) exitWith {
@ -18,15 +35,14 @@ _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 {
private ["_condition", "_statement", "_id"];
_condition = { _condition = {
params ["", "_caller"];
if ( if (
[_this select 1] call EFUNC(common,canUseWeapon) [_caller] call EFUNC(common,canUseWeapon)
&& { && {
if (currentMuzzle (_this select 1) in ((_this select 1) getVariable [QGVAR(safedWeapons), []])) then { if (currentMuzzle _caller in (_caller getVariable [QGVAR(safedWeapons), []])) then {
if (inputAction "nextWeapon" > 0) exitWith { if (inputAction "nextWeapon" > 0) exitWith {
[_this select 1, currentWeapon (_this select 1), currentMuzzle (_this select 1)] call FUNC(unlockSafety); [_this select 1, currentWeapon _caller, currentMuzzle _caller] call FUNC(unlockSafety);
false false
}; };
true true
@ -44,7 +60,8 @@ if (_unit getVariable [QGVAR(actionID), -1] == -1) then {
}; };
_statement = { _statement = {
[_this select 1, currentWeapon (_this select 1), currentMuzzle (_this select 1)] call FUNC(unlockSafety); 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, format ["<t color=""#FFFF00"" >%1</t>", localize LSTRING(TakeOffSafety)], "DefaultAction", _condition, {}, {true}, _statement, 10] call EFUNC(common,addActionMenuEventHandler);
@ -54,12 +71,11 @@ if (_unit getVariable [QGVAR(actionID), -1] == -1) then {
}; };
if ((typeName _muzzle) == (typeName "")) then { if ((typeName _muzzle) == (typeName "")) then {
_unit selectWeapon _muzzle;//_weapon _unit selectWeapon _muzzle; //_weapon
}; };
// play fire mode selector sound // play fire mode selector sound
[_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound); [_unit, _weapon, _muzzle] call FUNC(playChangeFiremodeSound);
private "_picture";
_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

@ -1,9 +1,25 @@
// by commy2 /*
* Author: commy2
* Play weapon firemode change sound.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
*
* Return Value:
* None
*
* Example:
* [ACE_player, currentWeapon ACE_player] call ace_safemode_fnc_playChangeFiremodeSound
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_2(_unit,_weapon); private ["_sound", "_position", "_soundCount"];
params ["_unit", "_weapon"];
private ["_sound"];
_sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound"); _sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound");
if (count _sound == 0) exitWith { if (count _sound == 0) exitWith {
@ -16,12 +32,13 @@ if ({(toLower (_sound select 0) find _x == (count toArray (_sound select 0) - co
}; };
// add default volume, pitch and distance // add default volume, pitch and distance
if (count _sound < 2) then {_sound pushBack 1}; _soundCount = count _sound;
if (count _sound < 3) then {_sound pushBack 1}; if (_soundCount < 2) then {_sound pushBack 1};
if (count _sound < 4) then {_sound pushBack 0}; if (_soundCount < 3) then {_sound pushBack 1};
if (_soundCount < 4) then {_sound pushBack 0};
private "_position";
_position = _unit modelToWorldVisual (_unit selectionPosition "RightHand"); _position = _unit modelToWorldVisual (_unit selectionPosition "RightHand");
_position set [2, (_position select 2) + ((getPosASLW _unit select 2) - (getPosATL _unit select 2) max 0)]; _position set [2, (_position select 2) + ((getPosASLW _unit select 2) - (getPosATL _unit select 2) max 0)];
playSound3D [_sound select 0, objNull, false, _position, _sound select 1, _sound select 2, _sound select 3]; _sound params ["_filename", "_volume", "_soundPitch", "_distance"]
playSound3D [_filename, objNull, false, _position, _volume, _soundPitch, _distance];

View File

@ -1,17 +1,31 @@
// by commy2 /*
* Author: commy2
* Show firemode indicator, representing safety lock
*
* Arguments:
* 0: Show firemode <BOOL>
*
* Return Value:
*
*
* Example:
* [true] call ace_safemode_fnc_setSafeModeVisual
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_1(_show); private ["_control", "_config"];
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

@ -1,9 +1,26 @@
// by commy2 /*
* Author: commy2
* Take weapon of safety lock.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
* 2: Muzzle <STRING>
*
* Return Value:
* None
*
* Example:
* [ACE_player, currentWeapon ACE_player, currentMuzzle ACE_player] call ace_safemode_fnc_unlockSafety
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_3(_unit,_weapon,_muzzle); private ["_safedWeapons", "_id", "_picture"];
params ["_unit", "_weapon", "_muzzle"];
private ["_safedWeapons"];
_safedWeapons = _unit getVariable [QGVAR(safedWeapons), []]; _safedWeapons = _unit getVariable [QGVAR(safedWeapons), []];
if (_weapon in _safedWeapons) then { if (_weapon in _safedWeapons) then {
@ -12,7 +29,6 @@ if (_weapon in _safedWeapons) then {
_unit setVariable [QGVAR(safedWeapons), _safedWeapons]; _unit setVariable [QGVAR(safedWeapons), _safedWeapons];
if (count _safedWeapons == 0) then { if (count _safedWeapons == 0) then {
private "_id";
_id = _unit getVariable [QGVAR(actionID), -1]; _id = _unit getVariable [QGVAR(actionID), -1];
//[_unit, "DefaultAction", _id] call EFUNC(common,removeActionMenuEventHandler); //[_unit, "DefaultAction", _id] call EFUNC(common,removeActionMenuEventHandler);
@ -36,7 +52,8 @@ if (inputAction "nextWeapon" > 0) then {
if (_x == "this") then { if (_x == "this") then {
_modes pushBack _weapon; _modes pushBack _weapon;
}; };
} forEach getArray (configfile >> "CfgWeapons" >> _weapon >> "modes"); nil
} count getArray (configfile >> "CfgWeapons" >> _weapon >> "modes");
// select last mode // select last mode
_mode = _modes select (count _modes - 1); _mode = _modes select (count _modes - 1);
@ -57,6 +74,5 @@ if (inputAction "nextWeapon" > 0) then {
// player hud // player hud
[true] call FUNC(setSafeModeVisual); [true] call FUNC(setSafeModeVisual);
private "_picture";
_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);