1
0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-25 12:12:32 +01:00

Added a way to reset all game options.

Fixed some of the fragmented translations.
Improved input rejection in control dialog.
This commit is contained in:
Muzychenko Andrey 2023-02-17 13:35:18 +03:00
parent 1749a2ba09
commit 466c875f8a
5 changed files with 87 additions and 46 deletions

View File

@ -67,56 +67,56 @@ optionsStruct options::Options
"New Game", "New Game",
Msg::Menu1_New_Game, Msg::Menu1_New_Game,
{InputTypes::Keyboard, SDLK_F2}, {InputTypes::Keyboard, SDLK_F2},
{InputTypes::None, -1}, {},
{InputTypes::None, -1} {}
}, },
{ {
"Toggle Pause", "Toggle Pause",
Msg::Menu1_Pause_Resume_Game, Msg::Menu1_Pause_Resume_Game,
{InputTypes::Keyboard, SDLK_F3}, {InputTypes::Keyboard, SDLK_F3},
{InputTypes::None, -1}, {},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_START} {InputTypes::GameController, SDL_CONTROLLER_BUTTON_START}
}, },
{ {
"Toggle FullScreen", "Toggle FullScreen",
Msg::Menu1_Full_Screen, Msg::Menu1_Full_Screen,
{InputTypes::Keyboard, SDLK_F4}, {InputTypes::Keyboard, SDLK_F4},
{InputTypes::None, -1}, {},
{InputTypes::None, -1} {}
}, },
{ {
"Toggle Sounds", "Toggle Sounds",
Msg::Menu1_Sounds, Msg::Menu1_Sounds,
{InputTypes::Keyboard, SDLK_F5}, {InputTypes::Keyboard, SDLK_F5},
{InputTypes::None, -1}, {},
{InputTypes::None, -1} {}
}, },
{ {
"Toggle Music", "Toggle Music",
Msg::Menu1_Music, Msg::Menu1_Music,
{InputTypes::Keyboard, SDLK_F6}, {InputTypes::Keyboard, SDLK_F6},
{InputTypes::None, -1}, {},
{InputTypes::None, -1} {}
}, },
{ {
"Show Control Dialog", "Show Control Dialog",
Msg::Menu1_Player_Controls, Msg::Menu1_Player_Controls,
{InputTypes::Keyboard, SDLK_F8}, {InputTypes::Keyboard, SDLK_F8},
{InputTypes::None, -1}, {},
{InputTypes::None, -1} {}
}, },
{ {
"Toggle Menu Display", "Toggle Menu Display",
Msg::Menu1_ToggleShowMenu, Msg::Menu1_ToggleShowMenu,
{InputTypes::Keyboard, SDLK_F9}, {InputTypes::Keyboard, SDLK_F9},
{InputTypes::None, -1}, {},
{InputTypes::None, -1} {}
}, },
{ {
"Exit", "Exit",
Msg::Menu1_Exit, Msg::Menu1_Exit,
{InputTypes::Keyboard, SDLK_ESCAPE}, {InputTypes::Keyboard, SDLK_ESCAPE},
{InputTypes::None, -1}, {},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_BACK} {InputTypes::GameController, SDL_CONTROLLER_BUTTON_BACK}
}, },
}, },
@ -172,24 +172,12 @@ void options::InitPrimary()
} }
for (const auto opt : AllOptions) for (const auto opt : AllOptions)
{
opt->Load(); opt->Load();
} PostProcessOptions();
winmain::ImIO->FontGlobalScale = Options.UIScale;
Options.FramesPerSecond = Clamp(Options.FramesPerSecond.V, MinFps, MaxFps);
Options.UpdatesPerSecond = Clamp(Options.UpdatesPerSecond.V, MinUps, MaxUps);
Options.UpdatesPerSecond = std::max(Options.UpdatesPerSecond.V, Options.FramesPerSecond.V);
Options.SoundChannels = Clamp(Options.SoundChannels.V, MinSoundChannels, MaxSoundChannels);
Options.SoundVolume = Clamp(Options.SoundVolume.V, MinVolume, MaxVolume);
Options.MusicVolume = Clamp(Options.MusicVolume.V, MinVolume, MaxVolume);
translations::SetCurrentLanguage(Options.Language.V.c_str());
} }
void options::InitSecondary() void options::InitSecondary()
{ {
winmain::UpdateFrameRate();
auto maxRes = fullscrn::GetMaxResolution(); auto maxRes = fullscrn::GetMaxResolution();
if (Options.Resolution >= 0 && Options.Resolution > maxRes) if (Options.Resolution >= 0 && Options.Resolution > maxRes)
Options.Resolution = maxRes; Options.Resolution = maxRes;
@ -467,6 +455,13 @@ std::vector<GameBindings> options::MapGameInput(GameInput key)
return result; return result;
} }
void options::ResetAllOptions()
{
for (const auto opt : AllOptions)
opt->Reset();
PostProcessOptions();
}
void options::MyUserData_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line) void options::MyUserData_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line)
{ {
auto& keyValueStore = *static_cast<std::unordered_map<std::string, std::string>*>(entry); auto& keyValueStore = *static_cast<std::unordered_map<std::string, std::string>*>(entry);
@ -496,6 +491,19 @@ void options::MyUserData_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handl
buf->append("\n"); buf->append("\n");
} }
void options::PostProcessOptions()
{
winmain::ImIO->FontGlobalScale = Options.UIScale;
Options.FramesPerSecond = Clamp(Options.FramesPerSecond.V, MinFps, MaxFps);
Options.UpdatesPerSecond = Clamp(Options.UpdatesPerSecond.V, MinUps, MaxUps);
Options.UpdatesPerSecond = std::max(Options.UpdatesPerSecond.V, Options.FramesPerSecond.V);
Options.SoundChannels = Clamp(Options.SoundChannels.V, MinSoundChannels, MaxSoundChannels);
Options.SoundVolume = Clamp(Options.SoundVolume.V, MinVolume, MaxVolume);
Options.MusicVolume = Clamp(Options.MusicVolume.V, MinVolume, MaxVolume);
translations::SetCurrentLanguage(Options.Language.V.c_str());
winmain::UpdateFrameRate();
}
std::string GameInput::GetFullInputDescription() const std::string GameInput::GetFullInputDescription() const
{ {
std::string prefix; std::string prefix;
@ -512,8 +520,7 @@ std::string GameInput::GetFullInputDescription() const
break; break;
case InputTypes::None: case InputTypes::None:
default: default:
prefix = "Unused"; return "Unused";
break;
} }
return prefix + GetShortInputDescription(); return prefix + GetShortInputDescription();
@ -566,13 +573,13 @@ std::string GameInput::GetShortInputDescription() const
if (Value >= SDL_BUTTON_LEFT && Value <= SDL_BUTTON_X2) if (Value >= SDL_BUTTON_LEFT && Value <= SDL_BUTTON_X2)
keyName = mouseButtons[Value]; keyName = mouseButtons[Value];
else else
keyName = std::to_string(Value); keyName = "MButton" + std::to_string(Value);
break; break;
case InputTypes::GameController: case InputTypes::GameController:
if (Value >= SDL_CONTROLLER_BUTTON_A && Value < std::min(static_cast<int>(SDL_CONTROLLER_BUTTON_MAX), 21)) if (Value >= SDL_CONTROLLER_BUTTON_A && Value < std::min(static_cast<int>(SDL_CONTROLLER_BUTTON_MAX), 21))
keyName = controllerButtons[Value]; keyName = controllerButtons[Value];
else else
keyName = std::to_string(Value); keyName = "CButton" + std::to_string(Value);
break; break;
case InputTypes::None: case InputTypes::None:
default: default:

