From 8840284309e4e4db7546c741d6f41ac7a7f1269b Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 20 Mar 2015 17:46:21 -0500 Subject: [PATCH] Fix progressBar --- addons/common/functions/fnc_progressBar.sqf | 134 ++++++++++---------- 1 file changed, 69 insertions(+), 65 deletions(-) diff --git a/addons/common/functions/fnc_progressBar.sqf b/addons/common/functions/fnc_progressBar.sqf index 15fbab1e24..69b91237e6 100644 --- a/addons/common/functions/fnc_progressBar.sqf +++ b/addons/common/functions/fnc_progressBar.sqf @@ -1,24 +1,24 @@ /* -* Author: commy2, Glowbal, PabstMirror -* -* Draw progress bar and execute given function if succesful. -* Finish/Failure/Conditional are all passed [_args, _elapsedTime, _totalTime, _errorCode] -* -* Argument: -* 0: NUMBER - Total Time (in game "time" seconds) -* 1: ARRAY - Arguments, passed to condition, fail and finish -* 2: CODE or STRING - On Finish: Code called or STRING raised as event. -* 3: CODE or STRING - On Failure: Code called or STRING raised as event. -* 4: STRING - (Optional) Localized Title -* 5: CODE - (Optional) Code to check each frame -* 6: ARRAY - (Optional) Exceptions for checking EGVAR(common,canInteractWith) -* -* Return value: -* Nothing -* -* Example: -* [5, [], {Hint "Finished!"}, {hint "Failure!"}, "My Title"] call ace_common_fnc_progressBar -*/ + * Author: commy2, Glowbal, PabstMirror + * + * Draw progress bar and execute given function if succesful. + * Finish/Failure/Conditional are all passed [_args, _elapsedTime, _totalTime, _errorCode] + * + * Argument: + * 0: NUMBER - Total Time (in game "time" seconds) + * 1: ARRAY - Arguments, passed to condition, fail and finish + * 2: CODE or STRING - On Finish: Code called or STRING raised as event. + * 3: CODE or STRING - On Failure: Code called or STRING raised as event. + * 4: STRING - (Optional) Localized Title + * 5: CODE - (Optional) Code to check each frame + * 6: ARRAY - (Optional) Exceptions for checking EFUNC(common,canInteractWith) + * + * Return value: + * Nothing + * + * Example: + * [5, [], {Hint "Finished!"}, {hint "Failure!"}, "My Title"] call ace_common_fnc_progressBar + */ #include "script_component.hpp" @@ -36,65 +36,69 @@ createDialog QGVAR(ProgressBar_Dialog); (uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlSetText _localizedTitle; if (GVAR(SettingProgressBarLocation) == 1) then { - private "_ctrlPos"; - _ctrlPos = [1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2), 29 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2), 38 * (((safezoneW / safezoneH) min 1.2) / 40), 0.8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)]; - (uiNamespace getVariable QGVAR(ctrlProgressBar)) ctrlSetPosition _ctrlPos; - (uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlSetPosition _ctrlPos; - (uiNamespace getVariable QGVAR(ctrlProgressBar)) ctrlCommit 0; - (uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlCommit 0; + private "_ctrlPos"; + _ctrlPos = [1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2), 29 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2), 38 * (((safezoneW / safezoneH) min 1.2) / 40), 0.8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)]; + (uiNamespace getVariable QGVAR(ctrlProgressBar)) ctrlSetPosition _ctrlPos; + (uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlSetPosition _ctrlPos; + (uiNamespace getVariable QGVAR(ctrlProgressBar)) ctrlCommit 0; + (uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlCommit 0; }; _perFrameFunction = { - PARAMS_2(_parameters,_pfhID); - EXPLODE_8_PVT(_parameters,_args,_onFinish,_onFail,_condition,_player,_startTime,_totalTime,_exceptions); - private ["_elapsedTime", "_errorCode"]; + PARAMS_2(_parameters,_pfhID); + EXPLODE_8_PVT(_parameters,_args,_onFinish,_onFail,_condition,_player,_startTime,_totalTime,_exceptions); + private ["_elapsedTime", "_errorCode"]; - _elapsedTime = time - _startTime; - _errorCode = -1; + _elapsedTime = time - _startTime; + _errorCode = -1; - if (isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then { - _errorCode = 1; - } else { - if (ACE_player != _player) then { - _errorCode = 2; + if (isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then { + _errorCode = 1; } else { - if (!([_args, _elapsedTime, _totalTime, _errorCode] call _condition)) then { - _errorCode = 3; - } else { - if (!([_player, objNull, _exceptions] call EGVAR(common,canInteractWith))) then { - _errorCode = 4; + if (ACE_player != _player) then { + _errorCode = 2; } else { - if (_elapsedTime >= _totalTime) then { - _errorCode = 0; - }; + if (!([_args, _elapsedTime, _totalTime, _errorCode] call _condition)) then { + _errorCode = 3; + } else { + if (!([_player, objNull, _exceptions] call EFUNC(common,canInteractWith))) then { + _errorCode = 4; + } else { + if (_elapsedTime >= _totalTime) then { + _errorCode = 0; + }; + }; + }; }; - }; }; - }; - if (_errorCode != -1) then { - //Error or Success, close dialog and remove PFEH - closeDialog 0; - [_pfhID] call CBA_fnc_removePerFrameHandler; + if (_errorCode != -1) then { + //Error or Success, close dialog and remove PFEH - if (_errorCode == 0) then { - if ((typeName _onFinish) == (typeName "")) then { - [_onFinish, [_args, _elapsedTime, _totalTime, _errorCode]] call FUNC(localEvent); - } else { - [_args, _elapsedTime, _totalTime, _errorCode] call _onFinish; - }; + //Only close dialog if it's the progressBar: + if (!isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then { + closeDialog 0; + }; + [_pfhID] call CBA_fnc_removePerFrameHandler; + + if (_errorCode == 0) then { + if ((typeName _onFinish) == (typeName "")) then { + [_onFinish, [_args, _elapsedTime, _totalTime, _errorCode]] call FUNC(localEvent); + } else { + [_args, _elapsedTime, _totalTime, _errorCode] call _onFinish; + }; + } else { + if ((typeName _onFail) == (typeName "")) then { + [_onFail, [_args, _elapsedTime, _totalTime, _errorCode]] call FUNC(localEvent); + } else { + [_args, _elapsedTime, _totalTime, _errorCode] call _onFail; + }; + }; } else { - if ((typeName _onFail) == (typeName "")) then { - [_onFail, [_args, _elapsedTime, _totalTime, _errorCode]] call FUNC(localEvent); - } else { - [_args, _elapsedTime, _totalTime, _errorCode] call _onFail; - }; + //Update Progress Bar (ratio of elepased:total) + (uiNamespace getVariable QGVAR(ctrlProgressBar)) progressSetPosition (_elapsedTime / _totalTime); }; - } else { - //Update Progress Bar (ratio of elepased:total) - (uiNamespace getVariable QGVAR(ctrlProgressBar)) progressSetPosition (_elapsedTime / _totalTime); - }; }; [_perFrameFunction, 0, [_args, _onFinish, _onFail, _condition, _player, time, _totalTime, _exceptions]] call CBA_fnc_addPerFrameHandler;