Skip to content

Commit

Permalink
Making the settings show buttons instead of keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncletrunks committed Nov 16, 2020
1 parent 47a7d7c commit 982af60
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
66 changes: 62 additions & 4 deletions src/Menu/OptionsControlsState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ void OptionsControlsState::addControls(const std::vector<OptionInfo> &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());
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}


}
1 change: 1 addition & 0 deletions src/Menu/OptionsControlsState.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class OptionsControlsState : public OptionsBaseState
void addControls(const std::vector<OptionInfo> &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);
Expand Down

0 comments on commit 982af60

Please sign in to comment.