-
Notifications
You must be signed in to change notification settings - Fork 148
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 7 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,50 @@ | ||
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; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_progressBar | ||
|
||
Description: | ||
Opens a progress bar. Closes the currently active progress bar. | ||
|
||
Parameters: | ||
_title - Title of the progress bar <STRING> | ||
_condition - Execute every frame. If reports false, close the progress bar <CODE> | ||
_time - Time for the progress bar to complete | ||
_onSuccess - Script to execute if the progress bar completed <CODE> | ||
_onFailure - Script to execute if the progress bar was aborted prematurely <CODE> | ||
_arguments - Arguments passed to the scripts (optional, default: []) <ANY> | ||
_allowClose - Allow ESC key to abort the progress bar (optional, default: true) <BOOLEAN> | ||
_blockInput - (optional, default: true) <BOOLEAN> | ||
|
||
Arguments: | ||
_this - same as _arguments <ANY> | ||
|
||
Returns: | ||
Nothing | ||
|
||
Examples: | ||
(begin example) | ||
["progress bar", {true}, 5, {hint "done"}, {hint "aborted"}] call CBA_fnc_progressBar; | ||
(end) | ||
|
||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
if (!hasInterface) exitWith {}; | ||
|
||
if (canSuspend) exitWith { | ||
isNil (uiNamespace getVariable _fnc_scriptName); | ||
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. What's this bit all about? 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. Run the function unscheduled every time. 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. 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. Maybe prefer fnc_directCall for clarity? 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. Yeah I just hadn't see the |
||
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 { | ||
// 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 | ||
if (_blockInput) then { | ||
_display = (uiNamespace getVariable "RscDisplayMission") createDisplay QGVAR(ProgressBar); | ||
} else { | ||
QGVAR(ProgressBar) cutRsc [QGVAR(ProgressBar), "PLAIN"]; | ||
_display = uiNamespace getVariable QGVAR(ProgressBar); | ||
}; | ||
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. todo, MouseMoving, MouseHolding don't work for cutRsc. |
||
|
||
_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 { | ||
// close display, execute on failure script | ||
_display closeDisplay 0; | ||
|
||
[_arguments, _onFailure] spawn { | ||
isNil { | ||
_this#0 call _this#1; | ||
}; | ||
}; | ||
|
||
_blockInput = true; | ||
}; | ||
|
||
_blockInput | ||
}]; | ||
|
||
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 closeDisplay 0; | ||
|
||
[_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; | ||
|
||
if (_runTime > _duration) exitWith { | ||
// close display, execute on success script | ||
_display closeDisplay 0; | ||
|
||
[_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]; | ||
|
||
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]; | ||
_display setVariable [QGVAR(allowClose), _allowClose]; | ||
_display setVariable [QGVAR(blockInput), _blockInput]; |
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.
_title