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