Skip to content

Commit

Permalink
ares_extras: add 'curatorMsg' and 'confirm' functions
Browse files Browse the repository at this point in the history
Signed-off-by: freghar <freghar@dummy.tld>
  • Loading branch information
freghar committed Jan 24, 2021
1 parent 45fd824 commit 017a7af
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addons/ares_extras/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class CfgFunctions {
class all {
file = "\a3aa\ares_extras";
class init { postInit = 1; };
class curatorMsg;
class confirm;
};
class task_force {
file = "\a3aa\ares_extras\task_force";
Expand Down
87 changes: 87 additions & 0 deletions addons/ares_extras/fn_confirm.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* wait for the curator to confirm something (Return = yes, Escape = no)
*
* your code will run unscheduled and will receive no argument (or your
* custom one)
*
* this function uses global vars, but is recursion-safe
*
* [
* "Select source units",
* {
* private _units = curatorSelected select 0;
* if (count _units == 0) exitWith {
* ["No units selected.", "cancel"]
* call a3aa_ares_extras_fnc_curatorMsg;
* };
* [
* "Select target groups",
* [_units, {
* private _units = _this;
* private _groups = curatorSelected select 1;
* if (count _groups > 0) then {
* systemChat format ["src units: %1", _units];
* systemChat format ["tgt groups: %1", _groups];
* };
* }]
* ] call a3aa_ares_extras_fnc_confirm;
* }
* ] call a3aa_ares_extras_fnc_confirm;
*/

#include "\A3\ui_f_curator\ui\defineResinclDesign.inc"
#include "\A3\ui_f\hpp\defineDIKCodes.inc"

params ["_msg", "_code"];

if (_code isEqualType []) then {
a3aa_ares_extras_confim_codearg = _code select 0;
a3aa_ares_extras_confim_code = _code select 1;
} else {
a3aa_ares_extras_confim_code = _code;
};

disableSerialization;
private _display = findDisplay IDD_RSCDISPLAYCURATOR;
if (isNull _display) exitWith {};

/* another confirmation in progress */
if (!isNil "a3aa_ares_extras_confim_EH") then {
_display displayRemoveEventHandler ["KeyDown", a3aa_ares_extras_confim_EH];
};

/* no _thisEventHandler for displayAddEventHandler */
a3aa_ares_extras_confim_EH = _display displayAddEventHandler ["KeyDown",
{
params ["_display", "_key"];
switch (_key) do {
case DIK_ESCAPE: {
_display displayRemoveEventHandler
["KeyDown", a3aa_ares_extras_confim_EH];
a3aa_ares_extras_confim_EH = nil;
["Cancelled.", "cancel"] call a3aa_ares_extras_fnc_curatorMsg;
true;
};
case DIK_NUMPADENTER;
case DIK_RETURN: {
_display displayRemoveEventHandler
["KeyDown", a3aa_ares_extras_confim_EH];
a3aa_ares_extras_confim_EH = nil;
["Confirmed.", "normal"] call a3aa_ares_extras_fnc_curatorMsg;
if (isNil "a3aa_ares_extras_confim_codearg") then {
call a3aa_ares_extras_confim_code;
} else {
a3aa_ares_extras_confim_codearg
call a3aa_ares_extras_confim_code;
};
true;
};
default {
false;
};
};
}];

if (!(_msg isEqualTo "")) then {
[_msg, "action"] call a3aa_ares_extras_fnc_curatorMsg;
};
45 changes: 45 additions & 0 deletions addons/ares_extras/fn_curatorMsg.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* custom message in the top bar, like BIS_fnc_showCuratorFeedbackMessage
* but with customizable sound
*/

#include "\A3\ui_f_curator\ui\defineResinclDesign.inc"

/* sound: normal, action, cancel, ... or classname .. or "" for silent */
params ["_msg", ["_sound", "normal"]];

disableSerialization;
private _display = findDisplay IDD_RSCDISPLAYCURATOR;
private _ctrl = _display displayCtrl IDC_RSCDISPLAYCURATOR_FEEDBACKMESSAGE;
if (isNull _ctrl) exitWith {};

switch (_sound) do {
case "normal": { playSound "RscDisplayCurator_error01" };
case "action": { playSound "FD_Finish_F" };
case "cancel": { playSound "FD_Start_F" };
case "": {};
default { playSound _sound };
};

/*
* replicate messaging logic from BIS_fnc_showCuratorFeedbackMessage,
* including the msg fade - use BIS identifier for the script, so that
* any BIS_fnc_showCuratorFeedbackMessage call can terminate it, making
* this function fully BIS_fnc_showCuratorFeedbackMessage compatible
*/

_ctrl ctrlSetText _msg;
_ctrl ctrlSetFade 1;
_ctrl ctrlCommit 0;
_ctrl ctrlSetFade 0;
_ctrl ctrlCommit 0.1;

if (!isNil "BIS_fnc_moduleCurator_feedbackMessage") then {
terminate BIS_fnc_moduleCurator_feedbackMessage;
};
BIS_fnc_moduleCurator_feedbackMessage = _ctrl spawn {
disableSerialization;
uiSleep 3;
_this ctrlSetFade 1;
_this ctrlCommit 0.5;
};

0 comments on commit 017a7af

Please sign in to comment.