From 982af608bbc9e3bb63d903c5d10ae71d3e359f27 Mon Sep 17 00:00:00 2001 From: uncletrunks Date: Sun, 15 Nov 2020 21:37:35 -0600 Subject: [PATCH] Making the settings show buttons instead of keys. --- src/Menu/OptionsControlsState.cpp | 66 +++++++++++++++++++++++++++++-- src/Menu/OptionsControlsState.h | 1 + 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/Menu/OptionsControlsState.cpp b/src/Menu/OptionsControlsState.cpp index 21f87e9e53..ab59a7b19d 100644 --- a/src/Menu/OptionsControlsState.cpp +++ b/src/Menu/OptionsControlsState.cpp @@ -145,9 +145,9 @@ void OptionsControlsState::addControls(const std::vector &keys) { std::string name = tr(i->description()); SDLKey *key = i->asKey(); - std::string keyName = ucWords(SDL_GetKeyName(*key)); - if (*key == SDLK_UNKNOWN || *key == SDLK_WORLD_95) - keyName = ""; + std::string keyName = keyToButton(*key); + /*if (*key == SDLK_UNKNOWN || *key == SDLK_WORLD_95) + keyName = "";*/ _lstControls->addRow(2, name.c_str(), keyName.c_str()); } } @@ -234,7 +234,7 @@ void OptionsControlsState::lstControlsKeyPress(Action *action) if (key != 0) { *_selKey->asKey() = key; - std::string name = ucWords(SDL_GetKeyName(*_selKey->asKey())); + std::string name = keyToButton(key); _lstControls->setCellText(_selected, 1, name); } _lstControls->setCellColor(_selected, 0, _colorNormal); @@ -244,4 +244,62 @@ void OptionsControlsState::lstControlsKeyPress(Action *action) } } +std::string OptionsControlsState::keyToButton(SDLKey key){ + std::string keyName; + switch (key){ + case SDLK_UP: + keyName = "Up"; + break; + case SDLK_DOWN: + keyName = "Down"; + break; + case SDLK_LEFT: + keyName = "Left"; + break; + case SDLK_RIGHT: + keyName = "Right"; + break; + case SDLK_LCTRL: + keyName = "A"; + break; + case SDLK_LALT: + keyName = "B"; + break; + case SDLK_LSHIFT: + keyName = "X"; + break; + case SDLK_SPACE: + keyName = "Y"; + break; + case SDLK_TAB: + keyName = "L"; + break; + case SDLK_BACKSPACE: + keyName = "R"; + break; + case SDLK_PAGEUP: + keyName = "L2"; + break; + case SDLK_PAGEDOWN: + keyName = "R2"; + break; + case SDLK_KP_DIVIDE: + keyName = "L3"; + break; + case SDLK_KP_PERIOD: + keyName = "R3"; + break; + case SDLK_RETURN: + keyName = "Start"; + break; + case SDLK_ESCAPE: + keyName = "Select"; + break; + default: + keyName = ""; + } + return keyName; +} + + } diff --git a/src/Menu/OptionsControlsState.h b/src/Menu/OptionsControlsState.h index 02f853b084..3cc74e02cf 100644 --- a/src/Menu/OptionsControlsState.h +++ b/src/Menu/OptionsControlsState.h @@ -43,6 +43,7 @@ class OptionsControlsState : public OptionsBaseState void addControls(const std::vector &keys); OptionInfo *getControl(size_t sel); std::string ucWords(std::string str); + std::string keyToButton(SDLKey key); public: /// Creates the Controls state. OptionsControlsState(OptionsOrigin origin);