1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

add OverlayActivation enum

+ fix Toolbar being toggleable when it shouldn't be able to
+ allow opening overlays in MenuState.Initial again
This commit is contained in:
Aergwyn 2018-05-28 13:43:47 +02:00
parent 1572635fc8
commit 2b3a630270
9 changed files with 89 additions and 44 deletions

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using OpenTK;
using osu.Framework.Configuration;
using osu.Game.Overlays;
namespace osu.Game.Graphics.Containers
{
@ -16,13 +17,16 @@ namespace osu.Game.Graphics.Containers
private SampleChannel samplePopIn;
private SampleChannel samplePopOut;
private readonly BindableBool allowOpeningOverlays = new BindableBool(true);
/// <summary>
/// Defaults to <see cref="OverlayActivation.All"/> so that the overlay works even if BDL couldn't pass an <see cref="OsuGame"/>.
/// </summary>
private readonly Bindable<OverlayActivation> allowOverlays = new Bindable<OverlayActivation>(OverlayActivation.All);
[BackgroundDependencyLoader(true)]
private void load(OsuGame osuGame, AudioManager audio)
{
if (osuGame != null)
allowOpeningOverlays.BindTo(osuGame.AllowOpeningOverlays);
allowOverlays.BindTo(osuGame.AllowOverlays);
samplePopIn = audio.Sample.Get(@"UI/overlay-pop-in");
samplePopOut = audio.Sample.Get(@"UI/overlay-pop-out");
@ -52,7 +56,7 @@ namespace osu.Game.Graphics.Containers
private void onStateChanged(Visibility visibility)
{
if (allowOpeningOverlays)
if (allowOverlays == OverlayActivation.All)
{
switch (visibility)
{

View File

@ -77,8 +77,7 @@ namespace osu.Game
public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight;
public readonly BindableBool HideOverlaysOnEnter = new BindableBool();
public readonly BindableBool AllowOpeningOverlays = new BindableBool(true);
public readonly Bindable<OverlayActivation> AllowOverlays = new Bindable<OverlayActivation>();
private OsuScreen screenStack;
@ -368,20 +367,13 @@ namespace osu.Game
settings.StateChanged += _ => updateScreenOffset();
notifications.StateChanged += _ => updateScreenOffset();
notifications.Enabled.BindTo(AllowOpeningOverlays);
AllowOverlays.ValueChanged += state => notifications.Enabled.Value = state == OverlayActivation.All;
}
HideOverlaysOnEnter.ValueChanged += hide =>
{
//central game screen change logic.
if (hide)
{
hideAllOverlays();
musicController.State = Visibility.Hidden;
Toolbar.State = Visibility.Hidden;
}
else
Toolbar.State = Visibility.Visible;
};
public void CloseAllOverlays()
{
hideAllOverlays();
musicController.State = Visibility.Hidden;
}
private void forwardLoggedErrorsToNotifications()

View File

@ -0,0 +1,12 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Overlays
{
public enum OverlayActivation
{
Disabled,
//UserTriggered, // currently there is no way to discern user action
All
}
}

View File

@ -10,6 +10,8 @@ using osu.Framework.Input;
using osu.Game.Graphics;
using OpenTK;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
namespace osu.Game.Overlays.Toolbar
{
@ -29,6 +31,11 @@ namespace osu.Game.Overlays.Toolbar
private const float alpha_hovering = 0.8f;
private const float alpha_normal = 0.6f;
/// <summary>
/// Defaults to <see cref="OverlayActivation.All"/> so that the overlay works even if BDL couldn't pass an <see cref="OsuGame"/>.
/// </summary>
private readonly Bindable<OverlayActivation> allowOverlays = new Bindable<OverlayActivation>(OverlayActivation.All);
public Toolbar()
{
Children = new Drawable[]
@ -76,6 +83,19 @@ namespace osu.Game.Overlays.Toolbar
Size = new Vector2(1, HEIGHT);
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame osuGame)
{
if (osuGame != null)
allowOverlays.BindTo(osuGame.AllowOverlays);
StateChanged += visibility =>
{
if (allowOverlays == OverlayActivation.Disabled)
State = Visibility.Hidden;
};
}
public class ToolbarBackground : Container
{
private readonly Box solidBackground;

View File

@ -20,6 +20,7 @@ using osu.Game.Input.Bindings;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Game.Overlays;
namespace osu.Game.Screens.Menu
{
@ -27,8 +28,7 @@ namespace osu.Game.Screens.Menu
{
public event Action<MenuState> StateChanged;
private readonly BindableBool hideOverlaysOnEnter = new BindableBool();
private readonly BindableBool allowOpeningOverlays = new BindableBool();
private readonly Bindable<OverlayActivation> allowOverlays = new Bindable<OverlayActivation>();
public Action OnEdit;
public Action OnExit;
@ -137,10 +137,7 @@ namespace osu.Game.Screens.Menu
private void load(AudioManager audio, OsuGame game)
{
if (game != null)
{
hideOverlaysOnEnter.BindTo(game.HideOverlaysOnEnter);
allowOpeningOverlays.BindTo(game.AllowOpeningOverlays);
}
allowOverlays.BindTo(game.AllowOverlays);
sampleBack = audio.Sample.Get(@"Menu/button-back-select");
}
@ -332,19 +329,19 @@ namespace osu.Game.Screens.Menu
case MenuState.Exit:
case MenuState.Initial:
logoTracking = false;
allowOverlays.Value = OverlayActivation.Disabled;
logoDelayedAction = Scheduler.AddDelayed(() =>
{
hideOverlaysOnEnter.Value = true;
allowOpeningOverlays.Value = false;
logo.ClearTransforms(targetMember: nameof(Position));
logo.RelativePositionAxes = Axes.Both;
logo.MoveTo(new Vector2(0.5f), 800, Easing.OutExpo);
logo.ScaleTo(1, 800, Easing.OutExpo);
}, 150);
if(state != MenuState.Exit)
allowOverlays.Value = OverlayActivation.All;
}, 150);
break;
case MenuState.TopLevel:
case MenuState.Play:
@ -365,9 +362,6 @@ namespace osu.Game.Screens.Menu
logoTracking = true;
logo.Impact();
hideOverlaysOnEnter.Value = false;
allowOpeningOverlays.Value = true;
}, 200);
break;
default:

View File

@ -9,6 +9,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Overlays;
namespace osu.Game.Screens.Menu
{
@ -19,7 +20,6 @@ namespace osu.Game.Screens.Menu
private Color4 iconColour;
protected override bool HideOverlaysOnEnter => true;
protected override bool AllowOpeningOverlays => false;
public override bool CursorVisible => false;
@ -93,6 +93,8 @@ namespace osu.Game.Screens.Menu
LoadComponentAsync(intro = new Intro());
iconColour = colours.Yellow;
AllowOverlays.Value = OverlayActivation.Disabled;
}
protected override void OnEntering(Screen last)

View File

@ -15,6 +15,7 @@ using osu.Game.IO.Archives;
using osu.Game.Screens.Backgrounds;
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Overlays;
namespace osu.Game.Screens.Menu
{
@ -32,7 +33,6 @@ namespace osu.Game.Screens.Menu
private SampleChannel seeya;
protected override bool HideOverlaysOnEnter => true;
protected override bool AllowOpeningOverlays => false;
public override bool CursorVisible => false;
@ -77,6 +77,8 @@ namespace osu.Game.Screens.Menu
welcome = audio.Sample.Get(@"welcome");
seeya = audio.Sample.Get(@"seeya");
AllowOverlays.Value = OverlayActivation.Disabled;
}
protected override void OnEntering(Screen last)

View File

@ -10,6 +10,7 @@ using osu.Framework.Input;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Charts;
using osu.Game.Screens.Direct;
@ -25,7 +26,6 @@ namespace osu.Game.Screens.Menu
private readonly ButtonSystem buttons;
protected override bool HideOverlaysOnEnter => buttons.State == MenuState.Initial;
protected override bool AllowOpeningOverlays => buttons.State != MenuState.Initial;
protected override bool AllowBackButton => buttons.State != MenuState.Initial;
@ -64,6 +64,8 @@ namespace osu.Game.Screens.Menu
},
sideFlashes = new MenuSideFlashes(),
};
buttons.StateChanged += state => UpdateOverlayStates?.Invoke();
}
[BackgroundDependencyLoader(true)]
@ -78,6 +80,8 @@ namespace osu.Game.Screens.Menu
}
preloadSongSelect();
AllowOverlays.Value = OverlayActivation.Disabled;
}
private void preloadSongSelect()

