diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 753b77791..d68d7fd58 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -452,9 +452,9 @@ void UiHandleEvents(SDL_Event *event) // For example, if the previous size was too large for a hardware cursor then it was invisible // but may now become visible. DoReinitializeHardwareCursor(); - } else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST) { + } else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST && *sgOptions.Gameplay.pauseOnFocusLoss) { music_mute(); - } else if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { + } else if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED && *sgOptions.Gameplay.pauseOnFocusLoss) { diablo_focus_unpause(); } } diff --git a/Source/init.cpp b/Source/init.cpp index f8602e565..1e145b78f 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -401,10 +401,12 @@ void MainWndProc(const SDL_Event &event) diablo_quit(0); break; case SDL_WINDOWEVENT_FOCUS_LOST: - diablo_focus_pause(); + if (*sgOptions.Gameplay.pauseOnFocusLoss) + diablo_focus_pause(); break; case SDL_WINDOWEVENT_FOCUS_GAINED: - diablo_focus_unpause(); + if (*sgOptions.Gameplay.pauseOnFocusLoss) + diablo_focus_unpause(); break; case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_RESIZED: diff --git a/Source/movie.cpp b/Source/movie.cpp index e74def06a..7ba5c48bc 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -59,10 +59,12 @@ void play_movie(const char *pszMovie, bool userCanClose) break; #ifndef USE_SDL1 case SDL_WINDOWEVENT: - if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) - diablo_focus_pause(); - else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) - diablo_focus_unpause(); + if (*sgOptions.Gameplay.pauseOnFocusLoss) { + if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) + diablo_focus_pause(); + else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) + diablo_focus_unpause(); + } break; #else case SDL_ACTIVEEVENT: diff --git a/Source/options.cpp b/Source/options.cpp index fe37d72d0..892660f35 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -1044,6 +1044,7 @@ GameplayOptions::GameplayOptions() , tickRate("Speed", OptionEntryFlags::Invisible, "Speed", "Gameplay ticks per second.", 20) , runInTown("Run in Town", OptionEntryFlags::CantChangeInMultiPlayer, N_("Run in Town"), N_("Enable jogging/fast walking in town for Diablo and Hellfire. This option was introduced in the expansion."), false) , grabInput("Grab Input", OptionEntryFlags::None, N_("Grab Input"), N_("When enabled mouse is locked to the game window."), false) + , pauseOnFocusLoss("Pause Game When Window Loses Focus", OptionEntryFlags::None, N_("Pause Game When Window Loses Focus"), N_("When enabled, the game will pause when focus is lost."), true) , theoQuest("Theo Quest", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::OnlyHellfire, N_("Theo Quest"), N_("Enable Little Girl quest."), false) , cowQuest("Cow Quest", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::OnlyHellfire, N_("Cow Quest"), N_("Enable Jersey's quest. Lester the farmer is replaced by the Complete Nut."), false) , friendlyFire("Friendly Fire", OptionEntryFlags::CantChangeInMultiPlayer, N_("Friendly Fire"), N_("Allow arrow/spell damage between players in multiplayer even when the friendly mode is on."), true) @@ -1128,6 +1129,7 @@ std::vector GameplayOptions::GetEntries() &disableCripplingShrines, &adriaRefillsMana, &grabInput, + &pauseOnFocusLoss, }; } diff --git a/Source/options.h b/Source/options.h index 6f2658383..ae3fba095 100644 --- a/Source/options.h +++ b/Source/options.h @@ -528,6 +528,8 @@ struct GameplayOptions : OptionCategoryBase { OptionEntryBoolean runInTown; /** @brief Do not let the mouse leave the application window. */ OptionEntryBoolean grabInput; + /** @brief Pause the game when focus is lost. */ + OptionEntryBoolean pauseOnFocusLoss; /** @brief Enable the Theo quest. */ OptionEntryBoolean theoQuest; /** @brief Enable the cow quest. */