Skip to content
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

Notify - Skippable parameter, Lifetime Setting, Use in Accessory component #1175

Merged
merged 10 commits into from
Jul 6, 2019
5 changes: 3 additions & 2 deletions addons/accessory/fnc_switchAttachment.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private _currWeaponType = call {
_currItem = "";
-1
};
if (_currWeaponType < 0) exitWith {hint "You are not holding a weapon!"; false};
if (_currWeaponType < 0) exitWith { false };

#define __cfgWeapons configfile >> "CfgWeapons"
#define __currItem __cfgWeapons >> _currItem
Expand Down Expand Up @@ -68,8 +68,9 @@ if (!isNil "_switchItem") then {
};
};
private _switchItemHintText = getText (__cfgWeapons >> _switchItem >> "MRT_SwitchItemHintText");
private _switchItemHintImage = getText (__cfgWeapons >> _switchItem >> "picture");
if !(_switchItemHintText isEqualTo "") then {
hintSilent format ["%1", _switchItemHintText];
[[_switchItemHintImage, 2.0], [_switchItemHintText], true] call CBA_fnc_notify;
};
playSound "click";
["CBA_attachmentSwitched", [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_localEvent;
Expand Down
22 changes: 4 additions & 18 deletions addons/ui/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
#include "script_component.hpp"

[
QGVAR(StorePasswords), "LIST",
[LLSTRING(StoreServerPasswords), LLSTRING(StoreServerPasswordsTooltip)],
LLSTRING(Category),
[[1, 0, -1], [
[LLSTRING(SavePasswords), LLSTRING(SavePasswordsTooltip)],
[LLSTRING(DoNotSavePasswords), LLSTRING(DoNotSavePasswordsTooltip)],
[LLSTRING(DeletePasswords), LLSTRING(DeletePasswordsTooltip)]
], 0],
2,
{
if (_this isEqualTo -1) then {
profileNamespace setVariable [QGVAR(ServerPasswords), nil];
};
ADDON = false;

profileNamespace setVariable [QGVAR(StorePasswords), _this];
saveProfileNamespace;
}
] call cba_settings_fnc_init;
#include "initSettings.sqf"

if (hasInterface) then {
call COMPILE_FILE(flexiMenu\init);
Expand Down Expand Up @@ -46,3 +30,5 @@ FUNC(menuShortcut) = CBA_fnc_flexiMenu_menuShortcut;
FUNC(mouseButtonDown) = CBA_fnc_flexiMenu_mouseButtonDown;
FUNC(highlightCaretKey) = CBA_fnc_flexiMenu_highlightCaretKey;
FUNC(execute) = CBA_fnc_flexiMenu_execute;

ADDON = true;
91 changes: 63 additions & 28 deletions addons/ui/fnc_notify.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ Description:
Display a text message. Multiple incoming messages are queued.

Parameters:
_content - ARRAY
_line1 - ARRAY
_line2 - ARRAY
_content - Notifications content (lines). <ARRAY>
_line1 - First content line. <ARRAY>
_line2 - Second content line. <ARRAY>
...
_lineN - ARRAY
_text - STRING, NUMBER: Text to display or path to .paa or .jpg image.
_size - NUMBER: Text or image size multiplier, optional, default: 1
_color - ARRAY: RGB or RGBA color (range 0-1), optional, default: [1,1,1,1]
_lineN - N-th content line (may be passed directly if only 1 line is required). <ARRAY>
_text - Text to display or path to .paa or .jpg image (may be passed directly if only text is required). <STRING, NUMBER>
_size - Text or image size multiplier. (optional, default: 1) <NUMBER>
_color - RGB or RGBA color (range 0-1). (optional, default: [1, 1, 1, 1]) <ARRAY>
_skippable - Skip or overwrite this notification if another entered the queue. (optional, default: false) <BOOL>

Examples:
(begin example)
"Banana" call CBA_fnc_notify;
["Banana", 1.5, [1, 1, 0, 1]] call CBA_fnc_notify;
[["Banana", 1.5, [1, 1, 0, 1]], ["Not Apple"], true] call CBA_fnc_notify;
(end)

Returns:
Expand All @@ -27,7 +30,6 @@ Authors:
commy2
---------------------------------------------------------------------------- */

#define LIFE_TIME 4
#define FADE_IN_TIME 0.2
#define FADE_OUT_TIME 1

Expand All @@ -47,8 +49,16 @@ if !(_this select 0 isEqualType []) then {
};

private _composition = [];
private _skippable = false;

{
// Additional arguments at the end
if (_x isEqualType true) exitWith {
TRACE_1("Skippable argument",_x);
_skippable = _x;
};

// Line
_composition pushBack lineBreak;

_x params [["_text", "", ["", 0]], ["_size", 1, [0]], ["_color", [], [[]], [3,4]]];
Expand Down Expand Up @@ -77,15 +87,34 @@ private _composition = [];

_composition deleteAt 0;

private _notification = [_composition, _skippable];

// add the queue
if (isNil QGVAR(notifyQueue)) then {
GVAR(notifyQueue) = [];
};

GVAR(notifyQueue) pushBack _composition;
GVAR(notifyQueue) pushBack _notification;

private _fnc_popQueue = {
params ["_controls", "_fnc_processQueue"];

GVAR(notifyQueue) deleteAt 0;
private _notification = GVAR(notifyQueue) select 0;

if (!isNil "_notification") then {
_notification call _fnc_processQueue;
} else {
// fade out
{
_x ctrlSetFade 1;
_x ctrlCommit (FADE_OUT_TIME);
} forEach _controls;
};
};

private _fnc_processQueue = {
private _composition = _this;
params ["_composition", "_skippable"];

QGVAR(notify) cutRsc ["RscTitleDisplayEmpty", "PLAIN", 0, true];
private _display = uiNamespace getVariable "RscTitleDisplayEmpty";
Expand Down Expand Up @@ -156,27 +185,33 @@ private _fnc_processQueue = {
_x ctrlCommit (FADE_IN_TIME);
} forEach _controls;

// pop queue
[{
params ["_controls", "_fnc_processQueue"];

GVAR(notifyQueue) deleteAt 0;
private _composition = GVAR(notifyQueue) select 0;

if (!isNil "_composition") then {
_composition call _fnc_processQueue;
} else {
// fade out
{
_x ctrlSetFade 1;
_x ctrlCommit (FADE_OUT_TIME);
} forEach _controls;
};
}, [_controls, _fnc_processQueue], LIFE_TIME] call CBA_fnc_waitAndExecute;
// pop queue - waitUntilAndExecute for skippable, waitAndExecute for non-skippable for less wasted condition checking
TRACE_3("Pop wait",_composition,_skippable,GVAR(notifyQueue));
if (_skippable) then {
[{
// Wait for another notification to be added
count GVAR(notifyQueue) > 1
}, {
// Condition met - Show next notification immediately
LOG("Skipped queue process");
params ["_fnc_popQueue", "_controls", "_fnc_processQueue"];
[_controls, _fnc_processQueue] call _fnc_popQueue;
}, [_fnc_popQueue, _controls, _fnc_processQueue], GVAR(notifyLifetime), {
// Timeout - Normally move to next notification
LOG("Normal queue process");
params ["_fnc_popQueue", "_controls", "_fnc_processQueue"];
[_controls, _fnc_processQueue] call _fnc_popQueue;
}] call CBA_fnc_waitUntilAndExecute;
} else {
[{
params ["_fnc_popQueue", "_controls", "_fnc_processQueue"];
[_controls, _fnc_processQueue] call _fnc_popQueue;
}, [_fnc_popQueue, _controls, _fnc_processQueue], GVAR(notifyLifetime)] call CBA_fnc_waitAndExecute;
};
};

if (count GVAR(notifyQueue) isEqualTo 1) then {
_composition call _fnc_processQueue;
_notification call _fnc_processQueue;
};

nil
28 changes: 28 additions & 0 deletions addons/ui/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
QGVAR(StorePasswords), "LIST",
[LLSTRING(StoreServerPasswords), LLSTRING(StoreServerPasswordsTooltip)],
LLSTRING(Category),
[[1, 0, -1], [
[LLSTRING(SavePasswords), LLSTRING(SavePasswordsTooltip)],
[LLSTRING(DoNotSavePasswords), LLSTRING(DoNotSavePasswordsTooltip)],
[LLSTRING(DeletePasswords), LLSTRING(DeletePasswordsTooltip)]
], 0],
2,
{
if (_this isEqualTo -1) then {
profileNamespace setVariable [QGVAR(ServerPasswords), nil];
};

profileNamespace setVariable [QGVAR(StorePasswords), _this];
saveProfileNamespace;
}
] call CBA_fnc_addSetting;

[
QGVAR(notifyLifetime),
"SLIDER",
[LLSTRING(NotifyLifetime), LLSTRING(NotifyLifetimeTooltip)],
LLSTRING(Category),
[1, 10, 4, 1], // default value
2 // global
] call CBA_fnc_addSetting;
8 changes: 4 additions & 4 deletions addons/ui/script_component.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#define COMPONENT ui
#define COMPONENT ui
#include "\x\cba\addons\main\script_mod.hpp"

//#define DEBUG_MODE_FULL
//#define DISABLE_COMPILE_CACHE
//#define DEBUG_ENABLED_UI
// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define DEBUG_ENABLED_UI

#ifdef DEBUG_ENABLED_UI
#define DEBUG_MODE_FULL
Expand Down
6 changes: 6 additions & 0 deletions addons/ui/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,11 @@
<Polish>Pokaż własne/wgrane misje</Polish>
<Italian>Mostra missioni custom</Italian>
</Key>
<Key ID="STR_CBA_Ui_NotifyLifetime">
<English>Notification Lifetime</English>
</Key>
<Key ID="STR_CBA_Ui_NotifyLifetimeTooltip">
<English>Notification display duration in seconds.</English>
</Key>
</Package>
</Project>