diff --git a/src/xrEngine/xr_level_controller.cpp b/src/xrEngine/xr_level_controller.cpp index 6a394a82e8e..a642a66b886 100644 --- a/src/xrEngine/xr_level_controller.cpp +++ b/src/xrEngine/xr_level_controller.cpp @@ -688,17 +688,30 @@ bool IsGroupMatching(EKeyGroup g1, EKeyGroup g2) return ((g1 == g2) || (g1 == _both) || (g2 == _both)); } -EGameActions GetBindedAction(int dik) +bool IsContextNotConflicted(EKeyContext c1, EKeyContext c2) +{ + return c1 != c2; +} + +bool IsContextMatching(EKeyContext c1, EKeyContext c2) +{ + return c1 == c2 || (c1 == EKeyContext::Undefined && c2 == EKeyContext::Undefined); +} + +EGameActions GetBindedAction(int dik, EKeyContext context /*= EKeyContext::Undefined*/) { for (int idx = 0; idx < bindings_count; ++idx) { key_binding* binding = &g_key_bindings[idx]; - bool isGroupMatching = IsGroupMatching(binding->m_action->key_group, g_current_keygroup); - + const bool isGroupMatching = IsGroupMatching(binding->m_action->key_group, g_current_keygroup); if (!isGroupMatching) continue; + const bool isContextMatching = IsContextMatching(binding->m_action->key_context, context); + if (!isContextMatching) + continue; + for (u8 i = 0; i < bindtypes_count && isGroupMatching; ++i) if (binding->m_keyboard[i] && binding->m_keyboard[i]->dik == dik) return binding->m_action->id; @@ -794,10 +807,11 @@ class CCC_Bind : public IConsole_Command if (binding == currBinding) continue; - bool isConflict = !IsGroupNotConflicted(binding->m_action->key_group, currBinding->m_action->key_group); + const bool groupConflict = !IsGroupNotConflicted(binding->m_action->key_group, currBinding->m_action->key_group); + const bool contextConflict = !IsContextNotConflicted(binding->m_action->key_context, currBinding->m_action->key_context); for (u8 i = 0; i < bindtypes_count; ++i) - if (binding->m_keyboard[i] == keyboard && isConflict) + if (binding->m_keyboard[i] == keyboard && (groupConflict && contextConflict)) binding->m_keyboard[i] = nullptr; } diff --git a/src/xrEngine/xr_level_controller.h b/src/xrEngine/xr_level_controller.h index b36b4931f5d..64eab28de0e 100644 --- a/src/xrEngine/xr_level_controller.h +++ b/src/xrEngine/xr_level_controller.h @@ -139,6 +139,11 @@ enum EGameActions : u32 kNOTBINDED }; +enum class EKeyContext +{ + Undefined = 0, // default behaviour +}; + constexpr char GAME_ACTION_MARK = 27; // escape symbol struct keyboard_key @@ -160,6 +165,7 @@ struct game_action pcstr action_name; EGameActions id; EKeyGroup key_group; + EKeyContext key_context{ EKeyContext::Undefined }; }; #define bindtypes_count 3 @@ -177,6 +183,7 @@ extern ENGINE_API keyboard_key keyboards[]; extern ENGINE_API key_binding g_key_bindings[]; ENGINE_API bool IsGroupNotConflicted(EKeyGroup g1, EKeyGroup g2); +ENGINE_API bool IsContextNotConflicted(EKeyContext c1, EKeyContext c2); ENGINE_API pcstr IdToActionName(EGameActions id); ENGINE_API EGameActions ActionNameToId(pcstr name); @@ -189,7 +196,7 @@ ENGINE_API keyboard_key* DikToPtr(int dik, bool safe); ENGINE_API bool IsBinded(EGameActions action_id, int dik); ENGINE_API int GetActionDik(EGameActions action_id, int idx = -1); -ENGINE_API EGameActions GetBindedAction(int dik); +ENGINE_API EGameActions GetBindedAction(int dik, EKeyContext context = EKeyContext::Undefined); ENGINE_API pcstr GetActionBinding(EGameActions action); diff --git a/src/xrGame/ui/UIEditKeyBind.cpp b/src/xrGame/ui/UIEditKeyBind.cpp index 79db5cd337c..9329ec09918 100644 --- a/src/xrGame/ui/UIEditKeyBind.cpp +++ b/src/xrGame/ui/UIEditKeyBind.cpp @@ -268,7 +268,10 @@ void CUIEditKeyBind::OnMessage(LPCSTR message) return; // fuck game_action* other_action = ActionNameToPtr(command); - if (IsGroupNotConflicted(m_action->key_group, other_action->key_group)) + + bool no_conflict = IsGroupNotConflicted(m_action->key_group, other_action->key_group); + no_conflict &= IsContextNotConflicted(m_action->key_context, other_action->key_context); + if (no_conflict) return; SetText("---");