From b82ad528bb90cce6964485030d856e2954f4e49d Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 21 Apr 2018 19:51:21 +0200 Subject: [PATCH 01/18] add CBA_fnc_progressBar --- addons/ui/CfgFunctions.hpp | 1 + addons/ui/ProgressBar.hpp | 41 +++++++++ addons/ui/config.cpp | 3 +- addons/ui/fnc_progressBar.sqf | 156 +++++++++++++++++++++++++++++++++ addons/ui/script_component.hpp | 5 ++ 5 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 addons/ui/ProgressBar.hpp create mode 100644 addons/ui/fnc_progressBar.sqf diff --git a/addons/ui/CfgFunctions.hpp b/addons/ui/CfgFunctions.hpp index 6e35a8ebc..dbd309a30 100644 --- a/addons/ui/CfgFunctions.hpp +++ b/addons/ui/CfgFunctions.hpp @@ -18,6 +18,7 @@ class CfgFunctions { file = QUOTE(PATHTOF(flexiMenu\fnc_openMenuByDef.sqf)); }; PATHTO_FNC(addPauseMenuOption); + PATHTO_FNC(progressBar); }; }; }; diff --git a/addons/ui/ProgressBar.hpp b/addons/ui/ProgressBar.hpp new file mode 100644 index 000000000..318cbb339 --- /dev/null +++ b/addons/ui/ProgressBar.hpp @@ -0,0 +1,41 @@ +class RscText; +class RscProgress; + +class GVAR(ProgressBar) { + idd = -1; + controls[] = {"Background", "TitleBackground", "ProgressBar", "TitleText"}; + + class Background: RscText { + x = "safezoneXAbs"; + y = "safezoneY"; + w = "safezoneWAbs"; + h = "safezoneH"; + }; + + class TitleBackground: RscText { + style = ST_CENTER; + sizeEx = 1 * GUI_GRID_CENTER_H; + colorBackground[] = {0,0,0,0.5}; + x = 1 * GUI_GRID_CENTER_W + GUI_GRID_CENTER_X; + y = 0 * GUI_GRID_CENTER_H + GUI_GRID_CENTER_Y; + w = 38 * GUI_GRID_CENTER_W; + h = 1 * GUI_GRID_CENTER_H; + }; + + class TitleText: TitleBackground { + idc = IDC_PROGRESSBAR_TITLE; + colorBackground[] = {0,0,0,0}; + colorText[] = {1,1,1,1}; + }; + + class ProgressBar: RscProgress { + idc = IDC_PROGRESSBAR_BAR; + colorFrame[] = {0,0,0,0.5}; + colorBar[] = GUI_BCG_COLOR; + texture = "#(argb,8,8,3)color(1,1,1,0.7)"; + x = 1 * GUI_GRID_CENTER_W + GUI_GRID_CENTER_X; + y = 0 * GUI_GRID_CENTER_H + GUI_GRID_CENTER_Y; + w = 38 * GUI_GRID_CENTER_W; + h = 1 * GUI_GRID_CENTER_H; + }; +}; diff --git a/addons/ui/config.cpp b/addons/ui/config.cpp index 4bc0a57cc..ac6237d40 100644 --- a/addons/ui/config.cpp +++ b/addons/ui/config.cpp @@ -19,9 +19,10 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgFunctions.hpp" +#include "ProgressBar.hpp" + //----------------------------------------------------------------------------- // TODO: Delete these rsc/_flexiMenu_RscShortcutButton classes soon and transfer properties to menu classes, if any. -class RscText; class RscShortcutButton; class _flexiMenu_RscShortcutButton: RscShortcutButton { class HitZone { diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf new file mode 100644 index 000000000..bc255a4ba --- /dev/null +++ b/addons/ui/fnc_progressBar.sqf @@ -0,0 +1,156 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_display + +Description: + Opens a progress bar. Closes the currently active progress bar. + +Parameters: + _condition - Execute every frame. If reports false, close the progress bar + _time - Time for the progress bar to complete + _onSuccess - Script to execute if the progress bar completed + _onFailure - Script to execute if the progress bar was aborted prematurely + _arguments - Arguments passed to the scripts (optional, default: []) + _allowClose - Allow ESC key to abort the progress bar (optional, default: true) + _blockInput - (optional, default: true) + +Arguments: + _this - same as _arguments + +Returns: + Nothing + +Examples: + (begin example) + ["progress bar", {true}, 5, {hint "done"}, {hint "aborted"}] call CBA_fnc_display; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +if (!hasInterface) exitWith {}; + +if (canSuspend) exitWith { + isNil (uiNamespace getVariable _fnc_scriptName); + nil; +}; + +params [ + ["_title", "", [""]], + ["_condition", {}, [{}, ""]], + ["_time", 0, [0]], + ["_onSuccess", {}, [{}, ""]], + ["_onFailure", {}, [{}, ""]], + ["_arguments", []], + ["_allowClose", true, [false]], + ["_blockInput", true, [false]] +]; + +if (isLocalized _title) then { + _title = localize _title; +}; + +if (_condition isEqualType "") then { + _condition = compile _condition; +}; + +if (_onSuccess isEqualType "") then { + _onSuccess = compile _onSuccess; +}; + +if (_onFailure isEqualType "") then { + _onFailure = compile _onFailure; +}; + +private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; + +if (isNull _display) then { + // create new progress bar + _display = (uiNamespace getVariable "RscDisplayMission") createDisplay QGVAR(ProgressBar); + uiNamespace setVariable [QGVAR(ProgressBar), _display]; + + _display displayAddEventHandler ["KeyDown", { + params ["_display", "_key", "_shift", "_control", "_alt"]; + + private _arguments = _display getVariable QGVAR(arguments); + private _onFailure = _display getVariable QGVAR(onFailure); + + if (_key isEqualTo DIK_ESCAPE) then { + // close display, execute on failure script + [_display, _arguments, _onFailure] spawn { + isNil { + _this#0 closeDisplay 0; + _this#1 call _this#2; + }; + }; + }; + true + }]; + + private _fnc_check = { + params ["_display"]; + + private _arguments = _display getVariable QGVAR(arguments); + private _condition = _display getVariable QGVAR(condition); + + private _continue = [_arguments, _condition] call { + private ["_display", "_arguments", "_condition"]; + _this#0 call _this#1; + }; + + private _onSuccess = _display getVariable QGVAR(onSuccess); + private _onFailure = _display getVariable QGVAR(onFailure); + + if (!_continue) exitWith { + // close display, execute on failure script + [_display, _arguments, _onFailure] spawn { + isNil { + _this#0 closeDisplay 0; + _this#1 call _this#2; + }; + }; + }; + + private _startTime = _display getVariable QGVAR(start); + private _duration = _display getVariable QGVAR(duration); + private _runTime = CBA_missionTime - _startTime; + + if (_runTime > _duration) exitWith { + // close display, execute on success script + [_display, _arguments, _onSuccess] spawn { + isNil { + _this#0 closeDisplay 0; + _this#1 call _this#2; + }; + }; + }; + + private _ctrlBar = _display displayCtrl IDC_PROGRESSBAR_BAR; + _ctrlBar progressSetPosition (_runTime / _duration); + }; + + _display displayAddEventHandler ["MouseMoving", _fnc_check]; + _display displayAddEventHandler ["MouseHolding", _fnc_check]; +} else { + // run failure code on previous progress bar + private _arguments = _display getVariable QGVAR(arguments); + private _onFailure = _display getVariable QGVAR(onFailure); + + // close display, execute on failure script + [_arguments, _onFailure] spawn { + isNil { + _this#1 call _this#2; + }; + }; +}; + +private _ctrlTitle = _display displayCtrl IDC_PROGRESSBAR_TITLE; +_ctrlTitle ctrlSetText _title; + +_display setVariable [QGVAR(start), CBA_missionTime]; +_display setVariable [QGVAR(duration), _time]; +_display setVariable [QGVAR(arguments), _arguments]; +_display setVariable [QGVAR(condition), _condition]; +_display setVariable [QGVAR(onSuccess), _onSuccess]; +_display setVariable [QGVAR(onFailure), _onFailure]; diff --git a/addons/ui/script_component.hpp b/addons/ui/script_component.hpp index dcef8b91e..a1eb6db40 100644 --- a/addons/ui/script_component.hpp +++ b/addons/ui/script_component.hpp @@ -1,6 +1,7 @@ #define COMPONENT ui #include "\x\cba\addons\main\script_mod.hpp" +#define DISABLE_COMPILE_CACHE //#define DEBUG_ENABLED_UI #ifdef DEBUG_ENABLED_UI @@ -14,9 +15,13 @@ #include "\x\cba\addons\main\script_macros.hpp" #include "\a3\ui_f\hpp\defineCommonGrids.inc" +#include "\a3\ui_f\hpp\defineCommonColors.inc" #include "\a3\ui_f\hpp\defineDIKCodes.inc" #include "\a3\ui_f\hpp\defineResincl.inc" +#define IDC_PROGRESSBAR_TITLE 10 +#define IDC_PROGRESSBAR_BAR 11 + #define IDC_ADDON_CONTROLS 127303 #define IDC_ADDON_OPTIONS 127307 From 31917a37a737e2e3a08ba1ad7d688fb9976b7fc8 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 21 Apr 2018 21:13:09 +0200 Subject: [PATCH 02/18] allow close, block input --- addons/ui/fnc_progressBar.sqf | 43 ++++++++++++++++++---------------- addons/ui/script_component.hpp | 3 ++- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index bc255a4ba..23f983767 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -5,6 +5,7 @@ Description: Opens a progress bar. Closes the currently active progress bar. Parameters: + _title - Title of the progress bar _condition - Execute every frame. If reports false, close the progress bar _time - Time for the progress bar to complete _onSuccess - Script to execute if the progress bar completed @@ -75,17 +76,21 @@ if (isNull _display) then { private _arguments = _display getVariable QGVAR(arguments); private _onFailure = _display getVariable QGVAR(onFailure); + private _allowClose = _display getVariable QGVAR(allowClose); + private _blockInput = _display getVariable QGVAR(blockInput); + + if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { + _display closeDisplay 0; - if (_key isEqualTo DIK_ESCAPE) then { // close display, execute on failure script - [_display, _arguments, _onFailure] spawn { - isNil { - _this#0 closeDisplay 0; - _this#1 call _this#2; - }; + [_arguments, _onFailure] spawn { + isNil {_this#0 call _this#1}; }; + + _blockInput = true; }; - true + + _blockInput }]; private _fnc_check = { @@ -103,12 +108,11 @@ if (isNull _display) then { private _onFailure = _display getVariable QGVAR(onFailure); if (!_continue) exitWith { + _display closeDisplay 0; + // close display, execute on failure script - [_display, _arguments, _onFailure] spawn { - isNil { - _this#0 closeDisplay 0; - _this#1 call _this#2; - }; + [_arguments, _onFailure] spawn { + isNil {_this#0 call _this#1}; }; }; @@ -117,12 +121,11 @@ if (isNull _display) then { private _runTime = CBA_missionTime - _startTime; if (_runTime > _duration) exitWith { + _display closeDisplay 0; + // close display, execute on success script - [_display, _arguments, _onSuccess] spawn { - isNil { - _this#0 closeDisplay 0; - _this#1 call _this#2; - }; + [_arguments, _onSuccess] spawn { + isNil {_this#0 call _this#1}; }; }; @@ -139,9 +142,7 @@ if (isNull _display) then { // close display, execute on failure script [_arguments, _onFailure] spawn { - isNil { - _this#1 call _this#2; - }; + isNil {_this#0 call _this#1}; }; }; @@ -154,3 +155,5 @@ _display setVariable [QGVAR(arguments), _arguments]; _display setVariable [QGVAR(condition), _condition]; _display setVariable [QGVAR(onSuccess), _onSuccess]; _display setVariable [QGVAR(onFailure), _onFailure]; +_display setVariable [QGVAR(allowClose), _allowClose]; +_display setVariable [QGVAR(blockInput), _blockInput]; diff --git a/addons/ui/script_component.hpp b/addons/ui/script_component.hpp index a1eb6db40..5a364eda2 100644 --- a/addons/ui/script_component.hpp +++ b/addons/ui/script_component.hpp @@ -1,7 +1,8 @@ #define COMPONENT ui #include "\x\cba\addons\main\script_mod.hpp" -#define DISABLE_COMPILE_CACHE +//#define DEBUG_MODE_FULL +//#define DISABLE_COMPILE_CACHE //#define DEBUG_ENABLED_UI #ifdef DEBUG_ENABLED_UI From 47794d54a34b1591207cd292490be38d5676d352 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 21 Apr 2018 22:04:39 +0200 Subject: [PATCH 03/18] add progress bar to layout editing menu --- addons/ui/CfgUIGrids.hpp | 30 ++++++++++++++++++++++++++++++ addons/ui/ProgressBar.hpp | 16 ++++++++-------- addons/ui/config.cpp | 1 + addons/ui/stringtable.xml | 8 ++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 addons/ui/CfgUIGrids.hpp diff --git a/addons/ui/CfgUIGrids.hpp b/addons/ui/CfgUIGrids.hpp new file mode 100644 index 000000000..69dbb249e --- /dev/null +++ b/addons/ui/CfgUIGrids.hpp @@ -0,0 +1,30 @@ +class CfgUIGrids { + class IGUI { + class Presets { + class Arma3 { + class Variables { + GVAR(grid)[] = { + { + 1 * GUI_GRID_CENTER_W + GUI_GRID_CENTER_X, + 0 * GUI_GRID_CENTER_H + GUI_GRID_CENTER_Y, + 38 * GUI_GRID_CENTER_W, + 1 * GUI_GRID_CENTER_H + }, + 0.5 * GUI_GRID_CENTER_W, + 0.5 * GUI_GRID_CENTER_H + }; + }; + }; + }; + + class Variables { + class GVAR(grid) { + displayName = CSTRING(ProgressBarPositionName); + description = CSTRING(ProgressBarPositionDescription); + preview = "#(argb,8,8,3)color(0,0,0,1)"; + saveToProfile[] = {0,1,2,3}; + canResize = 1; + }; + }; + }; +}; diff --git a/addons/ui/ProgressBar.hpp b/addons/ui/ProgressBar.hpp index 318cbb339..03ba7b146 100644 --- a/addons/ui/ProgressBar.hpp +++ b/addons/ui/ProgressBar.hpp @@ -16,10 +16,10 @@ class GVAR(ProgressBar) { style = ST_CENTER; sizeEx = 1 * GUI_GRID_CENTER_H; colorBackground[] = {0,0,0,0.5}; - x = 1 * GUI_GRID_CENTER_W + GUI_GRID_CENTER_X; - y = 0 * GUI_GRID_CENTER_H + GUI_GRID_CENTER_Y; - w = 38 * GUI_GRID_CENTER_W; - h = 1 * GUI_GRID_CENTER_H; + x = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),X)', 0]; + y = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),Y)', 0]; + w = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),W)', 0]; + h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; }; class TitleText: TitleBackground { @@ -33,9 +33,9 @@ class GVAR(ProgressBar) { colorFrame[] = {0,0,0,0.5}; colorBar[] = GUI_BCG_COLOR; texture = "#(argb,8,8,3)color(1,1,1,0.7)"; - x = 1 * GUI_GRID_CENTER_W + GUI_GRID_CENTER_X; - y = 0 * GUI_GRID_CENTER_H + GUI_GRID_CENTER_Y; - w = 38 * GUI_GRID_CENTER_W; - h = 1 * GUI_GRID_CENTER_H; + x = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),X)', 0]; + y = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),Y)', 0]; + w = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),W)', 0]; + h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; }; }; diff --git a/addons/ui/config.cpp b/addons/ui/config.cpp index ac6237d40..f9255d93c 100644 --- a/addons/ui/config.cpp +++ b/addons/ui/config.cpp @@ -20,6 +20,7 @@ class CfgPatches { #include "CfgFunctions.hpp" #include "ProgressBar.hpp" +#include "CfgUIGrids.hpp" //----------------------------------------------------------------------------- // TODO: Delete these rsc/_flexiMenu_RscShortcutButton classes soon and transfer properties to menu classes, if any. diff --git a/addons/ui/stringtable.xml b/addons/ui/stringtable.xml index 3ad2eb42f..c1577076d 100644 --- a/addons/ui/stringtable.xml +++ b/addons/ui/stringtable.xml @@ -9,5 +9,13 @@ Extensões de Base Comunitária - Interface ao Usuário Community Base Addons - Пользовательский Интерфейс + + Progress Bar + Fortschrittsanzeige + + + Position of the progress bar. + Position der Fortschrittsanzeige. + From 58c878d6cc157fe7538460af800bbf1a46bd8ab4 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 21 Apr 2018 22:18:19 +0200 Subject: [PATCH 04/18] don't carry over progress bar --- addons/ui/ProgressBar.hpp | 1 + addons/ui/fnc_progressBar.sqf | 121 ++++++++++++++++++---------------- 2 files changed, 66 insertions(+), 56 deletions(-) diff --git a/addons/ui/ProgressBar.hpp b/addons/ui/ProgressBar.hpp index 03ba7b146..d6a98c861 100644 --- a/addons/ui/ProgressBar.hpp +++ b/addons/ui/ProgressBar.hpp @@ -2,6 +2,7 @@ class RscText; class RscProgress; class GVAR(ProgressBar) { + onLoad = uiNamespace setVariable ['GVAR(ProgressBar)', _this select 0]; idd = -1; controls[] = {"Background", "TitleBackground", "ProgressBar", "TitleText"}; diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 23f983767..cb1237cd5 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -66,86 +66,95 @@ if (_onFailure isEqualType "") then { private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; -if (isNull _display) then { - // create new progress bar - _display = (uiNamespace getVariable "RscDisplayMission") createDisplay QGVAR(ProgressBar); - uiNamespace setVariable [QGVAR(ProgressBar), _display]; +if (!isNull _display) then { + // run failure code on previous progress bar + private _arguments = _display getVariable QGVAR(arguments); + private _onFailure = _display getVariable QGVAR(onFailure); + + // close display, execute on failure script + _display closeDisplay 0; + + [_arguments, _onFailure] spawn { + isNil { + _this#0 call _this#1; + }; + }; +}; + +// create new progress bar +_display = (uiNamespace getVariable "RscDisplayMission") createDisplay QGVAR(ProgressBar); - _display displayAddEventHandler ["KeyDown", { - params ["_display", "_key", "_shift", "_control", "_alt"]; +_display displayAddEventHandler ["KeyDown", { + params ["_display", "_key", "_shift", "_control", "_alt"]; - private _arguments = _display getVariable QGVAR(arguments); - private _onFailure = _display getVariable QGVAR(onFailure); - private _allowClose = _display getVariable QGVAR(allowClose); - private _blockInput = _display getVariable QGVAR(blockInput); + private _arguments = _display getVariable QGVAR(arguments); + private _onFailure = _display getVariable QGVAR(onFailure); + private _allowClose = _display getVariable QGVAR(allowClose); + private _blockInput = _display getVariable QGVAR(blockInput); - if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { - _display closeDisplay 0; + if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { + // close display, execute on failure script + _display closeDisplay 0; - // close display, execute on failure script - [_arguments, _onFailure] spawn { - isNil {_this#0 call _this#1}; + [_arguments, _onFailure] spawn { + isNil { + _this#0 call _this#1; }; - - _blockInput = true; }; - _blockInput - }]; + _blockInput = true; + }; + + _blockInput +}]; - private _fnc_check = { - params ["_display"]; +private _fnc_check = { + params ["_display"]; - private _arguments = _display getVariable QGVAR(arguments); - private _condition = _display getVariable QGVAR(condition); + private _arguments = _display getVariable QGVAR(arguments); + private _condition = _display getVariable QGVAR(condition); - private _continue = [_arguments, _condition] call { - private ["_display", "_arguments", "_condition"]; - _this#0 call _this#1; - }; + private _continue = [_arguments, _condition] call { + private ["_display", "_arguments", "_condition"]; + _this#0 call _this#1; + }; - private _onSuccess = _display getVariable QGVAR(onSuccess); - private _onFailure = _display getVariable QGVAR(onFailure); + private _onSuccess = _display getVariable QGVAR(onSuccess); + private _onFailure = _display getVariable QGVAR(onFailure); - if (!_continue) exitWith { - _display closeDisplay 0; + if (!_continue) exitWith { + // close display, execute on failure script + _display closeDisplay 0; - // close display, execute on failure script - [_arguments, _onFailure] spawn { - isNil {_this#0 call _this#1}; + [_arguments, _onFailure] spawn { + isNil { + _this#0 call _this#1; }; }; + }; - private _startTime = _display getVariable QGVAR(start); - private _duration = _display getVariable QGVAR(duration); - private _runTime = CBA_missionTime - _startTime; + private _startTime = _display getVariable QGVAR(start); + private _duration = _display getVariable QGVAR(duration); + private _runTime = CBA_missionTime - _startTime; - if (_runTime > _duration) exitWith { - _display closeDisplay 0; + if (_runTime > _duration) exitWith { + // close display, execute on success script + _display closeDisplay 0; - // close display, execute on success script - [_arguments, _onSuccess] spawn { - isNil {_this#0 call _this#1}; + [_arguments, _onSuccess] spawn { + isNil { + _this#0 call _this#1; }; }; - - private _ctrlBar = _display displayCtrl IDC_PROGRESSBAR_BAR; - _ctrlBar progressSetPosition (_runTime / _duration); }; - _display displayAddEventHandler ["MouseMoving", _fnc_check]; - _display displayAddEventHandler ["MouseHolding", _fnc_check]; -} else { - // run failure code on previous progress bar - private _arguments = _display getVariable QGVAR(arguments); - private _onFailure = _display getVariable QGVAR(onFailure); - - // close display, execute on failure script - [_arguments, _onFailure] spawn { - isNil {_this#0 call _this#1}; - }; + private _ctrlBar = _display displayCtrl IDC_PROGRESSBAR_BAR; + _ctrlBar progressSetPosition (_runTime / _duration); }; +_display displayAddEventHandler ["MouseMoving", _fnc_check]; +_display displayAddEventHandler ["MouseHolding", _fnc_check]; + private _ctrlTitle = _display displayCtrl IDC_PROGRESSBAR_TITLE; _ctrlTitle ctrlSetText _title; From 862ab94920e7fbc01bc6d7a855c8fee33862be64 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 21 Apr 2018 22:47:07 +0200 Subject: [PATCH 05/18] enable mouse during progress bar --- addons/ui/{ProgressBar.hpp => RscTitles.hpp} | 8 ++++++++ addons/ui/config.cpp | 2 +- addons/ui/fnc_progressBar.sqf | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-) rename addons/ui/{ProgressBar.hpp => RscTitles.hpp} (91%) diff --git a/addons/ui/ProgressBar.hpp b/addons/ui/RscTitles.hpp similarity index 91% rename from addons/ui/ProgressBar.hpp rename to addons/ui/RscTitles.hpp index d6a98c861..84552342a 100644 --- a/addons/ui/ProgressBar.hpp +++ b/addons/ui/RscTitles.hpp @@ -40,3 +40,11 @@ class GVAR(ProgressBar) { h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; }; }; + +class RscTitles { + class GVAR(ProgressBar): GVAR(ProgressBar) { + duration = 1e+011; + fadeIn = 0; + fadeOut = 0; + }; +}; diff --git a/addons/ui/config.cpp b/addons/ui/config.cpp index f9255d93c..cbbb4d0c4 100644 --- a/addons/ui/config.cpp +++ b/addons/ui/config.cpp @@ -19,7 +19,7 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgFunctions.hpp" -#include "ProgressBar.hpp" +#include "RscTitles.hpp" #include "CfgUIGrids.hpp" //----------------------------------------------------------------------------- diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index cb1237cd5..fd0b616ee 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -82,7 +82,12 @@ if (!isNull _display) then { }; // create new progress bar -_display = (uiNamespace getVariable "RscDisplayMission") createDisplay QGVAR(ProgressBar); +if (_blockInput) then { + _display = (uiNamespace getVariable "RscDisplayMission") createDisplay QGVAR(ProgressBar); +} else { + QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; + _display = uiNamespace getVariable QGVAR(ProgressBar); +}; _display displayAddEventHandler ["KeyDown", { params ["_display", "_key", "_shift", "_control", "_alt"]; From 87b26a11cd4ee4b1e37185af6594d01338bd7384 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 22 Apr 2018 08:39:06 +0200 Subject: [PATCH 06/18] fix function name --- addons/ui/fnc_progressBar.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index cb1237cd5..c58f2123f 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Function: CBA_fnc_display +Function: CBA_fnc_progressBar Description: Opens a progress bar. Closes the currently active progress bar. @@ -22,7 +22,7 @@ Returns: Examples: (begin example) - ["progress bar", {true}, 5, {hint "done"}, {hint "aborted"}] call CBA_fnc_display; + ["progress bar", {true}, 5, {hint "done"}, {hint "aborted"}] call CBA_fnc_progressBar; (end) Author: From e1c72f717b736204295798eb5c3d98c11bde1be4 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 22 Apr 2018 16:30:05 +0200 Subject: [PATCH 07/18] ellapsedTime, totalTime, success args like ACE progress bar --- addons/ui/fnc_progressBar.sqf | 52 ++++++++++++++++------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 977e797a8..0c8832a7b 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -7,7 +7,7 @@ Description: Parameters: _title - Title of the progress bar _condition - Execute every frame. If reports false, close the progress bar - _time - Time for the progress bar to complete + _totalTime - Time for the progress bar to complete _onSuccess - Script to execute if the progress bar completed _onFailure - Script to execute if the progress bar was aborted prematurely _arguments - Arguments passed to the scripts (optional, default: []) @@ -15,7 +15,11 @@ Parameters: _blockInput - (optional, default: true) Arguments: - _this - same as _arguments + _this: + #0 - same as _arguments + #1 - true: success, false: failure + #2 - elapsed time, not more than _totalTime + #3 - total time, same as _totalTime Returns: Nothing @@ -40,7 +44,7 @@ if (canSuspend) exitWith { params [ ["_title", "", [""]], ["_condition", {}, [{}, ""]], - ["_time", 0, [0]], + ["_totalTime", 0, [0]], ["_onSuccess", {}, [{}, ""]], ["_onFailure", {}, [{}, ""]], ["_arguments", []], @@ -98,14 +102,14 @@ _display displayAddEventHandler ["KeyDown", { private _blockInput = _display getVariable QGVAR(blockInput); if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { + private _startTime = _display getVariable QGVAR(startTime); + private _totalTime = _display getVariable QGVAR(totalTime); + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + // close display, execute on failure script _display closeDisplay 0; - [_arguments, _onFailure] spawn { - isNil { - _this#0 call _this#1; - }; - }; + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; _blockInput = true; }; @@ -119,8 +123,12 @@ private _fnc_check = { private _arguments = _display getVariable QGVAR(arguments); private _condition = _display getVariable QGVAR(condition); - private _continue = [_arguments, _condition] call { - private ["_display", "_arguments", "_condition"]; + private _startTime = _display getVariable QGVAR(startTime); + private _totalTime = _display getVariable QGVAR(totalTime); + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { + private ["_display", "_arguments", "_condition", "_startTime", "_totalTime", "_elapsedTime"]; _this#0 call _this#1; }; @@ -131,30 +139,18 @@ private _fnc_check = { // close display, execute on failure script _display closeDisplay 0; - [_arguments, _onFailure] spawn { - isNil { - _this#0 call _this#1; - }; - }; + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; - private _startTime = _display getVariable QGVAR(start); - private _duration = _display getVariable QGVAR(duration); - private _runTime = CBA_missionTime - _startTime; - - if (_runTime > _duration) exitWith { + if (_elapsedTime > _totalTime) exitWith { // close display, execute on success script _display closeDisplay 0; - [_arguments, _onSuccess] spawn { - isNil { - _this#0 call _this#1; - }; - }; + [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; private _ctrlBar = _display displayCtrl IDC_PROGRESSBAR_BAR; - _ctrlBar progressSetPosition (_runTime / _duration); + _ctrlBar progressSetPosition (_elapsedTime / _totalTime); }; _display displayAddEventHandler ["MouseMoving", _fnc_check]; @@ -163,8 +159,8 @@ _display displayAddEventHandler ["MouseHolding", _fnc_check]; private _ctrlTitle = _display displayCtrl IDC_PROGRESSBAR_TITLE; _ctrlTitle ctrlSetText _title; -_display setVariable [QGVAR(start), CBA_missionTime]; -_display setVariable [QGVAR(duration), _time]; +_display setVariable [QGVAR(startTime), CBA_missionTime]; +_display setVariable [QGVAR(totalTime), _totalTime]; _display setVariable [QGVAR(arguments), _arguments]; _display setVariable [QGVAR(condition), _condition]; _display setVariable [QGVAR(onSuccess), _onSuccess]; From 94bfc65fbe6721d7c5ef9f46aa0c40d7157c1f77 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 22 Apr 2018 16:46:39 +0200 Subject: [PATCH 08/18] progress bar allow mouse movement --- addons/ui/fnc_progressBar.sqf | 79 ++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 0c8832a7b..6c3dabd56 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -12,7 +12,8 @@ Parameters: _onFailure - Script to execute if the progress bar was aborted prematurely _arguments - Arguments passed to the scripts (optional, default: []) _allowClose - Allow ESC key to abort the progress bar (optional, default: true) - _blockInput - (optional, default: true) + _blockInput - true: block keyboard + mouse, + false: block mouse, but only if _allowClose is true (optional, default: true) Arguments: _this: @@ -75,50 +76,52 @@ if (!isNull _display) then { private _arguments = _display getVariable QGVAR(arguments); private _onFailure = _display getVariable QGVAR(onFailure); - // close display, execute on failure script - _display closeDisplay 0; + private _startTime = _display getVariable QGVAR(startTime); + private _totalTime = _display getVariable QGVAR(totalTime); + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - [_arguments, _onFailure] spawn { - isNil { - _this#0 call _this#1; - }; - }; + _display closeDisplay 0; + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; // create new progress bar -if (_blockInput) then { +private _blockMouse = _blockInput || _allowClose; + +if (_blockMouse) then { _display = (uiNamespace getVariable "RscDisplayMission") createDisplay QGVAR(ProgressBar); -} else { - QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; - _display = uiNamespace getVariable QGVAR(ProgressBar); -}; -_display displayAddEventHandler ["KeyDown", { - params ["_display", "_key", "_shift", "_control", "_alt"]; + _display displayAddEventHandler ["KeyDown", { + params ["_display", "_key", "_shift", "_control", "_alt"]; - private _arguments = _display getVariable QGVAR(arguments); - private _onFailure = _display getVariable QGVAR(onFailure); - private _allowClose = _display getVariable QGVAR(allowClose); - private _blockInput = _display getVariable QGVAR(blockInput); + private _arguments = _display getVariable QGVAR(arguments); + private _onFailure = _display getVariable QGVAR(onFailure); + private _allowClose = _display getVariable QGVAR(allowClose); + private _blockInput = _display getVariable QGVAR(blockInput); - if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { - private _startTime = _display getVariable QGVAR(startTime); - private _totalTime = _display getVariable QGVAR(totalTime); - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { + private _startTime = _display getVariable QGVAR(startTime); + private _totalTime = _display getVariable QGVAR(totalTime); + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - // close display, execute on failure script - _display closeDisplay 0; + _display closeDisplay 0; + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - - _blockInput = true; - }; + _blockInput = true; + }; - _blockInput -}]; + _blockInput + }]; +} else { + QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; + _display = uiNamespace getVariable QGVAR(ProgressBar); +}; private _fnc_check = { - params ["_display"]; + private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; + + if (isNull _display) exitWith { + removeMissionEventHandler ["Draw3D", _thisEventHandler]; + }; private _arguments = _display getVariable QGVAR(arguments); private _condition = _display getVariable QGVAR(condition); @@ -136,16 +139,12 @@ private _fnc_check = { private _onFailure = _display getVariable QGVAR(onFailure); if (!_continue) exitWith { - // close display, execute on failure script _display closeDisplay 0; - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; if (_elapsedTime > _totalTime) exitWith { - // close display, execute on success script _display closeDisplay 0; - [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; @@ -153,8 +152,12 @@ private _fnc_check = { _ctrlBar progressSetPosition (_elapsedTime / _totalTime); }; -_display displayAddEventHandler ["MouseMoving", _fnc_check]; -_display displayAddEventHandler ["MouseHolding", _fnc_check]; +if (_blockMouse) then { + _display displayAddEventHandler ["MouseMoving", _fnc_check]; + _display displayAddEventHandler ["MouseHolding", _fnc_check]; +} else { + addMissionEventHandler ["Draw3D", _fnc_check]; +}; private _ctrlTitle = _display displayCtrl IDC_PROGRESSBAR_TITLE; _ctrlTitle ctrlSetText _title; From 990ef09b95e5db3b71cd3fb64defc8b8ea5ecd17 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 23 Apr 2018 16:03:28 +0200 Subject: [PATCH 09/18] CBA_fnc_directCall --- addons/ui/fnc_progressBar.sqf | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 6c3dabd56..ef95658bf 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -38,8 +38,7 @@ Author: if (!hasInterface) exitWith {}; if (canSuspend) exitWith { - isNil (uiNamespace getVariable _fnc_scriptName); - nil; + [CBA_fnc_progressBar, _this] call CBA_fnc_directCall; }; params [ @@ -143,7 +142,7 @@ private _fnc_check = { [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; - if (_elapsedTime > _totalTime) exitWith { + if (_elapsedTime >= _totalTime) exitWith { _display closeDisplay 0; [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; From 36bd11a020389b73d330f036a11c19b8298fa1be Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 23 Apr 2018 18:35:08 +0200 Subject: [PATCH 10/18] block mouse --- addons/ui/ProgressBar.hpp | 48 +++++++++++ addons/ui/RscTitles.hpp | 50 ----------- addons/ui/config.cpp | 2 +- addons/ui/fnc_progressBar.sqf | 152 +++++++++++++++++---------------- addons/ui/script_component.hpp | 10 +++ 5 files changed, 136 insertions(+), 126 deletions(-) create mode 100644 addons/ui/ProgressBar.hpp delete mode 100644 addons/ui/RscTitles.hpp diff --git a/addons/ui/ProgressBar.hpp b/addons/ui/ProgressBar.hpp new file mode 100644 index 000000000..92669b0d7 --- /dev/null +++ b/addons/ui/ProgressBar.hpp @@ -0,0 +1,48 @@ +class RscControlsGroupNoScrollbars; +class RscText; +class RscProgress; + +class GVAR(ProgressBar): RscControlsGroupNoScrollbars { + onLoad = uiNamespace setVariable ['GVAR(ProgressBar)', _this select 0]; + x = "safezoneXAbs"; + y = "safezoneY"; + w = "safezoneWAbs"; + h = "safezoneH"; + + class controls { + class TitleBackground: RscText { + style = ST_CENTER; + sizeEx = 1 * GUI_GRID_CENTER_H; + colorBackground[] = {0,0,0,0.5}; + x = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),X)', 0]; + y = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),Y)', 0]; + w = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),W)', 0]; + h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; + }; + + class ProgressBar: RscProgress { + idc = IDC_PROGRESSBAR_BAR; + colorFrame[] = {0,0,0,0.5}; + colorBar[] = GUI_BCG_COLOR; + texture = "#(argb,8,8,3)color(1,1,1,0.7)"; + x = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),X)', 0]; + y = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),Y)', 0]; + w = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),W)', 0]; + h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; + }; + + class TitleText: TitleBackground { + idc = IDC_PROGRESSBAR_TITLE; + colorBackground[] = {0,0,0,0}; + colorText[] = {1,1,1,1}; + }; + }; +}; + +class GVAR(ProgressBarDisplay) { + idd = IDD_PROGRESSBAR; + + class controls { + class GVAR(ProgressBar): GVAR(ProgressBar) {}; + }; +}; diff --git a/addons/ui/RscTitles.hpp b/addons/ui/RscTitles.hpp deleted file mode 100644 index 84552342a..000000000 --- a/addons/ui/RscTitles.hpp +++ /dev/null @@ -1,50 +0,0 @@ -class RscText; -class RscProgress; - -class GVAR(ProgressBar) { - onLoad = uiNamespace setVariable ['GVAR(ProgressBar)', _this select 0]; - idd = -1; - controls[] = {"Background", "TitleBackground", "ProgressBar", "TitleText"}; - - class Background: RscText { - x = "safezoneXAbs"; - y = "safezoneY"; - w = "safezoneWAbs"; - h = "safezoneH"; - }; - - class TitleBackground: RscText { - style = ST_CENTER; - sizeEx = 1 * GUI_GRID_CENTER_H; - colorBackground[] = {0,0,0,0.5}; - x = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),X)', 0]; - y = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),Y)', 0]; - w = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),W)', 0]; - h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; - }; - - class TitleText: TitleBackground { - idc = IDC_PROGRESSBAR_TITLE; - colorBackground[] = {0,0,0,0}; - colorText[] = {1,1,1,1}; - }; - - class ProgressBar: RscProgress { - idc = IDC_PROGRESSBAR_BAR; - colorFrame[] = {0,0,0,0.5}; - colorBar[] = GUI_BCG_COLOR; - texture = "#(argb,8,8,3)color(1,1,1,0.7)"; - x = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),X)', 0]; - y = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),Y)', 0]; - w = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),W)', 0]; - h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; - }; -}; - -class RscTitles { - class GVAR(ProgressBar): GVAR(ProgressBar) { - duration = 1e+011; - fadeIn = 0; - fadeOut = 0; - }; -}; diff --git a/addons/ui/config.cpp b/addons/ui/config.cpp index cbbb4d0c4..f9255d93c 100644 --- a/addons/ui/config.cpp +++ b/addons/ui/config.cpp @@ -19,7 +19,7 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgFunctions.hpp" -#include "RscTitles.hpp" +#include "ProgressBar.hpp" #include "CfgUIGrids.hpp" //----------------------------------------------------------------------------- diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index ef95658bf..a167ef613 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -11,9 +11,11 @@ Parameters: _onSuccess - Script to execute if the progress bar completed _onFailure - Script to execute if the progress bar was aborted prematurely _arguments - Arguments passed to the scripts (optional, default: []) - _allowClose - Allow ESC key to abort the progress bar (optional, default: true) - _blockInput - true: block keyboard + mouse, - false: block mouse, but only if _allowClose is true (optional, default: true) + _blockMouse - Block mouse input (optional, default: true) + _blockKeys - Block keyboard input + requires _blockMouse to be set to true (optional, default: true) + _allowClose - Allow ESC key to abort the progress bar + requires _blockMouse to be set to true (optional, default: true) Arguments: _this: @@ -48,8 +50,9 @@ params [ ["_onSuccess", {}, [{}, ""]], ["_onFailure", {}, [{}, ""]], ["_arguments", []], - ["_allowClose", true, [false]], - ["_blockInput", true, [false]] + ["_blockMouse", true, [false]], + ["_blockKeys", true, [false]], + ["_allowClose", true, [false]] ]; if (isLocalized _title) then { @@ -68,104 +71,103 @@ if (_onFailure isEqualType "") then { _onFailure = compile _onFailure; }; -private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; - -if (!isNull _display) then { - // run failure code on previous progress bar - private _arguments = _display getVariable QGVAR(arguments); - private _onFailure = _display getVariable QGVAR(onFailure); - - private _startTime = _display getVariable QGVAR(startTime); - private _totalTime = _display getVariable QGVAR(totalTime); - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - - _display closeDisplay 0; - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; -}; - -// create new progress bar -private _blockMouse = _blockInput || _allowClose; - -if (_blockMouse) then { - _display = (uiNamespace getVariable "RscDisplayMission") createDisplay QGVAR(ProgressBar); - - _display displayAddEventHandler ["KeyDown", { - params ["_display", "_key", "_shift", "_control", "_alt"]; - - private _arguments = _display getVariable QGVAR(arguments); - private _onFailure = _display getVariable QGVAR(onFailure); - private _allowClose = _display getVariable QGVAR(allowClose); - private _blockInput = _display getVariable QGVAR(blockInput); - - if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { - private _startTime = _display getVariable QGVAR(startTime); - private _totalTime = _display getVariable QGVAR(totalTime); - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - - _display closeDisplay 0; - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - - _blockInput = true; - }; - - _blockInput - }]; -} else { - QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; - _display = uiNamespace getVariable QGVAR(ProgressBar); -}; - private _fnc_check = { - private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; + private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; - if (isNull _display) exitWith { + if (isNull _control) exitWith { removeMissionEventHandler ["Draw3D", _thisEventHandler]; }; - private _arguments = _display getVariable QGVAR(arguments); - private _condition = _display getVariable QGVAR(condition); + private _arguments = _control getVariable QGVAR(arguments); + private _condition = _control getVariable QGVAR(condition); - private _startTime = _display getVariable QGVAR(startTime); - private _totalTime = _display getVariable QGVAR(totalTime); + private _startTime = _control getVariable QGVAR(startTime); + private _totalTime = _control getVariable QGVAR(totalTime); private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { - private ["_display", "_arguments", "_condition", "_startTime", "_totalTime", "_elapsedTime"]; + private ["_control", "_arguments", "_condition", "_startTime", "_totalTime", "_elapsedTime"]; _this#0 call _this#1; }; - private _onSuccess = _display getVariable QGVAR(onSuccess); - private _onFailure = _display getVariable QGVAR(onFailure); + private _onSuccess = _control getVariable QGVAR(onSuccess); + private _onFailure = _control getVariable QGVAR(onFailure); if (!_continue) exitWith { - _display closeDisplay 0; + CLOSE(_control); [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; if (_elapsedTime >= _totalTime) exitWith { - _display closeDisplay 0; + CLOSE(_control); [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; - private _ctrlBar = _display displayCtrl IDC_PROGRESSBAR_BAR; + private _ctrlBar = _control controlsGroupCtrl IDC_PROGRESSBAR_BAR; _ctrlBar progressSetPosition (_elapsedTime / _totalTime); }; +private _display = uiNamespace getVariable "RscDisplayMission"; +private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; + +if (!isNull _control) then { + // run failure code on previous progress bar + private _arguments = _control getVariable QGVAR(arguments); + private _onFailure = _control getVariable QGVAR(onFailure); + + private _startTime = _control getVariable QGVAR(startTime); + private _totalTime = _control getVariable QGVAR(totalTime); + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + CLOSE(_control); + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; +}; + +// create new progress bar if (_blockMouse) then { - _display displayAddEventHandler ["MouseMoving", _fnc_check]; - _display displayAddEventHandler ["MouseHolding", _fnc_check]; + private _progressBar = _display createDisplay QGVAR(ProgressBarDisplay); + + _progressBar displayAddEventHandler ["KeyDown", { + params ["", "_key", "_shift", "_control", "_alt"]; + private _control = uiNamespace getVariable QGVAR(ProgressBar); + + private _arguments = _control getVariable QGVAR(arguments); + private _onFailure = _control getVariable QGVAR(onFailure); + private _allowClose = _control getVariable QGVAR(allowClose); + private _blockKeys = _control getVariable QGVAR(blockKeys); + + if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { + private _startTime = _control getVariable QGVAR(startTime); + private _totalTime = _control getVariable QGVAR(totalTime); + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + CLOSE(_control); + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + + _blockKeys = true; + }; + + _blockKeys + }]; + + _progressBar displayAddEventHandler ["MouseMoving", _fnc_check]; + _progressBar displayAddEventHandler ["MouseHolding", _fnc_check]; } else { + _display ctrlCreate [QGVAR(ProgressBar), -1]; + addMissionEventHandler ["Draw3D", _fnc_check]; }; -private _ctrlTitle = _display displayCtrl IDC_PROGRESSBAR_TITLE; +_control = uiNamespace getVariable QGVAR(ProgressBar); + +private _ctrlTitle = _control controlsGroupCtrl IDC_PROGRESSBAR_TITLE; _ctrlTitle ctrlSetText _title; -_display setVariable [QGVAR(startTime), CBA_missionTime]; -_display setVariable [QGVAR(totalTime), _totalTime]; -_display setVariable [QGVAR(arguments), _arguments]; -_display setVariable [QGVAR(condition), _condition]; -_display setVariable [QGVAR(onSuccess), _onSuccess]; -_display setVariable [QGVAR(onFailure), _onFailure]; -_display setVariable [QGVAR(allowClose), _allowClose]; -_display setVariable [QGVAR(blockInput), _blockInput]; +_control setVariable [QGVAR(startTime), CBA_missionTime]; +_control setVariable [QGVAR(totalTime), _totalTime]; +_control setVariable [QGVAR(arguments), _arguments]; +_control setVariable [QGVAR(condition), _condition]; +_control setVariable [QGVAR(onSuccess), _onSuccess]; +_control setVariable [QGVAR(onFailure), _onFailure]; +_control setVariable [QGVAR(allowClose), _allowClose]; +_control setVariable [QGVAR(blockKeys), _blockKeys]; diff --git a/addons/ui/script_component.hpp b/addons/ui/script_component.hpp index 5a364eda2..1cacdb95a 100644 --- a/addons/ui/script_component.hpp +++ b/addons/ui/script_component.hpp @@ -20,6 +20,7 @@ #include "\a3\ui_f\hpp\defineDIKCodes.inc" #include "\a3\ui_f\hpp\defineResincl.inc" +#define IDD_PROGRESSBAR 127400 #define IDC_PROGRESSBAR_TITLE 10 #define IDC_PROGRESSBAR_BAR 11 @@ -31,6 +32,15 @@ #define POS_W(N) ((N) * GUI_GRID_W) #define POS_H(N) ((N) * GUI_GRID_H) +#define CLOSE(control) call {\ + private _display = ctrlParent (control);\ + if (ctrlIDD _display isEqualTo IDD_PROGRESSBAR) then {\ + _display closeDisplay 0;\ + } else {\ + ctrlDelete (control);\ + };\ +}; + // Warning: this block below is a duplicate copy of the contents from common.hpp // #include "\x\cba\addons\ui\flexiMenu\data\common.hpp" From a78a37033a5b6d47d649263d60dc2c3fadff1805 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 23 Apr 2018 18:38:07 +0200 Subject: [PATCH 11/18] data type in functions header --- addons/ui/fnc_progressBar.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index a167ef613..7f7183de0 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -7,7 +7,7 @@ Description: Parameters: _title - Title of the progress bar _condition - Execute every frame. If reports false, close the progress bar - _totalTime - Time for the progress bar to complete + _totalTime - Time for the progress bar to complete _onSuccess - Script to execute if the progress bar completed _onFailure - Script to execute if the progress bar was aborted prematurely _arguments - Arguments passed to the scripts (optional, default: []) From 99c227c3c8fc520e8ba8c1c0e8915fa8f01ce627 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 23 Apr 2018 19:55:33 +0200 Subject: [PATCH 12/18] use self deleting draw event, cleanup for editor restarts --- addons/ui/ProgressBar.hpp | 7 ++++ addons/ui/XEH_preClientInit.sqf | 3 ++ addons/ui/fnc_progressBar.sqf | 73 +++++++++++++++------------------ 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/addons/ui/ProgressBar.hpp b/addons/ui/ProgressBar.hpp index 92669b0d7..999dcaa07 100644 --- a/addons/ui/ProgressBar.hpp +++ b/addons/ui/ProgressBar.hpp @@ -1,6 +1,7 @@ class RscControlsGroupNoScrollbars; class RscText; class RscProgress; +class RscMapControl; class GVAR(ProgressBar): RscControlsGroupNoScrollbars { onLoad = uiNamespace setVariable ['GVAR(ProgressBar)', _this select 0]; @@ -36,6 +37,12 @@ class GVAR(ProgressBar): RscControlsGroupNoScrollbars { colorBackground[] = {0,0,0,0}; colorText[] = {1,1,1,1}; }; + + class Update: RscMapControl { + onDraw = QUOTE(call (ctrlParentControlsGroup (_this select 0) getVariable 'GVAR(EachFrame)')); + w = 0; + h = 0; + }; }; }; diff --git a/addons/ui/XEH_preClientInit.sqf b/addons/ui/XEH_preClientInit.sqf index dbac001d0..785104da6 100644 --- a/addons/ui/XEH_preClientInit.sqf +++ b/addons/ui/XEH_preClientInit.sqf @@ -3,3 +3,6 @@ LOG(MSG_INIT); call COMPILE_FILE(flexiMenu\init); + +private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; +CLOSE(_control); diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 7f7183de0..81b18cafa 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -71,42 +71,6 @@ if (_onFailure isEqualType "") then { _onFailure = compile _onFailure; }; -private _fnc_check = { - private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; - - if (isNull _control) exitWith { - removeMissionEventHandler ["Draw3D", _thisEventHandler]; - }; - - private _arguments = _control getVariable QGVAR(arguments); - private _condition = _control getVariable QGVAR(condition); - - private _startTime = _control getVariable QGVAR(startTime); - private _totalTime = _control getVariable QGVAR(totalTime); - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - - private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { - private ["_control", "_arguments", "_condition", "_startTime", "_totalTime", "_elapsedTime"]; - _this#0 call _this#1; - }; - - private _onSuccess = _control getVariable QGVAR(onSuccess); - private _onFailure = _control getVariable QGVAR(onFailure); - - if (!_continue) exitWith { - CLOSE(_control); - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - }; - - if (_elapsedTime >= _totalTime) exitWith { - CLOSE(_control); - [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - }; - - private _ctrlBar = _control controlsGroupCtrl IDC_PROGRESSBAR_BAR; - _ctrlBar progressSetPosition (_elapsedTime / _totalTime); -}; - private _display = uiNamespace getVariable "RscDisplayMission"; private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; @@ -149,17 +113,44 @@ if (_blockMouse) then { _blockKeys }]; - - _progressBar displayAddEventHandler ["MouseMoving", _fnc_check]; - _progressBar displayAddEventHandler ["MouseHolding", _fnc_check]; } else { _display ctrlCreate [QGVAR(ProgressBar), -1]; - - addMissionEventHandler ["Draw3D", _fnc_check]; }; _control = uiNamespace getVariable QGVAR(ProgressBar); +_control setVariable [QGVAR(EachFrame), { + private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; + + private _arguments = _control getVariable QGVAR(arguments); + private _condition = _control getVariable QGVAR(condition); + + private _startTime = _control getVariable QGVAR(startTime); + private _totalTime = _control getVariable QGVAR(totalTime); + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { + private ["_control", "_arguments", "_condition", "_startTime", "_totalTime", "_elapsedTime"]; + _this#0 call _this#1; + }; + + private _onSuccess = _control getVariable QGVAR(onSuccess); + private _onFailure = _control getVariable QGVAR(onFailure); + + if (!_continue) exitWith { + CLOSE(_control); + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + }; + + if (_elapsedTime >= _totalTime) exitWith { + CLOSE(_control); + [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + }; + + private _ctrlBar = _control controlsGroupCtrl IDC_PROGRESSBAR_BAR; + _ctrlBar progressSetPosition (_elapsedTime / _totalTime); +}]; + private _ctrlTitle = _control controlsGroupCtrl IDC_PROGRESSBAR_TITLE; _ctrlTitle ctrlSetText _title; From e07a7772c4a2e6ea25d1e12adbc35f9a631bdaf8 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 23 Apr 2018 20:05:29 +0200 Subject: [PATCH 13/18] change arg order --- addons/ui/fnc_progressBar.sqf | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 81b18cafa..597491a1f 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -6,10 +6,11 @@ Description: Parameters: _title - Title of the progress bar - _condition - Execute every frame. If reports false, close the progress bar _totalTime - Time for the progress bar to complete + _condition - Execute every frame. If reports false, close the progress bar _onSuccess - Script to execute if the progress bar completed - _onFailure - Script to execute if the progress bar was aborted prematurely + _onFailure - Script to execute if the progress bar was aborted prematurely + (optional, default: {}) _arguments - Arguments passed to the scripts (optional, default: []) _blockMouse - Block mouse input (optional, default: true) _blockKeys - Block keyboard input @@ -29,7 +30,7 @@ Returns: Examples: (begin example) - ["progress bar", {true}, 5, {hint "done"}, {hint "aborted"}] call CBA_fnc_progressBar; + ["progress bar", 5, {true}, {hint "done"}, {hint "aborted"}] call CBA_fnc_progressBar; (end) Author: @@ -45,8 +46,8 @@ if (canSuspend) exitWith { params [ ["_title", "", [""]], - ["_condition", {}, [{}, ""]], ["_totalTime", 0, [0]], + ["_condition", {}, [{}, ""]], ["_onSuccess", {}, [{}, ""]], ["_onFailure", {}, [{}, ""]], ["_arguments", []], From ccfae4a6ba153d1a288a6c6e91a7173a949dac95 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 24 Apr 2018 21:38:18 +0200 Subject: [PATCH 14/18] change around progress bar logic --- addons/ui/CfgEventHandlers.hpp | 3 + addons/ui/ProgressBar.hpp | 17 +--- addons/ui/XEH_preClientInit.sqf | 2 +- addons/ui/XEH_preStart.sqf | 1 + addons/ui/fnc_initDisplayMission.sqf | 9 ++ addons/ui/fnc_progressBar.sqf | 124 +++++++++++---------------- addons/ui/script_component.hpp | 11 +-- 7 files changed, 68 insertions(+), 99 deletions(-) create mode 100644 addons/ui/fnc_initDisplayMission.sqf diff --git a/addons/ui/CfgEventHandlers.hpp b/addons/ui/CfgEventHandlers.hpp index b85678ae8..610c8d796 100644 --- a/addons/ui/CfgEventHandlers.hpp +++ b/addons/ui/CfgEventHandlers.hpp @@ -20,4 +20,7 @@ class Extended_DisplayLoad_EventHandlers { class RscDisplayMultiplayerSetup { ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayMultiplayerSetup)')); }; + class RscDisplayMission { + ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayMission)')); + }; }; diff --git a/addons/ui/ProgressBar.hpp b/addons/ui/ProgressBar.hpp index 999dcaa07..479bcc901 100644 --- a/addons/ui/ProgressBar.hpp +++ b/addons/ui/ProgressBar.hpp @@ -1,10 +1,8 @@ class RscControlsGroupNoScrollbars; class RscText; class RscProgress; -class RscMapControl; class GVAR(ProgressBar): RscControlsGroupNoScrollbars { - onLoad = uiNamespace setVariable ['GVAR(ProgressBar)', _this select 0]; x = "safezoneXAbs"; y = "safezoneY"; w = "safezoneWAbs"; @@ -12,6 +10,7 @@ class GVAR(ProgressBar): RscControlsGroupNoScrollbars { class controls { class TitleBackground: RscText { + idc = IDC_PROGRESSBAR_BACKGROUND; style = ST_CENTER; sizeEx = 1 * GUI_GRID_CENTER_H; colorBackground[] = {0,0,0,0.5}; @@ -37,19 +36,5 @@ class GVAR(ProgressBar): RscControlsGroupNoScrollbars { colorBackground[] = {0,0,0,0}; colorText[] = {1,1,1,1}; }; - - class Update: RscMapControl { - onDraw = QUOTE(call (ctrlParentControlsGroup (_this select 0) getVariable 'GVAR(EachFrame)')); - w = 0; - h = 0; - }; - }; -}; - -class GVAR(ProgressBarDisplay) { - idd = IDD_PROGRESSBAR; - - class controls { - class GVAR(ProgressBar): GVAR(ProgressBar) {}; }; }; diff --git a/addons/ui/XEH_preClientInit.sqf b/addons/ui/XEH_preClientInit.sqf index 785104da6..a076fc3eb 100644 --- a/addons/ui/XEH_preClientInit.sqf +++ b/addons/ui/XEH_preClientInit.sqf @@ -5,4 +5,4 @@ LOG(MSG_INIT); call COMPILE_FILE(flexiMenu\init); private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; -CLOSE(_control); +_control ctrlShow false; diff --git a/addons/ui/XEH_preStart.sqf b/addons/ui/XEH_preStart.sqf index 1c0dd3b78..382017646 100644 --- a/addons/ui/XEH_preStart.sqf +++ b/addons/ui/XEH_preStart.sqf @@ -2,3 +2,4 @@ PREP(initDisplayInterrupt); PREP(initDisplayMultiplayerSetup); +PREP(initDisplayMission); diff --git a/addons/ui/fnc_initDisplayMission.sqf b/addons/ui/fnc_initDisplayMission.sqf new file mode 100644 index 000000000..60bec4fed --- /dev/null +++ b/addons/ui/fnc_initDisplayMission.sqf @@ -0,0 +1,9 @@ +#include "script_component.hpp" + +params ["_display"]; + +private _control = _display ctrlCreate [QGVAR(ProgressBar), -1]; + +_control ctrlShow false; + +uiNamespace setVariable [QGVAR(ProgressBar), _control]; diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 597491a1f..bd0fa9a7a 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -72,94 +72,74 @@ if (_onFailure isEqualType "") then { _onFailure = compile _onFailure; }; -private _display = uiNamespace getVariable "RscDisplayMission"; +// show progress bar with new title private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; +_control ctrlShow true; -if (!isNull _control) then { - // run failure code on previous progress bar - private _arguments = _control getVariable QGVAR(arguments); - private _onFailure = _control getVariable QGVAR(onFailure); - - private _startTime = _control getVariable QGVAR(startTime); - private _totalTime = _control getVariable QGVAR(totalTime); - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - - CLOSE(_control); - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; -}; - -// create new progress bar -if (_blockMouse) then { - private _progressBar = _display createDisplay QGVAR(ProgressBarDisplay); +private _ctrlTitle = _control controlsGroupCtrl IDC_PROGRESSBAR_TITLE; +_ctrlTitle ctrlSetText _title; - _progressBar displayAddEventHandler ["KeyDown", { - params ["", "_key", "_shift", "_control", "_alt"]; - private _control = uiNamespace getVariable QGVAR(ProgressBar); +if (isNil QGVAR(ProgressBarParams)) then { + // update progress bar, run condition + addMissionEventHandler ["EachFrame", { + private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; - private _arguments = _control getVariable QGVAR(arguments); - private _onFailure = _control getVariable QGVAR(onFailure); - private _allowClose = _control getVariable QGVAR(allowClose); - private _blockKeys = _control getVariable QGVAR(blockKeys); + GVAR(ProgressBarParams) params ["_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime"]; + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - if (_allowClose && {_key isEqualTo DIK_ESCAPE}) then { - private _startTime = _control getVariable QGVAR(startTime); - private _totalTime = _control getVariable QGVAR(totalTime); - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { + private ["_control", "_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_elapsedTime"]; + _this#0 call _this#1; + }; - CLOSE(_control); + if (!_continue) exitWith { + removeMissionEventHandler ["EachFrame", _thisEventHandler]; + GVAR(ProgressBarParams) = nil; + _control ctrlShow false; [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + }; - _blockKeys = true; + if (_elapsedTime >= _totalTime) exitWith { + removeMissionEventHandler ["EachFrame", _thisEventHandler]; + GVAR(ProgressBarParams) = nil; + _control ctrlShow false; + [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; }; - _blockKeys + private _ctrlBar = _control controlsGroupCtrl IDC_PROGRESSBAR_BAR; + _ctrlBar progressSetPosition (_elapsedTime / _totalTime); }]; } else { - _display ctrlCreate [QGVAR(ProgressBar), -1]; -}; - -_control = uiNamespace getVariable QGVAR(ProgressBar); - -_control setVariable [QGVAR(EachFrame), { - private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; - - private _arguments = _control getVariable QGVAR(arguments); - private _condition = _control getVariable QGVAR(condition); - - private _startTime = _control getVariable QGVAR(startTime); - private _totalTime = _control getVariable QGVAR(totalTime); + // run failure code on previous progress bar + GVAR(ProgressBarParams) params ["_arguments", "", "", "_onFailure", "_startTime", "_totalTime"]; private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { - private ["_control", "_arguments", "_condition", "_startTime", "_totalTime", "_elapsedTime"]; - _this#0 call _this#1; - }; - - private _onSuccess = _control getVariable QGVAR(onSuccess); - private _onFailure = _control getVariable QGVAR(onFailure); + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; +}; - if (!_continue) exitWith { - CLOSE(_control); - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - }; +GVAR(ProgressBarParams) = [_arguments, _condition, _onSuccess, _onFailure, CBA_missionTime, _totalTime, _blockMouse, _blockKeys, _allowClose]; - if (_elapsedTime >= _totalTime) exitWith { - CLOSE(_control); - [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - }; +// create empty display to block input +if (_blockMouse) then { + private _blockInputDisplay = ctrlParent _control createDisplay "RscDisplayEmpty"; - private _ctrlBar = _control controlsGroupCtrl IDC_PROGRESSBAR_BAR; - _ctrlBar progressSetPosition (_elapsedTime / _totalTime); -}]; + _blockInputDisplay displayAddEventHandler ["KeyDown", { + params ["", "_key", "_shift", "_control", "_alt"]; + private _control = uiNamespace getVariable QGVAR(ProgressBar); -private _ctrlTitle = _control controlsGroupCtrl IDC_PROGRESSBAR_TITLE; -_ctrlTitle ctrlSetText _title; + GVAR(ProgressBarParams) params ["", "", "", "", "", "", "_blockMouse", "_blockKeys", "_allowClose"]; + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + if (_key isEqualTo DIK_ESCAPE) then { + if (_allowClose) then { + // let progressbar handler fail next frame + GVAR(ProgressBarParams) set [1, {false}]; + _blockKeys = true; + } else { + _blockKeys = false; + }; + }; -_control setVariable [QGVAR(startTime), CBA_missionTime]; -_control setVariable [QGVAR(totalTime), _totalTime]; -_control setVariable [QGVAR(arguments), _arguments]; -_control setVariable [QGVAR(condition), _condition]; -_control setVariable [QGVAR(onSuccess), _onSuccess]; -_control setVariable [QGVAR(onFailure), _onFailure]; -_control setVariable [QGVAR(allowClose), _allowClose]; -_control setVariable [QGVAR(blockKeys), _blockKeys]; + _blockKeys + }]; +}; diff --git a/addons/ui/script_component.hpp b/addons/ui/script_component.hpp index 1cacdb95a..7991b0b10 100644 --- a/addons/ui/script_component.hpp +++ b/addons/ui/script_component.hpp @@ -20,9 +20,9 @@ #include "\a3\ui_f\hpp\defineDIKCodes.inc" #include "\a3\ui_f\hpp\defineResincl.inc" -#define IDD_PROGRESSBAR 127400 #define IDC_PROGRESSBAR_TITLE 10 #define IDC_PROGRESSBAR_BAR 11 +#define IDC_PROGRESSBAR_BACKGROUND 12 #define IDC_ADDON_CONTROLS 127303 #define IDC_ADDON_OPTIONS 127307 @@ -32,15 +32,6 @@ #define POS_W(N) ((N) * GUI_GRID_W) #define POS_H(N) ((N) * GUI_GRID_H) -#define CLOSE(control) call {\ - private _display = ctrlParent (control);\ - if (ctrlIDD _display isEqualTo IDD_PROGRESSBAR) then {\ - _display closeDisplay 0;\ - } else {\ - ctrlDelete (control);\ - };\ -}; - // Warning: this block below is a duplicate copy of the contents from common.hpp // #include "\x\cba\addons\ui\flexiMenu\data\common.hpp" From 305ad9917272cc6e006c3ae4c2cbf8c36cb5a9fd Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 24 Apr 2018 23:20:27 +0200 Subject: [PATCH 15/18] change around progress bar logic --- addons/ui/XEH_preClientInit.sqf | 3 ++- addons/ui/fnc_initDisplayMission.sqf | 2 +- addons/ui/fnc_progressBar.sqf | 21 +++++++++++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/addons/ui/XEH_preClientInit.sqf b/addons/ui/XEH_preClientInit.sqf index a076fc3eb..8cc94def7 100644 --- a/addons/ui/XEH_preClientInit.sqf +++ b/addons/ui/XEH_preClientInit.sqf @@ -4,5 +4,6 @@ LOG(MSG_INIT); call COMPILE_FILE(flexiMenu\init); -private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; +private _display = uiNamespace getVariable ["RscDisplayMission", displayNull]; +private _control = _display getVariable [QGVAR(ProgressBar), controlNull]; _control ctrlShow false; diff --git a/addons/ui/fnc_initDisplayMission.sqf b/addons/ui/fnc_initDisplayMission.sqf index 60bec4fed..9901e79f1 100644 --- a/addons/ui/fnc_initDisplayMission.sqf +++ b/addons/ui/fnc_initDisplayMission.sqf @@ -6,4 +6,4 @@ private _control = _display ctrlCreate [QGVAR(ProgressBar), -1]; _control ctrlShow false; -uiNamespace setVariable [QGVAR(ProgressBar), _control]; +_display setVariable [QGVAR(ProgressBar), _control]; diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index bd0fa9a7a..63b3a1426 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -73,7 +73,8 @@ if (_onFailure isEqualType "") then { }; // show progress bar with new title -private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; +private _display = uiNamespace getVariable ["RscDisplayMission", displayNull]; +private _control = _display getVariable [QGVAR(ProgressBar), controlNull]; _control ctrlShow true; private _ctrlTitle = _control controlsGroupCtrl IDC_PROGRESSBAR_TITLE; @@ -82,13 +83,14 @@ _ctrlTitle ctrlSetText _title; if (isNil QGVAR(ProgressBarParams)) then { // update progress bar, run condition addMissionEventHandler ["EachFrame", { - private _control = uiNamespace getVariable [QGVAR(ProgressBar), controlNull]; + private _display = uiNamespace getVariable ["RscDisplayMission", displayNull]; + private _control = _display getVariable [QGVAR(ProgressBar), controlNull]; GVAR(ProgressBarParams) params ["_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime"]; private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { - private ["_control", "_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_elapsedTime"]; + private ["_display", "_control", "_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_elapsedTime"]; _this#0 call _this#1; }; @@ -119,13 +121,15 @@ if (isNil QGVAR(ProgressBarParams)) then { GVAR(ProgressBarParams) = [_arguments, _condition, _onSuccess, _onFailure, CBA_missionTime, _totalTime, _blockMouse, _blockKeys, _allowClose]; +/* // create empty display to block input if (_blockMouse) then { - private _blockInputDisplay = ctrlParent _control createDisplay "RscDisplayEmpty"; + private _display = ctrlParent _control createDisplay "RscDisplayEmpty"; - _blockInputDisplay displayAddEventHandler ["KeyDown", { + _display displayAddEventHandler ["KeyDown", { params ["", "_key", "_shift", "_control", "_alt"]; - private _control = uiNamespace getVariable QGVAR(ProgressBar); + private _display = uiNamespace getVariable ["RscDisplayMission", displayNull]; + private _control = _display getVariable QGVAR(ProgressBar); GVAR(ProgressBarParams) params ["", "", "", "", "", "", "_blockMouse", "_blockKeys", "_allowClose"]; private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; @@ -142,4 +146,9 @@ if (_blockMouse) then { _blockKeys }]; + + private _control = _display ctrlCreate [QGVAR(ProgressBar), -1]; + _display setVariable [QGVAR(ProgressBar), _control]; + uiNamespace setVariable [QGVAR(ProgressBar), _display]; }; +*/ From 1c1a6faed85b613610a001ab6adab8e38ed85e34 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 25 Apr 2018 01:49:12 +0200 Subject: [PATCH 16/18] fix the progress bar logic --- addons/ui/CfgEventHandlers.hpp | 3 - addons/ui/{ProgressBar.hpp => RscTitles.hpp} | 39 +++++++--- addons/ui/XEH_preClientInit.sqf | 9 ++- addons/ui/XEH_preStart.sqf | 2 +- addons/ui/config.cpp | 2 +- addons/ui/fnc_initDisplayMission.sqf | 9 --- addons/ui/fnc_initProgressBar.sqf | 82 ++++++++++++++++++++ addons/ui/fnc_progressBar.sqf | 76 ++---------------- addons/ui/script_component.hpp | 1 - 9 files changed, 125 insertions(+), 98 deletions(-) rename addons/ui/{ProgressBar.hpp => RscTitles.hpp} (64%) delete mode 100644 addons/ui/fnc_initDisplayMission.sqf create mode 100644 addons/ui/fnc_initProgressBar.sqf diff --git a/addons/ui/CfgEventHandlers.hpp b/addons/ui/CfgEventHandlers.hpp index 610c8d796..b85678ae8 100644 --- a/addons/ui/CfgEventHandlers.hpp +++ b/addons/ui/CfgEventHandlers.hpp @@ -20,7 +20,4 @@ class Extended_DisplayLoad_EventHandlers { class RscDisplayMultiplayerSetup { ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayMultiplayerSetup)')); }; - class RscDisplayMission { - ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayMission)')); - }; }; diff --git a/addons/ui/ProgressBar.hpp b/addons/ui/RscTitles.hpp similarity index 64% rename from addons/ui/ProgressBar.hpp rename to addons/ui/RscTitles.hpp index 479bcc901..be0a70391 100644 --- a/addons/ui/ProgressBar.hpp +++ b/addons/ui/RscTitles.hpp @@ -1,14 +1,25 @@ -class RscControlsGroupNoScrollbars; class RscText; class RscProgress; +class RscMapControl; -class GVAR(ProgressBar): RscControlsGroupNoScrollbars { - x = "safezoneXAbs"; - y = "safezoneY"; - w = "safezoneWAbs"; - h = "safezoneH"; +class RscTitles { + class GVAR(ProgressBar) { + onLoad = call (uiNamespace getVariable 'FUNC(initProgressBar)'); + idd = -1; + duration = 1e+11; + fadeIn = 0.2; + fadeOut = 0.2; + + controls[] = {"Background", "TitleBackground", "ProgressBar", "TitleText", "Script"}; + + class Background: RscText { + colorBackground[] = {0,0,0,0}; + x = "safezoneXAbs"; + y = "safezoneY"; + w = "safezoneWAbs"; + h = "safezoneH"; + }; - class controls { class TitleBackground: RscText { idc = IDC_PROGRESSBAR_BACKGROUND; style = ST_CENTER; @@ -20,6 +31,12 @@ class GVAR(ProgressBar): RscControlsGroupNoScrollbars { h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; }; + class TitleText: TitleBackground { + idc = IDC_PROGRESSBAR_TITLE; + colorBackground[] = {0,0,0,0}; + colorText[] = {1,1,1,1}; + }; + class ProgressBar: RscProgress { idc = IDC_PROGRESSBAR_BAR; colorFrame[] = {0,0,0,0.5}; @@ -31,10 +48,10 @@ class GVAR(ProgressBar): RscControlsGroupNoScrollbars { h = profileNamespace getVariable ['TRIPLES(IGUI,GVAR(grid),H)', 0]; }; - class TitleText: TitleBackground { - idc = IDC_PROGRESSBAR_TITLE; - colorBackground[] = {0,0,0,0}; - colorText[] = {1,1,1,1}; + class Script: RscMapControl { + onDraw = call (ctrlParent (_this select 0) getVariable 'GVAR(script)'); + w = 0; + h = 0; }; }; }; diff --git a/addons/ui/XEH_preClientInit.sqf b/addons/ui/XEH_preClientInit.sqf index 8cc94def7..6febc990e 100644 --- a/addons/ui/XEH_preClientInit.sqf +++ b/addons/ui/XEH_preClientInit.sqf @@ -4,6 +4,9 @@ LOG(MSG_INIT); call COMPILE_FILE(flexiMenu\init); -private _display = uiNamespace getVariable ["RscDisplayMission", displayNull]; -private _control = _display getVariable [QGVAR(ProgressBar), controlNull]; -_control ctrlShow false; +// recreate after loading a savegame +addMissionEventHandler ["Loaded", { + if (!isNil QGVAR(ProgressBarParams)) then { + QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; + }; +}]; diff --git a/addons/ui/XEH_preStart.sqf b/addons/ui/XEH_preStart.sqf index 382017646..a43558f0b 100644 --- a/addons/ui/XEH_preStart.sqf +++ b/addons/ui/XEH_preStart.sqf @@ -2,4 +2,4 @@ PREP(initDisplayInterrupt); PREP(initDisplayMultiplayerSetup); -PREP(initDisplayMission); +PREP(initProgressBar); diff --git a/addons/ui/config.cpp b/addons/ui/config.cpp index f9255d93c..cbbb4d0c4 100644 --- a/addons/ui/config.cpp +++ b/addons/ui/config.cpp @@ -19,7 +19,7 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgFunctions.hpp" -#include "ProgressBar.hpp" +#include "RscTitles.hpp" #include "CfgUIGrids.hpp" //----------------------------------------------------------------------------- diff --git a/addons/ui/fnc_initDisplayMission.sqf b/addons/ui/fnc_initDisplayMission.sqf deleted file mode 100644 index 9901e79f1..000000000 --- a/addons/ui/fnc_initDisplayMission.sqf +++ /dev/null @@ -1,9 +0,0 @@ -#include "script_component.hpp" - -params ["_display"]; - -private _control = _display ctrlCreate [QGVAR(ProgressBar), -1]; - -_control ctrlShow false; - -_display setVariable [QGVAR(ProgressBar), _control]; diff --git a/addons/ui/fnc_initProgressBar.sqf b/addons/ui/fnc_initProgressBar.sqf new file mode 100644 index 000000000..c26195634 --- /dev/null +++ b/addons/ui/fnc_initProgressBar.sqf @@ -0,0 +1,82 @@ +#include "script_component.hpp" + +params ["_display"]; +uiNamespace setVariable [QGVAR(ProgressBar), _display]; + +_display setVariable [QGVAR(script), { + private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; + + GVAR(ProgressBarParams) params ["_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_blockMouse"]; + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + // block mouse input + private _mission = uiNamespace getVariable ["RscDisplayMission", displayNull]; + private _blockInputDisplay = _mission getVariable [QGVAR(BlockInputDisplay), displayNull]; + + if (_blockMouse) then { + if (isNull _blockInputDisplay) then { + _blockInputDisplay = _mission createDisplay "RscDisplayEmpty"; + _mission setVariable [QGVAR(BlockInputDisplay), _blockInputDisplay]; + + _blockInputDisplay displayAddEventHandler ["KeyDown", { + params ["", "_key", "_shift", "_control", "_alt"]; + private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; + + GVAR(ProgressBarParams) params ["_arguments", "", "", "_onFailure", "_startTime", "_totalTime", "_blockMouse", "_blockKeys", "_allowClose"]; + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + if (_key isEqualTo DIK_ESCAPE) then { + if (_allowClose) then { + // let progressbar handler fail next frame + GVAR(ProgressBarParams) = nil; + QGVAR(ProgressBar) cutText ["", "PLAIN"]; + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + + _blockKeys = true; + } else { + _blockKeys = false; + }; + }; + + _blockKeys + }]; + + private _close = { + params ["_blockInputDisplay"]; + private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; + + if (isNull _display) then { + _blockInputDisplay closeDisplay 0; + }; + }; + + _blockInputDisplay displayAddEventHandler ["MouseMoving", _close]; + _blockInputDisplay displayAddEventHandler ["MouseHolding", _close]; + }; + } else { + if (!isNull _blockInputDisplay) then { + _blockInputDisplay closeDisplay 0; + }; + }; + + // update bar, check condition, execute success or failure scripts + private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { + private ["_display", "_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_elapsedTime", "_blockMouse"]; + _this#0 call _this#1; + }; + + if (!_continue) exitWith { + GVAR(ProgressBarParams) = nil; + {QGVAR(ProgressBar) cutText ["", "PLAIN"]} call CBA_fnc_execNextFrame; + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + }; + + if (_elapsedTime >= _totalTime) exitWith { + GVAR(ProgressBarParams) = nil; + {QGVAR(ProgressBar) cutText ["", "PLAIN"]} call CBA_fnc_execNextFrame; + [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + }; + + private _ctrlBar = _display displayCtrl IDC_PROGRESSBAR_BAR; + _ctrlBar progressSetPosition (_elapsedTime / _totalTime); +}]; diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 63b3a1426..90a3b1aad 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -72,47 +72,15 @@ if (_onFailure isEqualType "") then { _onFailure = compile _onFailure; }; -// show progress bar with new title -private _display = uiNamespace getVariable ["RscDisplayMission", displayNull]; -private _control = _display getVariable [QGVAR(ProgressBar), controlNull]; -_control ctrlShow true; +// show progress bar and set title +QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; +private _display = uiNamespace getVariable QGVAR(ProgressBar); -private _ctrlTitle = _control controlsGroupCtrl IDC_PROGRESSBAR_TITLE; +private _ctrlTitle = _display displayCtrl IDC_PROGRESSBAR_TITLE; _ctrlTitle ctrlSetText _title; -if (isNil QGVAR(ProgressBarParams)) then { - // update progress bar, run condition - addMissionEventHandler ["EachFrame", { - private _display = uiNamespace getVariable ["RscDisplayMission", displayNull]; - private _control = _display getVariable [QGVAR(ProgressBar), controlNull]; - - GVAR(ProgressBarParams) params ["_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime"]; - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - - private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { - private ["_display", "_control", "_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_elapsedTime"]; - _this#0 call _this#1; - }; - - if (!_continue) exitWith { - removeMissionEventHandler ["EachFrame", _thisEventHandler]; - GVAR(ProgressBarParams) = nil; - _control ctrlShow false; - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - }; - - if (_elapsedTime >= _totalTime) exitWith { - removeMissionEventHandler ["EachFrame", _thisEventHandler]; - GVAR(ProgressBarParams) = nil; - _control ctrlShow false; - [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - }; - - private _ctrlBar = _control controlsGroupCtrl IDC_PROGRESSBAR_BAR; - _ctrlBar progressSetPosition (_elapsedTime / _totalTime); - }]; -} else { - // run failure code on previous progress bar +// run failure code on previous progress bar +if (!isNil QGVAR(ProgressBarParams)) then { GVAR(ProgressBarParams) params ["_arguments", "", "", "_onFailure", "_startTime", "_totalTime"]; private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; @@ -121,34 +89,4 @@ if (isNil QGVAR(ProgressBarParams)) then { GVAR(ProgressBarParams) = [_arguments, _condition, _onSuccess, _onFailure, CBA_missionTime, _totalTime, _blockMouse, _blockKeys, _allowClose]; -/* -// create empty display to block input -if (_blockMouse) then { - private _display = ctrlParent _control createDisplay "RscDisplayEmpty"; - - _display displayAddEventHandler ["KeyDown", { - params ["", "_key", "_shift", "_control", "_alt"]; - private _display = uiNamespace getVariable ["RscDisplayMission", displayNull]; - private _control = _display getVariable QGVAR(ProgressBar); - - GVAR(ProgressBarParams) params ["", "", "", "", "", "", "_blockMouse", "_blockKeys", "_allowClose"]; - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - - if (_key isEqualTo DIK_ESCAPE) then { - if (_allowClose) then { - // let progressbar handler fail next frame - GVAR(ProgressBarParams) set [1, {false}]; - _blockKeys = true; - } else { - _blockKeys = false; - }; - }; - - _blockKeys - }]; - - private _control = _display ctrlCreate [QGVAR(ProgressBar), -1]; - _display setVariable [QGVAR(ProgressBar), _control]; - uiNamespace setVariable [QGVAR(ProgressBar), _display]; -}; -*/ +nil diff --git a/addons/ui/script_component.hpp b/addons/ui/script_component.hpp index 7991b0b10..5a364eda2 100644 --- a/addons/ui/script_component.hpp +++ b/addons/ui/script_component.hpp @@ -22,7 +22,6 @@ #define IDC_PROGRESSBAR_TITLE 10 #define IDC_PROGRESSBAR_BAR 11 -#define IDC_PROGRESSBAR_BACKGROUND 12 #define IDC_ADDON_CONTROLS 127303 #define IDC_ADDON_OPTIONS 127307 From 88e3fe104a19d1453bd9a77d986fdfb99fb7af26 Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 26 Apr 2018 05:24:05 +0200 Subject: [PATCH 17/18] simplify --- addons/ui/RscTitles.hpp | 8 +-- addons/ui/XEH_preStart.sqf | 1 - addons/ui/fnc_initProgressBar.sqf | 82 ----------------------------- addons/ui/fnc_progressBar.sqf | 87 +++++++++++++++++++++++++------ addons/ui/script_component.hpp | 1 + 5 files changed, 77 insertions(+), 102 deletions(-) delete mode 100644 addons/ui/fnc_initProgressBar.sqf diff --git a/addons/ui/RscTitles.hpp b/addons/ui/RscTitles.hpp index be0a70391..0c350e00e 100644 --- a/addons/ui/RscTitles.hpp +++ b/addons/ui/RscTitles.hpp @@ -4,11 +4,11 @@ class RscMapControl; class RscTitles { class GVAR(ProgressBar) { - onLoad = call (uiNamespace getVariable 'FUNC(initProgressBar)'); + onLoad = uiNamespace setVariable ['GVAR(ProgressBar)', _this select 0]; idd = -1; duration = 1e+11; - fadeIn = 0.2; - fadeOut = 0.2; + fadeIn = 0; + fadeOut = 0; controls[] = {"Background", "TitleBackground", "ProgressBar", "TitleText", "Script"}; @@ -49,7 +49,7 @@ class RscTitles { }; class Script: RscMapControl { - onDraw = call (ctrlParent (_this select 0) getVariable 'GVAR(script)'); + idc = IDC_PROGRESSBAR_SCRIPT w = 0; h = 0; }; diff --git a/addons/ui/XEH_preStart.sqf b/addons/ui/XEH_preStart.sqf index a43558f0b..1c0dd3b78 100644 --- a/addons/ui/XEH_preStart.sqf +++ b/addons/ui/XEH_preStart.sqf @@ -2,4 +2,3 @@ PREP(initDisplayInterrupt); PREP(initDisplayMultiplayerSetup); -PREP(initProgressBar); diff --git a/addons/ui/fnc_initProgressBar.sqf b/addons/ui/fnc_initProgressBar.sqf deleted file mode 100644 index c26195634..000000000 --- a/addons/ui/fnc_initProgressBar.sqf +++ /dev/null @@ -1,82 +0,0 @@ -#include "script_component.hpp" - -params ["_display"]; -uiNamespace setVariable [QGVAR(ProgressBar), _display]; - -_display setVariable [QGVAR(script), { - private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; - - GVAR(ProgressBarParams) params ["_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_blockMouse"]; - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - - // block mouse input - private _mission = uiNamespace getVariable ["RscDisplayMission", displayNull]; - private _blockInputDisplay = _mission getVariable [QGVAR(BlockInputDisplay), displayNull]; - - if (_blockMouse) then { - if (isNull _blockInputDisplay) then { - _blockInputDisplay = _mission createDisplay "RscDisplayEmpty"; - _mission setVariable [QGVAR(BlockInputDisplay), _blockInputDisplay]; - - _blockInputDisplay displayAddEventHandler ["KeyDown", { - params ["", "_key", "_shift", "_control", "_alt"]; - private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; - - GVAR(ProgressBarParams) params ["_arguments", "", "", "_onFailure", "_startTime", "_totalTime", "_blockMouse", "_blockKeys", "_allowClose"]; - private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; - - if (_key isEqualTo DIK_ESCAPE) then { - if (_allowClose) then { - // let progressbar handler fail next frame - GVAR(ProgressBarParams) = nil; - QGVAR(ProgressBar) cutText ["", "PLAIN"]; - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - - _blockKeys = true; - } else { - _blockKeys = false; - }; - }; - - _blockKeys - }]; - - private _close = { - params ["_blockInputDisplay"]; - private _display = uiNamespace getVariable [QGVAR(ProgressBar), displayNull]; - - if (isNull _display) then { - _blockInputDisplay closeDisplay 0; - }; - }; - - _blockInputDisplay displayAddEventHandler ["MouseMoving", _close]; - _blockInputDisplay displayAddEventHandler ["MouseHolding", _close]; - }; - } else { - if (!isNull _blockInputDisplay) then { - _blockInputDisplay closeDisplay 0; - }; - }; - - // update bar, check condition, execute success or failure scripts - private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { - private ["_display", "_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_elapsedTime", "_blockMouse"]; - _this#0 call _this#1; - }; - - if (!_continue) exitWith { - GVAR(ProgressBarParams) = nil; - {QGVAR(ProgressBar) cutText ["", "PLAIN"]} call CBA_fnc_execNextFrame; - [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - }; - - if (_elapsedTime >= _totalTime) exitWith { - GVAR(ProgressBarParams) = nil; - {QGVAR(ProgressBar) cutText ["", "PLAIN"]} call CBA_fnc_execNextFrame; - [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; - }; - - private _ctrlBar = _display displayCtrl IDC_PROGRESSBAR_BAR; - _ctrlBar progressSetPosition (_elapsedTime / _totalTime); -}]; diff --git a/addons/ui/fnc_progressBar.sqf b/addons/ui/fnc_progressBar.sqf index 90a3b1aad..89dd1da9e 100644 --- a/addons/ui/fnc_progressBar.sqf +++ b/addons/ui/fnc_progressBar.sqf @@ -38,18 +38,21 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" +// no progress bar without interface if (!hasInterface) exitWith {}; +// execute in unscheduled environment if (canSuspend) exitWith { [CBA_fnc_progressBar, _this] call CBA_fnc_directCall; }; +// arguments params [ ["_title", "", [""]], ["_totalTime", 0, [0]], - ["_condition", {}, [{}, ""]], - ["_onSuccess", {}, [{}, ""]], - ["_onFailure", {}, [{}, ""]], + ["_condition", {}, [{true}]], + ["_onSuccess", {}, [{}]], + ["_onFailure", {}, [{}]], ["_arguments", []], ["_blockMouse", true, [false]], ["_blockKeys", true, [false]], @@ -60,18 +63,6 @@ if (isLocalized _title) then { _title = localize _title; }; -if (_condition isEqualType "") then { - _condition = compile _condition; -}; - -if (_onSuccess isEqualType "") then { - _onSuccess = compile _onSuccess; -}; - -if (_onFailure isEqualType "") then { - _onFailure = compile _onFailure; -}; - // show progress bar and set title QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; private _display = uiNamespace getVariable QGVAR(ProgressBar); @@ -89,4 +80,70 @@ if (!isNil QGVAR(ProgressBarParams)) then { GVAR(ProgressBarParams) = [_arguments, _condition, _onSuccess, _onFailure, CBA_missionTime, _totalTime, _blockMouse, _blockKeys, _allowClose]; +// update bar, check condition, execute success or failure scripts +private _ctrlScript = _display displayCtrl IDC_PROGRESSBAR_SCRIPT; +_ctrlScript ctrlAddEventHandler ["Draw", { + params ["_ctrlScript"]; + private _display = ctrlParent _ctrlScript; + + GVAR(ProgressBarParams) params ["_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime"]; + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + private _continue = [[_arguments, true, _elapsedTime, _totalTime], _condition] call { + private ["_ctrlScript", "_display", "_arguments", "_condition", "_onSuccess", "_onFailure", "_startTime", "_totalTime", "_elapsedTime"]; + _this#0 call _this#1; + }; + + private _blockInputDisplay = uiNamespace getVariable [QGVAR(BlockInputDisplay), displayNull]; + + if (!_continue) exitWith { + GVAR(ProgressBarParams) = nil; + {QGVAR(ProgressBar) cutText ["", "PLAIN"]} call CBA_fnc_execNextFrame; // game would crash if display is killed from Draw event + _blockInputDisplay closeDisplay 0; + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + }; + + if (_elapsedTime >= _totalTime) exitWith { + GVAR(ProgressBarParams) = nil; + {QGVAR(ProgressBar) cutText ["", "PLAIN"]} call CBA_fnc_execNextFrame; // game would crash if display is killed from Draw event + _blockInputDisplay closeDisplay 0; + [_onSuccess, [_arguments, true, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + }; + + private _ctrlBar = _display displayCtrl IDC_PROGRESSBAR_BAR; + _ctrlBar progressSetPosition (_elapsedTime / _totalTime); +}]; + +// block input while the bar is shown +private _blockInputDisplay = uiNamespace getVariable [QGVAR(BlockInputDisplay), displayNull]; +_blockInputDisplay closeDisplay 0; + +if (_blockMouse) then { + private _mission = uiNamespace getVariable "RscDisplayMission"; + _blockInputDisplay = _mission createDisplay "RscDisplayEmpty"; + uiNamespace setVariable [QGVAR(BlockInputDisplay), _blockInputDisplay]; + + _blockInputDisplay displayAddEventHandler ["KeyDown", { + params ["_blockInputDisplay", "_key", "_shift", "_control", "_alt"]; + + GVAR(ProgressBarParams) params ["_arguments", "", "", "_onFailure", "_startTime", "_totalTime", "_blockMouse", "_blockKeys", "_allowClose"]; + private _elapsedTime = (CBA_missionTime - _startTime) min _totalTime; + + if (_key isEqualTo DIK_ESCAPE) then { + if (_allowClose) then { + GVAR(ProgressBarParams) = nil; + QGVAR(ProgressBar) cutText ["", "PLAIN"]; + _blockInputDisplay closeDisplay 0; + [_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; + + _blockKeys = false; + } else { + _blockKeys = true; + }; + }; + + _blockKeys + }]; +}; + nil diff --git a/addons/ui/script_component.hpp b/addons/ui/script_component.hpp index 5a364eda2..a048bec61 100644 --- a/addons/ui/script_component.hpp +++ b/addons/ui/script_component.hpp @@ -22,6 +22,7 @@ #define IDC_PROGRESSBAR_TITLE 10 #define IDC_PROGRESSBAR_BAR 11 +#define IDC_PROGRESSBAR_SCRIPT 12 #define IDC_ADDON_CONTROLS 127303 #define IDC_ADDON_OPTIONS 127307 From b2f09edeb29ac19af69430fd48a813ce6b358ba0 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 28 Apr 2018 03:45:23 +0200 Subject: [PATCH 18/18] Update RscTitles.hpp --- addons/ui/RscTitles.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/ui/RscTitles.hpp b/addons/ui/RscTitles.hpp index 0c350e00e..ed9f9dc9e 100644 --- a/addons/ui/RscTitles.hpp +++ b/addons/ui/RscTitles.hpp @@ -49,7 +49,7 @@ class RscTitles { }; class Script: RscMapControl { - idc = IDC_PROGRESSBAR_SCRIPT + idc = IDC_PROGRESSBAR_SCRIPT; w = 0; h = 0; };