-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
141 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#include "script_component.hpp" | ||
|
||
PREP(keyHandler); | ||
PREP(keyHandlerDown); | ||
PREP(keyHandlerUp); | ||
#include "script_component.hpp" | ||
|
||
PREP(keyHandler); | ||
PREP(keyHandlerDown); | ||
PREP(keyHandlerUp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,77 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Internal Function: CBA_events_fnc_keyHandlerDown | ||
Description: | ||
Executes the key's handler | ||
Author: | ||
Sickboy, commy2 | ||
---------------------------------------------------------------------------- */ | ||
// #define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
SCRIPT(keyHandlerDown); | ||
|
||
params ["", "_inputKey"]; | ||
|
||
if (_inputKey == 0) exitWith {}; | ||
|
||
private _inputSettings = _this select [2,3]; | ||
|
||
private _blockInput = false; | ||
|
||
{ | ||
private _keybindParams = GVAR(keyHandlersDown) getVariable _x; | ||
|
||
_keybindParams params ["", "_keybindSettings", "_code", "_allowHold", "_holdDelay"]; | ||
|
||
// Verify if the required modifier keys are present | ||
if (_keybindSettings isEqualTo _inputSettings) then { | ||
private _xUp = _x + "_cbadefaultuphandler"; | ||
private _execute = true; | ||
private _holdTime = 0; | ||
|
||
if (_holdDelay > 0) then { | ||
_holdTime = GVAR(keyHoldTimers) getVariable _xUp; | ||
|
||
if (isNil "_holdTime") then { | ||
_holdTime = diag_tickTime + _holdDelay; | ||
GVAR(keyHoldTimers) setVariable [_xUp, _holdTime]; | ||
}; | ||
|
||
if (diag_tickTime < _holdTime) then { | ||
_execute = false; | ||
}; | ||
}; | ||
|
||
// check if either holding down a key is enabled or if the key wasn't already held down | ||
if (_execute && {_allowHold || {GVAR(keyUpActiveList) pushBackUnique _xUp != -1}}) then { | ||
private _params = + _this; | ||
_params pushBack + _keybindParams; | ||
_params pushBack _x; | ||
|
||
_blockInput = _params call _code; | ||
|
||
#ifdef DEBUG_MODE_FULL | ||
if ((isNil "_blockInput") || {!(_blockInput isEqualType false)}) then { | ||
LOG(PFORMAT_2("Keybind Handler returned nil or non-bool", _x, _blockInput)); | ||
}; | ||
#endif | ||
}; | ||
|
||
if (_blockInput isEqualTo true) exitWith {}; | ||
}; | ||
} forEach (GVAR(keyDownStates) param [_inputKey, []]); | ||
|
||
// To have a valid key up we first need to have a valid key down of the same combo! | ||
// If we do, we add it to a list of pressed key up combos, then on key up we check that list to see if we have a valid key up. | ||
{ | ||
private _keybindParams = GVAR(keyHandlersUp) getVariable _x; | ||
|
||
_keybindParams params ["", "_keybindSettings"]; | ||
|
||
// Verify if the required modifier keys are present | ||
if (_keybindSettings isEqualTo _inputSettings) then { | ||
GVAR(keyDownActiveList) pushBackUnique _x; | ||
}; | ||
} forEach (GVAR(keyUpStates) param [_inputKey, []]); | ||
|
||
//Only return true if _blockInput is defined and is type bool (handlers could return anything): | ||
(!isNil "_blockInput") && {_blockInput isEqualTo true} | ||
/* ---------------------------------------------------------------------------- | ||
Internal Function: CBA_events_fnc_keyHandlerDown | ||
Description: | ||
Executes the key's handler | ||
Author: | ||
Sickboy, commy2 | ||
---------------------------------------------------------------------------- */ | ||
// #define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
SCRIPT(keyHandlerDown); | ||
|
||
params ["", "_inputKey"]; | ||
|
||
if (_inputKey == 0) exitWith {}; | ||
|
||
private _inputSettings = _this select [2,3]; | ||
|
||
private _blockInput = false; | ||
|
||
{ | ||
private _keybindParams = GVAR(keyHandlersDown) getVariable _x; | ||
|
||
_keybindParams params ["", "_keybindSettings", "_code", "_allowHold", "_holdDelay"]; | ||
|
||
// Verify if the required modifier keys are present | ||
if (_keybindSettings isEqualTo _inputSettings) then { | ||
private _xUp = _x + "_cbadefaultuphandler"; | ||
private _execute = true; | ||
private _holdTime = 0; | ||
|
||
if (_holdDelay > 0) then { | ||
_holdTime = GVAR(keyHoldTimers) getVariable _xUp; | ||
|
||
if (isNil "_holdTime") then { | ||
_holdTime = diag_tickTime + _holdDelay; | ||
GVAR(keyHoldTimers) setVariable [_xUp, _holdTime]; | ||
}; | ||
|
||
if (diag_tickTime < _holdTime) then { | ||
_execute = false; | ||
}; | ||
}; | ||
|
||
// check if either holding down a key is enabled or if the key wasn't already held down | ||
if (_execute && {_allowHold || {GVAR(keyUpActiveList) pushBackUnique _xUp != -1}}) then { | ||
private _params = + _this; | ||
_params pushBack + _keybindParams; | ||
_params pushBack _x; | ||
|
||
_blockInput = _params call _code; | ||
|
||
#ifdef DEBUG_MODE_FULL | ||
if ((isNil "_blockInput") || {!(_blockInput isEqualType false)}) then { | ||
LOG(PFORMAT_2("Keybind Handler returned nil or non-bool", _x, _blockInput)); | ||
}; | ||
#endif | ||
}; | ||
|
||
if (_blockInput isEqualTo true) exitWith {}; | ||
}; | ||
} forEach (GVAR(keyDownStates) param [_inputKey, []]); | ||
|
||
// To have a valid key up we first need to have a valid key down of the same combo! | ||
// If we do, we add it to a list of pressed key up combos, then on key up we check that list to see if we have a valid key up. | ||
{ | ||
private _keybindParams = GVAR(keyHandlersUp) getVariable _x; | ||
|
||
_keybindParams params ["", "_keybindSettings"]; | ||
|
||
// Verify if the required modifier keys are present | ||
if (_keybindSettings isEqualTo _inputSettings) then { | ||
GVAR(keyDownActiveList) pushBackUnique _x; | ||
}; | ||
} forEach (GVAR(keyUpStates) param [_inputKey, []]); | ||
|
||
//Only return true if _blockInput is defined and is type bool (handlers could return anything): | ||
(!isNil "_blockInput") && {_blockInput isEqualTo true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_targetEvent | ||
Description: | ||
Raises a CBA event on all machines where this object or at least one of these objects are local. | ||
Parameters: | ||
_eventName - Type of event to publish. <STRING> | ||
_params - Parameters to pass to the event handlers. <ANY> | ||
_targets - Where to execute events. <OBJECT, GROUP, ARRAY> | ||
Returns: | ||
None | ||
Examples: | ||
(begin example) | ||
["test", ["target"], cursorTarget] call CBA_fnc_targetEvent; | ||
(end) | ||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(targetEvent); | ||
|
||
params [["_eventName", "", [""]], ["_params", []], ["_targets", objNull, [objNull, grpNull, []]]]; | ||
|
||
if !(_targets isEqualType []) then { | ||
_targets = [_targets]; | ||
}; | ||
|
||
private _remoteTargets = _targets select {!local GETOBJ(_x)}; | ||
|
||
// do local events if there is a local target | ||
if (count _targets > count _remoteTargets) then { | ||
CALL_EVENT(_params,_eventName); | ||
}; | ||
|
||
// no networking when no targets are remote | ||
if (_remoteTargets isEqualTo []) exitWith {}; | ||
|
||
if (isServer) then { | ||
private _sentOwners = []; | ||
|
||
{ | ||
private _owner = owner GETOBJ(_x); | ||
|
||
// only send event once each time this function is called, even if multipe targets are local to the same machine | ||
if !(_owner in _sentOwners) then { | ||
_sentOwners pushBack _owner; | ||
SEND_EVENT_TO_CLIENT(_params,_eventName,_owner); | ||
}; | ||
} forEach _remoteTargets; | ||
} else { | ||
// only server knows object owners. let server handle the event. | ||
SEND_TEVENT_TO_SERVER(_params,_eventName,_remoteTargets); | ||
}; | ||
|
||
nil | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_targetEvent | ||
Description: | ||
Raises a CBA event on all machines where this object or at least one of these objects are local. | ||
Parameters: | ||
_eventName - Type of event to publish. <STRING> | ||
_params - Parameters to pass to the event handlers. <ANY> | ||
_targets - Where to execute events. <OBJECT, GROUP, ARRAY> | ||
Returns: | ||
None | ||
Examples: | ||
(begin example) | ||
["test", ["target"], cursorTarget] call CBA_fnc_targetEvent; | ||
(end) | ||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(targetEvent); | ||
|
||
params [["_eventName", "", [""]], ["_params", []], ["_targets", objNull, [objNull, grpNull, []]]]; | ||
|
||
if !(_targets isEqualType []) then { | ||
_targets = [_targets]; | ||
}; | ||
|
||
private _remoteTargets = _targets select {!local GETOBJ(_x)}; | ||
|
||
// do local events if there is a local target | ||
if (count _targets > count _remoteTargets) then { | ||
CALL_EVENT(_params,_eventName); | ||
}; | ||
|
||
// no networking when no targets are remote | ||
if (_remoteTargets isEqualTo []) exitWith {}; | ||
|
||
if (isServer) then { | ||
private _sentOwners = []; | ||
|
||
{ | ||
private _owner = owner GETOBJ(_x); | ||
|
||
// only send event once each time this function is called, even if multipe targets are local to the same machine | ||
if !(_owner in _sentOwners) then { | ||
_sentOwners pushBack _owner; | ||
SEND_EVENT_TO_CLIENT(_params,_eventName,_owner); | ||
}; | ||
} forEach _remoteTargets; | ||
} else { | ||
// only server knows object owners. let server handle the event. | ||
SEND_TEVENT_TO_SERVER(_params,_eventName,_remoteTargets); | ||
}; | ||
|
||
nil |