-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add CBA_fnc_progressBar #912
Changes from 18 commits
b82ad52
31917a3
47794d5
58c878d
862ab94
87b26a1
dc549c8
e1c72f7
94bfc65
990ef09
36bd11a
a78a370
99c227c
e07a777
ccfae4a
305ad99
1c1a6fa
88e3fe1
b2f09ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class RscText; | ||
class RscProgress; | ||
class RscMapControl; | ||
|
||
class RscTitles { | ||
class GVAR(ProgressBar) { | ||
onLoad = uiNamespace setVariable ['GVAR(ProgressBar)', _this select 0]; | ||
idd = -1; | ||
duration = 1e+11; | ||
fadeIn = 0; | ||
fadeOut = 0; | ||
|
||
controls[] = {"Background", "TitleBackground", "ProgressBar", "TitleText", "Script"}; | ||
|
||
class Background: RscText { | ||
colorBackground[] = {0,0,0,0}; | ||
x = "safezoneXAbs"; | ||
y = "safezoneY"; | ||
w = "safezoneWAbs"; | ||
h = "safezoneH"; | ||
}; | ||
|
||
class TitleBackground: RscText { | ||
idc = IDC_PROGRESSBAR_BACKGROUND; | ||
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 Script: RscMapControl { | ||
idc = IDC_PROGRESSBAR_SCRIPT | ||
w = 0; | ||
h = 0; | ||
}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_progressBar | ||
|
||
Description: | ||
Opens a progress bar. Closes the currently active progress bar. | ||
|
||
Parameters: | ||
_title - Title of the progress bar <STRING> | ||
_totalTime - Time for the progress bar to complete <NUMBER> | ||
_condition - Execute every frame. If reports false, close the progress bar <CODE> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _title |
||
_onSuccess - Script to execute if the progress bar completed <CODE> | ||
_onFailure - Script to execute if the progress bar was aborted prematurely | ||
(optional, default: {}) <CODE> | ||
_arguments - Arguments passed to the scripts (optional, default: []) <ANY> | ||
_blockMouse - Block mouse input (optional, default: true) <BOOLEAN> | ||
_blockKeys - Block keyboard input | ||
requires _blockMouse to be set to true (optional, default: true) <BOOLEAN> | ||
_allowClose - Allow ESC key to abort the progress bar | ||
requires _blockMouse to be set to true (optional, default: true) <BOOLEAN> | ||
|
||
Arguments: | ||
_this: | ||
#0 - same as _arguments <ANY> | ||
#1 - true: success, false: failure <BOOLEAN> | ||
#2 - elapsed time, not more than _totalTime <NUMBER> | ||
#3 - total time, same as _totalTime <NUMBER> | ||
|
||
Returns: | ||
Nothing | ||
|
||
Examples: | ||
(begin example) | ||
["progress bar", 5, {true}, {hint "done"}, {hint "aborted"}] call CBA_fnc_progressBar; | ||
(end) | ||
|
||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#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", {}, [{true}]], | ||
["_onSuccess", {}, [{}]], | ||
["_onFailure", {}, [{}]], | ||
["_arguments", []], | ||
["_blockMouse", true, [false]], | ||
["_blockKeys", true, [false]], | ||
["_allowClose", true, [false]] | ||
]; | ||
|
||
if (isLocalized _title) then { | ||
_title = localize _title; | ||
}; | ||
|
||
// show progress bar and set title | ||
QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; | ||
private _display = uiNamespace getVariable QGVAR(ProgressBar); | ||
|
||
private _ctrlTitle = _display displayCtrl IDC_PROGRESSBAR_TITLE; | ||
_ctrlTitle ctrlSetText _title; | ||
|
||
// 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; | ||
|
||
[_onFailure, [_arguments, false, _elapsedTime, _totalTime]] call CBA_fnc_execNextFrame; | ||
}; | ||
|
||
GVAR(ProgressBarParams) = [_arguments, _condition, _onSuccess, _onFailure, CBA_missionTime, _totalTime, _blockMouse, _blockKeys, _allowClose]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that it really matters, but you could set these on the display itself and that way it get's cleaned up automatically There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The display dies when saving and loading a savegame. Only thing that doesn't work is the block input display, but I just assume that this only ever happens to mouse enabled progress bars, since only then you can use Esc to open the menu to save. |
||
|
||
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File x\cba\addons\ui\RscTitles.hpp, line 51: '/RscTitles/cba_ui_ProgressBar/Script.idc': Missing ';' at the end of line