Merge pull request #93 from KoffeinFlummi/progresBarNew

#87 - New Progress Bar
This commit is contained in:
PabstMirror 2015-01-27 19:28:51 -06:00
commit bf791e32c4
5 changed files with 149 additions and 146 deletions

View File

@ -1,3 +1,6 @@
class ACE_gui_RscProgress;
class ACE_gui_staticBase;
class GVAR(ProgressBar_Dialog) { class GVAR(ProgressBar_Dialog) {
idd = -1; idd = -1;
@ -25,43 +28,26 @@ class GVAR(ProgressBar_Dialog) {
h = "safezoneH"; h = "safezoneH";
}; };
class Progress_Bar { class Progress: ACE_gui_RscProgress {
idc = 1; idc = 1;
moving = 0; x = "1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)";
text = ""; y = "0.1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)";
font = "PuristaMedium"; w = "38 * (((safezoneW / safezoneH) min 1.2) / 40)";
sizeEx = "1 / 40 / (getResolution select 5)";// * safezoneX / safezoneXAbs"; h = ".8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";
lineSpacing = 0; colorFrame[] = {0,0,0,0.025};
access = 0; colorBar[] = {0.27,0.5,0.31,0.8};
type = 0; texture = "#(argb,8,8,3)color(1,1,1,0.7)";
style = 2;
size = 1;
colorBackground[] = {1, 0.647, 0, 0.5};
colorText[] = {1,1,1,1};
x = "safezoneX + 0.1 * safezoneW";
y = "safezoneY + 0.2 * safezoneH";
w = "0.0 * safezoneW";
h = "0.01 * safezoneH";
}; };
class Title_Bar : Progress_Bar { class Title_Bar : ACE_gui_staticBase {
idc = 2; idc = 2;
//type = 13; style = 0x22;
//size = 1;
colorBackground[] = {0, 0, 0, 0}; colorBackground[] = {0, 0, 0, 0};
x = "safezoneX + 0.1 * safezoneW"; colorText[] = {1, 1, 1, 1};
y = "safezoneY + 0.1 * safezoneH"; x = "1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)";
w = "0.8 * safezoneW"; y = "0 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)";
h = "0.05 * safezoneH"; w = "38 * (((safezoneW / safezoneH) min 1.2) / 40)";
/*class Attributes { h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)";
font = "TahomaB";
color = "#000000";
align = "center";
valign = "middle";
shadow = false;
shadowColor = "#ff0000";
size = "1";
};*/
}; };
}; };
}; };

View File

