Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Aircraft Loadout Dialog #5238

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion addons/aircraft/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -1 +1 @@
z\ace\addons\aircraft
z\ace\addons\aircraft
16 changes: 16 additions & 0 deletions addons/aircraft/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ACE_Settings {
class GVAR(enableLoadoutMenu) {
category = CSTRING(Category_Aircraft);
displayName = CSTRING(EnableLoadoutMenu);
description = CSTRING(EnableLoadoutMenu_description);
value = 1;
typeName = "BOOL";
};
class GVAR(makeNewPylonsEmpty) {
category = CSTRING(Category_Aircraft);
displayName = CSTRING(MakeNewPylonsEmpty);
description = CSTRING(MakeNewPylonsEmpty_description);
value = 0;
typeName = "BOOL";
};
};
17 changes: 17 additions & 0 deletions addons/aircraft/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
1 change: 1 addition & 0 deletions addons/aircraft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ The people responsible for merging changes to this component or answering potent
- [KoffeinFlummi](https://github.com/KoffeinFlummi)
- [commy2](https://github.com/commy2)
- [jaynus](https://github.com/walterpearce)
- [654wak654](https://github.com/654wak654)
8 changes: 8 additions & 0 deletions addons/aircraft/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PREP(onButtonApply);
PREP(onButtonDelete);
PREP(onButtonLoad);
PREP(onButtonSave);
PREP(onComboSelChange);
PREP(onNameChange);
PREP(onPylonMirror);
PREP(showDialog);
31 changes: 31 additions & 0 deletions addons/aircraft/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
["ace_settingsInitialized", {
if (!GVAR(enableLoadoutMenu)) exitWith {};

private _filter = "isClass (_x >> 'Components' >> 'TransportPylonsComponent')";
private _aircraftWithPylons = _filter configClasses (configFile >> "CfgVehicles" >> "Air");
{
[configName _x, "init", {
params ["_aircraft"];

private _loadoutAction = [
QGVAR(loadoutAction),
localize LSTRING(ConfigurePylons),
"",
{[_target] call FUNC(showDialog)},
{
private _rearmVehicles = _target nearObjects ["LandVehicle", AIRCRAFT_ACTION_DISTANCE + 10];

if (["ace_rearm"] call EFUNC(common,isModLoaded)) then {
FILTER(_rearmVehicles,(_x getVariable [QEGVAR(rearm,magazineSupply), 0]) > 0);
} else {
FILTER(_rearmVehicles,getAmmoCargo _x > 0);
};

({([_x, _target] call EFUNC(interaction,getInteractionDistance)) < AIRCRAFT_ACTION_DISTANCE} count _rearmVehicles) > 0
}
] call EFUNC(interact_menu,createAction);

[_aircraft, 0, ["ACE_MainActions"], _loadoutAction] call EFUNC(interact_menu,addActionToObject);
}] call CBA_fnc_addClassEventHandler;
} forEach _aircraftWithPylons;
}] call CBA_fnc_addEventHandler;
9 changes: 9 additions & 0 deletions addons/aircraft/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

ADDON = true;
3 changes: 3 additions & 0 deletions addons/aircraft/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
7 changes: 5 additions & 2 deletions addons/aircraft/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
requiredAddons[] = {"ace_common", "ace_interact_menu", "ace_rearm"};
author = ECSTRING(common,ACETeam);
authors[] = {"KoffeinFlummi", "Crusty", "commy2", "jaynus", "Kimi"};
authors[] = {"KoffeinFlummi", "Crusty", "commy2", "jaynus", "Kimi", "654wak654"};
url = ECSTRING(main,URL);
VERSION_CONFIG;

Expand All @@ -17,8 +17,11 @@ class CfgPatches {
};
};

#include "ACE_Settings.hpp"
#include "CfgAmmo.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgMagazines.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
#include "RscInGameUI.hpp"
#include "menu.hpp"
32 changes: 32 additions & 0 deletions addons/aircraft/functions/fnc_onButtonApply.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Author: 654wak654
* Applies the current configuration of pylons to the aircraft
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_aircraft_fnc_onButtonApply
*
* Public: No
*/
#include "script_component.hpp"

{
private _pylon = (_x select 0) lbData (lbCurSel (_x select 0));

if (GVAR(makeNewPylonsEmpty)) then {
private _pylonMagazines = getPylonMagazines GVAR(currentAircraft);
if ((_pylonMagazines select _forEachIndex) != _pylon) then {
GVAR(currentAircraft) setPylonLoadout [_forEachIndex + 1, _pylon, true];
GVAR(currentAircraft) setAmmoOnPylon [_forEachIndex + 1, 0];
};
} else {
private _count = [configFile >> "CfgMagazines" >> _pylon >> "count", "number", 0] call CBA_fnc_getConfigEntry;
GVAR(currentAircraft) setPylonLoadout [_forEachIndex + 1, _pylon, true];
GVAR(currentAircraft) setAmmoOnPylon [_forEachIndex + 1, _count];
};
} forEach GVAR(comboBoxes);
24 changes: 24 additions & 0 deletions addons/aircraft/functions/fnc_onButtonDelete.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Author: 654wak654
* Deletes the selected pylon configuration from profileNamespace
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_aircraft_fnc_onButtonDelete
*
* Public: No
*/
#include "script_component.hpp"

private _selection = lbText [160, lbCurSel 160];

lbDelete [160, lbCurSel 160];

private _aircraftLoadouts = profileNamespace getVariable [QGVAR(aircraftLoadouts), []];
FILTER(_aircraftLoadouts,(_x select 0) != _selection);
profileNamespace setVariable [QGVAR(aircraftLoadouts), _aircraftLoadouts];
55 changes: 55 additions & 0 deletions addons/aircraft/functions/fnc_onButtonLoad.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Author: 654wak654
* Loads selected pylon configuration from either config or profile
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_aircraft_fnc_onButtonLoad
*
* Public: No
*/
#include "script_component.hpp"

[false] call FUNC(onPylonMirror);
((findDisplay 654654) displayCtrl 130) cbSetChecked false;

private _loadoutName = ctrlText 170;

private _fnc_setSelections = {
params ["_mags"];

{
private _ctrl = _x select 0;

private _index = 0;
for "_i" from 1 to ((lbSize _ctrl) - 1) do {
if ((_ctrl lbData _i) == (_mags param [_forEachIndex, ""])) exitWith {
_index = _i;
};
};
_ctrl lbSetCurSel _index;
} forEach GVAR(comboBoxes);
};

private _loadoutFound = false;
private _pylonComponent = configFile >> "CfgVehicles" >> typeOf GVAR(currentAircraft) >> "Components" >> "TransportPylonsComponent";
{
if (getText (_x >> "displayName") == _loadoutName) exitWith {
[getArray (_x >> "attachment")] call _fnc_setSelections;
_loadoutFound = true;
};
} forEach ("true" configClasses (_pylonComponent >> "Presets"));

if (_loadoutFound) exitWith {};

private _aircraftLoadouts = profileNamespace getVariable [QGVAR(aircraftLoadouts), []];
{
if ((_x select 0) == _loadoutName) exitWith {
[_x select 1] call _fnc_setSelections;
};
} forEach _aircraftLoadouts;
29 changes: 29 additions & 0 deletions addons/aircraft/functions/fnc_onButtonSave.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Author: 654wak654
* Saves the selected pylon configuration to profileNamespace
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_aircraft_fnc_onButtonSave
*
* Public: No
*/
#include "script_component.hpp"

private _loadoutName = ctrlText 170;
private _loadoutPylons = [];
{
_loadoutPylons pushBack ((_x select 0) lbData (lbCurSel (_x select 0)));
} forEach GVAR(comboBoxes);

private _index = lbAdd [160, _loadoutName];
lbSetCurSel [160, _index];

private _aircraftLoadouts = profileNamespace getVariable [QGVAR(aircraftLoadouts), []];
_aircraftLoadouts pushBack [_loadoutName, _loadoutPylons, typeOf GVAR(currentAircraft)];
profileNamespace setVariable [QGVAR(aircraftLoadouts), _aircraftLoadouts];
33 changes: 33 additions & 0 deletions addons/aircraft/functions/fnc_onComboSelChange.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Author: 654wak654
* Mirrors magazine selection to the opposite pylon if mirroring is on
*
* Arguments:
* 0: Combobox <CONTROL>
* 1: Index of selected magazine in the combobox <NUMBER>
*
* Return Value:
* None
*
* Example:
* [false] call ace_aircraft_fnc_onComboSelChange
*
* Public: No
*/
#include "script_component.hpp"

params ["_ctrl", "_index"];

private _checkBox = (findDisplay 654654) displayCtrl 130;
if (!cbChecked _checkBox) exitWith {};

{
if (_ctrl == (_x select 0) && {(_x select 1) == -1}) exitWith {
private _indexOf = _forEachIndex;
{
if ((_x select 1) == _indexOf) exitWith {
(_x select 0) lbSetCurSel _index;
};
} forEach GVAR(comboBoxes);
};
} forEach GVAR(comboBoxes);
25 changes: 25 additions & 0 deletions addons/aircraft/functions/fnc_onNameChange.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Author: 654wak654
* Called when current loadout name is changed
* Prevents default presets from gettings deleted / overwritten
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_aircraft_fnc_onNameChange
*
* Public: No
*/
#include "script_component.hpp"

if ((ctrlText 170) in GVAR(defaultLoadoutNames)) then {
ctrlEnable [180, false];
ctrlEnable [200, false];
} else {
ctrlEnable [180, true];
ctrlEnable [200, true];
};
33 changes: 33 additions & 0 deletions addons/aircraft/functions/fnc_onPylonMirror.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Author: 654wak654
* Called when the "mirror" checkbox on the loadout dialog is checked
* Changes the comboboxes to be mirrored / normal
*
* Arguments:
* 0: Checked status <BOOL>
*
* Return Value:
* None
*
* Example:
* [false] call ace_aircraft_fnc_onPylonMirror
*
* Public: No
*/
#include "script_component.hpp"

params ["_checked"];

if (_checked) then {
{
if ((_x select 1) != -1) then {
private _selection = lbCurSel ((GVAR(comboBoxes) select (_x select 1)) select 0);
(_x select 0) lbSetCurSel _selection;
(_x select 0) ctrlEnable false;
};
} forEach GVAR(comboBoxes);
} else {
{
(_x select 0) ctrlEnable true;
} forEach GVAR(comboBoxes);
};
Loading