Browse Source

Option to not pause the game when the window loses focus (#7046)

pull/7095/head
djvs 2 years ago committed by GitHub
parent
commit
a6e2481a3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      Source/DiabloUI/diabloui.cpp
  2. 6
      Source/init.cpp
  3. 10
      Source/movie.cpp
  4. 2
      Source/options.cpp
  5. 2
      Source/options.h

4
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();
}
}

6
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:

10
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:

2
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<OptionEntryBase *> GameplayOptions::GetEntries()
&disableCripplingShrines,
&adriaRefillsMana,
&grabInput,
&pauseOnFocusLoss,
};
}

2
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. */

Loading…
Cancel
Save