-
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 5 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
#include "\a3\ui_f\hpp\defineDIKCodes.inc" | ||
SCRIPT(XEH_preInit); | ||
|
||
LOG(MSG_INIT); | ||
|
@@ -78,3 +79,19 @@ activateAddons GVAR(addons); | |
["CAManBase", "InitPost", CBA_fnc_randomizeFacewear] call CBA_fnc_addClassEventHandler; | ||
|
||
ADDON = true; | ||
|
||
["CBA QTE", "QTE_Up_Key", ["↑", "Up key used in QTE events."], {}, { | ||
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. Personally have a problem with Making it
|
||
["↑"] call CBA_fnc_keyPressedQTE; | ||
}, [DIK_UP, [false, true, false]]] call CBA_fnc_addKeybind; | ||
|
||
["CBA QTE", "QTE_Down_Key", ["↓", "Down key used in QTE events."], {}, { | ||
["↓"] call CBA_fnc_keyPressedQTE; | ||
}, [DIK_DOWN, [false, true, false]]] call CBA_fnc_addKeybind; | ||
|
||
["CBA QTE", "QTE_Left_Key", ["←", "Left key used in QTE events."], {}, { | ||
["←"] call CBA_fnc_keyPressedQTE; | ||
}, [DIK_LEFT, [false, true, false]]] call CBA_fnc_addKeybind; | ||
|
||
["CBA QTE", "QTE_Right_Key", ["→", "Right key used in QTE events."], {}, { | ||
["→"] call CBA_fnc_keyPressedQTE; | ||
}, [DIK_RIGHT, [false, true, false]]] call CBA_fnc_addKeybind; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||
#include "script_component.hpp" | ||||||
/* ---------------------------------------------------------------------------- | ||||||
Function: CBA_fnc_generateQTESequence | ||||||
|
||||||
Description: | ||||||
Generate a QTE sequence of a given length. | ||||||
|
||||||
Parameters: | ||||||
_length - <NUMBER> | ||||||
|
||||||
john681611 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Example: | ||||||
[5] call CBA_fnc_generateQTESequence; | ||||||
|
||||||
Returns: | ||||||
QTE seqence of requested length made up of ["↑", "↓", "→", "←"] <ARRAY> | ||||||
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
|
||||||
|
||||||
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,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 | ||
*/ | ||
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. 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 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||
#include "script_component.hpp" | ||||||
/* ---------------------------------------------------------------------------- | ||||||
Function: CBA_fnc_keyPressedQTE | ||||||
|
||||||
Description: | ||||||
Process QTE Key Press | ||||||
|
||||||
Parameters: | ||||||
_eventQTE - <STRING> | ||||||
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. Argument needs description. |
||||||
|
||||||
john681611 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Example: | ||||||
["↑"] call CBA_fnc_keyPressedQTE; | ||||||
|
||||||
Returns: | ||||||
Nil | ||||||
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. It would be We want to "override" input if it's a valid QTE keypress, meaning that e.g. if you have bound your arrow up key to move forwards, you wouldn't move forwards while you are doing a QTE. 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. Is this where we return true/false in terms of input override? 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. Yep |
||||||
|
||||||
Author: | ||||||
john681611 | ||||||
---------------------------------------------------------------------------- */ | ||||||
|
||||||
|
||||||
params ["_eventQTE"]; | ||||||
GVAR(QTERunning) = RETDEF(GVAR(QTERunning),false); | ||||||
if!(GVAR(QTERunning)) exitWith {}; | ||||||
if!(_eventQTE in ["↑", "↓", "→", "←"]) exitWith {}; | ||||||
|
||||||
john681611 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
private _object = GVAR(QTEArgs) get "object"; | ||||||
private _args = GVAR(QTEArgs) get "args"; | ||||||
private _onDisplay = GVAR(QTEArgs) get "onDisplay"; | ||||||
private _onFinish = GVAR(QTEArgs) get "onFinish"; | ||||||
private _onFail = GVAR(QTEArgs) get "onFail"; | ||||||
private _max_distance = GVAR(QTEArgs) get "max_distance"; | ||||||
private _qte_seqence = GVAR(QTEArgs) get "qte_seqence"; | ||||||
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
|
||||||
private _start_time = GVAR(QTEArgs) get "start_time"; | ||||||
|
||||||
private _elapsedTime = CBA_missionTime - _start_time; | ||||||
|
||||||
GVAR(QTEHistory) pushBack _eventQTE; | ||||||
|
||||||
|
||||||
if (GVAR(QTEHistory) isEqualTo _qte_seqence) exitWith { | ||||||
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
|
||||||
GVAR(QTEHistory) = []; | ||||||
GVAR(QTERunning) = false; | ||||||
TRACE_1("QTE Completed",_elapsedTime); | ||||||
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 { | ||||||
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
|
||||||
GVAR(QTEHistory) = []; | ||||||
}; | ||||||
|
||||||
if (_onDisplay isEqualType "") then { | ||||||
[_onDisplay, [_args, _qte_seqence, GVAR(QTEHistory)]] call CBA_fnc_localEvent; | ||||||
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
|
||||||
} else { | ||||||
[_args, _qte_seqence, GVAR(QTEHistory)] call _onDisplay; | ||||||
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
|
||||||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,99 @@ | ||||||
#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, _qte_seqence, _qte_history]. <CODE, STRING> | ||||||
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
|
||||||
_onFinish - Code callback on QTE completed passed [_args, _elapsedTime]. <CODE, STRING> | ||||||
_onFinish - Code callback on QTE timeout/outranged passed [_args, _elapsedTime]. <CODE, STRING> | ||||||
_qte_seqence - QTE seqence usually made up of ["↑", "↓", "→", "←"] <ARRAY> | ||||||
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
|
||||||
_max_distance - max interaction distance from attached object <NUMBER> (default: 10) | ||||||
_timeout - ingame timeout <NUMBER> (default: 30) | ||||||
|
||||||
Example: | ||||||
[ | ||||||
car, | ||||||
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. A lot of tabs in this file at least. |
||||||
[], | ||||||
{ | ||||||
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: | ||||||
Nil | ||||||
|
||||||
Author: | ||||||
john681611 | ||||||
---------------------------------------------------------------------------- */ | ||||||
|
||||||
|
||||||
params ["_object", "_args", "_onDisplay", "_onFinish", "_onFail", "_qte_seqence", ["_max_distance", 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.
Suggested change
|
||||||
if (GVAR(QTERunning)) exitWith { | ||||||
TRACE_1("QTE already running qeueing up",GVAR(QTERunning)); | ||||||
[{ | ||||||
!GVAR(QTERunning) | ||||||
}, { | ||||||
_this call FUNC(runQTE); | ||||||
}, _this] call CBA_fnc_waitUntilAndExecute; | ||||||
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'm still not a fan of this. Depending, we might have to wait indefinitely. It also means that multiple QTE can queue up, which could cause unforeseen headaches, albeit unlikely. I think we'd be better off returning a boolean telling the caller if the QTE was successfully run or not. |
||||||
}; | ||||||
|
||||||
GVAR(QTEHistory) = []; | ||||||
GVAR(QTERunning) = true; | ||||||
private _start_time = CBA_missionTime; | ||||||
private _qteArgsArray = [ | ||||||
["object", _object], | ||||||
["args", _args], | ||||||
["onDisplay", _onDisplay], | ||||||
["onFinish", _onFinish], | ||||||
["onFail", _onFail], | ||||||
["max_distance", _max_distance], | ||||||
["qte_seqence", _qte_seqence], | ||||||
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
|
||||||
["start_time", _start_time], | ||||||
["timeout", _timeout] | ||||||
]; | ||||||
GVAR(QTEArgs) = createHashMapObject [_qteArgsArray]; | ||||||
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. As far as I can tell, there is no reason to use a hashmap object.
Suggested change
|
||||||
|
||||||
// Setup | ||||||
[{ | ||||||
private _timeout = GVAR(QTEArgs) get "timeout"; | ||||||
private _object = GVAR(QTEArgs) get "object"; | ||||||
private _max_distance = GVAR(QTEArgs) get "max_distance"; | ||||||
private _elapsedTime = CBA_missionTime - (GVAR(QTEArgs) get "start_time"); | ||||||
|
||||||
!GVAR(QTERunning) || player distance _object > _max_distance || _elapsedTime > _timeout; | ||||||
}, { | ||||||
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"); | ||||||
TRACE_1("QTE Failed",_args); | ||||||
if (_onFail isEqualType "") then { | ||||||
[_onFail, [_args, _elapsedTime]] call CBA_fnc_localEvent; | ||||||
} else { | ||||||
[_args, _elapsedTime] call _onFail; | ||||||
}; | ||||||
}, _this] call CBA_fnc_waitUntilAndExecute; | ||||||
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. You can't pass Regardless, |
||||||
|
||||||
if (_onDisplay isEqualType "") then { | ||||||
[_onDisplay, [_args, _qte_seqence, []]] call CBA_fnc_localEvent; | ||||||
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
|
||||||
} else { | ||||||
[_args, _qte_seqence, []] call _onDisplay; | ||||||
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
|
||||||
}; | ||||||
john681611 marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
All the code should be added before this line.
However, more importantly adding keybinds in
common
doesn't work.keybinding
depends oncommon
, meaning the code below is called whenCBA_fnc_addKeybind
is not defined.This means that this code needs to be moved to another component. I'm not sure if
events
is the right place or if we should add another component, just for this.