Skip to content

Commit

Permalink
CSW - Rework settings (#9901)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnb432 authored Sep 11, 2024
1 parent 0f756dc commit c5935dc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
24 changes: 19 additions & 5 deletions addons/csw/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,32 @@ GVAR(vehicleMagCache) = createHashMap;
// needs a small delay for network syncing, or we end up with duplicate mags with ammo handling
[LINKFUNC(initVehicle), _this, 1] call CBA_fnc_waitAndExecute;
}, true, [], true] call CBA_fnc_addClassEventHandler;

GVAR(quickmountEnabled) = (
missionNamespace getVariable [QEGVAR(quickmount,enabled), false] &&
{(missionNamespace getVariable [QEGVAR(quickmount,enableMenu), -1]) in [1,3]}
);
}] call CBA_fnc_addEventHandler;

// Also triggered at mission start
["CBA_SettingChanged", {
GVAR(quickmountEnabled) = (
missionNamespace getVariable [QEGVAR(quickmount,enabled), false] &&
{(missionNamespace getVariable [QEGVAR(quickmount,enableMenu), -1]) in [1,3]}
);

// Do not allow no ammo handling when advanced assembly is enabled
// Reason: When using advanced assembly, the amount of ammo is not stored anywhere, so when you reassemble a static, it will spawn full ammo
if (GVAR(defaultAssemblyMode) && GVAR(ammoHandling) == 0) then {
if (isServer) then {
[QGVAR(ammoHandling), 2, 2, "server"] call CBA_settings_fnc_set;
};

// Notify everyone about change
[QEGVAR(common,displayTextStructured), [composeText [
lineBreak,
parseText format [
"<t align='center'>%1</t>", format ["%1 requires %2 to be set higher than 0.", QGVAR(defaultAssemblyMode), QGVAR(ammoHandling)]
],
lineBreak,
parseText format ["<t align='center'>%1</t>", "No mission restart is required."]
], 4]] call CBA_fnc_localEvent;
};
}] call CBA_fnc_addEventHandler;

// Event handlers:
Expand Down
2 changes: 2 additions & 0 deletions addons/csw/functions/fnc_ai_handleFired.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Public: No
*/

if (GVAR(ammoHandling) != 2) exitWith {};

params ["_vehicle", "_weapon", "", "", "", "_magazine", "", "_gunner"];
TRACE_4("firedEH:",_vehicle,_weapon,_magazine,_gunner);

Expand Down
2 changes: 2 additions & 0 deletions addons/csw/functions/fnc_ai_handleGetIn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Public: No
*/

if (GVAR(ammoHandling) != 2) exitWith {};

params ["_vehicle", "", "_gunner"];
TRACE_2("getInEH:",_vehicle,_gunner);

Expand Down
12 changes: 10 additions & 2 deletions addons/csw/functions/fnc_initVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,17 @@ if (hasInterface && {!(_typeOf in GVAR(initializedStaticTypes))}) then {
};

if (["ace_reload"] call EFUNC(common,isModLoaded)) then {
// move reload's check ammo action to the ammo handling point (remove and re-add)
[_typeOf, 0, ["ACE_MainActions", QEGVAR(reload,CheckAmmo)]] call EFUNC(interact_menu,removeActionFromClass);
private _checkAmmoAction = [QGVAR(checkAmmo), LELSTRING(reload,checkAmmo), "", EFUNC(reload,checkAmmo), EFUNC(reload,canCheckAmmo)] call EFUNC(interact_menu,createAction);

// Replace existing check ammo interaction with one that takes into account if the magazine actions are available
private _checkAmmoAction = [QEGVAR(reload,CheckAmmo), LELSTRING(reload,checkAmmo), "", EFUNC(reload,checkAmmo), {
if !((GVAR(ammoHandling) == 0) && {!([false, true, true, GVAR(defaultAssemblyMode)] select (_target getVariable [QGVAR(assemblyMode), 3]))}) exitWith { false };
_this call EFUNC(reload,canCheckAmmo)
}] call ace_interact_menu_fnc_createAction;
[_typeOf, 0, ["ACE_MainActions"], _checkAmmoAction] call EFUNC(interact_menu,addActionToClass);

// Add another check ammo action to the ammo handling point
_checkAmmoAction = [QGVAR(checkAmmo), LELSTRING(reload,checkAmmo), "", EFUNC(reload,checkAmmo), EFUNC(reload,canCheckAmmo)] call EFUNC(interact_menu,createAction);
[_typeOf, 0, _ammoActionPath, _checkAmmoAction] call EFUNC(interact_menu,addActionToClass);
};
};
43 changes: 20 additions & 23 deletions addons/csw/initSettings.inc.sqf
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
private _categoryArray = [format ["ACE %1", localize LSTRING(DisplayName)]];
private _categoryArray = [format ["ACE %1", LLSTRING(DisplayName)]];

