mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 04:23:14 +08:00
Rewrite much state logic
This commit is contained in:
parent
9e25e02696
commit
55921efffb
@ -93,6 +93,8 @@ namespace osu.Game
|
||||
|
||||
private SettingsOverlay settings;
|
||||
|
||||
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
|
||||
|
||||
// todo: move this to SongSelect once Screen has the ability to unsuspend.
|
||||
public readonly Bindable<IEnumerable<Mod>> SelectedMods = new Bindable<IEnumerable<Mod>>(new List<Mod>());
|
||||
|
||||
@ -105,6 +107,17 @@ namespace osu.Game
|
||||
|
||||
public void ToggleDirect() => direct.ToggleVisibility();
|
||||
|
||||
/// <summary>
|
||||
/// Close all game-wide overlays.
|
||||
/// </summary>
|
||||
/// <param name="toolbar">Whether the toolbar should also be hidden.</param>
|
||||
public void CloseAllOverlays(bool toolbar = true)
|
||||
{
|
||||
foreach (var o in overlays)
|
||||
o.State = Visibility.Hidden;
|
||||
if (toolbar) Toolbar.State = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private DependencyContainer dependencies;
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) =>
|
||||
@ -250,7 +263,7 @@ namespace osu.Game
|
||||
Depth = -5,
|
||||
OnHome = delegate
|
||||
{
|
||||
hideAllOverlays();
|
||||
CloseAllOverlays(false);
|
||||
intro?.ChildScreen?.MakeCurrent();
|
||||
},
|
||||
}, overlayContent.Add);
|
||||
@ -307,6 +320,8 @@ namespace osu.Game
|
||||
|
||||
// ensure only one of these overlays are open at once.
|
||||
var singleDisplayOverlays = new OverlayContainer[] { chat, social, direct };
|
||||
overlays.AddRange(singleDisplayOverlays);
|
||||
|
||||
foreach (var overlay in singleDisplayOverlays)
|
||||
{
|
||||
overlay.StateChanged += state =>
|
||||
@ -322,6 +337,8 @@ namespace osu.Game
|
||||
}
|
||||
|
||||
var singleDisplaySideOverlays = new OverlayContainer[] { settings, notifications };
|
||||
overlays.AddRange(singleDisplaySideOverlays);
|
||||
|
||||
foreach (var overlay in singleDisplaySideOverlays)
|
||||
{
|
||||
overlay.StateChanged += state =>
|
||||
@ -338,6 +355,8 @@ namespace osu.Game
|
||||
|
||||
// eventually informational overlays should be displayed in a stack, but for now let's only allow one to stay open at a time.
|
||||
var informationalOverlays = new OverlayContainer[] { beatmapSetOverlay, userProfile };
|
||||
overlays.AddRange(informationalOverlays);
|
||||
|
||||
foreach (var overlay in informationalOverlays)
|
||||
{
|
||||
overlay.StateChanged += state =>
|
||||
@ -352,6 +371,11 @@ namespace osu.Game
|
||||
};
|
||||
}
|
||||
|
||||
OverlayActivationMode.ValueChanged += v =>
|
||||
{
|
||||
if (v != OverlayActivation.All) CloseAllOverlays();
|
||||
};
|
||||
|
||||
void updateScreenOffset()
|
||||
{
|
||||
float offset = 0;
|
||||
@ -368,12 +392,6 @@ namespace osu.Game
|
||||
notifications.StateChanged += _ => updateScreenOffset();
|
||||
}
|
||||
|
||||
public void CloseAllOverlays()
|
||||
{
|
||||
hideAllOverlays();
|
||||
musicController.State = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void forwardLoggedErrorsToNotifications()
|
||||
{
|
||||
int recentErrorCount = 0;
|
||||
@ -488,16 +506,6 @@ namespace osu.Game
|
||||
private OsuScreen currentScreen;
|
||||
private FrameworkConfigManager frameworkConfig;
|
||||
|
||||
private void hideAllOverlays()
|
||||
{
|
||||
settings.State = Visibility.Hidden;
|
||||
chat.State = Visibility.Hidden;
|
||||
direct.State = Visibility.Hidden;
|
||||
social.State = Visibility.Hidden;
|
||||
userProfile.State = Visibility.Hidden;
|
||||
notifications.State = Visibility.Hidden;
|
||||
}
|
||||
|
||||
protected override bool OnExiting()
|
||||
{
|
||||
if (screenStack.ChildScreen == null) return false;
|
||||
|
@ -16,6 +16,7 @@ using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Overlays;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
@ -129,9 +130,12 @@ namespace osu.Game.Screens.Menu
|
||||
buttonFlow.AddRange(buttonsTopLevel);
|
||||
}
|
||||
|
||||
private OsuGame game;
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(AudioManager audio)
|
||||
private void load(AudioManager audio, OsuGame game)
|
||||
{
|
||||
this.game = game;
|
||||
sampleBack = audio.Sample.Get(@"Menu/button-back-select");
|
||||
}
|
||||
|
||||
@ -321,6 +325,8 @@ namespace osu.Game.Screens.Menu
|
||||
{
|
||||
logoTracking = false;
|
||||
|
||||
game.OverlayActivationMode.Value = state == MenuState.Exit ? OverlayActivation.Disabled : OverlayActivation.UserTriggered;
|
||||
|
||||
logo.ClearTransforms(targetMember: nameof(Position));
|
||||
logo.RelativePositionAxes = Axes.Both;
|
||||
|
||||
@ -352,6 +358,9 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
if (impact)
|
||||
logo.Impact();
|
||||
|
||||
game.OverlayActivationMode.Value = OverlayActivation.All;
|
||||
game.Toolbar.State = Visibility.Visible;
|
||||
}, 200);
|
||||
break;
|
||||
default:
|
||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Screens.Menu
|
||||
private Color4 iconColour;
|
||||
|
||||
protected override bool HideOverlaysOnEnter => true;
|
||||
protected override OverlayActivation OverlayActivationLevel => OverlayActivation.Disabled;
|
||||
protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled;
|
||||
|
||||
public override bool CursorVisible => false;
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace osu.Game.Screens.Menu
|
||||
private SampleChannel seeya;
|
||||
|
||||
protected override bool HideOverlaysOnEnter => true;
|
||||
protected override OverlayActivation OverlayActivationLevel => OverlayActivation.Disabled;
|
||||
protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled;
|
||||
|
||||
public override bool CursorVisible => false;
|
||||
|
||||
|
@ -63,8 +63,6 @@ namespace osu.Game.Screens.Menu
|
||||
},
|
||||
sideFlashes = new MenuSideFlashes(),
|
||||
};
|
||||
|
||||
buttons.StateChanged += state => UpdateOverlayStates?.Invoke();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
|
@ -44,22 +44,17 @@ namespace osu.Game.Screens
|
||||
|
||||
private Action updateOverlayStates;
|
||||
|
||||
/// <summary>
|
||||
/// Allows manually updating visibility of all overlays if <see cref="HideOverlaysOnEnter"/> is not enough.
|
||||
/// </summary>
|
||||
protected Action UpdateOverlayStates => updateOverlayStates;
|
||||
|
||||
/// <summary>
|
||||
/// Whether all overlays should be hidden when this screen is entered or resumed.
|
||||
/// </summary>
|
||||
protected virtual bool HideOverlaysOnEnter => false;
|
||||
|
||||
private readonly Bindable<OverlayActivation> allowOverlays = new Bindable<OverlayActivation>();
|
||||
protected readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
|
||||
|
||||
/// <summary>
|
||||
/// Whether overlays should be able to be opened once this screen is entered or resumed.
|
||||
/// </summary>
|
||||
protected virtual OverlayActivation OverlayActivationLevel => OverlayActivation.All;
|
||||
protected virtual OverlayActivation InitialOverlayActivationMode => OverlayActivation.All;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this <see cref="OsuScreen"/> allows the cursor to be displayed.
|
||||
@ -110,15 +105,12 @@ namespace osu.Game.Screens
|
||||
if (osuGame != null)
|
||||
{
|
||||
Ruleset.BindTo(osuGame.Ruleset);
|
||||
allowOverlays.BindTo(osuGame.OverlayActivationMode);
|
||||
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
|
||||
|
||||
updateOverlayStates = () =>
|
||||
{
|
||||
if (HideOverlaysOnEnter)
|
||||
{
|
||||
osuGame.CloseAllOverlays();
|
||||
osuGame.Toolbar.State = Visibility.Hidden;
|
||||
}
|
||||
else
|
||||
osuGame.Toolbar.State = Visibility.Visible;
|
||||
};
|
||||
@ -257,7 +249,7 @@ namespace osu.Game.Screens
|
||||
if (backgroundParallaxContainer != null)
|
||||
backgroundParallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * BackgroundParallaxAmount;
|
||||
|
||||
allowOverlays.Value = OverlayActivationLevel;
|
||||
OverlayActivationMode.Value = InitialOverlayActivationMode;
|
||||
|
||||
updateOverlayStates?.Invoke();
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
protected override bool HideOverlaysOnEnter => true;
|
||||
|
||||
protected override OverlayActivation OverlayActivationLevel => OverlayActivation.UserTriggered;
|
||||
protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered;
|
||||
|
||||
public Action RestartRequested;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user