2023-09-12 18:58:10 +00:00
#include "..\script_component.hpp"
2023-02-02 05:28:55 +00:00
#include "\a3\ui_f_curator\ui\defineResinclDesign.inc"
2024-01-07 17:59:38 +00:00
#include "\a3\ui_f\hpp\defineDIKCodes.inc"
2015-01-11 16:42:31 +00:00
/*
2024-01-07 17:59:38 +00:00
* Author: commy2, johnb43
2015-01-11 16:42:31 +00:00
* Disables key input. ESC can still be pressed to open the menu.
*
2015-04-11 17:52:30 +00:00
* Arguments:
* 0: True to disable key inputs, false to re-enable them <BOOL>
2015-01-11 16:42:31 +00:00
*
2015-09-20 20:16:51 +00:00
* Return Value:
* None
2015-04-11 17:52:30 +00:00
*
2017-06-08 13:31:51 +00:00
* Example:
* [true] call ace_common_fnc_disableUserInput
*
2015-09-20 20:16:51 +00:00
* Public: No
2015-01-11 16:42:31 +00:00
*/
2020-06-19 15:36:24 +00:00
#define IDD_TEAMSWITCH 632
2015-09-20 20:16:51 +00:00
params ["_state"];
2019-08-06 13:10:33 +00:00
TRACE_1("disableUserInput",_state);
2015-01-11 16:42:31 +00:00
if (_state) then {
2015-04-11 17:52:30 +00:00
disableSerialization;
2015-01-11 16:42:31 +00:00
2015-04-11 17:52:30 +00:00
if (!isNull (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull])) exitWith {};
2015-09-20 20:16:51 +00:00
if (!isNil QGVAR(disableInputPFH)) exitWith {};
2015-01-11 16:42:31 +00:00
2024-01-07 17:59:38 +00:00
// End TFAR and ACRE2 radio transmissions
2015-04-11 17:52:30 +00:00
call FUNC(endRadioTransmission);
2015-01-11 16:42:31 +00:00
2015-04-11 17:52:30 +00:00
// Close map
if (visibleMap && {!(player getVariable ["ACE_canSwitchUnits", false])}) then {
openMap false;
};
2015-01-11 16:42:31 +00:00
2020-06-19 15:36:24 +00:00
if (isNull findDisplay IDD_INTERRUPT && {isNull findDisplay IDD_RSCDISPLAYCURATOR} && {isNull findDisplay IDD_TEAMSWITCH}) then {
closeDialog 0;
createDialog QGVAR(DisableMouse_Dialog);
2015-01-11 16:42:31 +00:00
2020-06-19 15:36:24 +00:00
private _display = uiNamespace getVariable QGVAR(dlgDisableMouse);
2015-01-11 16:42:31 +00:00
2021-06-27 20:39:17 +00:00
// Hide cursor by using custom transparent cursor
private _map = _display displayCtrl 101;
_map ctrlMapCursor ["", QGVAR(blank)];
2024-01-07 17:59:38 +00:00
GVAR(keyboardInputMain) = createHashMap;
GVAR(keyboardInputCombo) = createHashMap;
2020-06-19 15:36:24 +00:00
_display displayAddEventHandler ["KeyDown", {
2024-01-07 17:59:38 +00:00
// If input is enabled again, ignore
if (isNil QGVAR(keyboardInputMain)) exitWith {};
2020-06-19 15:36:24 +00:00
params ["", "_key"];
2015-01-11 16:42:31 +00:00
2024-01-07 17:59:38 +00:00
// Get key info; Stored as [isPressed, pressedCount]
private _keyPressedInfo = GVAR(keyboardInputMain) getOrDefault [_key, [false, 0], true];
_keyPressedInfo params ["_keyPressed", "_keyPressedCount"];
// For regular keys: If pressed, set to release and remove one key press
if (!_keyPressed) then {
_keyPressedInfo set [0, true];
_keyPressedInfo set [1, _keyPressedCount + 1];
};
// For combo keys, register only if pushed or released (no keypress count)
if !(GVAR(keyboardInputCombo) getOrDefault [_key, false]) then {
GVAR(keyboardInputCombo) set [_key, true];
};
// Look if keybinds of various actions have been pressed
private _action = "";
private _comboDikPressed = false;
private _return = false;
// This technique has a limitation: It can't process the Escape key properly (KeyUp EH does not fire)
(["TeamSwitch", "CuratorInterface", "ShowMap", "DefaultAction", "Throw", "Chat", "PrevChannel", "NextChannel"] apply {
_action = _x;
{
_x params ["_mainKeyArray", "_comboKeyArray", "_isDoubleTap"];
_mainKeyArray params ["_mainDik", "_mainDevice"];
// If keybind doesn't contain key combo, it returns empty array; Therefore, return true
_comboDikPressed = if (_comboKeyArray isEqualTo []) then {
true
} else {
_comboKeyArray params ["_comboDik", "_comboDevice"];
_comboDevice == "KEYBOARD" && {GVAR(keyboardInputCombo) getOrDefault [_comboDik, false]}
};
2015-04-11 17:52:30 +00:00
2024-01-07 17:59:38 +00:00
// Check if the necessary keys were pressed for a keybind
_return = _comboDikPressed &&
{_mainDevice == "KEYBOARD"} &&
2024-02-10 15:58:14 +00:00
{((GVAR(keyboardInputMain) getOrDefault [_mainDik, [false, 0]]) select 1) > (parseNumber _isDoubleTap)}; // check how many times the main key was pressed
2024-01-07 17:59:38 +00:00
// Keybind was detected
if (_return) exitWith {
TRACE_1("Action triggered: ",_action);
};
} forEach (actionKeysEx _action);
_return
}) params ["_teamSwitch", "_curatorInterface", "_showMap", "_defaultAction", "_throw", "_chat", "_prevChannel", "_nextChannel"];
// Handle Escape separately because of limitation mentioned above
if (_key == DIK_ESCAPE && {alive player}) then {
2020-06-19 15:36:24 +00:00
disableSerialization;
2015-09-20 20:16:51 +00:00
2024-01-07 17:59:38 +00:00
private _isMultiplayer = isMultiplayer;
private _is3DENPreview = is3DENPreview;
createDialog (["RscDisplayInterrupt", "RscDisplayMPInterrupt"] select _isMultiplayer);
2020-06-19 15:36:24 +00:00
private _dlg = findDisplay 49;
2015-04-11 17:52:30 +00:00
2020-06-19 15:36:24 +00:00
for "_index" from 100 to 2000 do {
(_dlg displayCtrl _index) ctrlEnable false;
};
2015-04-11 17:52:30 +00:00
2024-01-07 17:59:38 +00:00
private _ctrl = _dlg displayCtrl 103;
_ctrl ctrlSetEventHandler ["ButtonClick", toString {
while {!isNull (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull])} do {
closeDialog 0
};
failMission "LOSER";
[false] call FUNC(disableUserInput);
}];
2020-06-19 15:36:24 +00:00
_ctrl ctrlEnable true;
2024-01-07 17:59:38 +00:00
_ctrl ctrlSetText localize (["str_disp_int_abort", "STR_3DEN_RscDisplayInterrupt_ButtonAbort_3DEN_text"] select (_is3DENPreview && !_isMultiplayer));
_ctrl ctrlSetTooltip localize ([
"STR_TOOLTIP_MAIN_ABORT_CAMPAIGN",
"STR_3DEN_RscDisplayInterrupt_ButtonAbort_3DEN_tooltip",
"STR_TOOLTIP_MAIN_ABORT"
] select (([_is3DENPreview, _isMultiplayer] call FUNC(toBitmask)) min 2));
_ctrl = _dlg displayCtrl ([104, 1010] select _isMultiplayer);
_ctrl ctrlSetEventHandler ["ButtonClick", toString {
closeDialog 0;
2024-05-31 20:07:50 +00:00
[player, "respawn_button"] call FUNC(setDead);
2024-01-07 17:59:38 +00:00
[false] call FUNC(disableUserInput);
}];
private _respawnEnabled = (getMissionConfigValue ["respawnButton", -1]) != 0;
_ctrl ctrlEnable _respawnEnabled; // handles 3den attribute or description.ext
_ctrl ctrlSetText localize "str_disp_int_respawn";
_ctrl ctrlSetTooltip localize (["str_3den_attributes_respawn_none_tooltip", "str_disp_int_respawn"] select _respawnEnabled);
2020-06-19 15:36:24 +00:00
};
2015-09-20 20:16:51 +00:00
2024-01-07 17:59:38 +00:00
if (_teamSwitch && teamSwitchEnabled) then {
2020-06-19 15:36:24 +00:00
(uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0;
2015-04-11 17:52:30 +00:00
2020-06-19 15:36:24 +00:00
private _acc = accTime;
teamSwitch;
setAccTime _acc;
};
2015-04-11 17:52:30 +00:00
2024-01-07 17:59:38 +00:00
if (_curatorInterface && {!isNull getAssignedCuratorLogic player}) then {
2020-06-19 15:36:24 +00:00
(uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0;
2024-01-07 17:59:38 +00:00
2020-06-19 15:36:24 +00:00
openCuratorInterface;
};
2015-04-11 17:52:30 +00:00
2024-01-07 17:59:38 +00:00
if (_showMap && {player getVariable ["ACE_canSwitchUnits", false]}) then {
2020-06-19 15:36:24 +00:00
(uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0;
2024-01-07 17:59:38 +00:00
2020-06-19 15:36:24 +00:00
openMap true;
2015-04-11 17:52:30 +00:00
};
2024-01-07 17:59:38 +00:00
if (isMultiplayer && {isServer || {serverCommandAvailable "#kick"}}) then {
if (!(_defaultAction || _throw) && {_chat || _prevChannel || _nextChannel}) then {
2020-06-19 15:36:24 +00:00
_key = 0;
};
};
_key > 0
}];
2015-04-11 17:52:30 +00:00
2024-01-07 17:59:38 +00:00
_display displayAddEventHandler ["KeyUp", {
// If input is enabled again, ignore
if (isNil QGVAR(keyboardInputMain)) exitWith {};
params ["", "_key"];
// For combo keys: If pressed, release
if (GVAR(keyboardInputCombo) getOrDefault [_key, false]) then {
GVAR(keyboardInputCombo) deleteAt _key;
};
private _keyPressedInfo = GVAR(keyboardInputMain) getOrDefault [_key, [false, 0]];
// If pressed, release it
if (_keyPressedInfo select 0) then {
_keyPressedInfo set [0, false];
};
// Cache keystrokes of regular keys for a small amount of time
[{
// If input is enabled again, ignore
if (isNil QGVAR(keyboardInputMain)) exitWith {};
params ["_key"];
private _keyPressedInfo = GVAR(keyboardInputMain) getOrDefault [_key, [false, 0]];
// Release it
_keyPressedInfo set [1, ((_keyPressedInfo select 1) - 1) max 0];
if (_keyPressedInfo isEqualTo [false, 0]) then {
2024-02-04 19:24:04 +00:00
GVAR(keyboardInputMain) deleteAt _key;
2024-01-07 17:59:38 +00:00
};
}, _key, 0.5] call CBA_fnc_waitAndExecute;
}];
2020-06-19 15:36:24 +00:00
};
2015-04-11 17:52:30 +00:00
2015-09-21 20:41:29 +00:00
GVAR(disableInputPFH) = [{
2023-01-31 23:14:50 +00:00
if (isNull (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) && {!visibleMap && {isNull findDisplay IDD_INTERRUPT} && {isNull findDisplay IDD_RSCDISPLAYCURATOR} && {isNull findDisplay IDD_TEAMSWITCH}}) exitWith {
2015-09-21 20:41:29 +00:00
[GVAR(disableInputPFH)] call CBA_fnc_removePerFrameHandler;
GVAR(disableInputPFH) = nil;
2015-04-11 17:52:30 +00:00
[true] call FUNC(disableUserInput);
};
2023-01-31 23:14:50 +00:00
// Allow user input if the player is respawning and a respawn template (menu position or spectator)
// is open (otherwise they cannot click the respawn button)
if (
!alive player
&& {playerRespawnTime != -1}
&& {
missionNamespace getVariable ["BIS_RscRespawnControlsMap_shown", false]
|| {missionNamespace getVariable ["BIS_RscRespawnControlsSpectate_shown", false]}
}
) exitWith {
[false] call FUNC(disableUserInput);
};
2015-09-21 20:41:29 +00:00
}, 0, []] call CBA_fnc_addPerFrameHandler;
2015-01-11 16:42:31 +00:00
} else {
2015-09-21 20:41:29 +00:00
if (!isNil QGVAR(disableInputPFH)) then {
[GVAR(disableInputPFH)] call CBA_fnc_removePerFrameHandler;
GVAR(disableInputPFH) = nil;
2015-04-11 17:52:30 +00:00
};
2015-01-11 16:42:31 +00:00
2015-04-11 17:52:30 +00:00
(uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0;
2024-01-07 17:59:38 +00:00
GVAR(keyboardInputMain) = nil;
GVAR(keyboardInputCombo) = nil;
2015-01-11 16:42:31 +00:00
};