Options refactor part 2.1: fixed control option labels.

This commit is contained in:
Muzychenko Andrey 2023-02-10 08:46:09 +03:00
parent d99fbb092e
commit 8df996f452
3 changed files with 44 additions and 45 deletions

View File

@ -23,36 +23,42 @@ optionsStruct options::Options
{ {
{ {
"Left Flipper key", "Left Flipper key",
Msg::KEYMAPPER_FlipperL,
{InputTypes::Keyboard, SDLK_z}, {InputTypes::Keyboard, SDLK_z},
{InputTypes::Mouse, SDL_BUTTON_LEFT}, {InputTypes::Mouse, SDL_BUTTON_LEFT},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_LEFTSHOULDER} {InputTypes::GameController, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}
}, },
{ {
"Right Flipper key", "Right Flipper key",
Msg::KEYMAPPER_FlipperR,
{InputTypes::Keyboard, SDLK_SLASH}, {InputTypes::Keyboard, SDLK_SLASH},
{InputTypes::Mouse,SDL_BUTTON_RIGHT}, {InputTypes::Mouse,SDL_BUTTON_RIGHT},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER} {InputTypes::GameController, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}
}, },
{ {
"Plunger key", "Plunger key",
Msg::KEYMAPPER_Plunger,
{InputTypes::Keyboard, SDLK_SPACE}, {InputTypes::Keyboard, SDLK_SPACE},
{InputTypes::Mouse,SDL_BUTTON_MIDDLE}, {InputTypes::Mouse,SDL_BUTTON_MIDDLE},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_A} {InputTypes::GameController, SDL_CONTROLLER_BUTTON_A}
}, },
{ {
"Left Table Bump key", "Left Table Bump key",
Msg::KEYMAPPER_BumpLeft,
{InputTypes::Keyboard, SDLK_x}, {InputTypes::Keyboard, SDLK_x},
{InputTypes::Mouse,SDL_BUTTON_X1}, {InputTypes::Mouse,SDL_BUTTON_X1},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_LEFT} {InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_LEFT}
}, },
{ {
"Right Table Bump key", "Right Table Bump key",
Msg::KEYMAPPER_BumpRight,
{InputTypes::Keyboard, SDLK_PERIOD}, {InputTypes::Keyboard, SDLK_PERIOD},
{InputTypes::Mouse,SDL_BUTTON_X2}, {InputTypes::Mouse,SDL_BUTTON_X2},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_RIGHT} {InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_RIGHT}
}, },
{ {
"Bottom Table Bump key", "Bottom Table Bump key",
Msg::KEYMAPPER_BumpBottom,
{InputTypes::Keyboard, SDLK_UP}, {InputTypes::Keyboard, SDLK_UP},
{InputTypes::Mouse,SDL_BUTTON_X2 + 1}, {InputTypes::Mouse,SDL_BUTTON_X2 + 1},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_UP} {InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_UP}
@ -299,16 +305,6 @@ void options::ShowControlDialog()
void options::RenderControlDialog() void options::RenderControlDialog()
{ {
static const Msg controlDescriptions[6]
{
Msg::KEYMAPPER_FlipperL,
Msg::KEYMAPPER_FlipperR,
Msg::KEYMAPPER_BumpLeft,
Msg::KEYMAPPER_BumpRight,
Msg::KEYMAPPER_BumpBottom,
Msg::KEYMAPPER_Plunger,
};
if (!ShowDialog) if (!ShowDialog)
return; return;
@ -325,7 +321,9 @@ void options::RenderControlDialog()
ImGui::TextUnformatted(pb::get_rc_string(Msg::KEYMAPPER_Groupbox1)); ImGui::TextUnformatted(pb::get_rc_string(Msg::KEYMAPPER_Groupbox1));
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{5, 10}); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{5, 10});
if (ImGui::BeginTable("Controls", 4, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders| ImGuiTableFlags_SizingStretchSame)) if (ImGui::BeginTable("Controls", 4,
ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders |
ImGuiTableFlags_SizingStretchSame))
{ {
ImGui::TableSetupColumn("Control"); ImGui::TableSetupColumn("Control");
ImGui::TableSetupColumn("Binding 1"); ImGui::TableSetupColumn("Binding 1");
@ -334,13 +332,11 @@ void options::RenderControlDialog()
ImGui::TableHeadersRow(); ImGui::TableHeadersRow();
int rowHash = 0; int rowHash = 0;
for (auto inputId = GameBindings::Min; inputId < GameBindings::Max; inputId++) for (auto& option : Options.Key)
{ {
auto& option = Options.Key[~inputId];
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0.5, 0, 0, 1}); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0.5, 0, 0, 1});
if (ImGui::Button(pb::get_rc_string(controlDescriptions[~inputId]))) if (ImGui::Button(pb::get_rc_string(option.Description), ImVec2(-1, 0)))
{ {
for (auto& input : option.Inputs) for (auto& input : option.Inputs)
input = {}; input = {};

View File

@ -191,11 +191,14 @@ struct BoolOption : OptionBaseT<bool>
struct ControlOption : OptionBase struct ControlOption : OptionBase
{ {
const Msg Description;
GameInput Defaults[3]; GameInput Defaults[3];
GameInput Inputs[3]; GameInput Inputs[3];
ControlOption(LPCSTR name, GameInput defaultKeyboard, GameInput defaultMouse, GameInput defaultController) : ControlOption(LPCSTR name, Msg description, GameInput defaultKeyboard, GameInput defaultMouse,
GameInput defaultController) :
OptionBase(name), OptionBase(name),
Description(description),
Defaults{defaultKeyboard, defaultMouse, defaultController}, Defaults{defaultKeyboard, defaultMouse, defaultController},
Inputs{ Inputs{
{InputTypes::Keyboard, -1}, {InputTypes::Keyboard, -1},