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

Added: QTE Framework #1649

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ea657b5
Added: QTE Framework
john681611 Mar 19, 2024
964cefe
Update addons/common/fnc_generateQTESequence.sqf
john681611 Mar 21, 2024
45929cd
refactor to use Keybinds
john681611 Mar 23, 2024
bfa6ea8
Merge branch 'quickTimeEvents' of github.com:john681611/CBA_A3 into q…
john681611 Mar 23, 2024
3576e8e
Fix null issue on key press
john681611 Mar 23, 2024
dbc5abe
review improvements
john681611 Mar 23, 2024
d35bfb8
Support localization
john681611 Mar 23, 2024
986d828
Update addons/common/XEH_preInit.sqf
john681611 Mar 26, 2024
26529cc
Update addons/common/fnc_generateQTESequence.sqf
john681611 Mar 26, 2024
5255969
Update addons/common/fnc_keyPressedQTE.sqf
john681611 Mar 26, 2024
96806a9
Update addons/common/fnc_runQTE.sqf
john681611 Mar 26, 2024
6597fc8
Update addons/common/stringtable.xml
john681611 Mar 26, 2024
9feffc8
Update addons/common/fnc_keyPressedQTE.sqf
john681611 Mar 26, 2024
c851040
Update addons/common/fnc_keyPressedQTE.sqf
john681611 Mar 26, 2024
68c586b
Update addons/common/fnc_keyPressedQTE.sqf
john681611 Mar 26, 2024
f48ebaa
review comments
john681611 Mar 26, 2024
d99bb4f
minor improvements
john681611 Mar 27, 2024
97fc243
Update addons/common/fnc_keyPressedQTE.sqf
john681611 Mar 27, 2024
29f9f11
Update addons/common/fnc_runQTE.sqf
john681611 Mar 27, 2024
1fbb063
Update addons/common/fnc_runQTE.sqf
john681611 Apr 2, 2024
c8e951b
Update addons/common/fnc_runQTE.sqf
john681611 Apr 2, 2024
24bf821
Update addons/common/fnc_runQTE.sqf
john681611 Apr 2, 2024
9eb7b18
format: camelcasing
john681611 Apr 30, 2024
7dc983f
Merge branch 'quickTimeEvents' of github.com:john681611/CBA_A3 into q…
john681611 Apr 30, 2024
a22d373
Update addons/common/XEH_preInit.sqf
john681611 Apr 30, 2024
9a6cfb2
migrate to quicktime component
john681611 Apr 30, 2024
976eca3
Merge branch 'quickTimeEvents' of github.com:john681611/CBA_A3 into q…
john681611 Apr 30, 2024
6d2f3fe
minor fixes
john681611 Apr 30, 2024
6024704
Fix sneaky keybind error
john681611 Apr 30, 2024
8e236f2
Review comment improvements
john681611 May 5, 2024
83ca39f
Use more generic condition and reset counter
john681611 May 5, 2024
46d200d
Update addons/quicktime/fnc_runQTE.sqf
john681611 Jun 24, 2024
91e2722
Implement Single Key press as Accessability option
john681611 Dec 2, 2024
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
6 changes: 6 additions & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,11 @@ class CfgFunctions {
class Broken {
PATHTO_FNC(actionArgument);
};

class QuickTimeEvent {
PATHTO_FNC(generateQTESequence);
PATHTO_FNC(getFormattedQTESequence);
PATHTO_FNC(runQTE);
};
};
};
28 changes: 28 additions & 0 deletions addons/common/fnc_generateQTESequence.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "script_component.hpp"
/*
* Author: john681611
* Generates a Quick Time Event seqence (= a random sequence of arrow characters of a given length).
john681611 marked this conversation as resolved.
Show resolved Hide resolved
*
* Arguments:
* 0: Code length <NUMBER>
*
* Return Value:
* Array of arrow characters <ARRAY>
*
* Example:
* 5 call ace_common_fnc_generateQTESequence
*
* Public: Yes
*/

params [["_length", 0, [0]]];

if (_length <= 0) exitWith {[]};

private _code = [];

for "_i" from 0 to _length do {
_code pushBack (selectRandom ["↑", "↓", "→", "←"]);
};

