From 5e932f8c712bf654e08c638bb119bb67cf6ee418 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Mon, 26 Jan 2015 00:24:33 -0600 Subject: [PATCH] Replace calls to progressBar Mag repack Defuse Swap Barrel --- addons/common/ProgressScreen.hpp | 25 +--- addons/common/XEH_preInit.sqf | 1 - addons/common/functions/fnc_progressBar.sqf | 122 ++++++++++-------- addons/common/functions/fnc_progressBar2.sqf | 80 ------------ .../explosives/functions/fnc_startDefuse.sqf | 13 +- .../functions/fnc_openSelectMagazineUI.sqf | 2 +- .../overheating/functions/fnc_swapBarrel.sqf | 2 +- 7 files changed, 85 insertions(+), 160 deletions(-) delete mode 100644 addons/common/functions/fnc_progressBar2.sqf diff --git a/addons/common/ProgressScreen.hpp b/addons/common/ProgressScreen.hpp index 8b13921e38..31184f00f4 100644 --- a/addons/common/ProgressScreen.hpp +++ b/addons/common/ProgressScreen.hpp @@ -28,37 +28,26 @@ class GVAR(ProgressBar_Dialog) { h = "safezoneH"; }; - class Progress: ACE_gui_RscProgress { idc = 1; x = "1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)"; - y = "5 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; + y = "0.1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; w = "38 * (((safezoneW / safezoneH) min 1.2) / 40)"; - h = "0.5 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; - colorFrame[] = {0,0,0,0}; - colorBar[] = {0.27,0.5,0.31,0.6}; - // colorBar[] = {"(profilenamespace getvariable ['GUI_BCG_RGB_R',0.69])","(profilenamespace getvariable ['GUI_BCG_RGB_G',0.75])","(profilenamespace getvariable ['GUI_BCG_RGB_B',0.5])", "(profilenamespace getvariable ['GUI_BCG_RGB_A',0.9])"}; + h = ".8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + colorFrame[] = {0,0,0,0.025}; + colorBar[] = {0.27,0.5,0.31,0.8}; texture = "#(argb,8,8,3)color(1,1,1,0.7)"; }; class Title_Bar : ACE_gui_staticBase { idc = 2; - //type = 13; - //size = 1; + style = 0x22; colorBackground[] = {0, 0, 0, 0}; + colorText[] = {1, 1, 1, 1}; x = "1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)"; - y = "4 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; + y = "0 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; w = "38 * (((safezoneW / safezoneH) min 1.2) / 40)"; h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; - class Attributes { - font = "TahomaB"; - color = "#000000"; - align = "center"; - valign = "middle"; - shadow = false; - shadowColor = "#ff0000"; - size = "1"; - }; }; }; }; diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index bbf587f9a3..ae6a343df9 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -93,7 +93,6 @@ PREP(owned); PREP(player); PREP(playerSide); PREP(progressBar); -PREP(progressBar2); PREP(queueAnimation); PREP(readBooleanParameterFromModule); PREP(readNumericParameterFromModule); diff --git a/addons/common/functions/fnc_progressBar.sqf b/addons/common/functions/fnc_progressBar.sqf index a50b1ecfdd..ca9187c86f 100644 --- a/addons/common/functions/fnc_progressBar.sqf +++ b/addons/common/functions/fnc_progressBar.sqf @@ -1,61 +1,81 @@ /* - * 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 - */ +* 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 - Finish: Code called or STRING raised as event. +* 3: CODE or STRING - Failure: Code called or STRING raised as event. +* 4: STRING - Localized Title +* 5: CODE - Code to check each frame +* +* Return value: +* Nothing +*/ + #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; createDialog QGVAR(ProgressBar_Dialog); +(uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlSetText _localizedTitle; -_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 QGVAR(ctrlProgressBar); - _ctrlProgressBarTitle = uiNamespace getVariable QGVAR(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 [QGVAR(ctrlProgressBar), controlNull])) || {!alive ACE_player} || {time > _time} - }; - - closeDialog 0; - - _progress = 1; - if (time > _time) then { - _arguments call _function; +_perFrameFunction = { + PARAMS_2(_parameters,_pfhID); + EXPLODE_7_PVT(_parameters,_args,_onFinish,_onFail,_condition,_player,_startTime,_totalTime); + private ["_elapsedTime", "_errorCode"]; + + _elapsedTime = time - _startTime; + _errorCode = -1; + + if (isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then { + _errorCode = 1; } else { - [localize QUOTE(DOUBLES(STR,GVAR(ActionAborted)))] call FUNC(displayTextStructured); - if (!isNil "_function2") then { - _progress = 1 - ((_time - time) / (_this select 0)) max 0 min 1; - _arguments call _function2; + if (ACE_player != _player) then { + _errorCode = 2; + } else { + 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; diff --git a/addons/common/functions/fnc_progressBar2.sqf b/addons/common/functions/fnc_progressBar2.sqf deleted file mode 100644 index d271f30a73..0000000000 --- a/addons/common/functions/fnc_progressBar2.sqf +++ /dev/null @@ -1,80 +0,0 @@ -/* -* Author: commy2, Glowbal, PabstMirror -* -* Draw progress bar and execute given function if succesful. -* -* Argument: -* 0: NUMBER - Total Time (in game "time" seconds) -* 1: ARRAY - Arguments, passed to condition, fail and finish -* 2: CODE or STRING - Finish: Code called or STRING raised as event. -* 3: CODE or STRING - Failure: Code called or STRING raised as event. -* 4: STRING - Localized Title -* 5: CODE - Code to check each frame -* -* Return value: -* Nothing -*/ - -#define DEBUG_MODE_FULL - -#include "script_component.hpp" - -PARAMS_4(_totalTime,_args,_onFinish,_onFail); -DEFAULT_PARAM(4,_localizedTitle,""); -DEFAULT_PARAM(5,_condition,{true}); -_player = ACE_player; - -closeDialog 0; -createDialog QGVAR(ProgressBar_Dialog); - -(uiNamespace getVariable QGVAR(ctrlProgressBarTitle)) ctrlSetText _localizedTitle; - -_perFrameFunction = { - PARAMS_2(_parameters,_pfhID); - EXPLODE_7_PVT(_parameters,_args,_onFinish,_onFail,_condition,_player,_startTime,_totalTime); - - _elapsedTime = time - _startTime; - - _errorCode = -1; - if (isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then { - _errorCode = 1; - } else { - if (ACE_player != _player) then { - _errorCode = 2; - } else { - if (!([_args, _elapsedTime, _totalTime] call _condition)) then { - _errorCode = 3; - } else { - if (_elapsedTime >= _totalTime) then { - _errorCode = 0; - }; - }; - }; - }; - - if (_errorCode != -1) then { - closeDialog 0; - [_pfhID] call CBA_fnc_removePerFrameHandler; - if (_errorCode == 0) then { - if (typeName _onFinish == typeName "") then { - [_onFinish, [_args, _elapsedTime, _totalTime, _errorCode]] call EFUNC(common,localEvent); - } else { - [_args, _elapsedTime, _totalTime, _errorCode] call _onFinish; - }; - } else { - if (typeName _onFail == typeName "") then { - [_onFail, [_args, _elapsedTime, _totalTime, _errorCode]] call EFUNC(common,localEvent); - } else { - [_args, _elapsedTime, _totalTime, _errorCode] call _onFail; - }; - }; - } else { - //Update Progress Bar - _progress = _elapsedTime / _totalTime; - systemChat str _progress; - systemChat str (uiNamespace getVariable QGVAR(ctrlProgressBar)); - (uiNamespace getVariable QGVAR(ctrlProgressBar)) progressSetPosition _progress; - }; -}; - -[_perFrameFunction, 0, [_args, _onFinish, _onFail, _condition, _player, time, _totalTime]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/explosives/functions/fnc_startDefuse.sqf b/addons/explosives/functions/fnc_startDefuse.sqf index 7908c3138c..7213da531c 100644 --- a/addons/explosives/functions/fnc_startDefuse.sqf +++ b/addons/explosives/functions/fnc_startDefuse.sqf @@ -56,13 +56,10 @@ if (ACE_player != _unit) then { }; } else { _unit playActionNow _actionToPlay; - if (GVAR(RequireSpecialist)) then { - if ([_unit] call EFUNC(Common,isEOD)) then { - [[true, _target] call _fnc_DefuseTime, [_unit,_target], - QFUNC(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); + private ["_defuseSeconds", "_isEOD"]; + _isEOD = [_unit] call EFUNC(Common,isEOD); + _defuseSeconds = [_isEOD, _target] call _fnc_DefuseTime; + if (_isEOD || {!GVAR(RequireSpecialist)}) then { + [_defuseSeconds, [_unit,_target], {(_this select 0) call FUNC(defuseExplosive)}, {}, (localize "STR_ACE_Explosives_DefusingExplosive")] call EFUNC(common,progressBar); }; }; diff --git a/addons/magazinerepack/functions/fnc_openSelectMagazineUI.sqf b/addons/magazinerepack/functions/fnc_openSelectMagazineUI.sqf index 362be7476b..b1a31c266c 100644 --- a/addons/magazinerepack/functions/fnc_openSelectMagazineUI.sqf +++ b/addons/magazinerepack/functions/fnc_openSelectMagazineUI.sqf @@ -30,7 +30,7 @@ for "_index" from 0 to (_count - 1) do { call EFUNC(interaction,hideMenu); if (isNil "_data") exitWith {}; _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); }, { diff --git a/addons/overheating/functions/fnc_swapBarrel.sqf b/addons/overheating/functions/fnc_swapBarrel.sqf index 1b8c75b71f..6bacbe5049 100644 --- a/addons/overheating/functions/fnc_swapBarrel.sqf +++ b/addons/overheating/functions/fnc_swapBarrel.sqf @@ -21,4 +21,4 @@ _player playActionNow "GestureDismountMuzzle"; _player playAction "GestureMountMuzzle"; 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);