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

Add sound parameter to CBA_fnc_notify #1488

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions addons/ui/fnc_notify.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Parameters:
_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>
_sound - Play notification sound when hint is displayed (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;
["Banana", 1.5, [1, 1, 0, 1], true, true] call CBA_fnc_notify;
[["Banana", 1.5, [1, 1, 0, 1]], ["Not Apple"], true, true] call CBA_fnc_notify;
(end)

Returns:
Expand All @@ -45,19 +46,19 @@ if !(_this isEqualType []) then {
};

if !(_this select 0 isEqualType []) then {
_this = [_this];
// Handle booleans at index 3-4
_this = [_this select [0, 3]] + (_this select [3, 2]);
};

// Handle boolean parameters
private _composition = [];
private _skippable = false;
(_this select {_x isEqualType true}) params [
["_skippable", false],
["_sound", false]
];
FILTER(_this,!(_x isEqualType true));

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

// Line
_composition pushBack lineBreak;

Expand Down Expand Up @@ -87,7 +88,7 @@ private _skippable = false;

_composition deleteAt 0;

private _notification = [_composition, _skippable];
private _notification = [_composition, _skippable, _sound];

// add the queue
if (isNil QGVAR(notifyQueue)) then {
Expand All @@ -114,7 +115,18 @@ private _fnc_popQueue = {
};

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

// Notification is skippable and the queue is not empty - skip to the next one immediately
if (_skippable && {count GVAR(notifyQueue) > 1}) exitWith {
LOG("Skipped queue process");
[[], _fnc_processQueue] call _fnc_popQueue;
};

if _sound then {
LOG("Played sound");
playSound "hint";
};

QGVAR(notify) cutRsc ["RscTitleDisplayEmpty", "PLAIN", 0, true];
private _display = uiNamespace getVariable "RscTitleDisplayEmpty";
Expand Down