From 1e3d9cc22ab4caad02357cd192d465330dcd89f1 Mon Sep 17 00:00:00 2001 From: amsteadrayle <2516219+amsteadrayle@users.noreply.github.com> Date: Thu, 12 Oct 2023 22:39:23 -0400 Subject: [PATCH] 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 * Add `private` keyword for inline functions Co-authored-by: PabstMirror * 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 Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- addons/medical_gui/XEH_PREP.hpp | 2 + .../functions/fnc_collectActions.sqf | 3 +- .../functions/fnc_countTreatmentItems.sqf | 53 +++++++++++++++++++ .../functions/fnc_formatItemCounts.sqf | 32 +++++++++++ .../functions/fnc_updateActions.sqf | 12 ++++- addons/medical_gui/stringtable.xml | 9 ++++ 6 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 addons/medical_gui/functions/fnc_countTreatmentItems.sqf create mode 100644 addons/medical_gui/functions/fnc_formatItemCounts.sqf diff --git a/addons/medical_gui/XEH_PREP.hpp b/addons/medical_gui/XEH_PREP.hpp index de73cba109..3d1ace8b4e 100644 --- a/addons/medical_gui/XEH_PREP.hpp +++ b/addons/medical_gui/XEH_PREP.hpp @@ -2,9 +2,11 @@ PREP(addTreatmentActions); PREP(bloodLossToRGBA); PREP(canOpenMenu); PREP(collectActions); +PREP(countTreatmentItems); PREP(damageToRGBA); PREP(displayPatientInformation); PREP(displayTriageCard); +PREP(formatItemCounts); PREP(handleToggle); PREP(handleTriageSelect); PREP(menuPFH); diff --git a/addons/medical_gui/functions/fnc_collectActions.sqf b/addons/medical_gui/functions/fnc_collectActions.sqf index 7a9902ad71..818decb017 100644 --- a/addons/medical_gui/functions/fnc_collectActions.sqf +++ b/addons/medical_gui/functions/fnc_collectActions.sqf @@ -24,8 +24,9 @@ GVAR(actions) = []; private _category = getText (_x >> "category"); private _condition = compile format [QUOTE([ARR_4(ACE_player, GVAR(target), %1 select GVAR(selectedBodyPart), '%2')] call DEFUNC(medical_treatment,canTreatCached)), ALL_BODY_PARTS, _configName]; private _statement = compile format [QUOTE([ARR_4(ACE_player, GVAR(target), %1 select GVAR(selectedBodyPart), '%2')] call DEFUNC(medical_treatment,treatment)), ALL_BODY_PARTS, _configName]; + private _items = getArray (_x >> "items"); - GVAR(actions) pushBack [_displayName, _category, _condition, _statement]; + GVAR(actions) pushBack [_displayName, _category, _condition, _statement, _items]; } forEach configProperties [configFile >> QEGVAR(medical_treatment,actions), "isClass _x"]; diff --git a/addons/medical_gui/functions/fnc_countTreatmentItems.sqf b/addons/medical_gui/functions/fnc_countTreatmentItems.sqf new file mode 100644 index 0000000000..102d996bb3 --- /dev/null +++ b/addons/medical_gui/functions/fnc_countTreatmentItems.sqf @@ -0,0 +1,53 @@ +#include "..\script_component.hpp" +/* + * Author: AmsteadRayle + * Counts how many of the given items are present between the medic and patient. + * If medic or patient are in a vehicle then vehicle's inventory will also be checked. + * + * Arguments: + * 0: Items + * + * Return Value: + * Counts (can be nil) + * + * Example: + * [items] call ace_medical_gui_fnc_countTreatmentItems + * + * Public: No + */ + +params ["_items"]; + +private _medicCount = 0; +private _patientCount = nil; +private _vehicleCount = nil; + +// Medic +{ + _medicCount = _medicCount + ([ACE_player, _x] call EFUNC(common,getCountOfItem)); +} forEach _items; + +// Patient +if (ACE_player != GVAR(target)) then { + _patientCount = 0; + { + _patientCount = _patientCount + ([GVAR(target), _x] call EFUNC(common,getCountOfItem)); + } forEach _items; +}; + +// Vehicle +private _medicVehicle = objectParent ACE_player; +private _patientVehicle = objectParent GVAR(target); +private _vehicle = if (!isNull _medicVehicle) then {_medicVehicle} else {_patientVehicle}; + +if (!isNull _vehicle) then { + _vehicleCount = 0; + (getItemCargo _vehicle) params ["_itemTypes", "_itemCounts"]; + { + private _item = _x; + private _index = _itemTypes find _item; + _vehicleCount = _vehicleCount + (_itemCounts param [_index, 0]); + } forEach _items; +}; + +[_medicCount, _patientCount, _vehicleCount] diff --git a/addons/medical_gui/functions/fnc_formatItemCounts.sqf b/addons/medical_gui/functions/fnc_formatItemCounts.sqf new file mode 100644 index 0000000000..7ef294f4eb --- /dev/null +++ b/addons/medical_gui/functions/fnc_formatItemCounts.sqf @@ -0,0 +1,32 @@ +#include "..\script_component.hpp" +/* + * Author: AmsteadRayle + * Format item counts to be shown in the tooltip. + * + * Arguments: + * 0: Medic count + * 1: Patient count + * 2: Vehicle count + * + * Return Value: + * Item count string + * + * Example: + * [medicCount, patientCount, vehicleCount] call ace_medical_gui_fnc_formatItemCounts + * + * Public: No + */ + +params ["_medicCount", "_patientCount", "_vehicleCount"]; + +private _countStrings = [format ["%1 %2", _medicCount, LLSTRING(TreatmentItemCount_Medic)]]; + +if ((EGVAR(medical_treatment,allowSharedEquipment) != 2) && {!isNil "_patientCount"}) then { + _countStrings pushBack format ["%1 %2", _patientCount, LLSTRING(TreatmentItemCount_Patient)]; +}; + +if (!isNil "_vehicleCount") then { + _countStrings pushBack format ["%1 %2", _vehicleCount, LLSTRING(TreatmentItemCount_Vehicle)]; +}; + +_countStrings joinString "\n" diff --git a/addons/medical_gui/functions/fnc_updateActions.sqf b/addons/medical_gui/functions/fnc_updateActions.sqf index 43141b9c10..ca5ca373eb 100644 --- a/addons/medical_gui/functions/fnc_updateActions.sqf +++ b/addons/medical_gui/functions/fnc_updateActions.sqf @@ -38,7 +38,7 @@ if (_showTriage) exitWith { // Show treatment options on action buttons private _shownIndex = 0; { - _x params ["_displayName", "_category", "_condition", "_statement"]; + _x params ["_displayName", "_category", "_condition", "_statement", "_items"]; // Check action category and condition if (_category == _selectedCategory && {call _condition}) then { @@ -50,6 +50,16 @@ private _shownIndex = 0; _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; diff --git a/addons/medical_gui/stringtable.xml b/addons/medical_gui/stringtable.xml index 531b34607a..3c0d2bc113 100644 --- a/addons/medical_gui/stringtable.xml +++ b/addons/medical_gui/stringtable.xml @@ -1349,5 +1349,14 @@ R + + in your inventory + + + in patient's inventory + + + in vehicle's inventory +