View File

@ -46,6 +46,14 @@ struct GameInput
InputTypes Type; InputTypes Type;
int Value; int Value;
GameInput() : GameInput(InputTypes::None, -1)
{
}
GameInput(InputTypes type, int value) : Type(type), Value(value)
{
}
bool operator==(const GameInput& other) const bool operator==(const GameInput& other) const
{ {
return Type == other.Type && Value == other.Value; return Type == other.Type && Value == other.Value;
@ -115,6 +123,7 @@ public:
static void RenderControlDialog(); static void RenderControlDialog();
static bool WaitingForInput() { return ControlWaitingForInput; } static bool WaitingForInput() { return ControlWaitingForInput; }
static std::vector<GameBindings> MapGameInput(GameInput key); static std::vector<GameBindings> MapGameInput(GameInput key);
static void ResetAllOptions();
private: private:
static std::unordered_map<std::string, std::string> settings; static std::unordered_map<std::string, std::string> settings;
static bool ShowDialog; static bool ShowDialog;
@ -123,6 +132,7 @@ private:
static void MyUserData_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); static void MyUserData_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line);
static void* MyUserData_ReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); static void* MyUserData_ReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name);
static void MyUserData_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf); static void MyUserData_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf);
static void PostProcessOptions();
}; };
@ -210,11 +220,7 @@ struct ControlOption : OptionBase
OptionBase(name), OptionBase(name),
Description(description), Description(description),
Defaults{defaultKeyboard, defaultMouse, defaultController}, Defaults{defaultKeyboard, defaultMouse, defaultController},
Inputs{ Inputs{defaultKeyboard, defaultMouse, defaultController}
{InputTypes::Keyboard, -1},
{InputTypes::Mouse, -1},
{InputTypes::GameController, -1}
}
{ {
} }

