ACE3/addons/arsenal/functions/fnc_buttonLoadoutsSave.sqf
Dedmen Miller e2ac18a05d [WIP] Fix script errors reporting wrong line numbers (#6407)
* advanced_ballistics

* advanced_fatigue

* advanced_throwing

* ai

* aircraft

* arsenal

* atragmx

* attach

* backpacks

* ballistics

* captives

* cargo

* chemlights

* common

* concertina_wire

* cookoff

* dagr

* disarming

* disposable

* dogtags

* dragging

* explosives

* fastroping

* fcs

* finger

* frag

* gestures

* gforces

* goggles

* grenades

* gunbag

* hearing

* hitreactions

* huntir

* interact_menu

* interaction

* inventory

* kestrel4500

* laser

* laserpointer

* logistics_uavbattery

* logistics_wirecutter

* magazinerepack

* map

* map_gestures

* maptools

* markers

* medical

* medical_ai

* medical_blood

* medical_menu

* microdagr

* minedetector

* missileguidance

* missionmodules

* mk6mortar

* modules

* movement

* nametags

* nightvision

* nlaw

* optics

* optionsmenu

* overheating

* overpressure

* parachute

* pylons

* quickmount

* rangecard

* rearm

* recoil

* refuel

* reload

* reloadlaunchers

* repair

* respawn

* safemode

* sandbag

* scopes

* slideshow

* spectator

* spottingscope

* switchunits

* tacticalladder

* tagging

* trenches

* tripod

* ui

* vector

* vehiclelock

* vehicles

* viewdistance

* weaponselect

* weather

* winddeflection

* yardage450

* zeus

* arsenal defines.hpp

* optionals

* DEBUG_MODE_FULL 1

* DEBUG_MODE_FULL 2

* Manual fixes

* Add SQF Validator check for #include after block comment

* explosives fnc_openTimerUI

* fix uniqueItems
2018-09-17 14:19:29 -05:00

289 lines
12 KiB
Plaintext

#include "script_component.hpp"
#include "..\defines.hpp"
/*
* Author: Alganthe
* Save selected loadout.
*
* Arguments:
* 0: Arsenal display <DISPLAY>
* 1: Button control <CONTROL>
*
* Return Value:
* None
*
* Public: No
*/
params ["_display", "_control"];
if !(ctrlEnabled _control) exitWith {};
private _editBoxCtrl = _display displayCtrl IDC_textEditBox;
private _editBoxContent = ctrlText _editBoxCtrl;
if (_editBoxContent == "") exitWith {
[(findDisplay IDD_ace_arsenal), localize LSTRING(saveEmptyNameBox)] call FUNC(message);
};
private _data = [+(profileNamespace getVariable [QGVAR(saved_loadouts),[]]), +(GVAR(defaultLoadoutsList))] select (GVAR(currentLoadoutsTab) == IDC_buttonDefaultLoadouts && {is3DEN});
private _contentPanelCtrl = _display displayCtrl IDC_contentPanel;
private _cursSelRow = lnbCurSelRow _contentPanelCtrl;
private _loadoutName = _contentPanelCtrl lnbText [_cursSelRow, 1];
private _curSelLoadout = (_contentPanelCtrl getVariable (_loadoutName + str GVAR(currentLoadoutsTab))) select 0;
private _loadout = getUnitLoadout GVAR(center);
private _loadoutIndex = (+(_data)) findIf {(_x select 0) == _editBoxContent};
private _sharedLoadoutsVars = GVAR(sharedLoadoutsNamespace) getVariable QGVAR(sharedLoadoutsVars);
// Make sure the loadout isn't yours (public tab) or being shared (my loadouts tab)
private _similarSharedLoadout = (profileName + _editBoxContent) in _sharedLoadoutsVars;
if ((_contentPanelCtrl lnbText [_cursSelRow, 0]) == profileName) exitWith {
[(findDisplay IDD_ace_arsenal), localize LSTRING(saveAuthorError)] call FUNC(message);
};
if (_similarSharedLoadout) exitWith {
[(findDisplay IDD_ace_arsenal), localize LSTRING(saveSharedError)] call FUNC(message);
};
switch (GVAR(currentLoadoutsTab)) do {
case IDC_buttonMyLoadouts:{
for "_dataIndex" from 0 to 10 do {
switch (_dataIndex) do {
case 0;
case 1;
case 2;
case 8: {
if (count (_loadout select _dataIndex) > 0) then {
private _weapon = (_loadout select _dataIndex) select 0;
if (_weapon != "") then {
private _baseWeapon = _weapon call BIS_fnc_baseWeapon;
if (_weapon != _baseWeapon) then {
(_loadout select _dataIndex) set [0, _baseWeapon];
};
};
};
};
case 3;
case 4;
case 5: {
if (count (_loadout select _dataIndex) > 0) then {
private _containerContents = (_loadout select _dataIndex) select 1;
if (count _containerContents > 0) then {
{
if (count _x == 2) then {
if ((_x select 0) isEqualType "") then {
private _item = (_x select 0);
if (_item != "") then {
private _uniqueBaseCfgText = getText (configFile >> "CfgWeapons" >> _item >> "ace_arsenal_uniqueBase");
if (_uniqueBaseCfgText != "") then {
_x set [0, _uniqueBaseCfgText];
};
};
} else {
private _weapon = (_x select 0) select 0;
if (_weapon != "") then {
private _baseWeapon = _weapon call BIS_fnc_baseWeapon;
if (_weapon != _baseWeapon) then {
(_x select 0)set [0, _baseWeapon];
};
};
};
};
} foreach _containerContents;
};
};
};
case 9: {
for "_subIndex" from 0 to 4 do {
private _item = (_loadout select _dataIndex) select _subIndex;
if (_item != "") then {
private _uniqueBaseCfgText = getText (configFile >> "CfgWeapons" >> _item >> "ace_arsenal_uniqueBase");
if (_uniqueBaseCfgText != "") then {
(_loadout select _dataIndex) set [_subIndex, _uniqueBaseCfgText];
};
};
};
};
};
};
if (_loadoutIndex == -1) then {
_data pushBack [_editBoxContent, _loadout];
} else {
_data set [_loadoutIndex, [[_editBoxContent, _loadoutName] select (_loadoutName isEqualTo _editBoxContent), _loadout]];
};
// Delete "old" loadout row
for '_i' from 0 to (((lnbsize _contentPanelCtrl) select 0) - 1) do {
if ((_contentPanelCtrl lnbText [_i, 1]) == _editBoxContent) exitwith {_contentPanelCtrl lnbDeleteRow _i};
};
private _newRow = _contentPanelCtrl lnbAddRow ["",_editBoxContent];
ADD_LOADOUTS_LIST_PICTURES
_contentPanelCtrl setVariable [_editBoxContent + str GVAR(currentLoadoutsTab), [_loadout] call FUNC(verifyLoadout)];
_contentPanelCtrl lnbSort [1, false];
// Select newly saved loadout
for '_i' from 0 to (((lnbsize _contentPanelCtrl) select 0) - 1) do {
if ((_contentPanelCtrl lnbText [_i, 1]) == _editBoxContent) exitwith {_contentPanelCtrl lnbSetCurSelRow _i};
};
profileNamespace setVariable [QGVAR(saved_loadouts), _data];
};
case IDC_buttonDefaultLoadouts:{
if (is3DEN) then {
private _loadoutIndex = (+(_data)) findId {(_x select 0) == _editBoxContent};
for "_dataIndex" from 0 to 10 do {
switch (_dataIndex) do {
case 0;
case 1;
case 2;
case 8: {
if (count (_loadout select _dataIndex) > 0) then {
private _weapon = (_loadout select _dataIndex) select 0;
if (_weapon != "") then {
private _baseWeapon = _weapon call BIS_fnc_baseWeapon;
if (_weapon != _baseWeapon) then {
(_loadout select _dataIndex) set [0, _baseWeapon];
};
};
};
};
case 3;
case 4;
case 5: {
if (count (_loadout select _dataIndex) > 0) then {
private _containerContents = (_loadout select _dataIndex) select 1;
if (count _containerContents > 0) then {
{
if (count _x == 2) then {
if ((_x select 0) isEqualType "") then {
private _item = (_x select 0);
if (_item != "") then {
private _uniqueBaseCfgText = getText (configFile >> "CfgWeapons" >> _item >> "ace_arsenal_uniqueBase");
if (_uniqueBaseCfgText != "") then {
_x set [0, _uniqueBaseCfgText];
};
};
} else {
private _weapon = (_x select 0) select 0;
if (_weapon != "") then {
private _baseWeapon = _weapon call BIS_fnc_baseWeapon;
if (_weapon != _baseWeapon) then {
(_x select 0)set [0, _baseWeapon];
};
};
};
};
} foreach _containerContents;
};
};
};
case 9: {
for "_subIndex" from 0 to 4 do {
private _item = (_loadout select _dataIndex) select _subIndex;
if (_item != "") then {
private _uniqueBaseCfgText = getText (configFile >> "CfgWeapons" >> _item >> "ace_arsenal_uniqueBase");
if (_uniqueBaseCfgText != "") then {
(_loadout select _dataIndex) set [_subIndex, _uniqueBaseCfgText];
};
};
};
};
};
};
if (_loadoutIndex == -1) then {
GVAR(defaultLoadoutsList) pushBack [_editBoxContent, _loadout];
} else {
GVAR(defaultLoadoutsList) set [_loadoutIndex, [[_editBoxContent, _loadoutName] select (_loadoutName isEqualTo _editBoxContent), _loadout]];
};
for '_i' from 0 to (((lnbsize _contentPanelCtrl) select 0) - 1) do {
if ((_contentPanelCtrl lnbText [_i, 1]) == _editBoxContent) exitwith {_contentPanelCtrl lnbDeleteRow _i};
};
private _newRow = _contentPanelCtrl lnbAddRow ["",_editBoxContent];
ADD_LOADOUTS_LIST_PICTURES
_contentPanelCtrl setVariable [_editBoxContent + str GVAR(currentLoadoutsTab), [_loadout] call FUNC(verifyLoadout)];
_contentPanelCtrl lnbSort [1, false];
// Select newly saved loadout
for '_i' from 0 to (((lnbsize _contentPanelCtrl) select 0) - 1) do {
if ((_contentPanelCtrl lnbText [_i, 1]) == _editBoxContent) exitwith {_contentPanelCtrl lnbSetCurSelRow _i};
};
set3DENMissionAttributes [[QGVAR(DummyCategory), QGVAR(DefaultLoadoutsListAttribute), GVAR(defaultLoadoutsList)]];
} else {
if (_loadoutIndex == -1) then {
_data pushBack [_editBoxContent, _curSelLoadout];
} else {
_data set [_loadoutIndex, [[_editBoxContent, _loadoutName] select (_loadoutName isEqualTo _editBoxContent), _curSelLoadout]];
_contentPanelCtrl setVariable [_editBoxContent + str IDC_buttonMyLoadouts, [_curSelLoadout] call FUNC(verifyLoadout)];
};
profileNamespace setVariable [QGVAR(saved_loadouts), _data];
};
};
case IDC_buttonSharedLoadouts :{
_loadout = (GVAR(sharedLoadoutsNamespace) getVariable ((_contentPanelCtrl lnbText [_cursSelRow, 0]) + (_contentPanelCtrl lnbText [_cursSelRow, 1]))) select 2;
if (_loadoutIndex == -1) then {
_data pushBack [_editBoxContent, _loadout];
} else {
_data set [_loadoutIndex, [[_editBoxContent, _loadoutName] select (_loadoutName isEqualTo _editBoxContent), _loadout]];
_contentPanelCtrl setVariable [_editBoxContent + str IDC_buttonMyLoadouts, [_loadout] call FUNC(verifyLoadout)];
};
profileNamespace setVariable [QGVAR(saved_loadouts), _data];
};
};
[(findDisplay IDD_ace_arsenal), [localize LSTRING(loadoutSaved), _editBoxContent] joinString " "] call FUNC(message);
private _savedLoadout = (_data select {_x select 0 == _editBoxContent}) select 0;
[QGVAR(onLoadoutSave), [_data find _savedLoadout, _savedLoadout]] call CBA_fnc_localEvent;