From 6288cc6e5c32fcc8790a9a31bf1b22f64292b11a Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:03:22 +0200 Subject: [PATCH 01/14] Refactor OnScreenDisplay to allow displaying of custom messages on OSD --- osu.Game/Overlays/OSD/OsdToast.cs | 40 ++++++ osu.Game/Overlays/OnScreenDisplay.cs | 203 ++------------------------- osu.Game/osu.Game.csproj | 3 + 3 files changed, 55 insertions(+), 191 deletions(-) create mode 100644 osu.Game/Overlays/OSD/OsdToast.cs diff --git a/osu.Game/Overlays/OSD/OsdToast.cs b/osu.Game/Overlays/OSD/OsdToast.cs new file mode 100644 index 0000000000..f700577ba1 --- /dev/null +++ b/osu.Game/Overlays/OSD/OsdToast.cs @@ -0,0 +1,40 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Shapes; +using osuTK.Graphics; + +namespace osu.Game.Overlays.OSD +{ + public class OsdToast : Container + { + private readonly Container content; + protected override Container Content => content; + + public OsdToast() + { + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + Width = 240; + RelativeSizeAxes = Axes.Y; + + InternalChildren = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + Alpha = 0.7f + }, + content = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + } + }; + } + } +} diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index 88a1edddc5..0577257080 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -8,17 +8,11 @@ using osu.Framework.Configuration; using osu.Framework.Configuration.Tracking; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; -using osu.Game.Graphics; using osuTK; -using osuTK.Graphics; -using osu.Framework.Extensions.Color4Extensions; -using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Transforms; using osu.Framework.Threading; using osu.Game.Configuration; -using osu.Game.Graphics.Sprites; +using osu.Game.Overlays.OSD; namespace osu.Game.Overlays { @@ -26,16 +20,9 @@ namespace osu.Game.Overlays { private readonly Container box; - private readonly SpriteText textLine1; - private readonly SpriteText textLine2; - private readonly SpriteText textLine3; - private const float height = 110; - private const float height_notext = 98; private const float height_contracted = height * 0.9f; - private readonly FillFlowContainer optionLights; - public OnScreenDisplay() { RelativeSizeAxes = Axes.Both; @@ -52,64 +39,6 @@ namespace osu.Game.Overlays Height = height_contracted, Alpha = 0, CornerRadius = 20, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black, - Alpha = 0.7f, - }, - new Container // purely to add a minimum width - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Width = 240, - RelativeSizeAxes = Axes.Y, - }, - textLine1 = new OsuSpriteText - { - Padding = new MarginPadding(10), - Font = OsuFont.GetFont(size: 14, weight: FontWeight.Black), - Spacing = new Vector2(1, 0), - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - }, - textLine2 = new OsuSpriteText - { - Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light), - Padding = new MarginPadding { Left = 10, Right = 10 }, - Anchor = Anchor.Centre, - Origin = Anchor.BottomCentre, - }, - new FillFlowContainer - { - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre, - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Vertical, - Children = new Drawable[] - { - optionLights = new FillFlowContainer - { - Padding = new MarginPadding { Top = 20, Bottom = 5 }, - Spacing = new Vector2(5, 0), - Direction = FillDirection.Horizontal, - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - AutoSizeAxes = Axes.Both - }, - textLine3 = new OsuSpriteText - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Margin = new MarginPadding { Bottom = 15 }, - Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), - Alpha = 0.3f, - }, - } - } - } }, }; } @@ -142,7 +71,7 @@ namespace osu.Game.Overlays return; configManager.LoadInto(trackedSettings); - trackedSettings.SettingChanged += display; + trackedSettings.SettingChanged += displayTrackedSettingChange; trackedConfigManagers.Add((source, configManager), trackedSettings); } @@ -162,56 +91,23 @@ namespace osu.Game.Overlays return; existing.Unload(); - existing.SettingChanged -= display; + existing.SettingChanged -= displayTrackedSettingChange; trackedConfigManagers.Remove((source, configManager)); } - private void display(SettingDescription description) + /// + /// Displays the given as parameter on the OSD + /// + /// + public void Display(OsdToast toast) { - Schedule(() => - { - textLine1.Text = description.Name.ToUpperInvariant(); - textLine2.Text = description.Value; - textLine3.Text = description.Shortcut.ToUpperInvariant(); - - if (string.IsNullOrEmpty(textLine3.Text)) - textLine3.Text = "NO KEY BOUND"; - - DisplayTemporarily(box); - - int optionCount = 0; - int selectedOption = -1; - - switch (description.RawValue) - { - case bool val: - optionCount = 1; - if (val) selectedOption = 0; - break; - - case Enum _: - var values = Enum.GetValues(description.RawValue.GetType()); - optionCount = values.Length; - selectedOption = Convert.ToInt32(description.RawValue); - break; - } - - textLine2.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre; - textLine2.Y = optionCount > 0 ? 0 : 5; - - if (optionLights.Children.Count != optionCount) - { - optionLights.Clear(); - for (int i = 0; i < optionCount; i++) - optionLights.Add(new OptionLight()); - } - - for (int i = 0; i < optionCount; i++) - optionLights.Children[i].Glowing = i == selectedOption; - }); + box.Child = toast; + DisplayTemporarily(box); } + private void displayTrackedSettingChange(SettingDescription description) => Schedule(() => Display(new OsdTrackedSettingToast(description))); + private TransformSequence fadeIn; private ScheduledDelegate fadeOut; @@ -236,80 +132,5 @@ namespace osu.Game.Overlays b => b.ResizeHeightTo(height_contracted, 1500, Easing.InQuint)); }, 500); } - - private class OptionLight : Container - { - private Color4 glowingColour, idleColour; - - private const float transition_speed = 300; - - private const float glow_strength = 0.4f; - - private readonly Box fill; - - public OptionLight() - { - Children = new[] - { - fill = new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 1, - }, - }; - } - - private bool glowing; - - public bool Glowing - { - set - { - glowing = value; - if (!IsLoaded) return; - - updateGlow(); - } - } - - private void updateGlow() - { - if (glowing) - { - fill.FadeColour(glowingColour, transition_speed, Easing.OutQuint); - FadeEdgeEffectTo(glow_strength, transition_speed, Easing.OutQuint); - } - else - { - FadeEdgeEffectTo(0, transition_speed, Easing.OutQuint); - fill.FadeColour(idleColour, transition_speed, Easing.OutQuint); - } - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - fill.Colour = idleColour = Color4.White.Opacity(0.4f); - glowingColour = Color4.White; - - Size = new Vector2(25, 5); - - Masking = true; - CornerRadius = 3; - - EdgeEffect = new EdgeEffectParameters - { - Colour = colours.BlueDark.Opacity(glow_strength), - Type = EdgeEffectType.Glow, - Radius = 8, - }; - } - - protected override void LoadComplete() - { - updateGlow(); - FinishTransforms(true); - } - } } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index e872cd1387..950a940fec 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -21,4 +21,7 @@ + + + From 4f0429d046da8d5ca21d43d26c40a1773febdd4b Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:03:46 +0200 Subject: [PATCH 02/14] Add OsdTrackedSettingToast --- .../Overlays/OSD/OsdTrackedSettingToast.cs | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 osu.Game/Overlays/OSD/OsdTrackedSettingToast.cs diff --git a/osu.Game/Overlays/OSD/OsdTrackedSettingToast.cs b/osu.Game/Overlays/OSD/OsdTrackedSettingToast.cs new file mode 100644 index 0000000000..411a33b000 --- /dev/null +++ b/osu.Game/Overlays/OSD/OsdTrackedSettingToast.cs @@ -0,0 +1,180 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Configuration.Tracking; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Effects; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osuTK; +using osuTK.Graphics; +using System; + +namespace osu.Game.Overlays.OSD +{ + public class OsdTrackedSettingToast : OsdToast + { + public OsdTrackedSettingToast(SettingDescription description) + { + SpriteText textLine2; + FillFlowContainer optionLights; + + Children = new Drawable[] + { + new OsuSpriteText + { + Padding = new MarginPadding(10), + Font = OsuFont.GetFont(size: 14, weight: FontWeight.Black), + Spacing = new Vector2(1, 0), + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = description.Name.ToUpperInvariant() + }, + textLine2 = new OsuSpriteText + { + Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light), + Padding = new MarginPadding { Left = 10, Right = 10 }, + Anchor = Anchor.Centre, + Origin = Anchor.BottomCentre, + Text = description.Value + }, + new FillFlowContainer + { + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + optionLights = new FillFlowContainer + { + Padding = new MarginPadding { Top = 20, Bottom = 5 }, + Spacing = new Vector2(5, 0), + Direction = FillDirection.Horizontal, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + AutoSizeAxes = Axes.Both + }, + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Margin = new MarginPadding { Bottom = 15 }, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Alpha = 0.3f, + Text = string.IsNullOrEmpty(description.Shortcut) ? "NO KEY BOUND" : description.Shortcut.ToUpperInvariant() + }, + } + } + }; + + int optionCount = 0; + int selectedOption = -1; + + switch (description.RawValue) + { + case bool val: + optionCount = 1; + if (val) selectedOption = 0; + break; + + case Enum _: + var values = Enum.GetValues(description.RawValue.GetType()); + optionCount = values.Length; + selectedOption = Convert.ToInt32(description.RawValue); + break; + } + + textLine2.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre; + textLine2.Y = optionCount > 0 ? 0 : 5; + + for (int i = 0; i < optionCount; i++) + { + optionLights.Add(new OptionLight + { + Glowing = i == selectedOption + }); + } + } + + private class OptionLight : Container + { + private Color4 glowingColour, idleColour; + + private const float transition_speed = 300; + + private const float glow_strength = 0.4f; + + private readonly Box fill; + + public OptionLight() + { + Children = new[] + { + fill = new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 1, + }, + }; + } + + private bool glowing; + + public bool Glowing + { + set + { + glowing = value; + if (!IsLoaded) return; + + updateGlow(); + } + } + + private void updateGlow() + { + if (glowing) + { + fill.FadeColour(glowingColour, transition_speed, Easing.OutQuint); + FadeEdgeEffectTo(glow_strength, transition_speed, Easing.OutQuint); + } + else + { + FadeEdgeEffectTo(0, transition_speed, Easing.OutQuint); + fill.FadeColour(idleColour, transition_speed, Easing.OutQuint); + } + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + fill.Colour = idleColour = Color4.White.Opacity(0.4f); + glowingColour = Color4.White; + + Size = new Vector2(25, 5); + + Masking = true; + CornerRadius = 3; + + EdgeEffect = new EdgeEffectParameters + { + Colour = colours.BlueDark.Opacity(glow_strength), + Type = EdgeEffectType.Glow, + Radius = 8, + }; + } + + protected override void LoadComplete() + { + updateGlow(); + FinishTransforms(true); + } + } + } +} From bc60b1dc13d2b069518d3b4b4d1698c43aa48ab9 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:04:47 +0200 Subject: [PATCH 03/14] Add test for empty OsdToast --- osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs index d900526c07..b28f794a58 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs @@ -22,6 +22,7 @@ namespace osu.Game.Tests.Visual.UserInterface osd.BeginTracking(this, config); Add(osd); + AddStep("Display empty osd toast", () => osd.Display(new Overlays.OSD.OsdToast())); AddRepeatStep("Change toggle (no bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingNoKeybind), 2); AddRepeatStep("Change toggle (with bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingWithKeybind), 2); AddRepeatStep("Change enum (no bind)", () => config.IncrementEnumSetting(TestConfigSetting.EnumSettingNoKeybind), 3); From df75f9d3124f169e2d7950fd317af11c5b481b1a Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:08:02 +0200 Subject: [PATCH 04/14] Revert changes made by VS to csproj --- osu.Game/osu.Game.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 950a940fec..e872cd1387 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -21,7 +21,4 @@ - - - From 3bc789fca892d8120e9916c6b285d56f64490086 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 15:09:06 +0900 Subject: [PATCH 05/14] Remove osd prefix and prefer upper-case OSD --- .../Visual/UserInterface/TestSceneOnScreenDisplay.cs | 3 ++- osu.Game/Overlays/OSD/{OsdToast.cs => Toast.cs} | 6 +++--- .../{OsdTrackedSettingToast.cs => TrackedSettingToast.cs} | 6 +++--- osu.Game/Overlays/OnScreenDisplay.cs | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) rename osu.Game/Overlays/OSD/{OsdToast.cs => Toast.cs} (94%) rename osu.Game/Overlays/OSD/{OsdTrackedSettingToast.cs => TrackedSettingToast.cs} (98%) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs index b28f794a58..59a35591bd 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs @@ -7,6 +7,7 @@ using osu.Framework.Configuration; using osu.Framework.Configuration.Tracking; using osu.Framework.Graphics; using osu.Game.Overlays; +using osu.Game.Overlays.OSD; namespace osu.Game.Tests.Visual.UserInterface { @@ -22,7 +23,7 @@ namespace osu.Game.Tests.Visual.UserInterface osd.BeginTracking(this, config); Add(osd); - AddStep("Display empty osd toast", () => osd.Display(new Overlays.OSD.OsdToast())); + AddStep("Display empty osd toast", () => osd.Display(new Toast())); AddRepeatStep("Change toggle (no bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingNoKeybind), 2); AddRepeatStep("Change toggle (with bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingWithKeybind), 2); AddRepeatStep("Change enum (no bind)", () => config.IncrementEnumSetting(TestConfigSetting.EnumSettingNoKeybind), 3); diff --git a/osu.Game/Overlays/OSD/OsdToast.cs b/osu.Game/Overlays/OSD/Toast.cs similarity index 94% rename from osu.Game/Overlays/OSD/OsdToast.cs rename to osu.Game/Overlays/OSD/Toast.cs index f700577ba1..6634959bca 100644 --- a/osu.Game/Overlays/OSD/OsdToast.cs +++ b/osu.Game/Overlays/OSD/Toast.cs @@ -1,19 +1,19 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osuTK.Graphics; namespace osu.Game.Overlays.OSD { - public class OsdToast : Container + public class Toast : Container { private readonly Container content; protected override Container Content => content; - public OsdToast() + public Toast() { Anchor = Anchor.Centre; Origin = Anchor.Centre; diff --git a/osu.Game/Overlays/OSD/OsdTrackedSettingToast.cs b/osu.Game/Overlays/OSD/TrackedSettingToast.cs similarity index 98% rename from osu.Game/Overlays/OSD/OsdTrackedSettingToast.cs rename to osu.Game/Overlays/OSD/TrackedSettingToast.cs index 411a33b000..8def8476f0 100644 --- a/osu.Game/Overlays/OSD/OsdTrackedSettingToast.cs +++ b/osu.Game/Overlays/OSD/TrackedSettingToast.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Configuration.Tracking; using osu.Framework.Extensions.Color4Extensions; @@ -13,13 +14,12 @@ using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osuTK; using osuTK.Graphics; -using System; namespace osu.Game.Overlays.OSD { - public class OsdTrackedSettingToast : OsdToast + public class TrackedSettingToast : Toast { - public OsdTrackedSettingToast(SettingDescription description) + public TrackedSettingToast(SettingDescription description) { SpriteText textLine2; FillFlowContainer optionLights; diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index 0577257080..a30ce5c56f 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -97,16 +97,16 @@ namespace osu.Game.Overlays } /// - /// Displays the given as parameter on the OSD + /// Displays the given as parameter on the OSD /// /// - public void Display(OsdToast toast) + public void Display(Toast toast) { box.Child = toast; DisplayTemporarily(box); } - private void displayTrackedSettingChange(SettingDescription description) => Schedule(() => Display(new OsdTrackedSettingToast(description))); + private void displayTrackedSettingChange(SettingDescription description) => Schedule(() => Display(new TrackedSettingToast(description))); private TransformSequence fadeIn; private ScheduledDelegate fadeOut; From dd13e2508ae854c483b60afcfa8aadd994393bc5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 15:14:57 +0900 Subject: [PATCH 06/14] Add note about toast height --- osu.Game/Overlays/OSD/Toast.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Overlays/OSD/Toast.cs b/osu.Game/Overlays/OSD/Toast.cs index 6634959bca..3ca010c5f4 100644 --- a/osu.Game/Overlays/OSD/Toast.cs +++ b/osu.Game/Overlays/OSD/Toast.cs @@ -18,6 +18,8 @@ namespace osu.Game.Overlays.OSD Anchor = Anchor.Centre; Origin = Anchor.Centre; Width = 240; + + // A toast's height is decided (and transformed) by the containing OnScreenDisplay. RelativeSizeAxes = Axes.Y; InternalChildren = new Drawable[] From 2c62891c4836ceb5b24957331dd6aa615ca8f85e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 15:15:34 +0900 Subject: [PATCH 07/14] Make Toast base class abstract --- .../Visual/UserInterface/TestSceneOnScreenDisplay.cs | 6 +++++- osu.Game/Overlays/OSD/Toast.cs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs index 59a35591bd..ca14822205 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs @@ -23,7 +23,7 @@ namespace osu.Game.Tests.Visual.UserInterface osd.BeginTracking(this, config); Add(osd); - AddStep("Display empty osd toast", () => osd.Display(new Toast())); + AddStep("Display empty osd toast", () => osd.Display(new EmptyToast())); AddRepeatStep("Change toggle (no bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingNoKeybind), 2); AddRepeatStep("Change toggle (with bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingWithKeybind), 2); AddRepeatStep("Change enum (no bind)", () => config.IncrementEnumSetting(TestConfigSetting.EnumSettingNoKeybind), 3); @@ -88,6 +88,10 @@ namespace osu.Game.Tests.Visual.UserInterface Setting4 } + private class EmptyToast : Toast + { + } + private class TestOnScreenDisplay : OnScreenDisplay { protected override void DisplayTemporarily(Drawable toDisplay) => toDisplay.FadeIn().ResizeHeightTo(110); diff --git a/osu.Game/Overlays/OSD/Toast.cs b/osu.Game/Overlays/OSD/Toast.cs index 3ca010c5f4..c6e3227cd1 100644 --- a/osu.Game/Overlays/OSD/Toast.cs +++ b/osu.Game/Overlays/OSD/Toast.cs @@ -8,12 +8,12 @@ using osuTK.Graphics; namespace osu.Game.Overlays.OSD { - public class Toast : Container + public abstract class Toast : Container { private readonly Container content; protected override Container Content => content; - public Toast() + protected Toast() { Anchor = Anchor.Centre; Origin = Anchor.Centre; From 09d679de8d6367ec6894e470318d3cda625d5fd3 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 12 Jul 2019 08:50:53 +0200 Subject: [PATCH 08/14] Move text display layout to Toast. --- .../UserInterface/TestSceneOnScreenDisplay.cs | 4 ++ osu.Game/Overlays/OSD/Toast.cs | 35 +++++++++++++++- osu.Game/Overlays/OSD/TrackedSettingToast.cs | 41 +++---------------- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs index ca14822205..4decfc7dd6 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs @@ -90,6 +90,10 @@ namespace osu.Game.Tests.Visual.UserInterface private class EmptyToast : Toast { + public EmptyToast() + : base("", "", "") + { + } } private class TestOnScreenDisplay : OnScreenDisplay diff --git a/osu.Game/Overlays/OSD/Toast.cs b/osu.Game/Overlays/OSD/Toast.cs index c6e3227cd1..6572830d10 100644 --- a/osu.Game/Overlays/OSD/Toast.cs +++ b/osu.Game/Overlays/OSD/Toast.cs @@ -4,6 +4,9 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osuTK; using osuTK.Graphics; namespace osu.Game.Overlays.OSD @@ -13,7 +16,7 @@ namespace osu.Game.Overlays.OSD private readonly Container content; protected override Container Content => content; - protected Toast() + protected Toast(string description, string value, string keybinding) { Anchor = Anchor.Centre; Origin = Anchor.Centre; @@ -35,7 +38,35 @@ namespace osu.Game.Overlays.OSD Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.Both, - } + }, + new OsuSpriteText + { + Padding = new MarginPadding(10), + Name = "Description", + Font = OsuFont.GetFont(size: 14, weight: FontWeight.Black), + Spacing = new Vector2(1, 0), + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = description.ToUpperInvariant() + }, + new OsuSpriteText + { + Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light), + Padding = new MarginPadding { Left = 10, Right = 10 }, + Name = "Value", + Anchor = Anchor.Centre, + Origin = Anchor.BottomCentre, + Text = value + }, + new OsuSpriteText + { + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + Name = "Shortcut", + Margin = new MarginPadding { Bottom = 15 }, + Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), + Text = string.IsNullOrEmpty(keybinding) ? "NO KEY BOUND" : keybinding.ToUpperInvariant() + }, }; } } diff --git a/osu.Game/Overlays/OSD/TrackedSettingToast.cs b/osu.Game/Overlays/OSD/TrackedSettingToast.cs index 8def8476f0..454ba84d70 100644 --- a/osu.Game/Overlays/OSD/TrackedSettingToast.cs +++ b/osu.Game/Overlays/OSD/TrackedSettingToast.cs @@ -9,9 +9,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; using osuTK; using osuTK.Graphics; @@ -20,55 +18,29 @@ namespace osu.Game.Overlays.OSD public class TrackedSettingToast : Toast { public TrackedSettingToast(SettingDescription description) + : base(description.Name, description.Value, description.Shortcut) { - SpriteText textLine2; FillFlowContainer optionLights; Children = new Drawable[] { - new OsuSpriteText - { - Padding = new MarginPadding(10), - Font = OsuFont.GetFont(size: 14, weight: FontWeight.Black), - Spacing = new Vector2(1, 0), - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Text = description.Name.ToUpperInvariant() - }, - textLine2 = new OsuSpriteText - { - Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light), - Padding = new MarginPadding { Left = 10, Right = 10 }, - Anchor = Anchor.Centre, - Origin = Anchor.BottomCentre, - Text = description.Value - }, new FillFlowContainer { - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre, - AutoSizeAxes = Axes.Both, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, Direction = FillDirection.Vertical, + Margin = new MarginPadding { Top = 70 }, Children = new Drawable[] { optionLights = new FillFlowContainer { - Padding = new MarginPadding { Top = 20, Bottom = 5 }, + Padding = new MarginPadding { Bottom = 5 }, Spacing = new Vector2(5, 0), Direction = FillDirection.Horizontal, Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, AutoSizeAxes = Axes.Both }, - new OsuSpriteText - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Margin = new MarginPadding { Bottom = 15 }, - Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), - Alpha = 0.3f, - Text = string.IsNullOrEmpty(description.Shortcut) ? "NO KEY BOUND" : description.Shortcut.ToUpperInvariant() - }, } } }; @@ -90,9 +62,6 @@ namespace osu.Game.Overlays.OSD break; } - textLine2.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre; - textLine2.Y = optionCount > 0 ? 0 : 5; - for (int i = 0; i < optionCount; i++) { optionLights.Add(new OptionLight From bbc3cbf5632fbe5fd8adffd0c9c29db639d4b7dc Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 12 Jul 2019 20:22:31 +0200 Subject: [PATCH 09/14] Restore deleted line --- osu.Game/Overlays/OSD/Toast.cs | 6 ++++-- osu.Game/Overlays/OSD/TrackedSettingToast.cs | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/OSD/Toast.cs b/osu.Game/Overlays/OSD/Toast.cs index 6572830d10..67c9b46c77 100644 --- a/osu.Game/Overlays/OSD/Toast.cs +++ b/osu.Game/Overlays/OSD/Toast.cs @@ -16,6 +16,8 @@ namespace osu.Game.Overlays.OSD private readonly Container content; protected override Container Content => content; + protected readonly OsuSpriteText ValueText; + protected Toast(string description, string value, string keybinding) { Anchor = Anchor.Centre; @@ -49,13 +51,13 @@ namespace osu.Game.Overlays.OSD Origin = Anchor.TopCentre, Text = description.ToUpperInvariant() }, - new OsuSpriteText + ValueText = new OsuSpriteText { Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light), Padding = new MarginPadding { Left = 10, Right = 10 }, Name = "Value", Anchor = Anchor.Centre, - Origin = Anchor.BottomCentre, + Origin = Anchor.Centre, Text = value }, new OsuSpriteText diff --git a/osu.Game/Overlays/OSD/TrackedSettingToast.cs b/osu.Game/Overlays/OSD/TrackedSettingToast.cs index 454ba84d70..9812dcd797 100644 --- a/osu.Game/Overlays/OSD/TrackedSettingToast.cs +++ b/osu.Game/Overlays/OSD/TrackedSettingToast.cs @@ -62,6 +62,8 @@ namespace osu.Game.Overlays.OSD break; } + ValueText.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre; + for (int i = 0; i < optionCount; i++) { optionLights.Add(new OptionLight From fc4c0cc2e72d9108881cba86f1854110ee17549e Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 10 Aug 2019 10:52:37 +0200 Subject: [PATCH 10/14] Fix visual discrepancies with master --- osu.Game/Overlays/OSD/Toast.cs | 1 + osu.Game/Overlays/OSD/TrackedSettingToast.cs | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/OSD/Toast.cs b/osu.Game/Overlays/OSD/Toast.cs index 67c9b46c77..db5e6e4a6a 100644 --- a/osu.Game/Overlays/OSD/Toast.cs +++ b/osu.Game/Overlays/OSD/Toast.cs @@ -65,6 +65,7 @@ namespace osu.Game.Overlays.OSD Anchor = Anchor.BottomCentre, Origin = Anchor.BottomCentre, Name = "Shortcut", + Alpha = 0.3f, Margin = new MarginPadding { Bottom = 15 }, Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), Text = string.IsNullOrEmpty(keybinding) ? "NO KEY BOUND" : keybinding.ToUpperInvariant() diff --git a/osu.Game/Overlays/OSD/TrackedSettingToast.cs b/osu.Game/Overlays/OSD/TrackedSettingToast.cs index 9812dcd797..0f4bd34779 100644 --- a/osu.Game/Overlays/OSD/TrackedSettingToast.cs +++ b/osu.Game/Overlays/OSD/TrackedSettingToast.cs @@ -17,6 +17,8 @@ namespace osu.Game.Overlays.OSD { public class TrackedSettingToast : Toast { + private const int lights_bottom_margin = 40; + public TrackedSettingToast(SettingDescription description) : base(description.Name, description.Value, description.Shortcut) { @@ -24,17 +26,16 @@ namespace osu.Game.Overlays.OSD Children = new Drawable[] { - new FillFlowContainer + new Container { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Direction = FillDirection.Vertical, - Margin = new MarginPadding { Top = 70 }, + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + Margin = new MarginPadding { Bottom = lights_bottom_margin }, Children = new Drawable[] { optionLights = new FillFlowContainer { - Padding = new MarginPadding { Bottom = 5 }, + Margin = new MarginPadding { Bottom = 5 }, Spacing = new Vector2(5, 0), Direction = FillDirection.Horizontal, Anchor = Anchor.TopCentre, From 9c15024014d9e196e97a9dee1e817c30993080af Mon Sep 17 00:00:00 2001 From: Lucas A Date: Mon, 12 Aug 2019 10:53:06 +0200 Subject: [PATCH 11/14] Reword and add missing xmldoc to OnScreenDisplay --- osu.Game/Overlays/OnScreenDisplay.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index a30ce5c56f..a92320945e 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -16,6 +16,10 @@ using osu.Game.Overlays.OSD; namespace osu.Game.Overlays { + /// + /// An on-screen display which automatically tracks and displays toast notifications for . + /// Can also display custom content via + /// public class OnScreenDisplay : Container { private readonly Container box; @@ -97,7 +101,7 @@ namespace osu.Game.Overlays } /// - /// Displays the given as parameter on the OSD + /// Displays the provided temporarily. /// /// public void Display(Toast toast) From 6533f114d42762d30e98a06770033fdfae247b8b Mon Sep 17 00:00:00 2001 From: Lucas A Date: Mon, 12 Aug 2019 12:09:09 +0200 Subject: [PATCH 12/14] Apply review suggestions --- .../UserInterface/TestSceneOnScreenDisplay.cs | 14 ++++++++++++++ osu.Game/Overlays/OSD/Toast.cs | 14 +++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs index 4decfc7dd6..558c027e1d 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs @@ -24,6 +24,11 @@ namespace osu.Game.Tests.Visual.UserInterface Add(osd); AddStep("Display empty osd toast", () => osd.Display(new EmptyToast())); + AddAssert("Toast width is 240", () => osd.Child.Width == 240); + + AddStep("Display toast with lengthy text", () => osd.Display(new LengthyToast())); + AddAssert("Toast width is greater than 240", () => osd.Child.Width > 240); + AddRepeatStep("Change toggle (no bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingNoKeybind), 2); AddRepeatStep("Change toggle (with bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingWithKeybind), 2); AddRepeatStep("Change enum (no bind)", () => config.IncrementEnumSetting(TestConfigSetting.EnumSettingNoKeybind), 3); @@ -96,6 +101,15 @@ namespace osu.Game.Tests.Visual.UserInterface } } + private class LengthyToast : Toast + { + public LengthyToast() + : base("Toast with a very very very long text", "A very very very very very very long text also", "A very very very very very long shortcut") + { + + } + } + private class TestOnScreenDisplay : OnScreenDisplay { protected override void DisplayTemporarily(Drawable toDisplay) => toDisplay.FadeIn().ResizeHeightTo(110); diff --git a/osu.Game/Overlays/OSD/Toast.cs b/osu.Game/Overlays/OSD/Toast.cs index db5e6e4a6a..46c53ec409 100644 --- a/osu.Game/Overlays/OSD/Toast.cs +++ b/osu.Game/Overlays/OSD/Toast.cs @@ -13,22 +13,30 @@ namespace osu.Game.Overlays.OSD { public abstract class Toast : Container { + private const int toast_minimum_width = 240; + private readonly Container content; protected override Container Content => content; protected readonly OsuSpriteText ValueText; - protected Toast(string description, string value, string keybinding) + protected Toast(string description, string value, string shortcut) { Anchor = Anchor.Centre; Origin = Anchor.Centre; - Width = 240; // A toast's height is decided (and transformed) by the containing OnScreenDisplay. RelativeSizeAxes = Axes.Y; + AutoSizeAxes = Axes.X; InternalChildren = new Drawable[] { + new Container //this container exists just to set a minimum width for the toast + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Width = toast_minimum_width + }, new Box { RelativeSizeAxes = Axes.Both, @@ -68,7 +76,7 @@ namespace osu.Game.Overlays.OSD Alpha = 0.3f, Margin = new MarginPadding { Bottom = 15 }, Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), - Text = string.IsNullOrEmpty(keybinding) ? "NO KEY BOUND" : keybinding.ToUpperInvariant() + Text = string.IsNullOrEmpty(shortcut) ? "NO KEY BOUND" : shortcut.ToUpperInvariant() }, }; } From 5e49d0fb28e704a5c53f34ce1358a20173269cdb Mon Sep 17 00:00:00 2001 From: Lucas A Date: Mon, 12 Aug 2019 12:11:01 +0200 Subject: [PATCH 13/14] Fix CI issues --- osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs index 558c027e1d..45720548c8 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs @@ -106,7 +106,6 @@ namespace osu.Game.Tests.Visual.UserInterface public LengthyToast() : base("Toast with a very very very long text", "A very very very very very very long text also", "A very very very very very long shortcut") { - } } From 5447e7cf222ea170409d18e0a8261185b090119a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 13 Aug 2019 11:34:45 +0900 Subject: [PATCH 14/14] Fix file ordering --- osu.Game/Overlays/OSD/TrackedSettingToast.cs | 35 +++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/osu.Game/Overlays/OSD/TrackedSettingToast.cs b/osu.Game/Overlays/OSD/TrackedSettingToast.cs index 0f4bd34779..8e8a99a0a7 100644 --- a/osu.Game/Overlays/OSD/TrackedSettingToast.cs +++ b/osu.Game/Overlays/OSD/TrackedSettingToast.cs @@ -66,12 +66,7 @@ namespace osu.Game.Overlays.OSD ValueText.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre; for (int i = 0; i < optionCount; i++) - { - optionLights.Add(new OptionLight - { - Glowing = i == selectedOption - }); - } + optionLights.Add(new OptionLight { Glowing = i == selectedOption }); } private class OptionLight : Container @@ -109,20 +104,6 @@ namespace osu.Game.Overlays.OSD } } - private void updateGlow() - { - if (glowing) - { - fill.FadeColour(glowingColour, transition_speed, Easing.OutQuint); - FadeEdgeEffectTo(glow_strength, transition_speed, Easing.OutQuint); - } - else - { - FadeEdgeEffectTo(0, transition_speed, Easing.OutQuint); - fill.FadeColour(idleColour, transition_speed, Easing.OutQuint); - } - } - [BackgroundDependencyLoader] private void load(OsuColour colours) { @@ -147,6 +128,20 @@ namespace osu.Game.Overlays.OSD updateGlow(); FinishTransforms(true); } + + private void updateGlow() + { + if (glowing) + { + fill.FadeColour(glowingColour, transition_speed, Easing.OutQuint); + FadeEdgeEffectTo(glow_strength, transition_speed, Easing.OutQuint); + } + else + { + FadeEdgeEffectTo(0, transition_speed, Easing.OutQuint); + fill.FadeColour(idleColour, transition_speed, Easing.OutQuint); + } + } } } }