ACE3/addons/medical_gui/functions/fnc_updateActions.sqf
amsteadrayle 1e3d9cc22a
Medical GUI - Show number of available treatment items in medical menu (#9474)
* Initial implementation of item count display

* Put everything inside function, add padding

* Extract and explain null string

* Fix tab in config file

* Add function header

* Use ACE item counting function

* Extract column width to variable

* Move constants declaration closer to usage

* Add special case for sutures

* Add setting to enable/disable

* Expand to allow showing in tooltip

* Split into counting and formatting function

* Fix incorrect check for case with no items

* Remove ineffective padding from tooltip

* Check for surgical kit item instead of display name

* Update return description in header

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Add `private` keyword for inline functions

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* capitalization/vars

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* nil checks, localize macro

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Remove button text mode and setting

* possessive

* Update addons/medical_gui/functions/fnc_formatItemCounts.sqf

---------

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
2023-10-12 22:39:23 -04:00

74 lines
2.2 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: mharis001
* Updates the action buttons based currently avaiable treatments.
*
* Arguments:
* 0: Medical Menu display <DISPLAY>
*
* Return Value:
* None
*
* Example:
* [_display] call ace_medical_gui_fnc_updateActions
*
* Public: No
*/
params ["_display"];
private _selectedCategory = GVAR(selectedCategory);
private _group = _display displayCtrl IDC_ACTION_BUTTON_GROUP;
private _actionButons = allControls _group;
// Handle triage list (no actions shown)
private _ctrlTriage = _display displayCtrl IDC_TRIAGE_CARD;
private _showTriage = _selectedCategory == "triage";
_ctrlTriage ctrlEnable _showTriage;
_group ctrlEnable !_showTriage;
lbClear _ctrlTriage;
if (_showTriage) exitWith {
{ ctrlDelete _x } forEach _actionButons;
[_ctrlTriage, GVAR(target)] call FUNC(updateTriageCard);
};
// Show treatment options on action buttons
private _shownIndex = 0;
{
_x params ["_displayName", "_category", "_condition", "_statement", "_items"];
// Check action category and condition
if (_category == _selectedCategory && {call _condition}) then {
private _ctrl = if (_shownIndex >= count _actionButons) then {
_actionButons pushBack (_display ctrlCreate ["ACE_Medical_Menu_ActionButton", -1, _group]);
};
_ctrl = _actionButons # _shownIndex;
_ctrl ctrlRemoveAllEventHandlers "ButtonClick";
_ctrl ctrlSetPositionY POS_H(1.1 * _shownIndex);
_ctrl ctrlCommit 0;
private _countText = "";
if (_items isNotEqualTo []) then {
if ("ACE_surgicalKit" in _items && {EGVAR(medical_treatment,consumeSurgicalKit) == 2}) then {
_items = ["ACE_suture"];
};
private _counts = [_items] call FUNC(countTreatmentItems);
_countText = _counts call FUNC(formatItemCounts);
};
_ctrl ctrlSetTooltip _countText;
_ctrl ctrlSetText _displayName;
_ctrl ctrlShow true;
_ctrl ctrlAddEventHandler ["ButtonClick", _statement];
_ctrl ctrlAddEventHandler ["ButtonClick", {GVAR(pendingReopen) = true}];
_shownIndex = _shownIndex + 1;
};
} forEach GVAR(actions);
{ ctrlDelete _x } forEach (_actionButons select [_shownIndex, 9999]);