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

Mission - Add Keypad functionality #723

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
126 changes: 126 additions & 0 deletions addons/mission/RscGUI.hpp
Original file line number Diff line number Diff line change
@@ -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));
};
};
};
2 changes: 2 additions & 0 deletions addons/mission/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ PREP(enableAI);
PREP(forceShooting);
PREP(groundFog);
PREP(jam);
PREP(keypadPress);
PREP(keypadSetup);
PREP(lockDoors);
PREP(markBuildings);
PREP(mortarStrike);
Expand Down
1 change: 1 addition & 0 deletions addons/mission/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ class CfgPatches {
};

#include "CfgEventHandlers.hpp"
#include "RscGUI.hpp"
76 changes: 76 additions & 0 deletions addons/mission/functions/fnc_keypadPress.sqf
Original file line number Diff line number Diff line change
@@ -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 <NUMBER/STRING> (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"];
};
};
47 changes: 47 additions & 0 deletions addons/mission/functions/fnc_keypadSetup.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "..\script_component.hpp"
/*
* Author: Mike
* Prepares an object for keypad GUI
*
* Call from init.sqf
*
* Arguments:
* 0: Keypad <OBJECT>
* 1: Required Code <STRING>
* 2: Maximum Failed Attempts <NUMBER> (default: 3)
* 2: Maximum Characters <NUMBER> (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);
1 change: 1 addition & 0 deletions addons/mission/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading