Skip to content

Commit

Permalink
Misc/GUI - Fix error on bandaging (#543)
Browse files Browse the repository at this point in the history
**When merged this pull request will:**
- Fix error after successful bandage use

### IMPORTANT

- [Development Guidelines](https://ace3.acemod.org/wiki/development/)
are read, understood and applied.
- Title of this PR uses our standard template `Component -
Add|Fix|Improve|Change|Make|Remove {changes}`.

---------

Co-authored-by: MiszczuZPolski <[email protected]>
  • Loading branch information
BlueTheKing and MiszczuZPolski authored Jun 4, 2024
1 parent 89beb50 commit e7196ae
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 150 deletions.
3 changes: 0 additions & 3 deletions addons/gui/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ class CfgFunctions {
class overwrite_medical_gui {
tag = "ace_medical_gui";
class ace_medical_gui {
class menuPFH {
file = QPATHTOF(functions\fnc_menuPFH.sqf);
};
class onMenuClose {
file = QPATHTOF(functions\fnc_onMenuClose.sqf);
};
Expand Down
59 changes: 0 additions & 59 deletions addons/gui/functions/fnc_menuPFH.sqf

This file was deleted.

168 changes: 84 additions & 84 deletions addons/misc/functions/fnc_treatment.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Public: No
*/

params ["_medic", "_patient", "_bodyPart", "_classname", "_bandageEffectiveness", ["_extraArgs",[]]];
params ["_medic", "_patient", "_bodyPart", "_classname", "_extraArgs"];

// Delay by a frame if cursor menu is open to prevent progress bar failing
if (uiNamespace getVariable [QACEGVAR(interact_menu,cursorMenuOpened), false]) exitWith {
Expand Down Expand Up @@ -54,16 +54,6 @@ private _userAndItem = if (GET_NUMBER_ENTRY(_config >> "consumeItem") == 1) then
[objNull, ""]; // Treatment does not require items to be consumed
};

_userAndItem params ["_itemUser", "_usedItem", ["_magazineCount", -1]];

if (((_classname call BIS_fnc_itemType) select 0) isEqualTo "Magazine") then {
if (count _extraArgs > 0) then {
_extraArgs pushBack _magazineCount;
} else {
_extraArgs =[-1,_magazineCount];
};
};

// Patient Animation Added from Old Ace
if (alive _patient) then {
private _patientAnim = getText (_config >> "animationPatient");
Expand All @@ -83,97 +73,107 @@ if (alive _patient) then {
};
//Old Ace Ending here

// Get treatment animation for the medic
private _medicAnim = if (_medic isEqualTo _patient) then {
getText (_config >> ["animationMedicSelf", "animationMedicSelfProne"] select (stance _medic == "PRONE"));
} else {
getText (_config >> ["animationMedic", "animationMedicProne"] select (stance _medic == "PRONE"));
};
_userAndItem params ["_itemUser", "_usedItem", "_createLitter"];

_medic setVariable [QACEGVAR(medical_treatment,selectedWeaponOnTreatment), weaponState _medic];
private _isInZeus = !isNull findDisplay 312;

// Adjust animation based on the current weapon of the medic
private _wpn = ["non", "rfl", "lnr", "pst"] param [["", primaryWeapon _medic, secondaryWeapon _medic, handgunWeapon _medic] find currentWeapon _medic, "non"];
_medicAnim = [_medicAnim, "[wpn]", _wpn] call CBA_fnc_replace;
if (_medic isNotEqualTo player || {!_isInZeus}) then {
// Get treatment animation for the medic
private _medicAnim = if (_medic isEqualTo _patient) then {
getText (_config >> ["animationMedicSelf", "animationMedicSelfProne"] select (stance _medic == "PRONE"));
} else {
getText (_config >> ["animationMedic", "animationMedicProne"] select (stance _medic == "PRONE"));
};

// This animation is missing, use alternative
if (_medicAnim == "AinvPknlMstpSlayWlnrDnon_medic") then {
_medicAnim = "AinvPknlMstpSlayWlnrDnon_medicOther";
};
_medic setVariable [QACEGVAR(medical_treatment,selectedWeaponOnTreatment), weaponState _medic];

// Determine the animation length
private _animDuration = ACEGVAR(medical_treatment,animDurations) getVariable _medicAnim;
if (isNil "_animDuration") then {
WARNING_2("animation [%1] for [%2] has no duration defined",_medicAnim,_classname);
_animDuration = 10;
};
// Adjust animation based on the current weapon of the medic
private _wpn = ["non", "rfl", "lnr", "pst"] param [["", primaryWeapon _medic, secondaryWeapon _medic, handgunWeapon _medic] find currentWeapon _medic, "non"];
_medicAnim = [_medicAnim, "[wpn]", _wpn] call CBA_fnc_replace;

// These animations have transitions that take a bit longer...
if (weaponLowered _medic) then {
_animDuration = _animDuration + 0.5;
// This animation is missing, use alternative
if (_medicAnim == "AinvPknlMstpSlayWlnrDnon_medic") then {
_medicAnim = "AinvPknlMstpSlayWlnrDnon_medicOther";
};

// Fix problems with lowered weapon transitions by raising the weapon first
if (currentWeapon _medic != "" && {_medicAnim != ""}) then {
_medic action ["WeaponInHand", _medic];
// Determine the animation length
private _animDuration = ACEGVAR(medical_treatment,animDurations) getVariable _medicAnim;
if (isNil "_animDuration") then {
WARNING_2("animation [%1] for [%2] has no duration defined",_medicAnim,_classname);
_animDuration = 10;
};
};

if (binocular _medic != "" && {binocular _medic == currentWeapon _medic}) then {
_animDuration = _animDuration + 1;
};
// These animations have transitions that take a bit longer...
if (weaponLowered _medic) then {
_animDuration = _animDuration + 0.5;

// Play treatment animation for medic and determine the ending animation
if (isNull objectParent _medic && {_medicAnim != ""}) then {
// Speed up animation based on treatment time (but cap max to prevent odd animiations/cam shake)
private _animRatio = _animDuration / _treatmentTime;
TRACE_3("setAnimSpeedCoef",_animRatio,_animDuration,_treatmentTime);
// Fix problems with lowered weapon transitions by raising the weapon first
if (currentWeapon _medic != "" && {_medicAnim != ""}) then {
_medic action ["WeaponInHand", _medic];
};
};

// Don't slow down animation too much to prevent it looking funny.
if (_animRatio < ANIMATION_SPEED_MIN_COEFFICIENT) then {
_animRatio = ANIMATION_SPEED_MIN_COEFFICIENT;
if (binocular _medic != "" && {binocular _medic == currentWeapon _medic}) then {
_animDuration = _animDuration + 1;
};

// Skip animation enitrely if progress bar too quick.
if (_animRatio > ANIMATION_SPEED_MAX_COEFFICIENT) exitWith {};
// Play treatment animation for medic and determine the ending animation
if (isNull objectParent _medic && {_medicAnim != ""}) then {
// Speed up animation based on treatment time (but cap max to prevent odd animiations/cam shake)
private _animRatio = _animDuration / _treatmentTime;
TRACE_3("setAnimSpeedCoef",_animRatio,_animDuration,_treatmentTime);

[QACEGVAR(common,setAnimSpeedCoef), [_medic, _animRatio]] call CBA_fnc_globalEvent;
// Don't slow down animation too much to prevent it looking funny.
if (_animRatio < ANIMATION_SPEED_MIN_COEFFICIENT) then {
_animRatio = ANIMATION_SPEED_MIN_COEFFICIENT;
};

// Play animation
private _endInAnim = "AmovP[pos]MstpS[stn]W[wpn]Dnon";
// Skip animation enitrely if progress bar too quick.
if (_animRatio > ANIMATION_SPEED_MAX_COEFFICIENT) exitWith {};

private _pos = ["knl", "pne"] select (stance _medic == "PRONE");
private _stn = "non";
[QACEGVAR(common,setAnimSpeedCoef), [_medic, _animRatio]] call CBA_fnc_globalEvent;

if (_wpn != "non") then {
_stn = ["ras", "low"] select (weaponLowered _medic);
};
// Play animation
private _endInAnim = "AmovP[pos]MstpS[stn]W[wpn]Dnon";

_endInAnim = [_endInAnim, "[pos]", _pos] call CBA_fnc_replace;
_endInAnim = [_endInAnim, "[stn]", _stn] call CBA_fnc_replace;
_endInAnim = [_endInAnim, "[wpn]", _wpn] call CBA_fnc_replace;
private _pos = ["knl", "pne"] select (stance _medic == "PRONE");
private _stn = "non";

[_medic, _medicAnim] call ACEFUNC(common,doAnimation);
[_medic, _endInAnim] call ACEFUNC(common,doAnimation);
_medic setVariable [QACEGVAR(medical_treatment,endInAnim), _endInAnim];
if (_wpn != "non") then {
_stn = ["ras", "low"] select (weaponLowered _medic);
};

_endInAnim = [_endInAnim, "[pos]", _pos] call CBA_fnc_replace;
_endInAnim = [_endInAnim, "[stn]", _stn] call CBA_fnc_replace;
_endInAnim = [_endInAnim, "[wpn]", _wpn] call CBA_fnc_replace;

[_medic, _medicAnim] call ACEFUNC(common,doAnimation);
[_medic, _endInAnim] call ACEFUNC(common,doAnimation);
_medic setVariable [QACEGVAR(medical_treatment,endInAnim), _endInAnim];

if (!isNil QACEGVAR(advanced_fatigue,setAnimExclusions)) then {
ACEGVAR(advanced_fatigue,setAnimExclusions) pushBack "ace_medical_treatment";
};
};

if (!isNil QACEGVAR(advanced_fatigue,setAnimExclusions)) then {
ACEGVAR(advanced_fatigue,setAnimExclusions) pushBack "ace_medical_treatment";
// Play a random treatment sound globally if defined
// Don't attempt to play if sounds array is empty
if (isArray (_config >> "sounds") && count getArray (_config >> "sounds") != 0) then {
selectRandom getArray (_config >> "sounds") params ["_file", ["_volume", 1], ["_pitch", 1], ["_distance", 10]];
GVAR(TreatmentSound) = playSound3D [_file, objNull, false, getPosASL _medic, _volume, _pitch, _distance];

[{
!dialog;
}, {
stopSound GVAR(TreatmentSound);
}, [], _treatmentTime, {
GVAR(TreatmentSound) = nil;
}] call CBA_fnc_waitUntilAndExecute;
};
};

// Play a random treatment sound globally if defined
// Don't attempt to play if sounds array is empty
if (isArray (_config >> "sounds") && count getArray (_config >> "sounds") != 0) then {
selectRandom getArray (_config >> "sounds") params ["_file", ["_volume", 1], ["_pitch", 1], ["_distance", 10]];
GVAR(TreatmentSound) = playSound3D [_file, objNull, false, getPosASL _medic, _volume, _pitch, _distance];

[{
!dialog;
}, {
stopSound GVAR(TreatmentSound);
}, [], _treatmentTime, {
GVAR(TreatmentSound) = nil;
}] call CBA_fnc_waitUntilAndExecute;
if (_isInZeus) then {
_treatmentTime = _treatmentTime * ACEGVAR(medical_treatment,treatmentTimeCoeffZeus);
};

GET_FUNCTION(_callbackStart,_config >> "callbackStart");
Expand All @@ -183,18 +183,18 @@ if (_callbackProgress isEqualTo {}) then {
_callbackProgress = {true};
};

[_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem, _bandageEffectiveness, _extraArgs] call _callbackStart;
[_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem, _createLitter, _extraArgs] call _callbackStart;

["ace_treatmentStarted", [_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem, _bandageEffectiveness, _extraArgs]] call CBA_fnc_localEvent;
["ace_treatmentStarted", [_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem, _createLitter, _extraArgs]] call CBA_fnc_localEvent;

[
_treatmentTime,
[_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem, _bandageEffectiveness, _extraArgs],
[_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem, _createLitter, _extraArgs],
ACEFUNC(medical_treatment,treatmentSuccess),
ACEFUNC(medical_treatment,treatmentFailure),
getText (_config >> "displayNameProgress"),
_callbackProgress,
["isNotInside", "isNotSwimming"]
["isNotInside", "isNotSwimming", "isNotInZeus"]
] call ACEFUNC(common,progressBar);

true
10 changes: 6 additions & 4 deletions addons/misc/functions/fnc_treatmentSuccess.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
* 3: Treatment <STRING>
* 4: Item User <OBJECT>
* 5: Used Item <STRING>
* 6: Extra Arguments <ARRAY>
* 6: Create Litter <BOOL>
* 7: Bandage Effectiveness <NUMBER>
* 8: Extra Arguments <ARRAY>
*
* Return Value:
* None
Expand All @@ -21,7 +23,7 @@
*/

params ["_args"];
_args params ["_medic", "_patient", "_bodyPart", "_classname", "_itemUser", "_usedItem", "_bandageEffectiveness", ["_extraArgs",[]]];
_args params ["_medic", "_patient", "_bodyPart", "_classname", "_itemUser", "_usedItem", "_createLitter", "_extraArgs"];

// Switch medic to end animation immediately
private _endInAnim = _medic getVariable QACEGVAR(medical_treatment,endInAnim);
Expand Down Expand Up @@ -64,7 +66,7 @@ GET_FUNCTION(_callbackSuccess,configFile >> QACEGVAR(medical_treatment,actions)
_args call _callbackSuccess;

// Call litter creation handler
_args call ACEFUNC(medical_treatment,createLitter);
if (_createLitter) then { _args call ACEFUNC(medical_treatment,createLitter); };

// Emit local event for medical API
["ace_treatmentSucceded", [_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem, _bandageEffectiveness, _extraArgs]] call CBA_fnc_localEvent;
["ace_treatmentSucceded", [_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem, _createLitter, _extraArgs]] call CBA_fnc_localEvent;
4 changes: 4 additions & 0 deletions addons/misc/functions/fnc_useItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

params ["_medic", "_patient", "_items"];

if (_medic isEqualTo player && {!isNull findDisplay 312}) exitWith {
[_medic, _items select 0]
};

scopeName "Main";

private _sharedUseOrder = [[_patient, _medic], [_medic, _patient], [_medic]] select ACEGVAR(medical_treatment,allowSharedEquipment);
Expand Down

0 comments on commit e7196ae

Please sign in to comment.