Rename requires to required in Hotkey.*
Accepted By: @vladislavbelov Differential Revision: https://code.wildfiregames.com/D5104 This was SVN commit r27812.
This commit is contained in:
parent
82bf9bb902
commit
4524188611
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -124,7 +124,7 @@ static void LoadConfigBindings(CConfigDB& configDB)
|
||||
|
||||
for (itKey2 = keyCombination.begin(); itKey2 != keyCombination.end(); ++itKey2)
|
||||
if (itKey != itKey2) // Push any auxiliary keys
|
||||
bindCode.requires.push_back(*itKey2);
|
||||
bindCode.required.push_back(*itKey2);
|
||||
|
||||
g_HotkeyMap[itKey->code].push_back(bindCode);
|
||||
}
|
||||
@ -320,7 +320,7 @@ InReaction HotkeyInputPrepHandler(const SDL_Event_* ev)
|
||||
continue;
|
||||
|
||||
bool accept = true;
|
||||
for (const SKey& k : hotkey.requires)
|
||||
for (const SKey& k : hotkey.required)
|
||||
{
|
||||
accept = isPressed(k);
|
||||
if (!accept)
|
||||
@ -330,14 +330,14 @@ InReaction HotkeyInputPrepHandler(const SDL_Event_* ev)
|
||||
continue;
|
||||
|
||||
// Check if this is an equally precise or more precise match
|
||||
if (hotkey.requires.size() + 1 >= closestMapMatch)
|
||||
if (hotkey.required.size() + 1 >= closestMapMatch)
|
||||
{
|
||||
// Check if more precise
|
||||
if (hotkey.requires.size() + 1 > closestMapMatch)
|
||||
if (hotkey.required.size() + 1 > closestMapMatch)
|
||||
{
|
||||
// Throw away the old less-precise matches
|
||||
newPressedHotkeys.clear();
|
||||
closestMapMatch = hotkey.requires.size() + 1;
|
||||
closestMapMatch = hotkey.required.size() + 1;
|
||||
}
|
||||
newPressedHotkeys.emplace_back(&hotkey, isReleasedKey);
|
||||
}
|
||||
@ -372,7 +372,7 @@ InReaction HotkeyInputActualHandler(const SDL_Event_* ev)
|
||||
std::find_if(newPressedHotkeys.begin(), newPressedHotkeys.end(),
|
||||
[&hotkey](const PressedHotkey& v){ return v.mapping->name == hotkey.mapping->name; })->retriggered = hotkey.retriggered;
|
||||
// If the already-pressed hotkey has a lower specificity than the new hotkey(s), de-activate it.
|
||||
else if (hotkey.mapping->requires.size() + 1 < closestMapMatch)
|
||||
else if (hotkey.mapping->required.size() + 1 < closestMapMatch)
|
||||
{
|
||||
releasedHotkeys.emplace_back(hotkey.mapping->name.c_str(), hotkey.retriggered);
|
||||
continue;
|
||||
@ -381,7 +381,7 @@ InReaction HotkeyInputActualHandler(const SDL_Event_* ev)
|
||||
// Check that the hotkey still matches all active keys.
|
||||
bool accept = isPressed(hotkey.mapping->primary);
|
||||
if (accept)
|
||||
for (const SKey& k : hotkey.mapping->requires)
|
||||
for (const SKey& k : hotkey.mapping->required)
|
||||
{
|
||||
accept = isPressed(k);
|
||||
if (!accept)
|
||||
@ -394,9 +394,9 @@ InReaction HotkeyInputActualHandler(const SDL_Event_* ev)
|
||||
// If this hotkey has higher specificity than the new hotkeys we wanted to trigger/retrigger,
|
||||
// then discard this new addition(s). This works because at any given time, all hotkeys
|
||||
// active must have the same specificity.
|
||||
if (hotkey.mapping->requires.size() + 1 > closestMapMatch)
|
||||
if (hotkey.mapping->required.size() + 1 > closestMapMatch)
|
||||
{
|
||||
closestMapMatch = hotkey.mapping->requires.size() + 1;
|
||||
closestMapMatch = hotkey.mapping->required.size() + 1;
|
||||
newPressedHotkeys.clear();
|
||||
newPressedHotkeys.emplace_back(hotkey.mapping, hotkey.retriggered);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -63,7 +63,7 @@ struct SHotkeyMapping
|
||||
{
|
||||
CStr name; // name of the hotkey
|
||||
SKey primary; // the primary key
|
||||
std::vector<SKey> requires; // list of non-primary keys that must also be active
|
||||
std::vector<SKey> required; // list of non-primary keys that must also be active
|
||||
};
|
||||
|
||||
typedef std::vector<SHotkeyMapping> KeyMapping;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -83,7 +83,7 @@ JS::Value GetHotkeyMap(const ScriptRequest& rq)
|
||||
std::vector<std::string> keymap;
|
||||
if (key.first != UNUSED_HOTKEY_CODE)
|
||||
keymap.push_back(FindScancodeName(static_cast<SDL_Scancode>(key.first)));
|
||||
for (const SKey& secondary_key : mapping.requires)
|
||||
for (const SKey& secondary_key : mapping.required)
|
||||
keymap.push_back(FindScancodeName(static_cast<SDL_Scancode>(secondary_key.code)));
|
||||
// If keymap is empty (== unused) or size 1, push the combination.
|
||||
// Otherwise, all permutations of the combination will exist, so pick one using an arbitrary order.
|
||||
@ -149,7 +149,7 @@ JS::Value GetConflicts(const ScriptRequest& rq, JS::HandleValue combination)
|
||||
// since we at least have one matching key.
|
||||
for (const SHotkeyMapping& keymap : it->second)
|
||||
{
|
||||
std::set<SKey> match(keymap.requires.begin(), keymap.requires.end());
|
||||
std::set<SKey> match(keymap.required.begin(), keymap.required.end());
|
||||
if (codes == match)
|
||||
conflicts.emplace_back(keymap.name);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user