ACE3/addons/common/functions/fnc_progressBar.sqf

101 lines
4.1 KiB
Plaintext
Raw Normal View History

/*
2015-03-20 22:46:21 +00:00
* Author: commy2, Glowbal, PabstMirror
* Draw progress bar and execute given function if succesful.
* Finish/Failure/Conditional are all passed [_args, _elapsedTime, _totalTime, _errorCode]
*
2015-09-18 23:50:17 +00:00
* Arguments:
* 0: NUMBER - Total Time (in game "time" seconds)
2015-03-20 22:46:21 +00:00
* 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)
*
2015-09-18 23:50:17 +00:00
* Return Value:
2015-03-20 22:46:21 +00:00
* Nothing
*
* Example:
* [5, [], {Hint "Finished!"}, {hint "Failure!"}, "My Title"] call ace_common_fnc_progressBar
2015-09-18 23:50:17 +00:00
*
* Public: Yes
2015-03-20 22:46:21 +00:00
*/
2015-01-13 19:56:02 +00:00
#include "script_component.hpp"
2015-09-18 23:50:17 +00:00
params ["_totalTime", "_args", "_onFinish", "_onFail", ["_localizedTitle", ""], ["_condition", {true}], ["_exceptions", []]];
private _player = ACE_player;
//Open Dialog and set the title
closeDialog 0;
2015-01-11 18:20:14 +00:00
createDialog QGVAR(ProgressBar_Dialog);
2015-09-18 23:50:17 +00:00
(uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlSetText _localizedTitle;
2015-04-15 17:55:16 +00:00
//Adjust position based on user setting:
private _ctrlPos = ctrlPosition (uiNamespace getVariable QGVAR(ctrlProgressBarTitle));
2015-04-15 17:55:16 +00:00
_ctrlPos set [1, ((0 + 29 * GVAR(SettingProgressBarLocation)) * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2))];
2015-04-17 14:51:43 +00:00
(uiNamespace getVariable QGVAR(ctrlProgressBG)) ctrlSetPosition _ctrlPos;
(uiNamespace getVariable QGVAR(ctrlProgressBG)) ctrlCommit 0;
2015-04-15 17:55:16 +00:00
(uiNamespace getVariable QGVAR(ctrlProgressBar)) ctrlSetPosition _ctrlPos;
(uiNamespace getVariable QGVAR(ctrlProgressBar)) ctrlCommit 0;
2015-04-17 14:51:43 +00:00
(uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlSetPosition _ctrlPos;
(uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlCommit 0;
[{
2015-09-18 23:50:17 +00:00
(_this select 0) params ["_args", "_onFinish", "_onFail", "_condition", "_player", "_startTime", "_totalTime", "_exceptions"];
private _elapsedTime = ACE_time - _startTime;
private _errorCode = -1;
2015-03-22 13:05:31 +00:00
// this does not check: target fell unconscious, target died, target moved inside vehicle / left vehicle, target moved outside of players range, target moves at all.
2015-03-20 22:46:21 +00:00
if (isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then {
_errorCode = 1;
} else {
if (ACE_player != _player || !alive _player) then {
2015-03-20 22:46:21 +00:00
_errorCode = 2;
} else {
2015-09-18 23:50:17 +00:00
if !([_args, _elapsedTime, _totalTime, _errorCode] call _condition) then {
2015-03-20 22:46:21 +00:00
_errorCode = 3;
} else {
2015-09-18 23:50:17 +00:00
if !([_player, objNull, _exceptions] call EFUNC(common,canInteractWith)) then {
2015-03-20 22:46:21 +00:00
_errorCode = 4;
} else {
if (_elapsedTime >= _totalTime) then {
_errorCode = 0;
};
};
};
};
};
2015-03-20 22:46:21 +00:00
if (_errorCode != -1) then {
//Error or Success, close dialog and remove PFEH
2015-03-20 22:46:21 +00:00
//Only close dialog if it's the progressBar:
if (!isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then {
closeDialog 0;
};
2015-09-18 23:50:17 +00:00
[_this select 1] call CBA_fnc_removePerFrameHandler;
2015-03-20 22:46:21 +00:00
if (_errorCode == 0) then {
if (_onFinish isEqualType "") then {
2015-03-20 22:46:21 +00:00
[_onFinish, [_args, _elapsedTime, _totalTime, _errorCode]] call FUNC(localEvent);
} else {
[_args, _elapsedTime, _totalTime, _errorCode] call _onFinish;
};
} else {
if (_onFail isEqualType "") then {
2015-03-20 22:46:21 +00:00
[_onFail, [_args, _elapsedTime, _totalTime, _errorCode]] call FUNC(localEvent);
} else {
[_args, _elapsedTime, _totalTime, _errorCode] call _onFail;
};
};
} else {
2015-03-20 22:46:21 +00:00
//Update Progress Bar (ratio of elepased:total)
(uiNamespace getVariable QGVAR(ctrlProgressBar)) progressSetPosition (_elapsedTime / _totalTime);
};
}, 0, [_args, _onFinish, _onFail, _condition, _player, ACE_time, _totalTime, _exceptions]] call CBA_fnc_addPerFrameHandler;