_code
20 changes: 20 additions & 0 deletions addons/common/fnc_getFormattedQTESequence.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "script_component.hpp"
/*
* Author: john681611
* Formats QTE code into something displayable.
*
* Argument:
* 0: QTE Code <ARRAY>
*
* Return Value:
* Formatted QTE Code <STRING>
*
* Example:
* [["↑", "↓", "→", "←"]] call ace_common_fnc_getFormattedQTESequence
*
* Public: Yes
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other headers are formatted different from this one.


params ["_code"];

_code joinString " " // Arma doesn't know how to space ↑ so we need loads of spaces between
163 changes: 163 additions & 0 deletions addons/common/fnc_runQTE.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineDIKCodes.inc"
/*
* Author: john681611
* Runs a Quick time Event.
*
* Arguments:
* 0: Object QTE is attached to <OBJECT>
* 1: Arguments, passed to condition, fail and finish <ARRAY>
* 2: On Display: Code callback on displayable event. <CODE, STRING>
* 2: On Finish: Code called or STRING raised as event. <CODE, STRING>
* 3: On Failure: Code called or STRING raised as event. <CODE, STRING>
* 4: QTE Seqence <ARRAY>
* 5: max interaction distance from attached object <NUMBER> (default: 10)
* 6: timout <NUMBER> (default: 30)
*
* Return Value:
* None
*
* Example:
* [car, [], {
hint "Finished!"
}, {
hint "Failure!"
}, ["↑", "↓", "→", "←"]] call ace_common_fnc_runQTE
*
* Public: Yes
*/

