diff --git a/src/game_config.cpp b/src/game_config.cpp index 8158ce55f6..49562716ce 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -19,6 +19,7 @@ #include "cmdline_parser.h" #include "filefinder.h" #include "input_buttons.h" +#include "keys.h" #include "output.h" #include "input.h" #include @@ -377,7 +378,7 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) { for (int i = 0; i < Input::BUTTON_COUNT; ++i) { auto button = static_cast(i); - auto name = Input::kButtonNames.tag(button); + auto name = Input::kInputButtonNames.tag(button); if (ini.HasValue("input", name)) { auto values = ini.GetString("input", name, ""); mappings.RemoveAll(button); @@ -390,9 +391,8 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) { if (Input::IsProtectedButton(button)) { // Check for protected (important) buttons if they have more than zero mappings for (const auto& key: keys) { - const auto& kNames = Input::Keys::kNames; - auto it = std::find(kNames.begin(), kNames.end(), key); - if (it != Input::Keys::kNames.end()) { + Input::Keys::InputKey k; + if (Input::Keys::kInputKeyNames.etag(key.c_str(), k)) { has_mapping = true; break; } @@ -406,10 +406,9 @@ void Game_Config::LoadFromStream(Filesystem_Stream::InputStream& is) { // Load mappings from ini for (const auto& key: keys) { - const auto& kNames = Input::Keys::kNames; - auto it = std::find(kNames.begin(), kNames.end(), key); - if (it != Input::Keys::kNames.end()) { - mappings.Add({button, static_cast(std::distance(kNames.begin(), it))}); + Input::Keys::InputKey k; + if (Input::Keys::kInputKeyNames.etag(key.c_str(), k)) { + mappings.Add({button, k}); } } } @@ -466,7 +465,7 @@ void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const { for (int i = 0; i < Input::BUTTON_COUNT; ++i) { auto button = static_cast(i); - auto name = Input::kButtonNames.tag(button); + auto name = Input::kInputButtonNames.tag(button); os << name << "="; std::stringstream ss; @@ -478,7 +477,7 @@ void Game_Config::WriteToStream(Filesystem_Stream::OutputStream& os) const { first = false; auto key = static_cast(ki->second); - auto kname = Input::Keys::kNames.tag(key); + auto kname = Input::Keys::kInputKeyNames.tag(key); os << kname; } diff --git a/src/input_buttons.h b/src/input_buttons.h index 286031fc90..e9dce4cb2d 100644 --- a/src/input_buttons.h +++ b/src/input_buttons.h @@ -88,7 +88,7 @@ namespace Input { BUTTON_COUNT }; - constexpr auto kButtonNames = lcf::makeEnumTags( + constexpr auto kInputButtonNames = lcf::makeEnumTags( "UP", "DOWN", "LEFT", @@ -133,7 +133,7 @@ namespace Input { "TOGGLE_ZOOM", "BUTTON_COUNT"); - constexpr auto kButtonHelp = lcf::makeEnumTags( + constexpr auto kInputButtonHelp = lcf::makeEnumTags( "Up Direction", "Down Direction", "Left Direction", @@ -231,7 +231,7 @@ namespace Input { NUM_DIRECTIONS = 10, }; - static constexpr auto kNames = lcf::makeEnumTags( + static constexpr auto kInputDirectionNames = lcf::makeEnumTags( "NONE", "DOWNLEFT", "DOWN", @@ -251,7 +251,7 @@ namespace Input { using ButtonMapping = ButtonMappingArray::pair_type; inline std::ostream& operator<<(std::ostream& os, ButtonMapping bm) { - os << "{ " << kButtonNames.tag(bm.first) << ", " << Keys::kNames.tag(bm.second) << " }"; + os << "{ " << kInputButtonNames.tag(bm.first) << ", " << Keys::kInputKeyNames.tag(bm.second) << " }"; return os; } @@ -261,7 +261,7 @@ namespace Input { using DirectionMapping = DirectionMappingArray::pair_type; inline std::ostream& operator<<(std::ostream& os, DirectionMapping dm) { - os << "{ " << Direction::kNames.tag(dm.first) << ", " << kButtonNames.tag(dm.second) << " }"; + os << "{ " << Direction::kInputDirectionNames.tag(dm.first) << ", " << kInputButtonNames.tag(dm.second) << " }"; return os; } diff --git a/src/input_source.cpp b/src/input_source.cpp index 3b7fefe7ef..25d6f19468 100644 --- a/src/input_source.cpp +++ b/src/input_source.cpp @@ -127,9 +127,9 @@ void Input::LogSource::Update() { } if (Main_Data::game_system->GetFrameCounter() == last_read_frame) { for (const auto& key : keys) { - auto it = std::find(Input::kButtonNames.begin(), Input::kButtonNames.end(), key); - if (it != Input::kButtonNames.end()) { - pressed_buttons[std::distance(Input::kButtonNames.begin(), it)] = true; + Input::InputButton btn; + if (Input::kInputButtonNames.etag(key.c_str(), btn)) { + pressed_buttons[(int)btn] = true; } } last_read_frame = -1; @@ -193,7 +193,7 @@ void Input::Source::Record() { continue; } - *record_log << ',' << Input::kButtonNames[i]; + *record_log << ',' << Input::kInputButtonNames[i]; } *record_log << '\n'; diff --git a/src/keys.h b/src/keys.h index e1f49a97f4..77751d82d8 100644 --- a/src/keys.h +++ b/src/keys.h @@ -226,7 +226,7 @@ namespace Input { KEYS_COUNT }; - constexpr auto kNames = lcf::makeEnumTags( + constexpr auto kInputKeyNames = lcf::makeEnumTags( "NONE", "BACKSPACE", "TAB", diff --git a/src/scene_settings.cpp b/src/scene_settings.cpp index 4d244816d4..bf564d0719 100644 --- a/src/scene_settings.cpp +++ b/src/scene_settings.cpp @@ -529,7 +529,7 @@ bool Scene_Settings::RefreshInputEmergencyReset() { } Input::ResetAllMappings(); } else { - Output::Info("Button {} reset to default", Input::kButtonNames.tag(input_window->GetInputButton())); + Output::Info("Button {} reset to default", Input::kInputButtonNames.tag(input_window->GetInputButton())); Output::Info("To reset all buttons hold 3 seconds longer"); if (input_window->GetActive()) { input_window->SetIndex(0); diff --git a/src/window_input_settings.cpp b/src/window_input_settings.cpp index 307384429a..def2e4803f 100644 --- a/src/window_input_settings.cpp +++ b/src/window_input_settings.cpp @@ -82,7 +82,7 @@ void Window_InputSettings::Refresh() { if (custom_name != custom_names.end()) { items.push_back(custom_name->second); } else { - items.push_back(Input::Keys::kNames.tag(key)); + items.push_back(Input::Keys::kInputKeyNames.tag(key)); } } diff --git a/src/window_settings.cpp b/src/window_settings.cpp index 62d440e3ca..cba597cedf 100644 --- a/src/window_settings.cpp +++ b/src/window_settings.cpp @@ -419,7 +419,7 @@ void Window_Settings::RefreshButtonList() { for (auto b: buttons) { auto button = static_cast(b); - std::string name = Input::kButtonNames.tag(button); + std::string name = Input::kInputButtonNames.tag(button); // Improve readability of the names bool first_letter = true; @@ -436,7 +436,7 @@ void Window_Settings::RefreshButtonList() { } } - std::string help = Input::kButtonHelp.tag(button); + std::string help = Input::kInputButtonHelp.tag(button); std::string value; // Append as many buttons as fit on the screen, then add ... @@ -453,7 +453,7 @@ void Window_Settings::RefreshButtonList() { if (custom_name != custom_names.end()) { cur_value = custom_name->second; } else { - cur_value = Input::Keys::kNames.tag(ki->second); + cur_value = Input::Keys::kInputKeyNames.tag(ki->second); } int cur_value_size = Text::GetSize(*Font::Default(), cur_value + ",").width;