From 9bb0cda5256a8c14f4cf4bc7b50b2fdc832d5e3b Mon Sep 17 00:00:00 2001 From: Aergwyn Date: Sat, 23 Dec 2017 14:33:43 +0100 Subject: [PATCH] fix NotificationOverlay going out of bounds at the bottom also fixes the overlap with the Toolbar at the top --- .../Visual/TestCaseNotificationOverlay.cs | 35 +++++++--------- osu.Game/OsuGame.cs | 1 + osu.Game/Overlays/NotificationOverlay.cs | 41 ++++++++++++------- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseNotificationOverlay.cs b/osu.Game.Tests/Visual/TestCaseNotificationOverlay.cs index 79d3d7d4ba..b93c2d812f 100644 --- a/osu.Game.Tests/Visual/TestCaseNotificationOverlay.cs +++ b/osu.Game.Tests/Visual/TestCaseNotificationOverlay.cs @@ -3,19 +3,17 @@ using System.Collections.Generic; using System.Linq; -using NUnit.Framework; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.MathUtils; using osu.Game.Overlays; using osu.Game.Overlays.Notifications; namespace osu.Game.Tests.Visual { - [TestFixture] public class TestCaseNotificationOverlay : OsuTestCase { private readonly NotificationOverlay manager; + private readonly List progressingNotifications = new List(); public TestCaseNotificationOverlay() { @@ -24,15 +22,14 @@ namespace osu.Game.Tests.Visual Content.Add(manager = new NotificationOverlay { Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, + Origin = Anchor.TopRight }); - AddToggleStep(@"show", state => manager.State = state ? Visibility.Visible : Visibility.Hidden); - - AddStep(@"simple #1", sendNotification1); - AddStep(@"simple #2", sendNotification2); - AddStep(@"progress #1", sendProgress1); - AddStep(@"progress #2", sendProgress2); + AddStep(@"toggle", manager.ToggleVisibility); + AddStep(@"simple #1", sendHelloNotification); + AddStep(@"simple #2", sendAmazingNotification); + AddStep(@"progress #1", sendUploadProgress); + AddStep(@"progress #2", sendDownloadProgress); AddStep(@"barrage", () => sendBarrage()); } @@ -41,16 +38,16 @@ namespace osu.Game.Tests.Visual switch (RNG.Next(0, 4)) { case 0: - sendNotification1(); + sendHelloNotification(); break; case 1: - sendNotification2(); + sendAmazingNotification(); break; case 2: - sendProgress1(); + sendUploadProgress(); break; case 3: - sendProgress2(); + sendDownloadProgress(); break; } @@ -80,7 +77,7 @@ namespace osu.Game.Tests.Visual } } - private void sendProgress2() + private void sendDownloadProgress() { var n = new ProgressNotification { @@ -91,9 +88,7 @@ namespace osu.Game.Tests.Visual progressingNotifications.Add(n); } - private readonly List progressingNotifications = new List(); - - private void sendProgress1() + private void sendUploadProgress() { var n = new ProgressNotification { @@ -104,12 +99,12 @@ namespace osu.Game.Tests.Visual progressingNotifications.Add(n); } - private void sendNotification2() + private void sendAmazingNotification() { manager.Post(new SimpleNotification { Text = @"You are amazing" }); } - private void sendNotification1() + private void sendHelloNotification() { manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" }); } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4745733bd9..4c66539cf1 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -209,6 +209,7 @@ namespace osu.Game loadComponentSingleFile(notificationOverlay = new NotificationOverlay { + GetToolbarHeight = () => ToolbarOffset, Depth = -4, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, diff --git a/osu.Game/Overlays/NotificationOverlay.cs b/osu.Game/Overlays/NotificationOverlay.cs index 260214a14f..a4b5486596 100644 --- a/osu.Game/Overlays/NotificationOverlay.cs +++ b/osu.Game/Overlays/NotificationOverlay.cs @@ -10,6 +10,7 @@ using osu.Game.Overlays.Notifications; using OpenTK.Graphics; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics.Containers; +using System; namespace osu.Game.Overlays { @@ -19,9 +20,13 @@ namespace osu.Game.Overlays public const float TRANSITION_LENGTH = 600; - private ScrollContainer scrollContainer; private FlowContainer sections; + /// + /// Provide a source for the toolbar height. + /// + public Func GetToolbarHeight; + [BackgroundDependencyLoader] private void load() { @@ -36,12 +41,12 @@ namespace osu.Game.Overlays { RelativeSizeAxes = Axes.Both, Colour = Color4.Black, - Alpha = 0.6f, + Alpha = 0.6f }, - scrollContainer = new OsuScrollContainer + new OsuScrollContainer { + Masking = true, RelativeSizeAxes = Axes.Both, - Margin = new MarginPadding { Top = Toolbar.Toolbar.HEIGHT }, Children = new[] { sections = new FillFlowContainer @@ -55,14 +60,14 @@ namespace osu.Game.Overlays { Title = @"Notifications", ClearText = @"Clear All", - AcceptTypes = new[] { typeof(SimpleNotification) }, + AcceptTypes = new[] { typeof(SimpleNotification) } }, new NotificationSection { Title = @"Running Tasks", ClearText = @"Cancel All", - AcceptTypes = new[] { typeof(ProgressNotification) }, - }, + AcceptTypes = new[] { typeof(ProgressNotification) } + } } } } @@ -103,14 +108,8 @@ namespace osu.Game.Overlays { base.PopIn(); - scrollContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); this.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); - this.FadeTo(1, TRANSITION_LENGTH / 2); - } - - private void markAllRead() - { - sections.Children.ForEach(s => s.MarkAllRead()); + this.FadeTo(1, TRANSITION_LENGTH, Easing.OutQuint); } protected override void PopOut() @@ -120,7 +119,19 @@ namespace osu.Game.Overlays markAllRead(); this.MoveToX(width, TRANSITION_LENGTH, Easing.OutQuint); - this.FadeTo(0, TRANSITION_LENGTH / 2); + this.FadeTo(0, TRANSITION_LENGTH, Easing.OutQuint); + } + + private void markAllRead() + { + sections.Children.ForEach(s => s.MarkAllRead()); + } + + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 }; } } }