mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-19 13:52:54 +01:00
Rename members of RegisteredShortcut
This commit is contained in:
@@ -622,7 +622,7 @@ public:
|
|||||||
{
|
{
|
||||||
auto& shortcutManager = GetShortcutManager();
|
auto& shortcutManager = GetShortcutManager();
|
||||||
auto* shortcut = shortcutManager.GetShortcut(shortcutId);
|
auto* shortcut = shortcutManager.GetShortcut(shortcutId);
|
||||||
return shortcut != nullptr ? shortcut->GetDisplayString() : std::string();
|
return shortcut != nullptr ? shortcut->getDisplayString() : std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMainView(const ScreenCoordsXY& viewPos, ZoomLevel zoom, int32_t rotation) override
|
void SetMainView(const ScreenCoordsXY& viewPos, ZoomLevel zoom, int32_t rotation) override
|
||||||
|
|||||||
@@ -490,7 +490,7 @@ void InputManager::processViewScrollEvent(std::string_view shortcutId, const Scr
|
|||||||
|
|
||||||
bool InputManager::getState(const RegisteredShortcut& shortcut) const
|
bool InputManager::getState(const RegisteredShortcut& shortcut) const
|
||||||
{
|
{
|
||||||
for (const auto& i : shortcut.Current)
|
for (const auto& i : shortcut.current)
|
||||||
{
|
{
|
||||||
if (getState(i))
|
if (getState(i))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,38 +25,38 @@
|
|||||||
|
|
||||||
using namespace OpenRCT2::Ui;
|
using namespace OpenRCT2::Ui;
|
||||||
|
|
||||||
std::string_view RegisteredShortcut::GetTopLevelGroup() const
|
std::string_view RegisteredShortcut::getTopLevelGroup() const
|
||||||
{
|
{
|
||||||
auto fullstopIndex = Id.find('.');
|
auto fullstopIndex = id.find('.');
|
||||||
if (fullstopIndex != std::string::npos)
|
if (fullstopIndex != std::string::npos)
|
||||||
{
|
{
|
||||||
return std::string_view(Id.c_str(), fullstopIndex);
|
return std::string_view(id.c_str(), fullstopIndex);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view RegisteredShortcut::GetGroup() const
|
std::string_view RegisteredShortcut::getGroup() const
|
||||||
{
|
{
|
||||||
auto fullstopIndex = Id.find_last_of('.');
|
auto fullstopIndex = id.find_last_of('.');
|
||||||
if (fullstopIndex != std::string::npos)
|
if (fullstopIndex != std::string::npos)
|
||||||
{
|
{
|
||||||
return std::string_view(Id.c_str(), fullstopIndex);
|
return std::string_view(id.c_str(), fullstopIndex);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredShortcut::Matches(const InputEvent& e) const
|
bool RegisteredShortcut::matches(const InputEvent& e) const
|
||||||
{
|
{
|
||||||
if (IsSuitableInputEvent(e))
|
if (isSuitableInputEvent(e))
|
||||||
{
|
{
|
||||||
auto result = std::find_if(
|
auto result = std::find_if(
|
||||||
Current.begin(), Current.end(), [e](const ShortcutInput& action) { return action.matches(e); });
|
current.begin(), current.end(), [e](const ShortcutInput& _action) { return _action.matches(e); });
|
||||||
return result != Current.end();
|
return result != current.end();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredShortcut::IsSuitableInputEvent(const InputEvent& e) const
|
bool RegisteredShortcut::isSuitableInputEvent(const InputEvent& e) const
|
||||||
{
|
{
|
||||||
// Do not intercept button releases
|
// Do not intercept button releases
|
||||||
if (e.state == InputEventState::release)
|
if (e.state == InputEventState::release)
|
||||||
@@ -92,13 +92,13 @@ bool RegisteredShortcut::IsSuitableInputEvent(const InputEvent& e) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RegisteredShortcut::GetDisplayString() const
|
std::string RegisteredShortcut::getDisplayString() const
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
auto numChords = Current.size();
|
auto numChords = current.size();
|
||||||
for (size_t i = 0; i < numChords; i++)
|
for (size_t i = 0; i < numChords; i++)
|
||||||
{
|
{
|
||||||
const auto& kc = Current[i];
|
const auto& kc = current[i];
|
||||||
result += kc.toLocalisedString();
|
result += kc.toLocalisedString();
|
||||||
if (i < numChords - 1)
|
if (i < numChords - 1)
|
||||||
{
|
{
|
||||||
@@ -118,12 +118,12 @@ ShortcutManager::ShortcutManager(IPlatformEnvironment& env)
|
|||||||
|
|
||||||
void ShortcutManager::RegisterShortcut(RegisteredShortcut&& shortcut)
|
void ShortcutManager::RegisterShortcut(RegisteredShortcut&& shortcut)
|
||||||
{
|
{
|
||||||
if (!shortcut.Id.empty() && GetShortcut(shortcut.Id) == nullptr)
|
if (!shortcut.id.empty() && GetShortcut(shortcut.id) == nullptr)
|
||||||
{
|
{
|
||||||
auto id = std::make_unique<std::string>(shortcut.Id);
|
auto id = std::make_unique<std::string>(shortcut.id);
|
||||||
auto idView = std::string_view(*id);
|
auto idView = std::string_view(*id);
|
||||||
_ids.push_back(std::move(id));
|
_ids.push_back(std::move(id));
|
||||||
shortcut.OrderIndex = Shortcuts.size();
|
shortcut.orderIndex = Shortcuts.size();
|
||||||
Shortcuts[idView] = shortcut;
|
Shortcuts[idView] = shortcut;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,22 +157,22 @@ void ShortcutManager::ProcessEvent(const InputEvent& e)
|
|||||||
{
|
{
|
||||||
for (const auto& shortcut : Shortcuts)
|
for (const auto& shortcut : Shortcuts)
|
||||||
{
|
{
|
||||||
if (shortcut.second.Matches(e))
|
if (shortcut.second.matches(e))
|
||||||
{
|
{
|
||||||
shortcut.second.Action();
|
shortcut.second.action();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto shortcut = GetShortcut(_pendingShortcutChange);
|
auto shortcut = GetShortcut(_pendingShortcutChange);
|
||||||
if (shortcut != nullptr && shortcut->IsSuitableInputEvent(e))
|
if (shortcut != nullptr && shortcut->isSuitableInputEvent(e))
|
||||||
{
|
{
|
||||||
auto shortcutInput = ShortcutInput::fromInputEvent(e);
|
auto shortcutInput = ShortcutInput::fromInputEvent(e);
|
||||||
if (shortcutInput.has_value())
|
if (shortcutInput.has_value())
|
||||||
{
|
{
|
||||||
shortcut->Current.clear();
|
shortcut->current.clear();
|
||||||
shortcut->Current.push_back(std::move(shortcutInput.value()));
|
shortcut->current.push_back(std::move(shortcutInput.value()));
|
||||||
}
|
}
|
||||||
_pendingShortcutChange.clear();
|
_pendingShortcutChange.clear();
|
||||||
|
|
||||||
@@ -186,9 +186,9 @@ void ShortcutManager::ProcessEvent(const InputEvent& e)
|
|||||||
bool ShortcutManager::ProcessEventForSpecificShortcut(const InputEvent& e, std::string_view id)
|
bool ShortcutManager::ProcessEventForSpecificShortcut(const InputEvent& e, std::string_view id)
|
||||||
{
|
{
|
||||||
auto shortcut = GetShortcut(id);
|
auto shortcut = GetShortcut(id);
|
||||||
if (shortcut != nullptr && shortcut->Matches(e))
|
if (shortcut != nullptr && shortcut->matches(e))
|
||||||
{
|
{
|
||||||
shortcut->Action();
|
shortcut->action();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -273,11 +273,11 @@ void ShortcutManager::LoadLegacyBindings(const fs::path& path)
|
|||||||
auto shortcut = GetShortcut(shortcutId);
|
auto shortcut = GetShortcut(shortcutId);
|
||||||
if (shortcut != nullptr)
|
if (shortcut != nullptr)
|
||||||
{
|
{
|
||||||
shortcut->Current.clear();
|
shortcut->current.clear();
|
||||||
auto input = ConvertLegacyBinding(value);
|
auto input = ConvertLegacyBinding(value);
|
||||||
if (input.has_value())
|
if (input.has_value())
|
||||||
{
|
{
|
||||||
shortcut->Current.push_back(std::move(input.value()));
|
shortcut->current.push_back(std::move(input.value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,16 +298,16 @@ void ShortcutManager::LoadUserBindings(const fs::path& path)
|
|||||||
const auto& shortcut = GetShortcut(key);
|
const auto& shortcut = GetShortcut(key);
|
||||||
if (shortcut != nullptr)
|
if (shortcut != nullptr)
|
||||||
{
|
{
|
||||||
shortcut->Current.clear();
|
shortcut->current.clear();
|
||||||
if (value.is_string())
|
if (value.is_string())
|
||||||
{
|
{
|
||||||
shortcut->Current.emplace_back(value.get<std::string>());
|
shortcut->current.emplace_back(value.get<std::string>());
|
||||||
}
|
}
|
||||||
else if (value.is_array())
|
else if (value.is_array())
|
||||||
{
|
{
|
||||||
for (auto& subValue : value)
|
for (auto& subValue : value)
|
||||||
{
|
{
|
||||||
shortcut->Current.emplace_back(subValue.get<std::string>());
|
shortcut->current.emplace_back(subValue.get<std::string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,15 +338,15 @@ void ShortcutManager::SaveUserBindings(const fs::path& path)
|
|||||||
|
|
||||||
for (const auto& shortcut : Shortcuts)
|
for (const auto& shortcut : Shortcuts)
|
||||||
{
|
{
|
||||||
auto& jShortcut = root[shortcut.second.Id];
|
auto& jShortcut = root[shortcut.second.id];
|
||||||
if (shortcut.second.Current.size() == 1)
|
if (shortcut.second.current.size() == 1)
|
||||||
{
|
{
|
||||||
jShortcut = shortcut.second.Current[0].toString();
|
jShortcut = shortcut.second.current[0].toString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jShortcut = nlohmann::json::array();
|
jShortcut = nlohmann::json::array();
|
||||||
for (const auto& binding : shortcut.second.Current)
|
for (const auto& binding : shortcut.second.current)
|
||||||
{
|
{
|
||||||
jShortcut.push_back(binding.toString());
|
jShortcut.push_back(binding.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,55 +56,55 @@ namespace OpenRCT2::Ui
|
|||||||
class RegisteredShortcut
|
class RegisteredShortcut
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string Id;
|
std::string id;
|
||||||
StringId LocalisedName = kStringIdNone;
|
StringId localisedName = kStringIdNone;
|
||||||
std::string CustomName;
|
std::string customName;
|
||||||
std::vector<ShortcutInput> Default;
|
std::vector<ShortcutInput> standard;
|
||||||
std::vector<ShortcutInput> Current;
|
std::vector<ShortcutInput> current;
|
||||||
std::function<void()> Action;
|
std::function<void()> action;
|
||||||
size_t OrderIndex = static_cast<size_t>(-1);
|
size_t orderIndex = static_cast<size_t>(-1);
|
||||||
|
|
||||||
RegisteredShortcut() = default;
|
RegisteredShortcut() = default;
|
||||||
RegisteredShortcut(std::string_view id, std::string_view name, const std::function<void()>& action)
|
RegisteredShortcut(std::string_view _id, std::string_view _name, const std::function<void()>& _action)
|
||||||
: Id(id)
|
: id(_id)
|
||||||
, CustomName(name)
|
, customName(_name)
|
||||||
, Action(action)
|
, action(_action)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredShortcut(std::string_view id, StringId localisedName, const std::function<void()>& action)
|
RegisteredShortcut(std::string_view _id, StringId _localisedName, const std::function<void()>& _action)
|
||||||
: Id(id)
|
: id(_id)
|
||||||
, LocalisedName(localisedName)
|
, localisedName(_localisedName)
|
||||||
, Action(action)
|
, action(_action)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredShortcut(
|
RegisteredShortcut(
|
||||||
std::string_view id, StringId localisedName, std::string_view defaultChord, const std::function<void()>& action)
|
std::string_view _id, StringId _localisedName, std::string_view _defaultChord, const std::function<void()>& _action)
|
||||||
: Id(id)
|
: id(_id)
|
||||||
, LocalisedName(localisedName)
|
, localisedName(_localisedName)
|
||||||
, Default({ defaultChord })
|
, standard({ _defaultChord })
|
||||||
, Current(Default)
|
, current(standard)
|
||||||
, Action(action)
|
, action(_action)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredShortcut(
|
RegisteredShortcut(
|
||||||
std::string_view id, StringId localisedName, std::string_view defaultChordA, std::string_view defaultChordB,
|
std::string_view _id, StringId _localisedName, std::string_view _defaultChordA, std::string_view _defaultChordB,
|
||||||
const std::function<void()>& action)
|
const std::function<void()>& _action)
|
||||||
: Id(id)
|
: id(_id)
|
||||||
, LocalisedName(localisedName)
|
, localisedName(_localisedName)
|
||||||
, Default({ defaultChordA, defaultChordB })
|
, standard({ _defaultChordA, _defaultChordB })
|
||||||
, Current(Default)
|
, current(standard)
|
||||||
, Action(action)
|
, action(_action)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view GetTopLevelGroup() const;
|
std::string_view getTopLevelGroup() const;
|
||||||
std::string_view GetGroup() const;
|
std::string_view getGroup() const;
|
||||||
bool Matches(const InputEvent& e) const;
|
bool matches(const InputEvent& e) const;
|
||||||
bool IsSuitableInputEvent(const InputEvent& e) const;
|
bool isSuitableInputEvent(const InputEvent& e) const;
|
||||||
std::string GetDisplayString() const;
|
std::string getDisplayString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ namespace OpenRCT2::Scripting
|
|||||||
RegisteredShortcut registeredShortcut(Id, Text, [this]() { Invoke(); });
|
RegisteredShortcut registeredShortcut(Id, Text, [this]() { Invoke(); });
|
||||||
for (const auto& binding : bindings)
|
for (const auto& binding : bindings)
|
||||||
{
|
{
|
||||||
registeredShortcut.Default.emplace_back(binding);
|
registeredShortcut.standard.emplace_back(binding);
|
||||||
}
|
}
|
||||||
registeredShortcut.Current = registeredShortcut.Default;
|
registeredShortcut.current = registeredShortcut.standard;
|
||||||
shortcutManager.RegisterShortcut(std::move(registeredShortcut));
|
shortcutManager.RegisterShortcut(std::move(registeredShortcut));
|
||||||
shortcutManager.LoadUserBindings();
|
shortcutManager.LoadUserBindings();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,9 +83,9 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
if (w != nullptr)
|
if (w != nullptr)
|
||||||
{
|
{
|
||||||
w->_shortcutId = shortcutId;
|
w->_shortcutId = shortcutId;
|
||||||
w->_shortcutLocalisedName = registeredShortcut->LocalisedName;
|
w->_shortcutLocalisedName = registeredShortcut->localisedName;
|
||||||
w->_shortcutCustomName = registeredShortcut->CustomName;
|
w->_shortcutCustomName = registeredShortcut->customName;
|
||||||
shortcutManager.SetPendingShortcutChange(registeredShortcut->Id);
|
shortcutManager.SetPendingShortcutChange(registeredShortcut->id);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
auto* shortcut = shortcutManager.GetShortcut(_shortcutId);
|
auto* shortcut = shortcutManager.GetShortcut(_shortcutId);
|
||||||
if (shortcut != nullptr)
|
if (shortcut != nullptr)
|
||||||
{
|
{
|
||||||
shortcut->Current.clear();
|
shortcut->current.clear();
|
||||||
shortcutManager.SaveUserBindings();
|
shortcutManager.SaveUserBindings();
|
||||||
}
|
}
|
||||||
close();
|
close();
|
||||||
@@ -349,7 +349,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
auto shortcut = shortcutManager.GetShortcut(item.ShortcutId);
|
auto shortcut = shortcutManager.GetShortcut(item.ShortcutId);
|
||||||
if (shortcut != nullptr)
|
if (shortcut != nullptr)
|
||||||
{
|
{
|
||||||
shortcut->Current = shortcut->Default;
|
shortcut->current = shortcut->standard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shortcutManager.SaveUserBindings();
|
shortcutManager.SaveUserBindings();
|
||||||
@@ -360,7 +360,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
bool IsInCurrentTab(const RegisteredShortcut& shortcut)
|
bool IsInCurrentTab(const RegisteredShortcut& shortcut)
|
||||||
{
|
{
|
||||||
auto groupFilter = _tabs[_currentTabIndex].IdGroup;
|
auto groupFilter = _tabs[_currentTabIndex].IdGroup;
|
||||||
auto group = shortcut.GetTopLevelGroup();
|
auto group = shortcut.getTopLevelGroup();
|
||||||
if (groupFilter.empty())
|
if (groupFilter.empty())
|
||||||
{
|
{
|
||||||
// Check it doesn't belong in any other tab
|
// Check it doesn't belong in any other tab
|
||||||
@@ -385,7 +385,7 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
// Get shortcuts and sort by group
|
// Get shortcuts and sort by group
|
||||||
auto shortcuts = GetShortcutsForCurrentTab();
|
auto shortcuts = GetShortcutsForCurrentTab();
|
||||||
std::stable_sort(shortcuts.begin(), shortcuts.end(), [](const RegisteredShortcut* a, const RegisteredShortcut* b) {
|
std::stable_sort(shortcuts.begin(), shortcuts.end(), [](const RegisteredShortcut* a, const RegisteredShortcut* b) {
|
||||||
return a->OrderIndex < b->OrderIndex;
|
return a->orderIndex < b->orderIndex;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create list items with a separator between each group
|
// Create list items with a separator between each group
|
||||||
@@ -395,11 +395,11 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
{
|
{
|
||||||
if (group.empty())
|
if (group.empty())
|
||||||
{
|
{
|
||||||
group = shortcut->GetGroup();
|
group = shortcut->getGroup();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto groupName = shortcut->GetGroup();
|
auto groupName = shortcut->getGroup();
|
||||||
if (group != groupName)
|
if (group != groupName)
|
||||||
{
|
{
|
||||||
// Add separator
|
// Add separator
|
||||||
@@ -409,10 +409,10 @@ namespace OpenRCT2::Ui::Windows
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShortcutStringPair ssp;
|
ShortcutStringPair ssp;
|
||||||
ssp.ShortcutId = shortcut->Id;
|
ssp.ShortcutId = shortcut->id;
|
||||||
ssp.StringId = shortcut->LocalisedName;
|
ssp.StringId = shortcut->localisedName;
|
||||||
ssp.CustomString = shortcut->CustomName;
|
ssp.CustomString = shortcut->customName;
|
||||||
ssp.Binding = shortcut->GetDisplayString();
|
ssp.Binding = shortcut->getDisplayString();
|
||||||
_list.push_back(std::move(ssp));
|
_list.push_back(std::move(ssp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user