params ["_object", "_args", "_onDisplay", "_onFinish", "_onFail", "_qte_seqence", ["_max_distance", 10], ["_timeout", 30]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
params ["_object", "_args", "_onDisplay", "_onFinish", "_onFail", "_qte_seqence", ["_max_distance", 10], ["_timeout", 30]];
params ["_object", "_args", "_onDisplay", "_onFinish", "_onFail", "_qte_sequence", ["_max_distance", 10], ["_timeout", 30]];


if (!GVAR(settingsInitFinished)) exitWith {
// only run this after the settings are initialized
GVAR(runAtSettingsInitialized) pushBack [FUNC(runQTE), _this];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now leave this aside, or bring it up-to-date with CBA.


if (GVAR(QTERunning)) exitWith {
TRACE_1("QTE already running qeueing up", GVAR(QTERunning));
[{
!GVAR(QTERunning)
}, {
_this call FUNC(runQTE);
}, _this] call CBA_fnc_waitUntilAndExecute;
};

private _display = findDisplay 46;

if (isNull _display) exitWith {
TRACE_1("Waiting for main display to be ready", isNull (_display));
[{
!isNull (findDisplay 46)
}, {
_this call FUNC(runQTE);
}, _this] call CBA_fnc_waitUntilAndExecute;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo it should be up to the user to check whenever it's ready. This should only return false or an error code that it couldn't run. The removal of these waitUntilAndExecute would make the _onDisplay event redundant.

The display on which the QTE is drawn should be an argument, so that people can run it wherever they want to (e.g. Zeus interface). Because of comment below, this is no longer relevant.

};

if (_onDisplay isEqualType "") then {
[_onDisplay, [_args, [_qte_seqence, [_qte_seqence] call FUNC(getFormattedQTESequence)], [[], ""]]] call CBA_fnc_localEvent;
} else {
[_args, [_qte_seqence, [_qte_seqence] call FUNC(getFormattedQTESequence)], [[], ""]] call _onDisplay;
};

GVAR(QTEHistory) = [];
GVAR(QTERunning) = true;
private _start_time = CBA_missionTime;

[_display, "KeyUp", {
params ["_displayOrControl", "_key", "_shift", "_ctrl", "_alt"];
_thisArgs params ["_object", "_args", "_onDisplay", "_onFinish", "_onFail", "_max_distance", "_qte_seqence", "_start_time", "_timeout", "_display"];
private _elapsedTime = CBA_missionTime - _start_time;

if (player distance _object > _max_distance || _elapsedTime > _timeout) exitWith {
_display displayRemoveEventHandler ["KeyUp", _thisID];
GVAR(QTERunning) = false;
if (_onFail isEqualType "") then {
[_onFail, [_args, _elapsedTime]] call CBA_fnc_localEvent;
} else {
[_args, _elapsedTime] call _onFail;
};
};

private _inputKeys = [DIK_UP, DIK_DOWN, DIK_LEFT, DIK_RIGHT];
switch (GVAR(QTEInputKeys)) do {
case 1: {
_inputKeys = [DIK_W, DIK_S, DIK_A, DIK_D];
};
case 2: {
_inputKeys = [DIK_I, DIK_K, DIK_J, DIK_L];
};
case 3: {
_inputKeys = [DIK_NUMPAD8, DIK_NUMPAD2, DIK_NUMPAD4, DIK_NUMPAD6];
};
default {
_inputKeys = [DIK_UP, DIK_DOWN, DIK_LEFT, DIK_RIGHT];
};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike this strongly. It uses CBA settings for keybind sets, when we can use CBA keybinds instead.
This would allow for way more flexibility and customisability, as 3rd party mods or mod makers could add their own extra keybinds.

Register 4 keybinds. Here's an example (strings would need to be localised and improved):

["QTE Keybinds", QGVAR(keyUpQTE), ["QTE up key", "Up key used in QTE events."], {
    [""] call FUNC(keyPressedQTE); // return
}, {}, [DIK_UP, [false, false, false]]] call CBA_fnc_addKeybind;

In fnc_keyPressedQTE, you'd check if the keypress is good or not:

params ["_eventQTE"];

// Check if the passed parameter is the next key in the QTE sequence
// If yes, continue
// If no, stop

Imo, we should make the QTE agonistic of the QTE chars themselves ("↑"). That should be configurable by the user. It will add an extra layer of complexity to the whole things, so we'll have to see if it's worth it.

Copy link
Author

@john681611 john681611 Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it simple and start with assigning keys to "↑" etc then we can look at expanding to other keys.


if !(_key in _inputKeys) exitWith {};

if ((GVAR(QTEHoldKey) == 0 && !_ctrl) ||
(GVAR(QTEHoldKey) == 1 &&!_alt) ||
(GVAR(QTEHoldKey) == 2 &&!_shift)) exitWith {
GVAR(QTEHistory) = [];
if (_onDisplay isEqualType "") then {
[_onDisplay, [
_args,
[_qte_seqence, [_qte_seqence] call FUNC(getFormattedQTESequence)],
[[GVAR(QTEHistory), [GVAR(QTEHistory)] call FUNC(getFormattedQTESequence)]]
]] call CBA_fnc_localEvent;
} else {
[_args, [_qte_seqence, [_qte_seqence] call FUNC(getFormattedQTESequence)], [[GVAR(QTEHistory), [GVAR(QTEHistory)] call FUNC(getFormattedQTESequence)]]] call _onDisplay;
};
};
_override = true;

if (_key == (_inputKeys select 0)) then {
GVAR(QTEHistory) pushBack "↑";
};

if (_key == (_inputKeys select 1)) then {
GVAR(QTEHistory) pushBack "↓";
};

if (_key == (_inputKeys select 2)) then {
GVAR(QTEHistory) pushBack "←";
};

if (_key == (_inputKeys select 3)) then {
GVAR(QTEHistory) pushBack "→";
};
if (GVAR(QTEHistory) isEqualTo _qte_seqence) exitWith {
GVAR(QTEHistory) = [];
_display displayRemoveEventHandler ["KeyUp", _thisID];
GVAR(QTERunning) = false;
if (_onFinish isEqualType "") then {
[_onFinish, [_args, _elapsedTime]] call CBA_fnc_localEvent;
} else {
[_args, _elapsedTime] call _onFinish;
};
};

if !(GVAR(QTEHistory) isEqualTo (_qte_seqence select [0, count GVAR(QTEHistory)])) then {
GVAR(QTEHistory) = [];
};

if (_onDisplay isEqualType "") then {
[_onDisplay, [_args, [_qte_seqence, [_qte_seqence] call FUNC(getFormattedQTESequence)], [[GVAR(QTEHistory), [GVAR(QTEHistory)] call FUNC(getFormattedQTESequence)]]]] call CBA_fnc_localEvent;
} else {
[_args, [_qte_seqence, [_qte_seqence] call FUNC(getFormattedQTESequence)], [[GVAR(QTEHistory), [GVAR(QTEHistory)] call FUNC(getFormattedQTESequence)]]] call _onDisplay;
};
true;
}, [
_object,
_args,
_onDisplay,
_onFinish,
_onFail,
_max_distance,
_qte_seqence,
_start_time,
_timeout,
_display
]] call CBA_fnc_addBISEventHandler;
18 changes: 18 additions & 0 deletions addons/common/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,23 @@
<Russian>CBA Оружие</Russian>
<Korean>CBA 무기</Korean>
</Key>
<Key ID="STR_cba_common_QTEHoldKey">
<English>Hold Down Key</English>
</Key>
<Key ID="STR_cba_common_QTEInputKeys">
<English>Input Keys</English>
</Key>
<Key ID="STR_cba_common_QTEInputArrows">
<English>Arrows</English>
</Key>
<Key ID="STR_cba_common_QTEInputWASD">
<English>WASD</English>
</Key>
<Key ID="STR_cba_common_QTEInputIJKL">
<English>IJKL</English>
</Key>
<Key ID="STR_cba_common_QTENumpad">
<English>Numpad</English>
</Key>
</Package>
</Project>