ACE3/addons/artillerytables/functions/fnc_rangeTableOpen.sqf

88 lines
3.8 KiB
Plaintext
Raw Normal View History

2019-03-02 06:26:02 +00:00
#include "script_component.hpp"
/*
* Author: PabstMirror
* Opens the rangetable and fills the charge listbox.
*
* Arguments:
2019-03-16 01:11:15 +00:00
* 0: Weapon configname <STRING>
* 1: Elevation Min (Deg) <NUMBER>
* 2: Elevation Max (Deg) <NUMBER>
* 3: Advanced Corrections Enabled <BOOL>
2019-03-02 06:26:02 +00:00
*
* Return Value:
* None
*
* Example:
* [] call ace_artillerytables_fnc_rangeTableOpen
*
* Public: No
*/
params ["_weaponName", "_elevMin", "_elevMax", "_advCorrection"];
2019-03-16 16:56:58 +00:00
TRACE_4("rangeTableOpen",_weaponName,_elevMin,_elevMax,_advCorrection);
2019-03-02 06:26:02 +00:00
2019-03-16 01:11:15 +00:00
BEGIN_COUNTER(rangeTableOpen);
2019-03-02 06:26:02 +00:00
createDialog QGVAR(rangeTableDialog);
private _dialog = uiNamespace getVariable [QGVAR(rangeTableDialog), displayNull];
if (isNull _dialog) exitWith{ERROR("Dialog failed to open");};
private _ctrlChargeList = _dialog displayCtrl IDC_CHARGELIST;
_dialog setVariable [QGVAR(elevMin),_elevMin];
_dialog setVariable [QGVAR(elevMax),_elevMax];
_dialog setVariable [QGVAR(advCorrection),_advCorrection];
TRACE_2("created dialog",_dialog,_ctrlChargeList);
// Get Mags:
private _mags = [_weaponName] call CBA_fnc_compatibleMagazines;
if (_mags isEqualTo []) exitWith {WARNING_1("No Mags",_weaponName);};
private _magCfg = configFile >> "CfgMagazines";
2019-03-16 01:11:15 +00:00
private _magParamsArray = [];
2019-03-02 06:26:02 +00:00
_mags = _mags apply {
private _initSpeed = getNumber (_magCfg >> _x >> "initSpeed");
2019-03-16 01:11:15 +00:00
_magParamsArray pushBackUnique _initSpeed;
private _airFriction = 0;
if (_advCorrection) then {
2019-03-16 05:04:39 +00:00
_airFriction = if (isNumber (_magCfg >> _x >> QGVAR(airFriction))) then { getNumber (_magCfg >> _x >> QGVAR(airFriction)) } else { DEFAULT_AIR_FRICTION };
2019-03-16 01:11:15 +00:00
};
_magParamsArray pushBackUnique _airFriction;
[getText (_magCfg >> _x >> "displayNameShort"), getText (_magCfg >> _x >> "displayName"), _initSpeed, _airFriction]
};
TRACE_2("",_magParamsArray,_mags);
if ((count _magParamsArray) == 2) then { // test if all magazines share the parameters
2019-03-16 16:56:58 +00:00
_mags = [["", "All Magazines", (_mags select 0) select 2, (_mags select 0) select 3]]; // simplify
2019-03-02 06:26:02 +00:00
};
// Get Firemodes:
private _fireModes = getArray (configFile >> "CfgWeapons" >> _weaponName >> "modes");
_fireModes = (_fireModes apply {configFile >> "CfgWeapons" >> _weaponName >> _x}) select {1 == getNumber (_x >> "showToPlayer")};
_fireModes = _fireModes apply {[getNumber (_x >> "artilleryCharge"), configName _x]};
_fireModes sort true;
2019-03-16 01:11:15 +00:00
private _allSameCharge = ((count _fireModes) == 1) && {((_fireModes select 0) select 0) == 1};
2019-03-02 06:26:02 +00:00
TRACE_2("",_allSameCharge,_fireModes);
2019-03-16 01:11:15 +00:00
GVAR(magModeData) = [];
2019-03-02 06:26:02 +00:00
{
2019-03-16 01:11:15 +00:00
_x params ["_xDisplayNameShort", "_xDisplayName", "_xInitSpeed", "_xAirFriction"];
2019-03-02 06:26:02 +00:00
if (_allSameCharge) then {
2019-03-16 01:11:15 +00:00
_ctrlChargeList lbAdd format ["%1", _xDisplayNameShort];
2019-03-16 16:56:58 +00:00
_ctrlChargeList lbSetTooltip [count GVAR(magModeData), format ["%1\n%2 m/s\n%3", _xDisplayName, _xInitSpeed toFixed 1, _xAirFriction]];
2019-03-16 01:11:15 +00:00
GVAR(magModeData) pushBack [_xInitSpeed, _xAirFriction];
2019-03-02 06:26:02 +00:00
} else {
{
2019-03-16 01:11:15 +00:00
_x params ["_xModeCharge"];
_ctrlChargeList lbAdd format ["[Charge %1] %2", _forEachIndex, _xDisplayNameShort]; // forEachIndex is from firemodes
2019-03-16 16:56:58 +00:00
_ctrlChargeList lbSetTooltip [count GVAR(magModeData), format ["%1\n%2 m/s\n%3", _xDisplayName, (_xInitSpeed * _xModeCharge) toFixed 1, _xAirFriction]];
2019-03-16 01:11:15 +00:00
GVAR(magModeData) pushBack [_xInitSpeed * _xModeCharge, _xAirFriction];
2019-03-02 06:26:02 +00:00
} forEach _fireModes;
};
} forEach _mags;
if (isNil QGVAR(lastElevationMode)) then {GVAR(lastElevationMode) = true;};
2019-03-16 01:11:15 +00:00
if (isNil QGVAR(lastTablePage)) then {GVAR(lastTablePage) = 0;};
if ((GVAR(lastTablePage) >= (count GVAR(magModeData))) || {GVAR(lastTablePage) < 0}) then { GVAR(lastTablePage) = 0; };
2019-03-02 06:26:02 +00:00
2019-03-16 01:11:15 +00:00
END_COUNTER(rangeTableOpen);
TRACE_2("trigger update",GVAR(lastElevationMode),GVAR(lastTablePage));
_ctrlChargeList lbSetCurSel GVAR(lastTablePage); // triggers call to FUNC(rangeTableUpdate)