mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 04:43:22 +08:00
Maintain the current gameplay state in OsuGame
This commit is contained in:
parent
782fc1d60f
commit
478f2dec96
@ -70,7 +70,7 @@ namespace osu.Game.Configuration
|
|||||||
|
|
||||||
Set(OsuSetting.MouseDisableButtons, false);
|
Set(OsuSetting.MouseDisableButtons, false);
|
||||||
Set(OsuSetting.MouseDisableWheel, false);
|
Set(OsuSetting.MouseDisableWheel, false);
|
||||||
Set(OsuSetting.ConfineMouseMode, OsuConfineMouseMode.WhenOverlaysDisabled);
|
Set(OsuSetting.ConfineMouseMode, OsuConfineMouseMode.DuringGameplay);
|
||||||
|
|
||||||
// Graphics
|
// Graphics
|
||||||
Set(OsuSetting.ShowFpsDisplay, false);
|
Set(OsuSetting.ShowFpsDisplay, false);
|
||||||
|
@ -7,30 +7,29 @@ using osu.Framework.Configuration;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Overlays;
|
|
||||||
|
|
||||||
namespace osu.Game.Input
|
namespace osu.Game.Input
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connects <see cref="OsuSetting.ConfineMouseMode"/> with <see cref="FrameworkSetting.ConfineMouseMode"/>,
|
/// Connects <see cref="OsuSetting.ConfineMouseMode"/> with <see cref="FrameworkSetting.ConfineMouseMode"/>.
|
||||||
/// while binding <see cref="OsuGame.OverlayActivationMode"/>.
|
/// If <see cref="OsuGame.IsGameplay"/> is true, we should also confine the mouse cursor if it has been
|
||||||
/// It is assumed that while overlay activation is <see cref="OverlayActivation.Disabled"/>, we should also confine the
|
/// requested with <see cref="OsuConfineMouseMode.DuringGameplay"/>.
|
||||||
/// mouse cursor if it has been requested with <see cref="OsuConfineMouseMode.WhenOverlaysDisabled"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ConfineMouseTracker : Component
|
public class ConfineMouseTracker : Component
|
||||||
{
|
{
|
||||||
private Bindable<ConfineMouseMode> frameworkConfineMode;
|
private Bindable<ConfineMouseMode> frameworkConfineMode;
|
||||||
private Bindable<OsuConfineMouseMode> osuConfineMode;
|
private Bindable<OsuConfineMouseMode> osuConfineMode;
|
||||||
private IBindable<OverlayActivation> overlayActivationMode;
|
private IBindable<bool> isGameplay;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuGame game, FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
|
private void load(OsuGame game, FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
|
||||||
{
|
{
|
||||||
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
|
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
|
||||||
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
|
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
|
||||||
|
isGameplay = game.IsGameplay.GetBoundCopy();
|
||||||
|
|
||||||
osuConfineMode.ValueChanged += _ => updateConfineMode();
|
osuConfineMode.ValueChanged += _ => updateConfineMode();
|
||||||
overlayActivationMode = game.OverlayActivationMode.GetBoundCopy();
|
isGameplay.BindValueChanged(_ => updateConfineMode(), true);
|
||||||
overlayActivationMode.BindValueChanged(_ => updateConfineMode(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateConfineMode()
|
private void updateConfineMode()
|
||||||
@ -45,8 +44,8 @@ namespace osu.Game.Input
|
|||||||
frameworkConfineMode.Value = ConfineMouseMode.Fullscreen;
|
frameworkConfineMode.Value = ConfineMouseMode.Fullscreen;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OsuConfineMouseMode.WhenOverlaysDisabled:
|
case OsuConfineMouseMode.DuringGameplay:
|
||||||
frameworkConfineMode.Value = overlayActivationMode?.Value == OverlayActivation.Disabled ? ConfineMouseMode.Always : ConfineMouseMode.Never;
|
frameworkConfineMode.Value = isGameplay.Value ? ConfineMouseMode.Always : ConfineMouseMode.Never;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OsuConfineMouseMode.Always:
|
case OsuConfineMouseMode.Always:
|
||||||
|
@ -23,11 +23,11 @@ namespace osu.Game.Input
|
|||||||
Fullscreen,
|
Fullscreen,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mouse cursor will be locked to the window bounds while overlays are disabled,
|
/// The mouse cursor will be locked to the window bounds during gameplay,
|
||||||
/// but may otherwise move freely.
|
/// but may otherwise move freely.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("During Gameplay")]
|
[Description("During Gameplay")]
|
||||||
WhenOverlaysDisabled,
|
DuringGameplay,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mouse cursor will always be locked to the window bounds while the game has focus.
|
/// The mouse cursor will always be locked to the window bounds while the game has focus.
|
||||||
|
@ -97,6 +97,11 @@ namespace osu.Game
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly IBindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
|
public readonly IBindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether gameplay is currently active.
|
||||||
|
/// </summary>
|
||||||
|
public readonly Bindable<bool> IsGameplay = new BindableBool();
|
||||||
|
|
||||||
protected OsuScreenStack ScreenStack;
|
protected OsuScreenStack ScreenStack;
|
||||||
|
|
||||||
protected BackButton BackButton;
|
protected BackButton BackButton;
|
||||||
|
@ -68,6 +68,8 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
private readonly Bindable<bool> storyboardReplacesBackground = new Bindable<bool>();
|
private readonly Bindable<bool> storyboardReplacesBackground = new Bindable<bool>();
|
||||||
|
|
||||||
|
private readonly Bindable<bool> isGameplay = new Bindable<bool>();
|
||||||
|
|
||||||
public int RestartCount;
|
public int RestartCount;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
@ -156,7 +158,7 @@ namespace osu.Game.Screens.Play
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audio, OsuConfigManager config)
|
private void load(AudioManager audio, OsuConfigManager config, OsuGame game)
|
||||||
{
|
{
|
||||||
Mods.Value = base.Mods.Value.Select(m => m.CreateCopy()).ToArray();
|
Mods.Value = base.Mods.Value.Select(m => m.CreateCopy()).ToArray();
|
||||||
|
|
||||||
@ -172,6 +174,8 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
|
mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
|
||||||
|
|
||||||
|
isGameplay.BindTo(game.IsGameplay);
|
||||||
|
|
||||||
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, Mods.Value);
|
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, Mods.Value);
|
||||||
|
|
||||||
ScoreProcessor = ruleset.CreateScoreProcessor();
|
ScoreProcessor = ruleset.CreateScoreProcessor();
|
||||||
@ -219,9 +223,9 @@ namespace osu.Game.Screens.Play
|
|||||||
skipOverlay.Hide();
|
skipOverlay.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawableRuleset.IsPaused.BindValueChanged(_ => updateOverlayActivationMode());
|
DrawableRuleset.IsPaused.BindValueChanged(_ => updateGameplayState());
|
||||||
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updateOverlayActivationMode());
|
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updateGameplayState());
|
||||||
breakTracker.IsBreakTime.BindValueChanged(_ => updateOverlayActivationMode());
|
breakTracker.IsBreakTime.BindValueChanged(_ => updateGameplayState());
|
||||||
|
|
||||||
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
|
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
|
||||||
|
|
||||||
@ -353,14 +357,11 @@ namespace osu.Game.Screens.Play
|
|||||||
HUDOverlay.KeyCounter.IsCounting = !isBreakTime.NewValue;
|
HUDOverlay.KeyCounter.IsCounting = !isBreakTime.NewValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateOverlayActivationMode()
|
private void updateGameplayState()
|
||||||
{
|
{
|
||||||
bool canTriggerOverlays = DrawableRuleset.IsPaused.Value || breakTracker.IsBreakTime.Value;
|
bool inGameplay = !DrawableRuleset.HasReplayLoaded.Value && !DrawableRuleset.IsPaused.Value && !breakTracker.IsBreakTime.Value;
|
||||||
|
OverlayActivationMode.Value = inGameplay ? OverlayActivation.Disabled : OverlayActivation.UserTriggered;
|
||||||
if (DrawableRuleset.HasReplayLoaded.Value || canTriggerOverlays)
|
isGameplay.Value = inGameplay;
|
||||||
OverlayActivationMode.Value = OverlayActivation.UserTriggered;
|
|
||||||
else
|
|
||||||
OverlayActivationMode.Value = OverlayActivation.Disabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePauseOnFocusLostState() =>
|
private void updatePauseOnFocusLostState() =>
|
||||||
@ -657,7 +658,7 @@ namespace osu.Game.Screens.Play
|
|||||||
foreach (var mod in Mods.Value.OfType<IApplicableToTrack>())
|
foreach (var mod in Mods.Value.OfType<IApplicableToTrack>())
|
||||||
mod.ApplyToTrack(musicController.CurrentTrack);
|
mod.ApplyToTrack(musicController.CurrentTrack);
|
||||||
|
|
||||||
updateOverlayActivationMode();
|
updateGameplayState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnSuspending(IScreen next)
|
public override void OnSuspending(IScreen next)
|
||||||
@ -693,6 +694,9 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
musicController.ResetTrackAdjustments();
|
musicController.ResetTrackAdjustments();
|
||||||
|
|
||||||
|
// Ensure we reset the IsGameplay state
|
||||||
|
isGameplay.Value = false;
|
||||||
|
|
||||||
fadeOut();
|
fadeOut();
|
||||||
return base.OnExiting(next);
|
return base.OnExiting(next);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user