[
QGVAR(defaultAssemblyMode), "CHECKBOX",
QGVAR(defaultAssemblyMode),
"CHECKBOX",
[LSTRING(defaultAssemblyMode_displayName), LSTRING(defaultAssemblyMode_description)],
_categoryArray,
false, // default value
true, // isGlobal
{[QGVAR(defaultAssemblyMode), _this] call EFUNC(common,cbaSettings_settingChanged)},
true // Needs mission restart
1 // isGlobal
] call CBA_fnc_addSetting;

[
QGVAR(handleExtraMagazines), "CHECKBOX",
QGVAR(handleExtraMagazines),
"CHECKBOX",
[LSTRING(handleExtraMagazines_displayName), LSTRING(handleExtraMagazines_description)],
_categoryArray,
true, // default value
true, // isGlobal
{[QGVAR(handleExtraMagazines), _this] call EFUNC(common,cbaSettings_settingChanged)},
true // Needs mission restart
1 // isGlobal
] call CBA_fnc_addSetting;

[
QGVAR(handleExtraMagazinesType), "LIST",
QGVAR(handleExtraMagazinesType),
"LIST",
[LSTRING(handleExtraMagazinesType_displayName), LSTRING(handleExtraMagazinesType_description)],
_categoryArray,
[[0, 1], [LSTRING(handleExtraMagazinesType_weaponHolder), LSTRING(handleExtraMagazinesType_ammoBox)], 0],
true, // isGlobal
{[QGVAR(handleExtraMagazinesType), _this] call EFUNC(common,cbaSettings_settingChanged)},
true // Needs mission restart
1 // isGlobal
] call CBA_fnc_addSetting;

[
QGVAR(ammoHandling), "LIST",
QGVAR(ammoHandling),
"LIST",
[LSTRING(ammoHandling_displayName), LSTRING(ammoHandling_description)],
_categoryArray,
[[0, 1, 2], [LELSTRING(common,Disabled), LELSTRING(common,playerOnly), LELSTRING(common,playersAndAI)], 2], // [_values, _valueTitles, _defaultIndex]
true, // isGlobal
{[QGVAR(ammoHandling), _this] call EFUNC(common,cbaSettings_settingChanged)},
true // Needs mission restart
1 // isGlobal
] call CBA_fnc_addSetting;

[
QGVAR(progressBarTimeCoefficent), "SLIDER",
QGVAR(progressBarTimeCoefficent),
"SLIDER",
[LSTRING(progressBarTimeCoefficent_displayName), LSTRING(progressBarTimeCoefficent_description)],
_categoryArray,
[0,2,1,2], // [min, max, default value, trailing decimals (-1 for whole numbers only)]
true // isGlobal
[0, 2, 1, 2], // [min, max, default value, trailing decimals (-1 for whole numbers only)]
1 // isGlobal
] call CBA_fnc_addSetting;

[
QGVAR(dragAfterDeploy), "CHECKBOX",
QGVAR(dragAfterDeploy),
"CHECKBOX",
[LSTRING(dragAfterDeploy_displayName), LSTRING(dragAfterDeploy_description)],
_categoryArray,
false // default value
_categoryArray
] call CBA_fnc_addSetting;

0 comments on commit c5935dc

Please sign in to comment.