View File

@ -18,6 +18,8 @@ using osu.Game.Rulesets;
using osu.Game.Screens.Menu;
using OpenTK;
using OpenTK.Input;
using osu.Game.Overlays;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Screens
{
@ -40,19 +42,23 @@ namespace osu.Game.Screens
/// </summary>
protected virtual BackgroundScreen CreateBackground() => null;
private readonly BindableBool hideOverlaysOnEnter = new BindableBool();
private Action updateOverlayStates;
/// <summary>
/// Whether overlays should be hidden when this screen is entered or resumed.
/// 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 BindableBool allowOpeningOverlays = new BindableBool();
/// <summary>
/// Whether overlays should be able to be opened while this screen is active.
/// Whether overlays should be able to be opened.
/// It's bound at load which means changes at construction will potentially disappear.
/// </summary>
protected virtual bool AllowOpeningOverlays => true;
protected readonly Bindable<OverlayActivation> AllowOverlays = new Bindable<OverlayActivation>();
/// <summary>
/// Whether this <see cref="OsuScreen"/> allows the cursor to be displayed.
@ -103,8 +109,18 @@ namespace osu.Game.Screens
if (osuGame != null)
{
Ruleset.BindTo(osuGame.Ruleset);
hideOverlaysOnEnter.BindTo(osuGame.HideOverlaysOnEnter);
allowOpeningOverlays.BindTo(osuGame.AllowOpeningOverlays);
AllowOverlays.BindTo(osuGame.AllowOverlays);
updateOverlayStates = () =>
{
if (HideOverlaysOnEnter)
{
osuGame.CloseAllOverlays();
osuGame.Toolbar.State = Visibility.Hidden;
}
else
osuGame.Toolbar.State = Visibility.Visible;
};
}
sampleExit = audio.Sample.Get(@"UI/screen-back");
@ -236,8 +252,7 @@ namespace osu.Game.Screens
if (backgroundParallaxContainer != null)
backgroundParallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * BackgroundParallaxAmount;
hideOverlaysOnEnter.Value = HideOverlaysOnEnter;
allowOpeningOverlays.Value = AllowOpeningOverlays;
updateOverlayStates?.Invoke();
}
private void onExitingLogo()