@ -1,61 +1,81 @@
/* /*
* Author: commy2 * Author: commy2, Glowbal, PabstMirror
* *
* Draw progress bar and execute given function if succesful. * Draw progress bar and execute given function if succesful.
* * Finish/Failure/Conditional are all passed [_args, _elapsedTime, _totalTime, _errorCode]
* Argument: *
* 0: Duration of the action (Number) * Argument:
* 1: Arguments of the callback function (Array) * 0: NUMBER - Total Time (in game "time" seconds)
* 2: Callback function name (String) * 1: ARRAY - Arguments, passed to condition, fail and finish
* 3: Title of the loading bar (String) * 2: CODE or STRING - Finish: Code called or STRING raised as event.
* 4: Name of the function that is called when the action is aborted via ESC (String, optional) * 3: CODE or STRING - Failure: Code called or STRING raised as event.
* * 4: STRING - Localized Title
* Return value: * 5: CODE - Code to check each frame
* Nothing *
*/ * Return value:
* Nothing
*/
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_4(_totalTime,_args,_onFinish,_onFail);
DEFAULT_PARAM(4,_localizedTitle,"");
DEFAULT_PARAM(5,_condition,{true});
private ["_player", "_perFrameFunction"];
_player = ACE_player;
//Open Dialog and set the title
closeDialog 0; closeDialog 0;
createDialog QGVAR(ProgressBar_Dialog); createDialog QGVAR(ProgressBar_Dialog);
(uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlSetText _localizedTitle;
_this spawn { _perFrameFunction = {
_time = _this select 0; PARAMS_2(_parameters,_pfhID);
_arguments = _this select 1; EXPLODE_7_PVT(_parameters,_args,_onFinish,_onFail,_condition,_player,_startTime,_totalTime);
_function = call compile (_this select 2); private ["_elapsedTime", "_errorCode"];
_title = _this select 3;
_function2 = call compile (_this select 4);
disableSerialization; _elapsedTime = time - _startTime;
_ctrlProgressBar = uiNamespace getVariable QGVAR(ctrlProgressBar); _errorCode = -1;
_ctrlProgressBarTitle = uiNamespace getVariable QGVAR(ctrlProgressBarTitle);
_ctrlProgressBar ctrlSetPosition [ if (isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then {
safezoneX + 0.1 * safezoneW, _errorCode = 1;
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 [QGVAR(ctrlProgressBar), controlNull])) || {!alive ACE_player} || {time > _time}
};
closeDialog 0;
_progress = 1;
if (time > _time) then {
_arguments call _function;
} else { } else {
[localize QUOTE(DOUBLES(STR,GVAR(ActionAborted)))] call FUNC(displayTextStructured); if (ACE_player != _player) then {
if (!isNil "_function2") then { _errorCode = 2;
_progress = 1 - ((_time - time) / (_this select 0)) max 0 min 1; } else {
_arguments call _function2; if (!([_args, _elapsedTime, _totalTime, _errorCode] call _condition)) then {
_errorCode = 3;
} 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 == 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 {
//Update Progress Bar (ratio of elepased:total)
(uiNamespace getVariable QGVAR(ctrlProgressBar)) progressSetPosition (_elapsedTime / _totalTime);
};
}; };
[_perFrameFunction, 0, [_args, _onFinish, _onFail, _condition, _player, time, _totalTime]] call CBA_fnc_addPerFrameHandler;

View File

@ -56,13 +56,10 @@ if (ACE_player != _unit) then {
}; };
} else { } else {
_unit playActionNow _actionToPlay; _unit playActionNow _actionToPlay;
if (GVAR(RequireSpecialist)) then { private ["_defuseSeconds", "_isEOD"];
if ([_unit] call EFUNC(Common,isEOD)) then { _isEOD = [_unit] call EFUNC(Common,isEOD);
[[true, _target] call _fnc_DefuseTime, [_unit,_target], _defuseSeconds = [_isEOD, _target] call _fnc_DefuseTime;
QFUNC(defuseExplosive), localize "STR_ACE_Explosives_DefusingExplosive"] call EFUNC(common,progressBar); if (_isEOD || {!GVAR(RequireSpecialist)}) then {
}; [_defuseSeconds, [_unit,_target], {(_this select 0) call FUNC(defuseExplosive)}, {}, (localize "STR_ACE_Explosives_DefusingExplosive")] call EFUNC(common,progressBar);
} else {
[[([_unit] call EFUNC(Common,isEOD)), _target] call _fnc_DefuseTime, [_unit,_target],
QFUNC(defuseExplosive), localize "STR_ACE_Explosives_DefusingExplosive"] call EFUNC(common,progressBar);
}; };
}; };

View File

@ -30,7 +30,7 @@ for "_index" from 0 to (_count - 1) do {
call EFUNC(interaction,hideMenu); call EFUNC(interaction,hideMenu);
if (isNil "_data") exitWith {}; if (isNil "_data") exitWith {};
_data set [2, [_data select 2] call EFUNC(common,toNumber)]; _data set [2, [_data select 2] call EFUNC(common,toNumber)];
[_data select 2, _data, QFUNC(magazineRepackCallback), localize "STR_ACE_MagazineRepack_RepackingMagazine"] call EFUNC(common,progressBar); [(_data select 2), _data, {(_this select 0) call FUNC(magazineRepackCallback)}, {}, (localize "STR_ACE_MagazineRepack_RepackingMagazine")] call EFUNC(common,progressBar);
[ACE_player] call EFUNC(common,goKneeling); [ACE_player] call EFUNC(common,goKneeling);
}, },
{ {

View File

@ -21,4 +21,4 @@ _player playActionNow "GestureDismountMuzzle";
_player playAction "GestureMountMuzzle"; _player playAction "GestureMountMuzzle";
playSound "ACE_BarrelSwap"; playSound "ACE_BarrelSwap";
[10, [_player, _weapon], QFUNC(swapBarrelCallback), localize "STR_ACE_Overheating_SwappingBarrel"] call EFUNC(common,progressBar); [10, [_player, _weapon], {(_this select 0) call FUNC(swapBarrelCallback)}, {}, (localize "STR_ACE_Overheating_SwappingBarrel")] call EFUNC(common,progressBar);