-
Notifications
You must be signed in to change notification settings - Fork 151
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
base: master
Are you sure you want to change the base?
Added: QTE Framework #1649
Changes from 29 commits
ea657b5
964cefe
45929cd
bfa6ea8
3576e8e
dbc5abe
d35bfb8
986d828
26529cc
5255969
96806a9
6597fc8
9feffc8
c851040
68c586b
f48ebaa
d99bb4f
97fc243
29f9f11
1fbb063
c8e951b
24bf821
9eb7b18
7dc983f
a22d373
9a6cfb2
976eca3
6d2f3fe
6024704
8e236f2
83ca39f
46d200d
91e2722
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x\cba\addons\quicktime |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Extended_PreStart_EventHandlers { | ||
class ADDON { | ||
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); | ||
}; | ||
}; | ||
|
||
class Extended_PreInit_EventHandlers { | ||
class ADDON { | ||
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); | ||
}; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||||
class CfgFunctions { | ||||||||||
class CBA { | ||||||||||
class QuickTimeEvent { | ||||||||||
PATHTO_FNC(generateQTESequence); | ||||||||||
PATHTO_FNC(getFormattedQTESequence); | ||||||||||
PATHTO_FNC(runQTE); | ||||||||||
PATHTO_FNC(keyPressedQTE); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Order them alphabetically.
Suggested change
|
||||||||||
}; | ||||||||||
}; | ||||||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "script_component.hpp" | ||
#include "\a3\ui_f\hpp\defineDIKCodes.inc" | ||
|
||
SCRIPT(XEH_preInit); | ||
|
||
ADDON = false; | ||
|
||
[LSTRING(QTEKeybindGroup), QGVAR(qteUpKey), ["↑", LSTRING(QTEKeybindUpTooltip)], { | ||
["↑"] call CBA_fnc_keyPressedQTE // return | ||
}, {}, [DIK_UP, [false, true, false]]] call CBA_fnc_addKeybind; | ||
|
||
[LSTRING(QTEKeybindGroup), QGVAR(qteDownKey), ["↓", LSTRING(QTEKeybindDownTooltip)], { | ||
["↓"] call CBA_fnc_keyPressedQTE // return | ||
}, {}, [DIK_DOWN, [false, true, false]]] call CBA_fnc_addKeybind; | ||
|
||
[LSTRING(QTEKeybindGroup), QGVAR(qteLeftKey), ["←", LSTRING(QTEKeybindLeftTooltip)], { | ||
["←"] call CBA_fnc_keyPressedQTE // return | ||
}, {}, [DIK_LEFT, [false, true, false]]] call CBA_fnc_addKeybind; | ||
|
||
[LSTRING(QTEKeybindGroup), QGVAR(qteRightKey), ["→", LSTRING(QTEKeybindRightTooltip)], { | ||
["→"] call CBA_fnc_keyPressedQTE // return | ||
}, {}, [DIK_RIGHT, [false, true, false]]] call CBA_fnc_addKeybind; | ||
|
||
ADDON = true; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need this file, remove it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "script_component.hpp" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "script_component.hpp" | ||
|
||
class CfgPatches { | ||
class ADDON { | ||
name = CSTRING(component); | ||
units[] = {}; | ||
weapons[] = {}; | ||
requiredVersion = REQUIRED_VERSION; | ||
requiredAddons[] = {"cba_common","cba_events"}; | ||
author = "$STR_CBA_Author"; | ||
authors[] = {"john681611"}; | ||
url = "$STR_CBA_URL"; | ||
VERSION_CONFIG; | ||
}; | ||
}; | ||
|
||
#include "CfgFunctions.hpp" | ||
#include "CfgEventHandlers.hpp" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "script_component.hpp" | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_generateQTESequence | ||
|
||
Description: | ||
Generate a Quick-Time sequence of a given length. | ||
|
||
Parameters: | ||
_length - Length of QTE sequence <NUMBER> | ||
|
||
Example: | ||
[5] call CBA_fnc_generateQTESequence; | ||
|
||
Returns: | ||
Quick-Time sequence of requested length made up of ["↑", "↓", "→", "←"] <ARRAY> | ||
|
||
Author: | ||
john681611 | ||
---------------------------------------------------------------------------- */ | ||
|
||
params [["_length", 0, [0]]]; | ||
|
||
if (_length <= 0) exitWith {[]}; | ||
|
||
private _code = []; | ||
|
||
for "_i" from 0 to _length do { | ||
_code pushBack (selectRandom ["↑", "↓", "→", "←"]); | ||
}; | ||
|
||
_code |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "script_component.hpp" | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_getFormattedQTESequence | ||
|
||
Description: | ||
Formats Quick-Time sequence into a displayable string. | ||
|
||
Parameters: | ||
_code - Quick-Time sequence <ARRAY> | ||
|
||
|
||
Example: | ||
[["↑", "↓", "→", "←"]] call CBA_fnc_getFormattedQTESequence; | ||
|
||
Returns: | ||
Formatted Quick-Time sequence <STRING> | ||
|
||
Author: | ||
john681611 | ||
---------------------------------------------------------------------------- */ | ||
|
||
params ["_code"]; | ||
|
||
_code joinString " " // Arma doesn't know how to space ↑ so we need loads of spaces between |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||||
#include "script_component.hpp" | ||||||||
/* ---------------------------------------------------------------------------- | ||||||||
Function: CBA_fnc_keyPressedQTE | ||||||||
|
||||||||
Description: | ||||||||
Process Quick-Time Key Press | ||||||||
|
||||||||
Parameters: | ||||||||
_eventQTE - Character to test against Quick-Time Event <STRING> | ||||||||
|
||||||||
Example: | ||||||||
["↑"] call CBA_fnc_keyPressedQTE; | ||||||||
|
||||||||
Returns: | ||||||||
True if QTE is running <BOOLEAN> | ||||||||
|
||||||||
Author: | ||||||||
john681611 | ||||||||
---------------------------------------------------------------------------- */ | ||||||||
|
||||||||
|
||||||||
params ["_eventQTE"]; | ||||||||
|
||||||||
if !(missionNamespace getVariable [QGVAR(QTERunning), false]) exitWith { | ||||||||
false | ||||||||
}; | ||||||||
|
||||||||
|
||||||||
private _args = GVAR(QTEArgs) get "args"; | ||||||||
private _qteSequence = GVAR(QTEArgs) get "qteSeqence"; | ||||||||
private _elapsedTime = CBA_missionTime - (GVAR(QTEArgs) get "startTime"); | ||||||||
|
||||||||
GVAR(QTEHistory) pushBack _eventQTE; | ||||||||
|
||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if (GVAR(QTEHistory) isEqualTo _qteSequence) exitWith { | ||||||||
GVAR(QTEHistory) = []; | ||||||||
GVAR(QTERunning) = false; | ||||||||
TRACE_1("QTE Completed",_elapsedTime); | ||||||||
private _onFinish = GVAR(QTEArgs) get "onFinish"; | ||||||||
if (_onFinish isEqualType "") then { | ||||||||
[_onFinish, [_args, _elapsedTime]] call CBA_fnc_localEvent; | ||||||||
} else { | ||||||||
[_args, _elapsedTime] call _onFinish; | ||||||||
}; | ||||||||
true | ||||||||
}; | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if (GVAR(QTEHistory) isNotEqualTo (_qteSequence select [0, count GVAR(QTEHistory)])) then { | ||||||||
GVAR(QTEHistory) = []; | ||||||||
}; | ||||||||
|
||||||||
private _onDisplay = GVAR(QTEArgs) get "onDisplay"; | ||||||||
if (_onDisplay isEqualType "") then { | ||||||||
[_onDisplay, [_args, _qteSequence, GVAR(QTEHistory)]] call CBA_fnc_localEvent; | ||||||||
} else { | ||||||||
[_args, _qteSequence, GVAR(QTEHistory)] call _onDisplay; | ||||||||
}; | ||||||||
|
||||||||
true |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,94 @@ | ||||||||||||||||
#include "script_component.hpp" | ||||||||||||||||
/* ---------------------------------------------------------------------------- | ||||||||||||||||
Function: CBA_fnc_runQTE | ||||||||||||||||
|
||||||||||||||||
Description: | ||||||||||||||||
Runs a Quick-Time Event. | ||||||||||||||||
|
||||||||||||||||
Parameters: | ||||||||||||||||
_object - <OBJECT> | ||||||||||||||||
_args - Extra arguments passed to the _on... functions<ARRAY> | ||||||||||||||||
_onDisplay - Code callback on displayable event passed [_args, _qteSequence, _qteHistory]. <CODE, STRING> | ||||||||||||||||
_onFinish - Code callback on Quick-Time Event completed passed [_args, _elapsedTime]. <CODE, STRING> | ||||||||||||||||
_onFinish - Code callback on Quick-Time Event timeout/outranged passed [_args, _elapsedTime]. <CODE, STRING> | ||||||||||||||||
_qteSequence - Quick-Time sequence made up of ["↑", "↓", "→", "←"] <ARRAY> | ||||||||||||||||
_maxDistance - max interaction distance from attached object <NUMBER> (default: 10) | ||||||||||||||||
_timeout - ingame timeout <NUMBER> (default: 30) | ||||||||||||||||
|
||||||||||||||||
Example: | ||||||||||||||||
[car, | ||||||||||||||||
[], | ||||||||||||||||
{ | ||||||||||||||||
hint format [ | ||||||||||||||||
"%1 \n %2", | ||||||||||||||||
[_this select 1] call CBA_fnc_getFormattedQTESequence, | ||||||||||||||||
[_this select 2] call CBA_fnc_getFormattedQTESequence | ||||||||||||||||
] | ||||||||||||||||
}, | ||||||||||||||||
{ | ||||||||||||||||
hint "Finished!"; | ||||||||||||||||
}, | ||||||||||||||||
{ | ||||||||||||||||
hint "Failure!"; | ||||||||||||||||
}, | ||||||||||||||||
["↑", "↓", "→", "←"]] call CBA_fnc_runQTE | ||||||||||||||||
|
||||||||||||||||
Returns: | ||||||||||||||||
True if the QTE was started, false if it was already running <BOOELAN> | ||||||||||||||||
john681611 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
||||||||||||||||
Author: | ||||||||||||||||
john681611 | ||||||||||||||||
---------------------------------------------------------------------------- */ | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
params ["_object", "_args", "_onDisplay", "_onFinish", "_onFail", "_qteSequence", ["_maxDistance", 10], ["_timeout", 30]]; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a public function, we need to sanitise the input:
Suggested change
You need to check if the input are valid (e.g. an empty QTE sequence should not be allowed). I haven't taken into account the other proposals I've made, so you'll need to adapt accordingly. |
||||||||||||||||
if (GVAR(QTERunning)) exitWith { | ||||||||||||||||
false | ||||||||||||||||
}; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You could move this line above the |
||||||||||||||||
|
||||||||||||||||
GVAR(QTEHistory) = []; | ||||||||||||||||
GVAR(QTERunning) = true; | ||||||||||||||||
private _startTime = CBA_missionTime; | ||||||||||||||||
private _qteArgsArray = [ | ||||||||||||||||
["object", _object], | ||||||||||||||||
["args", _args], | ||||||||||||||||
["onDisplay", _onDisplay], | ||||||||||||||||
["onFinish", _onFinish], | ||||||||||||||||
["onFail", _onFail], | ||||||||||||||||
["maxDistance", _maxDistance], | ||||||||||||||||
["qteSeqence", _qteSequence], | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor typo has slipped in (change where necessary).
Suggested change
|
||||||||||||||||
["startTime", _startTime], | ||||||||||||||||
["timeout", _timeout] | ||||||||||||||||
]; | ||||||||||||||||
GVAR(QTEArgs) = createHashMapFromArray _qteArgsArray; | ||||||||||||||||
|
||||||||||||||||
// Setup | ||||||||||||||||
[{ | ||||||||||||||||
private _timeout = GVAR(QTEArgs) get "timeout"; | ||||||||||||||||
private _object = GVAR(QTEArgs) get "object"; | ||||||||||||||||
private _maxDistance = GVAR(QTEArgs) get "maxDistance"; | ||||||||||||||||
private _elapsedTime = CBA_missionTime - (GVAR(QTEArgs) get "startTime"); | ||||||||||||||||
|
||||||||||||||||
!GVAR(QTERunning) || player distance _object > _maxDistance || _elapsedTime > _timeout; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think having You'd evaluate it by calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not go a step further and remove the timeout and just pass |
||||||||||||||||
}, { | ||||||||||||||||
TRACE_1("QTE ended",GVAR(QTERunning)); | ||||||||||||||||
if(!GVAR(QTERunning)) exitWith {}; | ||||||||||||||||
GVAR(QTERunning) = false; | ||||||||||||||||
GVAR(QTEHistory) = []; | ||||||||||||||||
private _onFail = (GVAR(QTEArgs) get "onFail"); | ||||||||||||||||
private _args = (GVAR(QTEArgs) get "args"); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary parenthesis:
Suggested change
|
||||||||||||||||
TRACE_1("QTE Failed",_args); | ||||||||||||||||
if (_onFail isEqualType "") then { | ||||||||||||||||
[_onFail, [_args, _elapsedTime]] call CBA_fnc_localEvent; | ||||||||||||||||
} else { | ||||||||||||||||
[_args, _elapsedTime] call _onFail; | ||||||||||||||||
}; | ||||||||||||||||
}, []] call CBA_fnc_waitUntilAndExecute; | ||||||||||||||||
|
||||||||||||||||
if (_onDisplay isEqualType "") then { | ||||||||||||||||
[_onDisplay, [_args, _qteSequence, []]] call CBA_fnc_localEvent; | ||||||||||||||||
} else { | ||||||||||||||||
[_args, _qteSequence, []] call _onDisplay; | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#define COMPONENT quicktime | ||
#include "\x\cba\addons\main\script_mod.hpp" | ||
|
||
//#define DEBUG_MODE_FULL | ||
//#define DISABLE_COMPILE_CACHE | ||
//#define DEBUG_ENABLED_quicktime | ||
|
||
#ifdef DEBUG_ENABLED_QUICKTIME | ||
#define DEBUG_MODE_FULL | ||
#endif | ||
|
||
#ifdef DEBUG_SETTINGS_QUICKTIME | ||
#define DEBUG_SETTINGS DEBUG_SETTINGS_QUICKTIME | ||
#endif | ||
|
||
#define DEBUG_SYNCHRONOUS | ||
#include "\x\cba\addons\main\script_macros.hpp" | ||
|
||
#include "\a3\ui_f\hpp\defineResincl.inc" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project name="CBA_A3"> | ||
<Package name="Quicktime"> | ||
<Key ID="STR_cba_quicktime_QTEKeybindGroup"> | ||
<English>CBA Quick-Time Events</English> | ||
</Key> | ||
<Key ID="STR_cba_quicktime_QTEKeybindUpTooltip"> | ||
<English>Up key used in Quick-Time Events.</English> | ||
</Key> | ||
<Key ID="STR_cba_quicktime_QTEKeybindDownTooltip"> | ||
<English>Down key used in Quick-Time Events.</English> | ||
</Key> | ||
<Key ID="STR_cba_quicktime_QTEKeybindLeftTooltip"> | ||
<English>Left key used in Quick-Time Events.</English> | ||
</Key> | ||
<Key ID="STR_cba_quicktime_QTEKeybindRightTooltip"> | ||
<English>Right key used in Quick-Time Events.</English> | ||
</Key> | ||
</Package> | ||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove along with the file.