1
0
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:
Gymnasiast
2025-09-30 22:57:43 +02:00
parent a288a91331
commit b86fc3715b
6 changed files with 83 additions and 83 deletions

View File

@@ -622,7 +622,7 @@ public:
{
auto& shortcutManager = GetShortcutManager();
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

View File

@@ -490,7 +490,7 @@ void InputManager::processViewScrollEvent(std::string_view shortcutId, const Scr
bool InputManager::getState(const RegisteredShortcut& shortcut) const
{
for (const auto& i : shortcut.Current)
for (const auto& i : shortcut.current)
{
if (getState(i))
{

View File

@@ -25,38 +25,38 @@
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)
{
return std::string_view(Id.c_str(), fullstopIndex);
return std::string_view(id.c_str(), fullstopIndex);
}
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)
{
return std::string_view(Id.c_str(), fullstopIndex);
return std::string_view(id.c_str(), fullstopIndex);
}
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(
Current.begin(), Current.end(), [e](const ShortcutInput& action) { return action.matches(e); });
return result != Current.end();
current.begin(), current.end(), [e](const ShortcutInput& _action) { return _action.matches(e); });
return result != current.end();
}
return false;
}
bool RegisteredShortcut::IsSuitableInputEvent(const InputEvent& e) const
bool RegisteredShortcut::isSuitableInputEvent(const InputEvent& e) const
{
// Do not intercept button releases
if (e.state == InputEventState::release)
@@ -92,13 +92,13 @@ bool RegisteredShortcut::IsSuitableInputEvent(const InputEvent& e) const
return true;
}
std::string RegisteredShortcut::GetDisplayString() const
std::string RegisteredShortcut::getDisplayString() const
{
std::string result;
auto numChords = Current.size();
auto numChords = current.size();
for (size_t i = 0; i < numChords; i++)
{
const auto& kc = Current[i];
const auto& kc = current[i];
result += kc.toLocalisedString();
if (i < numChords - 1)
{
@@ -118,12 +118,12 @@ ShortcutManager::ShortcutManager(IPlatformEnvironment& env)
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);
_ids.push_back(std::move(id));
shortcut.OrderIndex = Shortcuts.size();
shortcut.orderIndex = Shortcuts.size();
Shortcuts[idView] = shortcut;
}
}
@@ -157,22 +157,22 @@ void ShortcutManager::ProcessEvent(const InputEvent& e)
{
for (const auto& shortcut : Shortcuts)
{
if (shortcut.second.Matches(e))
if (shortcut.second.matches(e))
{
shortcut.second.Action();
shortcut.second.action();
}
}
}
else
{
auto shortcut = GetShortcut(_pendingShortcutChange);
if (shortcut != nullptr && shortcut->IsSuitableInputEvent(e))
if (shortcut != nullptr && shortcut->isSuitableInputEvent(e))
{
auto shortcutInput = ShortcutInput::fromInputEvent(e);
if (shortcutInput.has_value())
{
shortcut->Current.clear();
shortcut->Current.push_back(std::move(shortcutInput.value()));
shortcut->current.clear();
shortcut->current.push_back(std::move(shortcutInput.value()));
}
_pendingShortcutChange.clear();
@@ -186,9 +186,9 @@ void ShortcutManager::ProcessEvent(const InputEvent& e)
bool ShortcutManager::ProcessEventForSpecificShortcut(const InputEvent& e, std::string_view id)
{
auto shortcut = GetShortcut(id);
if (shortcut != nullptr && shortcut->Matches(e))
if (shortcut != nullptr && shortcut->matches(e))
{
shortcut->Action();
shortcut->action();
return true;
}
return false;
@@ -273,11 +273,11 @@ void ShortcutManager::LoadLegacyBindings(const fs::path& path)
auto shortcut = GetShortcut(shortcutId);
if (shortcut != nullptr)
{
shortcut->Current.clear();
shortcut->current.clear();
auto input = ConvertLegacyBinding(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);
if (shortcut != nullptr)
{
shortcut->Current.clear();
shortcut->current.clear();
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())
{
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)
{
auto& jShortcut = root[shortcut.second.Id];
if (shortcut.second.Current.size() == 1)
auto& jShortcut = root[shortcut.second.id];
if (shortcut.second.current.size() == 1)
{
jShortcut = shortcut.second.Current[0].toString();
jShortcut = shortcut.second.current[0].toString();
}
else
{
jShortcut = nlohmann::json::array();
for (const auto& binding : shortcut.second.Current)
for (const auto& binding : shortcut.second.current)
{
jShortcut.push_back(binding.toString());
}

View File

@@ -56,55 +56,55 @@ namespace OpenRCT2::Ui
class RegisteredShortcut
{
public:
std::string Id;
StringId LocalisedName = kStringIdNone;
std::string CustomName;
std::vector<ShortcutInput> Default;
std::vector<ShortcutInput> Current;
std::function<void()> Action;
size_t OrderIndex = static_cast<size_t>(-1);
std::string id;
StringId localisedName = kStringIdNone;
std::string customName;
std::vector<ShortcutInput> standard;
std::vector<ShortcutInput> current;
std::function<void()> action;
size_t orderIndex = static_cast<size_t>(-1);
RegisteredShortcut() = default;
RegisteredShortcut(std::string_view id, std::string_view name, const std::function<void()>& action)
: Id(id)
, CustomName(name)
, Action(action)
RegisteredShortcut(std::string_view _id, std::string_view _name, const std::function<void()>& _action)
: id(_id)
, customName(_name)
, action(_action)
{
}
RegisteredShortcut(std::string_view id, StringId localisedName, const std::function<void()>& action)
: Id(id)
, LocalisedName(localisedName)
, Action(action)
RegisteredShortcut(std::string_view _id, StringId _localisedName, const std::function<void()>& _action)
: id(_id)
, localisedName(_localisedName)
, action(_action)
{
}
RegisteredShortcut(
std::string_view id, StringId localisedName, std::string_view defaultChord, const std::function<void()>& action)
: Id(id)
, LocalisedName(localisedName)
, Default({ defaultChord })
, Current(Default)
, Action(action)
std::string_view _id, StringId _localisedName, std::string_view _defaultChord, const std::function<void()>& _action)
: id(_id)
, localisedName(_localisedName)
, standard({ _defaultChord })
, current(standard)
, action(_action)
{
}
RegisteredShortcut(
std::string_view id, StringId localisedName, std::string_view defaultChordA, std::string_view defaultChordB,
const std::function<void()>& action)
: Id(id)
, LocalisedName(localisedName)
, Default({ defaultChordA, defaultChordB })
, Current(Default)
, Action(action)
std::string_view _id, StringId _localisedName, std::string_view _defaultChordA, std::string_view _defaultChordB,
const std::function<void()>& _action)
: id(_id)
, localisedName(_localisedName)
, standard({ _defaultChordA, _defaultChordB })
, current(standard)
, action(_action)
{
}
std::string_view GetTopLevelGroup() const;
std::string_view GetGroup() const;
bool Matches(const InputEvent& e) const;
bool IsSuitableInputEvent(const InputEvent& e) const;
std::string GetDisplayString() const;
std::string_view getTopLevelGroup() const;
std::string_view getGroup() const;
bool matches(const InputEvent& e) const;
bool isSuitableInputEvent(const InputEvent& e) const;
std::string getDisplayString() const;
private:
};

View File

@@ -43,9 +43,9 @@ namespace OpenRCT2::Scripting
RegisteredShortcut registeredShortcut(Id, Text, [this]() { Invoke(); });
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.LoadUserBindings();
}

View File

@@ -83,9 +83,9 @@ namespace OpenRCT2::Ui::Windows
if (w != nullptr)
{
w->_shortcutId = shortcutId;
w->_shortcutLocalisedName = registeredShortcut->LocalisedName;
w->_shortcutCustomName = registeredShortcut->CustomName;
shortcutManager.SetPendingShortcutChange(registeredShortcut->Id);
w->_shortcutLocalisedName = registeredShortcut->localisedName;
w->_shortcutCustomName = registeredShortcut->customName;
shortcutManager.SetPendingShortcutChange(registeredShortcut->id);
return w;
}
}
@@ -146,7 +146,7 @@ namespace OpenRCT2::Ui::Windows
auto* shortcut = shortcutManager.GetShortcut(_shortcutId);
if (shortcut != nullptr)
{
shortcut->Current.clear();
shortcut->current.clear();
shortcutManager.SaveUserBindings();
}
close();
@@ -349,7 +349,7 @@ namespace OpenRCT2::Ui::Windows
auto shortcut = shortcutManager.GetShortcut(item.ShortcutId);
if (shortcut != nullptr)
{
shortcut->Current = shortcut->Default;
shortcut->current = shortcut->standard;
}
}
shortcutManager.SaveUserBindings();
@@ -360,7 +360,7 @@ namespace OpenRCT2::Ui::Windows
bool IsInCurrentTab(const RegisteredShortcut& shortcut)
{
auto groupFilter = _tabs[_currentTabIndex].IdGroup;
auto group = shortcut.GetTopLevelGroup();
auto group = shortcut.getTopLevelGroup();
if (groupFilter.empty())
{
// Check it doesn't belong in any other tab
@@ -385,7 +385,7 @@ namespace OpenRCT2::Ui::Windows
// Get shortcuts and sort by group
auto shortcuts = GetShortcutsForCurrentTab();
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
@@ -395,11 +395,11 @@ namespace OpenRCT2::Ui::Windows
{
if (group.empty())
{
group = shortcut->GetGroup();
group = shortcut->getGroup();
}
else
{
auto groupName = shortcut->GetGroup();
auto groupName = shortcut->getGroup();
if (group != groupName)
{
// Add separator
@@ -409,10 +409,10 @@ namespace OpenRCT2::Ui::Windows
}
ShortcutStringPair ssp;
ssp.ShortcutId = shortcut->Id;
ssp.StringId = shortcut->LocalisedName;
ssp.CustomString = shortcut->CustomName;
ssp.Binding = shortcut->GetDisplayString();
ssp.ShortcutId = shortcut->id;
ssp.StringId = shortcut->localisedName;
ssp.CustomString = shortcut->customName;
ssp.Binding = shortcut->getDisplayString();
_list.push_back(std::move(ssp));
}