diff --git a/addons/mission/RscGUI.hpp b/addons/mission/RscGUI.hpp new file mode 100644 index 00000000..d7a46149 --- /dev/null +++ b/addons/mission/RscGUI.hpp @@ -0,0 +1,126 @@ +class RscText; +class RscButton; +class RscFrame; + +// Keypad for button pressing +class GVAR(Keypad) { + idd = -1; + movingEnable = 1; + class Controls { + class GVAR(Keypad_Frame): RscFrame { + idc = 1800; + x = QUOTE(0.438745 * safezoneW + safezoneX); + y = QUOTE(0.177928 * safezoneH + safezoneY); + w = QUOTE(0.262522 * safezoneW); + h = QUOTE(0.476106 * safezoneH); + }; + class GVAR(Keypad_Box) { + type = CT_STATIC; + idc = -1; + style = ST_CENTER; + shadow = 2; + colorText[] = {1, 1, 1, 1}; + font = "PuristaMedium"; + sizeEx = 0.02; + colorBackground[] = {0.2, 0.2, 0.2, 0.9}; + text = ""; + x = QUOTE(0.438745 * safezoneW + safezoneX); + y = QUOTE(0.177928 * safezoneH + safezoneY); + w = QUOTE(0.262522 * safezoneW); + h = QUOTE(0.476106 * safezoneH); + }; + class GVAR(Keypad_Display): RscText { + idc = 1000; + colorBackground[] = {0, 0, 0, 1}; + font = "EtelkaMonospacePro"; + text = "Enter Keycode"; + style = ST_CENTER; + sizeEx = 0.1; + x = QUOTE(0.456246 * safezoneW + safezoneX); + y = QUOTE(0.191931 * safezoneH + safezoneY); + w = QUOTE(0.227519 * safezoneW); + h = QUOTE(0.0840187 * safezoneH); + }; + class GVAR(Keypad_Btn0): RscButton { + idc = 1600; + text = "0"; + x = QUOTE(0.535003 * safezoneW + safezoneX); + y = QUOTE(0.556012 * safezoneH + safezoneY); + w = QUOTE(0.0700059 * safezoneW); + h = QUOTE(0.0700156 * safezoneH); + action = QUOTE(0 call FUNC(keypadPress)); + soundEnter[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundEnter", 0.09, 1}; + soundPush[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundPush", 0.09, 1}; + soundClick[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundClick", 0.09, 1}; + soundEscape[] = {"\A3\ui_f\data\sound\RscButtonMenu\soundEscape", 0.09, 1}; + }; + class GVAR(Keypad_Btn1): GVAR(Keypad_Btn0) { + idc = 1601; + text = "1"; + x = QUOTE(0.456246 * safezoneW + safezoneX); + y = QUOTE(0.303956 * safezoneH + safezoneY); + action = QUOTE(1 call FUNC(keypadPress)); + }; + class GVAR(Keypad_Btn2): GVAR(Keypad_Btn0) { + idc = 1602; + text = "2"; + y = QUOTE(0.303956 * safezoneH + safezoneY); + action = QUOTE(2 call FUNC(keypadPress)); + }; + class GVAR(Keypad_Btn3): GVAR(Keypad_Btn0) { + idc = 1603; + text = "3"; + x = QUOTE(0.61376 * safezoneW + safezoneX); + y = QUOTE(0.303956 * safezoneH + safezoneY); + action = QUOTE(3 call FUNC(keypadPress)); + }; + class GVAR(Keypad_Btn4): GVAR(Keypad_Btn1) { + idc = 1604; + text = "4"; + y = QUOTE(0.387975 * safezoneH + safezoneY); + action = QUOTE(4 call FUNC(keypadPress)); + }; + class GVAR(Keypad_Btn5): GVAR(Keypad_Btn0) { + idc = 1605; + text = "5"; + y = QUOTE(0.387975 * safezoneH + safezoneY); + action = QUOTE(5 call FUNC(keypadPress)); + }; + class GVAR(Keypad_Btn6): GVAR(Keypad_Btn3) { + idc = 1606; + text = "6"; + y = QUOTE(0.387975 * safezoneH + safezoneY); + action = QUOTE(6 call FUNC(keypadPress)); + }; + class GVAR(Keypad_Btn7): GVAR(Keypad_Btn1) { + idc = 1607; + text = "7"; + y = QUOTE(0.471994 * safezoneH + safezoneY); + action = QUOTE(7 call FUNC(keypadPress)); + }; + class GVAR(Keypad_Btn8): GVAR(Keypad_Btn0) { + idc = 1608; + text = "8"; + y = QUOTE(0.471994 * safezoneH + safezoneY); + action = QUOTE(8 call FUNC(keypadPress)); + }; + class GVAR(Keypad_Btn9): GVAR(Keypad_Btn3) { + idc = 1609; + text = "9"; + y = QUOTE(0.471994 * safezoneH + safezoneY); + action = QUOTE(9 call FUNC(keypadPress)); + }; + class GVAR(Keypad_BtnClear): GVAR(Keypad_Btn1) { + idc = 1610; + text = "Clear"; + y = QUOTE(0.556012 * safezoneH + safezoneY); + action = QUOTE('Clear' call FUNC(keypadPress)); + }; + class GVAR(Keypad_BtnEnter): GVAR(Keypad_Btn3) { + idc = 1611; + text = "Enter"; + y = QUOTE(0.556012 * safezoneH + safezoneY); + action = QUOTE('Enter' call FUNC(keypadPress)); + }; + }; +}; diff --git a/addons/mission/XEH_PREP.hpp b/addons/mission/XEH_PREP.hpp index 9dee857d..34efdf53 100644 --- a/addons/mission/XEH_PREP.hpp +++ b/addons/mission/XEH_PREP.hpp @@ -27,6 +27,8 @@ PREP(enableAI); PREP(forceShooting); PREP(groundFog); PREP(jam); +PREP(keypadPress); +PREP(keypadSetup); PREP(lockDoors); PREP(markBuildings); PREP(mortarStrike); diff --git a/addons/mission/config.cpp b/addons/mission/config.cpp index 090593d1..13157b5b 100644 --- a/addons/mission/config.cpp +++ b/addons/mission/config.cpp @@ -14,3 +14,4 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" +#include "RscGUI.hpp" diff --git a/addons/mission/functions/fnc_keypadPress.sqf b/addons/mission/functions/fnc_keypadPress.sqf new file mode 100644 index 00000000..ab986132 --- /dev/null +++ b/addons/mission/functions/fnc_keypadPress.sqf @@ -0,0 +1,76 @@ +#include "..\script_component.hpp" +/* + * Author: Mike + * Handles specific keypad presses, runs locally on whichever player is interacting. + * + * Called from GUI + * + * Arguments: + * 0: Button Press (default: "Clear") + * + * Return Value: + * None + * + * Example: + * [0] call FUNC(keypadPress) + */ + +params [["_keypadInput", "Clear"]]; + +private _keypad = ace_player getVariable [QGVAR(keypadInUse), objNull]; + +private _currentFailedAttempts = _keypad getVariable [QGVAR(Keypad_currentFailedAttempts), 0]; +private _maxFailedAttempts = _keypad getVariable [QGVAR(Keypad_maxFailedAttempts), 0]; +private _maxCharacters = _keypad getVariable [QGVAR(Keypad_maxCharacters), 0]; +private _requiredCode = _keypad getVariable [QGVAR(Keypad_requiredCode), 0]; +private _text = _keypad getVariable [QGVAR(Keypad_Text), ""]; + +if (_keypadInput isEqualTo "Clear") exitWith { + _keypad setVariable [QGVAR(Keypad_Text), "", true]; + ctrlSetText [1000, "Code Cleared"]; +}; + +if (_keypadInput isEqualTo "Enter") exitWith { + + // Handle failures + if (_text isNotEqualTo _requiredCode) exitWith { + ctrlSetText [1000, "Invalid"]; + _keypad setVariable [QGVAR(Keypad_Text), "", true]; + private _failedAttempts = _currentFailedAttempts + 1; + _keypad setVariable [QGVAR(Keypad_currentFailedAttempts), _failedAttempts, true]; + + // Block keypad if too many failed attempts. + if (_failedAttempts >= _maxFailedAttempts) exitWith { + [QGVAR(keypadFailure), [_keypad, ace_player, _failedAttempts]] call CBA_fnc_globalEvent; + _keypad setVariable [QGVAR(keypadBlocked), true, true]; + ctrlSetText [1000, "Keypad Locked"]; + [{ + closeDialog 2; + }, [], 2] call CBA_fnc_waitAndExecute; + }; + }; + + // Success + ctrlSetText [1000, "Accepted!"]; + [QGVAR(keypadSuccess), [_keypad, ace_player]] call CBA_fnc_globalEvent; + _keypad setVariable [QGVAR(keypadFinished), true, true]; + + [{ + closeDialog 2; + }, [], 2] call CBA_fnc_waitAndExecute; +}; + +// Numbers +if (_keypadInput isEqualType 0) then { + private _newText = _text + format ["%1", _keypadInput]; + _keypad setVariable [QGVAR(Keypad_Text), _newText, true]; + ctrlSetText [1000, _newText]; + + // Handles max characters + private _characterCount = count _newText; + if (_characterCount > _maxCharacters) exitWith { + "Code too long, Resetting" call CBA_fnc_notify; + _keypad setVariable [QGVAR(Keypad_Text), "", true]; + ctrlSetText [1000, "Enter Keycode"]; + }; +}; diff --git a/addons/mission/functions/fnc_keypadSetup.sqf b/addons/mission/functions/fnc_keypadSetup.sqf new file mode 100644 index 00000000..52eea95e --- /dev/null +++ b/addons/mission/functions/fnc_keypadSetup.sqf @@ -0,0 +1,47 @@ +#include "..\script_component.hpp" +/* + * Author: Mike + * Prepares an object for keypad GUI + * + * Call from init.sqf + * + * Arguments: + * 0: Keypad + * 1: Required Code + * 2: Maximum Failed Attempts (default: 3) + * 2: Maximum Characters (default: 10) + * + * Return Value: + * None + * + * Example: + * [MyObject, "8008153", 5, 7] call MFUNC(keypadSetup) + */ + +params ["_object", "_requiredCode", ["_maxFailedAttempts", 3], ["_maxCharacters", 10]]; + +if (isServer) then { + _object setVariable [QGVAR(Keypad_currentFailedAttempts), 0, true]; + _object setVariable [QGVAR(Keypad_maxFailedAttempts), _maxFailedAttempts, true]; + _object setVariable [QGVAR(Keypad_maxCharacters), _maxCharacters, true]; + _object setVariable [QGVAR(Keypad_requiredCode), _requiredCode, true]; + _object setVariable [QGVAR(Keypad_Text), "", true]; +}; + +if (!hasInterface) exitWith {}; + +private _keypadAction = [ + format [QGVAR(keypadAction_%1), _object], + "Enter Code", + "", + { + createDialog QGVAR(Keypad); + _player setVariable [QGVAR(keypadInUse), _target, true]; + }, + { + !(_target getVariable [QGVAR(keypadFinished), false]) && + !(_target getVariable [QGVAR(keypadBlocked), false]) + } +] call ACEFUNC(interact_menu,createAction); + +[_object, 0, ["ACE_MainActions"], _keypadAction] call ACEFUNC(interact_menu,addActionToObject); diff --git a/addons/mission/script_component.hpp b/addons/mission/script_component.hpp index 6988baad..17550230 100644 --- a/addons/mission/script_component.hpp +++ b/addons/mission/script_component.hpp @@ -14,6 +14,7 @@ #define DEBUG_SETTINGS DEBUG_SETTINGS_MISSION #endif +#include "\a3\ui_f\hpp\defineResincl.inc" #include "\x\tac\addons\main\script_macros.hpp" #include "script_macros_mission.hpp"