ACE3/addons/core/functions/fn_progressBar.sqf

61 lines
1.7 KiB
Plaintext

/*
* Author: commy2
*
* Draw progress bar and execute given function if succesful.
*
* Argument:
* 0: Duration of the action (Number)
* 1: Arguments of the callback function (Array)
* 2: Callback function name (String)
* 3: Title of the loading bar (String)
* 4: Name of the function that is called when the action is aborted via ESC (String, optional)
*
* Return value:
* Nothing
*/
closeDialog 0;
createDialog "GVAR(ProgressBar_Dialog)";
_this spawn {
_time = _this select 0;
_arguments = _this select 1;
_function = call compile (_this select 2);
_title = _this select 3;
_function2 = call compile (_this select 4);
disableSerialization;
_ctrlProgressBar = uiNamespace getVariable "GVAR(ctrlProgressBar)";
_ctrlProgressBarTitle = uiNamespace getVariable "GVAR(ctrlProgressBarTitle)";
_ctrlProgressBar ctrlSetPosition [
safezoneX + 0.1 * safezoneW,
safezoneY + 0.2 * safezoneH,
0.8 * safezoneW,
0.01 * safezoneH
];
_ctrlProgressBar ctrlCommit (_time / accTime);
_ctrlProgressBarTitle ctrlSetText _title;
//_ctrlProgressBarTitle ctrlSetStructuredText _title;
_time = time + _time;
waitUntil {
//make sure the progressBar is still open, not just any dialog
(isNull (uiNamespace getVariable ["GVAR(ctrlProgressBar)", controlNull])) || {!alive AGM_player} || {time > _time}
};
closeDialog 0;
_progress = 1;
if (time > _time) then {
_arguments call _function;
} else {
[localize "STR_GVAR(ActionAborted)"] call GVAR(fnc_displayTextStructured);
if (!isNil "_function2") then {
_progress = 1 - ((_time - time) / (_this select 0)) max 0 min 1;
_arguments call _function2;
};
};
};