Коммит 5f9ca4b3 создал по автору xottab-duty's avatar xottab-duty
Просмотр файлов

Contextual input bindings

Depending on the context (e.g. different UI windows) input mapping can be different.
This feature is needed for gamepads, because they have limited amount of buttons. (#943)
владелец 1ef6b747
......@@ -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 @@ public:
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;
}
......
......@@ -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);
......
......@@ -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("---");
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать