Skip to content

Commit 85574d6

Browse files
author
Isak Almgren
committed
Added ability to consume actions
1 parent d16495c commit 85574d6

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

KeyBindings.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,52 @@ bool KeyBindings::ActionDownUp( InputContext& input, BindContextHandle bindConte
121121
}
122122
}
123123

124+
bool KeyBindings::ActionUpDownConsume( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType, bool ignorePause ) const {
125+
assert( static_cast<int>( action ) < m_ActionDescriptions.size() );
126+
const BindContext* context = GetBindContext( bindContextHandle );
127+
if ( inputType == INPUT_TYPE_KEYBOARD ) {
128+
return input.KeyUpDownConsume( context->GetKeyBindCollection().GetPrimaryScancodeFromAction( action )/*, ignorePause*/ ) ||
129+
input.KeyUpDownConsume( context->GetKeyBindCollection().GetSecondaryScancodeFromAction( action )/*, ignorePause*/ );
130+
} else if ( inputType == INPUT_TYPE_ANY ) {
131+
if ( ActionUpDownConsume( input, bindContextHandle, action, INPUT_TYPE_KEYBOARD, ignorePause ) ) {
132+
return true;
133+
}
134+
for ( int i = 0; i < INPUT_MAX_NR_OF_GAMEPADS; ++i ) {
135+
if ( ActionUpDownConsume( input, bindContextHandle, action, static_cast<INPUT_TYPE>( i ), ignorePause ) ) {
136+
return true;
137+
}
138+
}
139+
return false;
140+
} else {
141+
assert( inputType >= 0 && static_cast<int>( inputType ) < INPUT_MAX_NR_OF_GAMEPADS );
142+
const GamepadContext& gamepad = input.GetGamepadContext( inputType );
143+
return gamepad.ButtonUpDown( context->GetGamepadBindCollection().GetButtonFromAction( action ) );
144+
}
145+
}
146+
147+
bool KeyBindings::ActionDownUpConsume( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType, bool ignorePause ) const {
148+
assert( static_cast<int>( action ) < m_ActionDescriptions.size() );
149+
const BindContext* context = GetBindContext( bindContextHandle );
150+
if ( inputType == INPUT_TYPE_KEYBOARD ) {
151+
return input.KeyDownUpConsume( context->GetKeyBindCollection().GetPrimaryScancodeFromAction( action )/*, ignorePause*/ ) ||
152+
input.KeyDownUpConsume( context->GetKeyBindCollection().GetSecondaryScancodeFromAction( action )/*, ignorePause*/ );
153+
} else if ( inputType == INPUT_TYPE_ANY ) {
154+
if ( ActionDownUpConsume( input, bindContextHandle, action, INPUT_TYPE_KEYBOARD, ignorePause ) ) {
155+
return true;
156+
}
157+
for ( int i = 0; i < INPUT_MAX_NR_OF_GAMEPADS; ++i ) {
158+
if ( ActionDownUpConsume( input, bindContextHandle, action, static_cast<INPUT_TYPE>( i ), ignorePause ) ) {
159+
return true;
160+
}
161+
}
162+
return false;
163+
} else {
164+
assert( inputType >= 0 && static_cast<int>( inputType ) < INPUT_MAX_NR_OF_GAMEPADS );
165+
const GamepadContext& gamepad = input.GetGamepadContext( inputType );
166+
return gamepad.ButtonDownUp( context->GetGamepadBindCollection().GetButtonFromAction( action ) );
167+
}
168+
}
169+
124170
bool KeyBindings::ActionUp( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType, bool ignorePause ) const {
125171
assert( static_cast<int>( action ) < m_ActionDescriptions.size() );
126172
const BindContext* context = GetBindContext( bindContextHandle );

KeyBindings.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ class KeyBindings {
2929
const pString &description, SDL_GameControllerButton = SDL_CONTROLLER_BUTTON_INVALID );
3030
INPUT_API void AddAction( ActionIdentifier actionIdentifier, BindContextHandle bindContextHandle, SDL_Scancode scancode, SDL_GameControllerButton = SDL_CONTROLLER_BUTTON_INVALID );
3131

32-
INPUT_API bool ActionUpDown ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
33-
INPUT_API bool ActionDownUp ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
34-
INPUT_API bool ActionUp ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
35-
INPUT_API bool ActionDown ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
32+
INPUT_API bool ActionUpDown ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
33+
INPUT_API bool ActionDownUp ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
34+
INPUT_API bool ActionUpDownConsume ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
35+
INPUT_API bool ActionDownUpConsume ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
36+
INPUT_API bool ActionUp ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
37+
INPUT_API bool ActionDown ( InputContext& input, BindContextHandle bindContextHandle, ActionIdentifier action, INPUT_TYPE inputType = INPUT_TYPE_KEYBOARD, bool ignorePause = false ) const;
3638

3739
INPUT_API const rVector<rString>& GetActionDescriptions () const;
3840

0 commit comments

Comments
 (0)