ACE3/addons/arsenal/functions/fnc_handleStats.sqf

320 lines
11 KiB
Plaintext
Raw Normal View History

Add ACE Arsenal stats (#6110) * Add test class * Add stats mockup * Merge branch 'master' of https://github.com/acemod/ACE3 into arsenalStats * Finish mockup, add basic hide/show logic * Add base for stats * Use CBA EHs for stats to allow 3rd party mods of it * Add handleStats and most of the UI behaviors for stats * Continue work on stats * Add container stats * Add page support for stats * Add text for the ROF stat * Add accuracy in MOA for the accuracy stat * Change accuracy shown number to 1 decimal instead of 2 * Add MIL in the dispersion stat text * Change stats layout, remove dummy text strings * Add some AB stats * Remove last test string * Replace configExtremes by normal lookup where it's relevant * Add "undefined value" string when AB stat isn't present Mostly for laucnhers * Fix typo in preInit * Change drag model stat to ballistic coef * Fix issue with unused stats, change text to white when bar is present * Rewrite some part of handleStats Reason: add support for conditions, less redundant code, less reasons for dedmen to emasculate me * Re-add _hideUnusedFnc, handle empty stats arrays * Pass args to stat conditions, add test condition stat * Add hearing related stats * Remove the padding between stats and the stat bar / text * Add strings for stats * Change stats window to fit baer's suggestion * Algin the close stats button, add missing strings * Finish code review * Add missing newline * Remove duplicate strings * Add explosive range stat * Use proper string for the explo range stat * Fix capitalization for ctrlParent * Fix conditional stats blocking other stats * Add better integration for ballistics, hearing and explosive stats * Replace the private array in handleStat by params * Add backblast stats * Add backblast stat strings * Add flashlight map color and g-force reduction stats * Shorten preInit * Change stats close button to fit arsenal design * Improve stats page indicator look * Rework how stats are stored and retrieved * Remove args config entry, add priority entry, add vanilla weapon stats * Add vanilla container stats * Remove some lines in preInit * Add ballistics stats * Add hearing stats * Remove uneeded config entries * Add explosive range stat * Add backblast stats * Add spaces after semicolons in statements To make JJ happy because I don't care. * Add flashlights map color stat * Add gforce reduction stat FINALLY FUCKING DONE * Fix headers for the new stats funcs * Add add / remove stat API * Fix typo in removeStat header * Remove uneeded inline func * Clean up add / remove stat * Move all CfgACEArsenalStats entries to their own file * Replace STR_ACE_Ballistics_statAmmo by a BI string * Add script profiler related macro and code * Use the highest ballistic coef instead of first one defined * Add support for future ammo displayname * Add ACE_standardAtmosphere for ballistic coef * Add mag muzzle velocity stat * Add weapon muzzle velocity stat * Add comment explaining the ENABLE_PERF_PROFILING macro * Change cfgACEArsenalStats to ACE_Arsenal_Stats * Make JJ less pissy about spaces around = * Fix indentation in weaponMuzzleVelocity, use param * Use GVAR and EGVAR when appropriate * Prefix all stats except the base class * Fix Merge * Fix aspect ratio scaling of stats panel * Minor fixes
2018-02-15 16:03:22 +00:00
/*
* Author: Alganthe
* Handles the stats control group
*
* Arguments:
* 0: Arsenal display <DISPLAY>
* 1: Current panel control <CONTROL>
* 2: Current panel selection <SCALAR>
* 3: Item config entry <CONFIG>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
#include "..\defines.hpp"
#ifdef ENABLE_PERF_PROFILING
private _scopeHandleStats = createProfileScope QFUNC(handleStats);
#endif
params ["_display", "_control", "_curSel", "_itemCfg"];
private _statsBoxCtrl = _display displayCtrl IDC_statsBox;
private _statsPreviousPageCtrl = _display displayCtrl IDC_statsPreviousPage;
private _statsNextPageCtrl = _display displayCtrl IDC_statsNextPage;
private _statsCurrentPageCtrl = _display displayCtrl IDC_statsCurrentPage;
private _hideUnusedFnc = {
params ["_numbers"];
{
private _statsTitleCtrl = _display displayCtrl (5101 + ((_x - 1) * 4));
private _statsTitleIDC = ctrlIDC _statsTitleCtrl;
private _statsBackgroundCtrl = _display displayCtrl (_statsTitleIDC + 1);
private _statsBarCtrl = _display displayCtrl (_statsTitleIDC + 2);
private _statsTextCtrl = _display displayCtrl (_statsTitleIDC + 3);
{
_x ctrlSetFade 1;
_x ctrlCommit 0;
} forEach [
_statsTitleCtrl,
_statsBackgroundCtrl,
_statsBarCtrl,
_statsTextCtrl
];
} forEach _numbers;
};
if !(isNil "_itemCfg") then {
private _handleStatsFnc = {
params ["_statsIndex", "_leftPanel"];
// Get the proper list and page
if (_leftPanel) then {
[true, (uiNamespace getVariable QGVAR(statsListLeftPanel)) select _statsIndex, GVAR(statsPagesLeft) select _statsIndex]
} else {
[false, (uiNamespace getVariable QGVAR(statsListRightPanel)) select _statsIndex, GVAR(statsPagesRight) select _statsIndex]
} params ["_isLeftPanel", "_statsArray", "_currentPage"];
private _statsList = _statsArray select _currentPage;
private _statsCount = 0;
// Handle titles, bars and text
_statsList = _statsList select [0, 5];
if !(_statsList isEqualTo []) then {
{
_x params ["_ID", "_configEntry", "_title", "_bools", "_statements"];
_bools params ["_showBar", "_showText"];
_statements params [["_barStatement", {}, [{}]], ["_textStatement", {}, [{}]], ["_condition", {true}, [{}]]];
private _statsTitleCtrl = _display displayCtrl (5101 + _forEachIndex * 4);
private _statsTitleIDC = ctrlIDC _statsTitleCtrl;
private _statsBackgroundCtrl = _display displayCtrl (_statsTitleIDC + 1);
private _statsBarCtrl = _display displayCtrl (_statsTitleIDC + 2);
private _statsTextCtrl = _display displayCtrl (_statsTitleIDC + 3);
_statsCount = _statsCount + 1;
_statsTitleCtrl ctrlSetText _title;
_statsTitleCtrl ctrlSetFade 0;
// Handle bars
if (_showBar) then {
_statsBarCtrl progressSetPosition ([_configEntry, _itemCfg] call _barStatement);
_statsBackgroundCtrl ctrlSetFade 0;
_statsBarCtrl ctrlSetFade 0;
} else {
_statsBackgroundCtrl ctrlSetFade 1;
_statsBarCtrl ctrlSetFade 1;
};
// Handle text entries
if (_showText) then {
private _textStatementResult = [_configEntry, _itemCfg] call _textStatement;
if (_textStatementResult isEqualtype "") then {
_statsTextCtrl ctrlSetText _textStatementResult;
} else {
_statsTextCtrl ctrlSetText (str _textStatementResult);
};
_statsTextCtrl ctrlSetTextColor ([[1,1,1,1], [0,0,0,1]] select (_showBar));
_statsTextCtrl ctrlSetFade 0;
} else {
_statsTextCtrl ctrlSetFade 1;
};
{
_x ctrlCommit 0;
} forEach [
_statsTitleCtrl,
_statsBackgroundCtrl,
_statsBarCtrl,
_statsTextCtrl
];
} forEach (_statsList select {
_x params ["_ID","_configEntry", "_title", "_bools", "_statements"];
_statements params [["_barStatement", {}, [{}]], ["_textStatement", {}, [{}]], ["_condition", {true}, [{}]]];
([_configEntry, _itemCfg] call _condition)
});
};
// Resize the window
switch (_statsCount) do {
case 0: {
[[1, 2, 3, 4, 5]] call _hideUnusedFnc;
_statsBoxCtrl ctrlSetPosition [
(0.5 - WIDTH_TOTAL / 2) + WIDTH_GAP,
safezoneY + 1.8 * GRID_H,
47 * GRID_W,
11 * GRID_H
];
_statsBoxCtrl ctrlCommit 0;
};
case 1: {
[[2, 3, 4, 5]] call _hideUnusedFnc;
_statsBoxCtrl ctrlSetPosition [
(0.5 - WIDTH_TOTAL / 2) + WIDTH_GAP,
safezoneY + 1.8 * GRID_H,
47 * GRID_W,
15 * GRID_H
];
_statsBoxCtrl ctrlCommit 0;
};
case 2: {
[[3, 4, 5]] call _hideUnusedFnc;
_statsBoxCtrl ctrlSetPosition [
(0.5 - WIDTH_TOTAL / 2) + WIDTH_GAP,
safezoneY + 1.8 * GRID_H,
47 * GRID_W,
25 * GRID_H
];
_statsBoxCtrl ctrlCommit 0;
};
case 3: {
[[4, 5]] call _hideUnusedFnc;
_statsBoxCtrl ctrlSetPosition [
(0.5 - WIDTH_TOTAL / 2) + WIDTH_GAP,
safezoneY + 1.8 * GRID_H,
47 * GRID_W,
35 * GRID_H
];
_statsBoxCtrl ctrlCommit 0;
};
case 4: {
[[5]] call _hideUnusedFnc;
_statsBoxCtrl ctrlSetPosition [
(0.5 - WIDTH_TOTAL / 2) + WIDTH_GAP,
safezoneY + 1.8 * GRID_H,
47 * GRID_W,
45 * GRID_H
];
_statsBoxCtrl ctrlCommit 0;
};
case 5: {
_statsBoxCtrl ctrlSetPosition [
(0.5 - WIDTH_TOTAL / 2) + WIDTH_GAP,
safezoneY + 1.8 * GRID_H,
47 * GRID_W,
55 * GRID_H
];
_statsBoxCtrl ctrlCommit 0;
};
};
GVAR(statsInfo) = [_isLeftPanel, _statsIndex, _control, _curSel, _itemCfg];
// Toggle page buttons
_statsPreviousPageCtrl ctrlEnable !(_currentPage == 0);
_statsNextPageCtrl ctrlEnable !(_currentPage + 1 >= count _statsArray);
_statsCurrentPageCtrl ctrlSetText ([localize LSTRING(page), str (_currentPage + 1)] joinString " ");
{
_x ctrlSetFade 0;
_x ctrlCommit 0;
} forEach [
_statsPreviousPageCtrl,
_statsNextPageCtrl,
_statsCurrentPageCtrl
];
};
if (ctrlIDC _control == IDC_leftTabContent) then {
switch (GVAR(currentLeftPanel)) do {
case IDC_buttonPrimaryWeapon: {
[0, true] call _handleStatsFnc;
};
case IDC_buttonHandgun: {
[1, true] call _handleStatsFnc;
};
case IDC_buttonSecondaryWeapon: {
[2, true] call _handleStatsFnc;
};
case IDC_buttonUniform: {
[3, true] call _handleStatsFnc;
};
case IDC_buttonVest: {
[4, true] call _handleStatsFnc;
};
case IDC_buttonBackpack: {
[5, true] call _handleStatsFnc;
};
case IDC_buttonHeadgear: {
[6, true] call _handleStatsFnc;
};
case IDC_buttonGoggles: {
[7, true] call _handleStatsFnc;
};
case IDC_buttonNVG: {
[8, true] call _handleStatsFnc;
};
case IDC_buttonBinoculars: {
[9, true] call _handleStatsFnc;
};
case IDC_buttonMap: {
[10, true] call _handleStatsFnc;
};
case IDC_buttonGPS: {
[11, true] call _handleStatsFnc;
};
case IDC_buttonRadio: {
[12, true] call _handleStatsFnc;
};
case IDC_buttonCompass: {
[13, true] call _handleStatsFnc;
};
case IDC_buttonWatch: {
[14, true] call _handleStatsFnc;
};
case IDC_buttonFace: {
[15, true] call _handleStatsFnc;
};
case IDC_buttonVoice: {
[16, true] call _handleStatsFnc;
};
case IDC_buttonInsigna: {
[17, true] call _handleStatsFnc;
};
};
} else {
switch (GVAR(currentRightPanel)) do {
case IDC_buttonOptic: {
[0, false] call _handleStatsFnc;
};
case IDC_buttonItemAcc: {
[1, false] call _handleStatsFnc;
};
case IDC_buttonMuzzle: {
[2, false] call _handleStatsFnc;
};
case IDC_buttonBipod: {
[3, false] call _handleStatsFnc;
};
case IDC_buttonCurrentMag;
case IDC_buttonCurrentMag2;
case IDC_buttonMag;
case IDC_buttonMagALL: {
[4, false] call _handleStatsFnc;
};
case IDC_buttonThrow: {
[5, false] call _handleStatsFnc;
};
case IDC_buttonPut: {
[6, false] call _handleStatsFnc;
};
case IDC_buttonMisc: {
[7, false] call _handleStatsFnc;
};
};
};
} else {
[[1, 2, 3, 4, 5]] call _hideUnusedFnc;
_statsBoxCtrl ctrlSetPosition [
(0.5 - WIDTH_TOTAL / 2) + WIDTH_GAP,
safezoneY + 1.8 * GRID_H,
47 * GRID_W,
11 * GRID_H
];
_statsBoxCtrl ctrlCommit 0;
{
_x ctrlSetFade 1;
_x ctrlCommit 0;
} forEach [
_statsPreviousPageCtrl,
_statsNextPageCtrl,
_statsCurrentPageCtrl
];
};