View File

@ -454,7 +454,12 @@ void pb::InputUp(GameInput input)
void pb::InputDown(GameInput input) void pb::InputDown(GameInput input)
{ {
if (options::WaitingForInput())
{
options::InputDown(input); options::InputDown(input);
return;
}
const auto bindings = options::MapGameInput(input); const auto bindings = options::MapGameInput(input);
for (const auto binding : bindings) for (const auto binding : bindings)
{ {

View File

@ -5464,11 +5464,11 @@ const TextArray translations::Translations =
{ {
Msg::KEYMAPPER_Help1, Msg::KEYMAPPER_Help1,
{ {
{ Lang::Arabic, "لتغيير عناصر التحكم باللعبة، حدد خيارات عناصر التحكم التي تريدها ثم انقر فوق أزرار الأسهم لتغيير مفاتيح محددة ثم اختر " }, { Lang::Arabic, "لتغيير عناصر التحكم باللعبة، حدد خيارات عناصر التحكم التي تريدها ثم انقر فوق أزرار الأسهم لتغيير مفاتيح محددة ثم اختر \"موافق\"" },
{ Lang::Czech, "Ovládání hry změníte vybráním ovládacího prvku a klepnutím na tlačítka šipek, která mění ovládací klávesy. Pak klepněte na tlačítko OK." }, { Lang::Czech, "Ovládání hry změníte vybráním ovládacího prvku a klepnutím na tlačítka šipek, která mění ovládací klávesy. Pak klepněte na tlačítko OK." },
{ Lang::Danish, "Hvis du vil ændre styretaster, skal du markere de ønskede indstillinger, klikke på pilknapperne for at ændre tasterne og derefter klikke på OK." }, { Lang::Danish, "Hvis du vil ændre styretaster, skal du markere de ønskede indstillinger, klikke på pilknapperne for at ændre tasterne og derefter klikke på OK." },
{ Lang::German, "Wählen Sie die gewünschten Optionen zum Ändern der Bedienelemente, und klicken Sie auf die Pfeile, um die Tastenbelegung zu ändern. Klicken Sie auf " }, { Lang::German, "Wählen Sie die gewünschten Optionen zum Ändern der Bedienelemente, und klicken Sie auf die Pfeile, um die Tastenbelegung zu ändern. Klicken Sie auf \"OK\"" },
{ Lang::Greek, "Για να αλλάξετε τα πλήκτρα ελέγχου, επιλέξτε το στοιχείο που θέλετε, χρησιμοποιήστε τα πλήκτρα βέλους για να αλλάξετε τα πλήκτρα και μετά επιλέξτε " }, { Lang::Greek, "Για να αλλάξετε τα πλήκτρα ελέγχου, επιλέξτε το στοιχείο που θέλετε, χρησιμοποιήστε τα πλήκτρα βέλους για να αλλάξετε τα πλήκτρα και μετά επιλέξτε \"OK\"" },
{ Lang::English, "To change game controls, choose the control options you want, click the Arrow buttons to change specific keys, and then choose OK." }, { Lang::English, "To change game controls, choose the control options you want, click the Arrow buttons to change specific keys, and then choose OK." },
{ Lang::Spanish, "Para cambiar los controles del juego, elija la opción de control deseada, haga clic en los botones de flecha y elija Aceptar." }, { Lang::Spanish, "Para cambiar los controles del juego, elija la opción de control deseada, haga clic en los botones de flecha y elija Aceptar." },
{ Lang::Finnish, "Muuta pelin ohjaimia valitsemalla haluamasi ohjainasetukset. Muuta näppäimistömäärityksiä nuolinäppäimillä ja valitse sitten OK." }, { Lang::Finnish, "Muuta pelin ohjaimia valitsemalla haluamasi ohjainasetukset. Muuta näppäimistömäärityksiä nuolinäppäimillä ja valitse sitten OK." },
@ -5493,11 +5493,11 @@ const TextArray translations::Translations =
{ {
Msg::KEYMAPPER_Help2, Msg::KEYMAPPER_Help2,
{ {
{ Lang::Arabic, "لاستعادة 3D Pinball إلى الإعدادات الأصلية، اختر " }, { Lang::Arabic, "لاستعادة 3D Pinball إلى الإعدادات الأصلية، اختر \"الافتراضي\" ثم اختر \"موافق\". لاستخدام مفاتيح الأسهم الموجودة في لوحة المفاتيح الرقمية، تأكد أن NUMLOCK مغلق" },
{ Lang::Czech, "Původní nastavení hry 3D Pinball obnovíte klepnutím na tlačítko Výchozí a poté OK. Pokud chcete používat šipkové klávesy na numerické klávesnici, musí být indikátor Num Lock vypnutý." }, { Lang::Czech, "Původní nastavení hry 3D Pinball obnovíte klepnutím na tlačítko Výchozí a poté OK. Pokud chcete používat šipkové klávesy na numerické klávesnici, musí být indikátor Num Lock vypnutý." },
{ Lang::Danish, "Hvis du vil gendanne de oprindelige indstillinger for 3D Pinball, skal du klikke på Standard og derefter på OK. Hvis du vil bruge tasterne på det numeriske tastatur, skal NumLock være slået fra." }, { Lang::Danish, "Hvis du vil gendanne de oprindelige indstillinger for 3D Pinball, skal du klikke på Standard og derefter på OK. Hvis du vil bruge tasterne på det numeriske tastatur, skal NumLock være slået fra." },
{ Lang::German, "Klicken Sie auf " }, { Lang::German, "Klicken Sie auf \"Standard\" und auf \"OK\", um die ursprünglichen Einstellungen von 3D-Pinball wiederherzustellen. Stellen Sie sicher, dass die Num-Taste ausgeschaltet ist, um mit den Pfeiltasten der Zehnertastatur arbeiten zu können." },
{ Lang::Greek, "Γι α να επαναφέρετε τις αρχικές ρυθμίσεις του Φλίπερ- 3Δ, επιλέξτε " }, { Lang::Greek, "Γι α να επαναφέρετε τις αρχικές ρυθμίσεις του Φλίπερ- 3Δ, επιλέξτε \"Προεπιλογή\" και μετά πατήστε \"ΟΚ\". Για να χρησιμοποιήσετε τα πλήκτρα βέλους του αριθμητικού πληκτρολογίου, βεβαιωθείτε ότι το NUMLOCK είναι ανενεργό." },
{ Lang::English, "To restore 3D Pinball to its original settings, choose Default, and then choose OK. To use the Arrow keys on the numeric keypad, make sure NUMLOCK is off." }, { Lang::English, "To restore 3D Pinball to its original settings, choose Default, and then choose OK. To use the Arrow keys on the numeric keypad, make sure NUMLOCK is off." },
{ Lang::Spanish, "Para recuperar la configuración original de 3D Pinball, elija Predeterminados y luego Aceptar. Cuando utilice las teclas de dirección en el teclado numérico, compruebe que Bloq Num está desactivado." }, { Lang::Spanish, "Para recuperar la configuración original de 3D Pinball, elija Predeterminados y luego Aceptar. Cuando utilice las teclas de dirección en el teclado numérico, compruebe que Bloq Num está desactivado." },
{ Lang::Finnish, "Palauta 3D Pinballin alkuperäiset asetukset valitsemalla Oletus ja sitten OK. Käytä numeronäppäimistön nuolinäppäimiä ja varmista, että NUM LOCK ei ole käytössä." }, { Lang::Finnish, "Palauta 3D Pinballin alkuperäiset asetukset valitsemalla Oletus ja sitten OK. Käytä numeronäppäimistön nuolinäppäimiä ja varmista, että NUM LOCK ei ole käytössä." },
@ -5512,9 +5512,9 @@ const TextArray translations::Translations =
{ Lang::Polish, "Aby przywrócić oryginalne ustawienia gry 3D Pinball, kliknij przycisk Domyślne, a następnie kliknij przycisk OK. Aby używać klawiszy strzałek na klawiaturze numerycznej upewnij się, że klawisz NUMLOCK jest wyłączony." }, { Lang::Polish, "Aby przywrócić oryginalne ustawienia gry 3D Pinball, kliknij przycisk Domyślne, a następnie kliknij przycisk OK. Aby używać klawiszy strzałek na klawiaturze numerycznej upewnij się, że klawisz NUMLOCK jest wyłączony." },
{ Lang::BrazilianPortuguese, "Para restaurar as configurações originais do Pinball 3D, clique em 'Padrão' e em 'OK'. Para usar as teclas de direção do teclado numérico, certifique-se de que a tecla NUMLOCK está desativada." }, { Lang::BrazilianPortuguese, "Para restaurar as configurações originais do Pinball 3D, clique em 'Padrão' e em 'OK'. Para usar as teclas de direção do teclado numérico, certifique-se de que a tecla NUMLOCK está desativada." },
{ Lang::Portuguese, "Para restaurar as definições originais do 3D Pinball, seleccione 'Predefinições' e, em seguida, seleccione 'OK'. Para usar as teclas de setas no teclado numérico, certifique-se de que o NUMLOCK está desligado." }, { Lang::Portuguese, "Para restaurar as definições originais do 3D Pinball, seleccione 'Predefinições' e, em seguida, seleccione 'OK'. Para usar as teclas de setas no teclado numérico, certifique-se de que o NUMLOCK está desligado." },
{ Lang::Russian, "Для сброса значений клавиш управления по умолчанию нажмите кнопку " }, { Lang::Russian, "Для сброса значений клавиш управления по умолчанию нажмите кнопку \"По умолчанию\", а затем кнопку OK." },
{ Lang::Swedish, "Om du vill återställa de ursprungliga inställningarna för 3D Pinball väljer du Standard och sedan OK. Om du vill använda piltangenterna på det numeriska tangentbordet måste NUMLOCK vara av." }, { Lang::Swedish, "Om du vill återställa de ursprungliga inställningarna för 3D Pinball väljer du Standard och sedan OK. Om du vill använda piltangenterna på det numeriska tangentbordet måste NUMLOCK vara av." },
{ Lang::Turkish, "3D Pinball" }, { Lang::Turkish, "\"3D Pinball\" ın özgün ayarlarını uygulamak için Varsayılan'ı seçip Tamam'ı tıklatın. Sayısal tuş takımındaki tuşları kullanmak için NUMLOCK'un kapalı olması gerekir." },
{ Lang::SimplifiedChinese, "要将“三维弹球”还原到其原设置,请选择 “默认值”,然后选择“确定”。要使用数字键盘上的箭头键,请确认 NUMLOCK 已关闭。" }, { Lang::SimplifiedChinese, "要将“三维弹球”还原到其原设置,请选择 “默认值”,然后选择“确定”。要使用数字键盘上的箭头键,请确认 NUMLOCK 已关闭。" },
{ Lang::TraditionalChinese, "若要將立體彈珠台還原成原始設定,請選擇[預設],然後選擇[確定]。請使用數字鍵台上的方向鍵,並確定 NUMLOCK 指示燈號在關閉狀態。" }, { Lang::TraditionalChinese, "若要將立體彈珠台還原成原始設定,請選擇[預設],然後選擇[確定]。請使用數字鍵台上的方向鍵,並確定 NUMLOCK 指示燈號在關閉狀態。" },
}, },

View File

@ -130,6 +130,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
mixOpened = true; mixOpened = true;
} }
auto resetAllOptions = strstr(lpCmdLine, "-reset") != nullptr;
do do
{ {
restart = false; restart = false;
@ -144,6 +145,11 @@ int winmain::WinMain(LPCSTR lpCmdLine)
// First option initialization step: just load settings from .ini. Needs ImGui context. // First option initialization step: just load settings from .ini. Needs ImGui context.
options::InitPrimary(); options::InitPrimary();
if (resetAllOptions)
{
resetAllOptions = false;
options::ResetAllOptions();
}
if (!Options.FontFileName.V.empty()) if (!Options.FontFileName.V.empty())
{ {
@ -678,6 +684,12 @@ void winmain::RenderUi()
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::Separator();
if (ImGui::MenuItem("Reset All Options"))
{
options::ResetAllOptions();
Restart();
}
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -806,6 +818,17 @@ void winmain::RenderUi()
int winmain::event_handler(const SDL_Event* event) int winmain::event_handler(const SDL_Event* event)
{ {
auto inputDown = false;
switch (event->type)
{
case SDL_KEYDOWN:
case SDL_MOUSEBUTTONDOWN:
case SDL_CONTROLLERBUTTONDOWN:
inputDown = true;
break;
default: break;
}
if (!options::WaitingForInput() || !inputDown)
ImGui_ImplSDL2_ProcessEvent(event); ImGui_ImplSDL2_ProcessEvent(event);
if (ImIO->WantCaptureMouse && !options::WaitingForInput()) if (ImIO->WantCaptureMouse && !options::WaitingForInput())