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

Add a bindable Enabled flag to NotificationManager

Also better handles delays before notifications are displayed.
This commit is contained in:
Dean Herbert 2017-12-25 18:52:09 +09:00
parent 45e4c09cb8
commit 71a94d6b44
13 changed files with 89 additions and 29 deletions

View File

@ -110,7 +110,7 @@ namespace osu.Desktop.Overlays
// only show a notification if we've previously saved a version to the config file (ie. not the first run).
if (!string.IsNullOrEmpty(lastVersion))
Scheduler.AddDelayed(() => notificationOverlay.Post(new UpdateCompleteNotification(version)), 5000);
notificationOverlay.Post(new UpdateCompleteNotification(version));
}
}

View File

@ -64,6 +64,8 @@ namespace osu.Game
public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight;
public readonly BindableBool ShowOverlays = new BindableBool();
private OsuScreen screenStack;
private VolumeControl volume;
@ -287,6 +289,21 @@ namespace osu.Game
settings.StateChanged += stateChanged;
notifications.StateChanged += stateChanged;
notifications.Enabled.BindTo(ShowOverlays);
ShowOverlays.ValueChanged += visible =>
{
//central game screen change logic.
if (!visible)
{
hideAllOverlays();
musicController.State = Visibility.Hidden;
Toolbar.State = Visibility.Hidden;
}
else
Toolbar.State = Visibility.Visible;
};
Cursor.State = Visibility.Hidden;
}
@ -357,6 +374,8 @@ namespace osu.Game
notifications.State = Visibility.Hidden;
}
private ScheduledDelegate notificationsEnabler;
private void screenChanged(Screen newScreen)
{
currentScreen = newScreen as OsuScreen;
@ -367,16 +386,6 @@ namespace osu.Game
return;
}
//central game screen change logic.
if (!currentScreen.ShowOverlays)
{
hideAllOverlays();
musicController.State = Visibility.Hidden;
Toolbar.State = Visibility.Hidden;
}
else
Toolbar.State = Visibility.Visible;
ScreenChanged?.Invoke(newScreen);
}

View File

