From 466c875f8a63d622918875c395f0bd1ca56bc422 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Fri, 17 Feb 2023 13:35:18 +0300 Subject: [PATCH] Added a way to reset all game options. Fixed some of the fragmented translations. Improved input rejection in control dialog. --- SpaceCadetPinball/options.cpp | 69 ++++++++++++++++-------------- SpaceCadetPinball/options.h | 16 ++++--- SpaceCadetPinball/pb.cpp | 7 ++- SpaceCadetPinball/translations.cpp | 16 +++---- SpaceCadetPinball/winmain.cpp | 25 ++++++++++- 5 files changed, 87 insertions(+), 46 deletions(-) diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index e8761cb..60778a9 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -67,56 +67,56 @@ optionsStruct options::Options "New Game", Msg::Menu1_New_Game, {InputTypes::Keyboard, SDLK_F2}, - {InputTypes::None, -1}, - {InputTypes::None, -1} + {}, + {} }, { "Toggle Pause", Msg::Menu1_Pause_Resume_Game, {InputTypes::Keyboard, SDLK_F3}, - {InputTypes::None, -1}, + {}, {InputTypes::GameController, SDL_CONTROLLER_BUTTON_START} }, { "Toggle FullScreen", Msg::Menu1_Full_Screen, {InputTypes::Keyboard, SDLK_F4}, - {InputTypes::None, -1}, - {InputTypes::None, -1} + {}, + {} }, { "Toggle Sounds", Msg::Menu1_Sounds, {InputTypes::Keyboard, SDLK_F5}, - {InputTypes::None, -1}, - {InputTypes::None, -1} + {}, + {} }, { "Toggle Music", Msg::Menu1_Music, {InputTypes::Keyboard, SDLK_F6}, - {InputTypes::None, -1}, - {InputTypes::None, -1} + {}, + {} }, { "Show Control Dialog", Msg::Menu1_Player_Controls, {InputTypes::Keyboard, SDLK_F8}, - {InputTypes::None, -1}, - {InputTypes::None, -1} + {}, + {} }, { "Toggle Menu Display", Msg::Menu1_ToggleShowMenu, {InputTypes::Keyboard, SDLK_F9}, - {InputTypes::None, -1}, - {InputTypes::None, -1} + {}, + {} }, { "Exit", Msg::Menu1_Exit, {InputTypes::Keyboard, SDLK_ESCAPE}, - {InputTypes::None, -1}, + {}, {InputTypes::GameController, SDL_CONTROLLER_BUTTON_BACK} }, }, @@ -172,24 +172,12 @@ void options::InitPrimary() } for (const auto opt : AllOptions) - { opt->Load(); - } - - 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()); + PostProcessOptions(); } void options::InitSecondary() { - winmain::UpdateFrameRate(); - auto maxRes = fullscrn::GetMaxResolution(); if (Options.Resolution >= 0 && Options.Resolution > maxRes) Options.Resolution = maxRes; @@ -467,6 +455,13 @@ std::vector options::MapGameInput(GameInput key) 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) { auto& keyValueStore = *static_cast*>(entry); @@ -496,6 +491,19 @@ void options::MyUserData_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handl 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 prefix; @@ -512,8 +520,7 @@ std::string GameInput::GetFullInputDescription() const break; case InputTypes::None: default: - prefix = "Unused"; - break; + return "Unused"; } return prefix + GetShortInputDescription(); @@ -566,13 +573,13 @@ std::string GameInput::GetShortInputDescription() const if (Value >= SDL_BUTTON_LEFT && Value <= SDL_BUTTON_X2) keyName = mouseButtons[Value]; else - keyName = std::to_string(Value); + keyName = "MButton" + std::to_string(Value); break; case InputTypes::GameController: if (Value >= SDL_CONTROLLER_BUTTON_A && Value < std::min(static_cast(SDL_CONTROLLER_BUTTON_MAX), 21)) keyName = controllerButtons[Value]; else - keyName = std::to_string(Value); + keyName = "CButton" + std::to_string(Value); break; case InputTypes::None: default: diff --git a/SpaceCadetPinball/options.h b/SpaceCadetPinball/options.h index 3d53c60..98db7f5 100644 --- a/SpaceCadetPinball/options.h +++ b/SpaceCadetPinball/options.h @@ -46,6 +46,14 @@ struct GameInput InputTypes Type; int Value; + GameInput() : GameInput(InputTypes::None, -1) + { + } + + GameInput(InputTypes type, int value) : Type(type), Value(value) + { + } + bool operator==(const GameInput& other) const { return Type == other.Type && Value == other.Value; @@ -115,6 +123,7 @@ public: static void RenderControlDialog(); static bool WaitingForInput() { return ControlWaitingForInput; } static std::vector MapGameInput(GameInput key); + static void ResetAllOptions(); private: static std::unordered_map settings; static bool ShowDialog; @@ -123,6 +132,7 @@ private: 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_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf); + static void PostProcessOptions(); }; @@ -210,11 +220,7 @@ struct ControlOption : OptionBase OptionBase(name), Description(description), Defaults{defaultKeyboard, defaultMouse, defaultController}, - Inputs{ - {InputTypes::Keyboard, -1}, - {InputTypes::Mouse, -1}, - {InputTypes::GameController, -1} - } + Inputs{defaultKeyboard, defaultMouse, defaultController} { } diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index 2becf0c..d41b664 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -454,7 +454,12 @@ void pb::InputUp(GameInput input) void pb::InputDown(GameInput input) { - options::InputDown(input); + if (options::WaitingForInput()) + { + options::InputDown(input); + return; + } + const auto bindings = options::MapGameInput(input); for (const auto binding : bindings) { diff --git a/SpaceCadetPinball/translations.cpp b/SpaceCadetPinball/translations.cpp index eebe99a..c1fb39b 100644 --- a/SpaceCadetPinball/translations.cpp +++ b/SpaceCadetPinball/translations.cpp @@ -5464,11 +5464,11 @@ const TextArray translations::Translations = { 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::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::Greek, "Για να αλλάξετε τα πλήκτρα ελέγχου, επιλέξτε το στοιχείο που θέλετε, χρησιμοποιήστε τα πλήκτρα βέλους για να αλλάξετε τα πλήκτρα και μετά επιλέξτε " }, + { 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, "Για να αλλάξετε τα πλήκτρα ελέγχου, επιλέξτε το στοιχείο που θέλετε, χρησιμοποιήστε τα πλήκτρα βέλους για να αλλάξετε τα πλήκτρα και μετά επιλέξτε \"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::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, { - { 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::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::Greek, "Γι α να επαναφέρετε τις αρχικές ρυθμίσεις του Φλίπερ- 3Δ, επιλέξτε " }, + { 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Δ, επιλέξτε \"Προεπιλογή\" και μετά πατήστε \"ΟΚ\". Για να χρησιμοποιήσετε τα πλήκτρα βέλους του αριθμητικού πληκτρολογίου, βεβαιωθείτε ότι το 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::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ä." }, @@ -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::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::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::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::TraditionalChinese, "若要將立體彈珠台還原成原始設定,請選擇[預設],然後選擇[確定]。請使用數字鍵台上的方向鍵,並確定 NUMLOCK 指示燈號在關閉狀態。" }, }, diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index d7e995b..a253d71 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -130,6 +130,7 @@ int winmain::WinMain(LPCSTR lpCmdLine) mixOpened = true; } + auto resetAllOptions = strstr(lpCmdLine, "-reset") != nullptr; do { restart = false; @@ -144,6 +145,11 @@ int winmain::WinMain(LPCSTR lpCmdLine) // First option initialization step: just load settings from .ini. Needs ImGui context. options::InitPrimary(); + if (resetAllOptions) + { + resetAllOptions = false; + options::ResetAllOptions(); + } if (!Options.FontFileName.V.empty()) { @@ -678,6 +684,12 @@ void winmain::RenderUi() } ImGui::EndMenu(); } + ImGui::Separator(); + if (ImGui::MenuItem("Reset All Options")) + { + options::ResetAllOptions(); + Restart(); + } ImGui::EndMenu(); } @@ -806,7 +818,18 @@ void winmain::RenderUi() int winmain::event_handler(const SDL_Event* event) { - ImGui_ImplSDL2_ProcessEvent(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); if (ImIO->WantCaptureMouse && !options::WaitingForInput()) {