@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -11,6 +10,9 @@ using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
using System;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Threading;
namespace osu.Game.Overlays
{
@ -20,6 +22,11 @@ namespace osu.Game.Overlays
public const float TRANSITION_LENGTH = 600;
/// <summary>
/// Whether posted notifications should be processed.
/// </summary>
public readonly BindableBool Enabled = new BindableBool(true);
private FlowContainer<NotificationSection> sections;
/// <summary>
@ -27,6 +34,27 @@ namespace osu.Game.Overlays
/// </summary>
public Func<float> GetToolbarHeight;
public NotificationOverlay()
{
ScheduledDelegate notificationsEnabler = null;
Enabled.ValueChanged += v =>
{
if (!IsLoaded)
{
processingPosts = v;
return;
}
notificationsEnabler?.Cancel();
if (v)
// we want a slight delay before toggling notifications on to avoid the user becoming overwhelmed.
notificationsEnabler = Scheduler.AddDelayed(() => processingPosts = true, 1000);
else
processingPosts = false;
};
}
[BackgroundDependencyLoader]
private void load()
{
@ -84,9 +112,13 @@ namespace osu.Game.Overlays
State = Visibility.Hidden;
}
private readonly Scheduler postScheduler = new Scheduler();
private bool processingPosts = true;
public void Post(Notification notification)
{
Schedule(() =>
postScheduler.Add(() =>
{
State = Visibility.Visible;
@ -104,6 +136,13 @@ namespace osu.Game.Overlays
});
}
protected override void Update()
{
base.Update();
if (processingPosts)
postScheduler.Update();
}
protected override void PopIn()
{
base.PopIn();

View File

@ -24,7 +24,7 @@ namespace osu.Game.Screens.Edit
{
protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4");
public override bool ShowOverlays => false;
public override bool ShowOverlaysOnEnter => false;
private readonly Box bottomBackground;
private readonly Container screenContainer;

View File

@ -17,7 +17,7 @@ namespace osu.Game.Screens
{
private bool showDisclaimer;
public override bool ShowOverlays => false;
public override bool ShowOverlaysOnEnter => false;
public Loader()
{

View File

@ -11,12 +11,12 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Overlays.Toolbar;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio;
using osu.Framework.Configuration;
using osu.Framework.Threading;
namespace osu.Game.Screens.Menu
@ -25,6 +25,8 @@ namespace osu.Game.Screens.Menu
{
public event Action<MenuState> StateChanged;
private readonly BindableBool showOverlays = new BindableBool();
public Action OnEdit;
public Action OnExit;
public Action OnDirect;
@ -34,8 +36,6 @@ namespace osu.Game.Screens.Menu
public Action OnChart;
public Action OnTest;
private Toolbar toolbar;
private readonly FlowContainerWithOrigin buttonFlow;
//todo: make these non-internal somehow.
@ -131,9 +131,9 @@ namespace osu.Game.Screens.Menu
}
[BackgroundDependencyLoader(true)]
private void load(AudioManager audio, OsuGame game = null)
private void load(AudioManager audio, OsuGame game)
{
toolbar = game?.Toolbar;
if (game != null) showOverlays.BindTo(game.ShowOverlays);
sampleBack = audio.Sample.Get(@"Menu/button-back-select");
}
@ -300,7 +300,7 @@ namespace osu.Game.Screens.Menu
logoDelayedAction = Scheduler.AddDelayed(() =>
{
toolbar?.Hide();
showOverlays.Value = false;
logo.ClearTransforms(targetMember: nameof(Position));
logo.RelativePositionAxes = Axes.Both;
@ -329,7 +329,7 @@ namespace osu.Game.Screens.Menu
logoTracking = true;
logo.Impact();
toolbar?.Show();
showOverlays.Value = true;
}, 200);
break;
default:

View File

@ -18,7 +18,7 @@ namespace osu.Game.Screens.Menu
private readonly SpriteIcon icon;
private Color4 iconColour;
public override bool ShowOverlays => false;
public override bool ShowOverlaysOnEnter => false;
public override bool HasLocalCursorDisplayed => true;

View File

@ -33,7 +33,7 @@ namespace osu.Game.Screens.Menu
public override bool HasLocalCursorDisplayed => true;
public override bool ShowOverlays => false;
public override bool ShowOverlaysOnEnter => false;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenEmpty();

View File

@ -24,7 +24,7 @@ namespace osu.Game.Screens.Menu
{
private readonly ButtonSystem buttons;
public override bool ShowOverlays => buttons.State != MenuState.Initial;
public override bool ShowOverlaysOnEnter => buttons.State != MenuState.Initial;
private readonly BackgroundScreenDefault background;
private Screen songSelect;

View File

@ -28,7 +28,12 @@ namespace osu.Game.Screens
/// </summary>
protected virtual BackgroundScreen CreateBackground() => null;
public virtual bool ShowOverlays => true;
protected BindableBool ShowOverlays = new BindableBool();
/// <summary>
/// Whether overlays should be shown when this screen is entered or resumed.
/// </summary>
public virtual bool ShowOverlaysOnEnter => true;
protected new OsuGameBase Game => base.Game as OsuGameBase;
@ -70,7 +75,10 @@ namespace osu.Game.Screens
}
if (osuGame != null)
{
Ruleset.BindTo(osuGame.Ruleset);
ShowOverlays.BindTo(osuGame.ShowOverlays);
}
sampleExit = audio.Sample.Get(@"UI/screen-back");
}
@ -94,6 +102,8 @@ namespace osu.Game.Screens
base.OnResuming(last);
logo.AppendAnimatingAction(() => LogoArriving(logo, true), true);
sampleExit?.Play();
ShowOverlays.Value = ShowOverlaysOnEnter;
}
protected override void OnSuspending(Screen next)
@ -139,6 +149,8 @@ namespace osu.Game.Screens
logo.AppendAnimatingAction(() => LogoArriving(logo, false), true);
base.OnEntering(last);
ShowOverlays.Value = ShowOverlaysOnEnter;
}
protected override bool OnExiting(Screen next)

View File

@ -35,7 +35,7 @@ namespace osu.Game.Screens.Play
{
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
public override bool ShowOverlays => false;
public override bool ShowOverlaysOnEnter => false;
public override bool HasLocalCursorDisplayed => !pauseContainer.IsPaused && !HasFailed && RulesetContainer.ProvidingUserCursor;

View File

@ -23,7 +23,7 @@ namespace osu.Game.Screens.Play
private BeatmapMetadataDisplay info;
private bool showOverlays = true;
public override bool ShowOverlays => showOverlays;
public override bool ShowOverlaysOnEnter => showOverlays;
public override bool AllowBeatmapRulesetChange => false;

View File

@ -29,7 +29,7 @@ namespace osu.Game.Screens.Tournament
{
private const string results_filename = "drawings_results.txt";
public override bool ShowOverlays => false;
public override bool ShowOverlaysOnEnter => false;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();