From 212b2c114206628c5030ff214bace924ad30a5bc Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Thu, 1 Jun 2017 04:45:46 -0300 Subject: [PATCH 01/18] Initial layout and animation --- osu-resources | 2 +- .../Tests/TestCaseMedalOverlay.cs | 28 +++ .../osu.Desktop.VisualTests.csproj | 1 + osu.Game/Overlays/MedalOverlay.cs | 212 ++++++++++++++++++ .../Overlays/MedalSplash/DrawableMedal.cs | 147 ++++++++++++ osu.Game/Users/Medal.cs | 11 + osu.Game/osu.Game.csproj | 3 + 7 files changed, 403 insertions(+), 1 deletion(-) create mode 100644 osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs create mode 100644 osu.Game/Overlays/MedalOverlay.cs create mode 100644 osu.Game/Overlays/MedalSplash/DrawableMedal.cs create mode 100644 osu.Game/Users/Medal.cs diff --git a/osu-resources b/osu-resources index 9f46a456dc..37e9e96d01 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 9f46a456dc3a56dcbff09671a3f588b16a464106 +Subproject commit 37e9e96d011ba7faeb4a302e65fb7bdb4dc16690 diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs new file mode 100644 index 0000000000..581675e66a --- /dev/null +++ b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs @@ -0,0 +1,28 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Testing; +using osu.Game.Overlays; +using osu.Game.Users; + +namespace osu.Desktop.VisualTests.Tests +{ + internal class TestCaseMedalOverlay : TestCase + { + public override string Description => @"medal get!"; + + public override void Reset() + { + base.Reset(); + + MedalOverlay overlay; + Add(overlay = new MedalOverlay(new Medal + { + Name = @"Animations", + Description = @"More complex than you think.", + })); + + AddStep(@"show", overlay.Show); + } + } +} diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index 5a532d7234..52e429efd8 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -224,6 +224,7 @@ + diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs new file mode 100644 index 0000000000..2d2a32fa4f --- /dev/null +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -0,0 +1,212 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Colour; +using osu.Framework.Graphics.Sprites; +using osu.Game.Users; +using osu.Game.Graphics; +using osu.Game.Graphics.Backgrounds; +using osu.Game.Overlays.MedalSplash; +using osu.Framework.Allocation; +using osu.Framework.Audio.Sample; +using osu.Framework.Audio; +using osu.Framework.Graphics.Textures; +using osu.Framework.Graphics.Transforms; +using osu.Framework.Input; +using OpenTK.Input; + +namespace osu.Game.Overlays +{ + public class MedalOverlay : FocusedOverlayContainer + { + public const float DISC_SIZE = 400; + + private const float border_width = 5; + + private readonly Box background; + private readonly FillFlowContainer backgroundStrip; + private readonly BackgroundStrip leftStrip, rightStrip; + private readonly CircularContainer disc; + private readonly Sprite innerSpin, outterSpin; + private readonly DrawableMedal drawableMedal; + + private SampleChannel getSample; + + protected override bool BlockPassThroughKeyboard => true; + + public MedalOverlay(Medal medal) + { + RelativeSizeAxes = Axes.Both; + Alpha = 0f; + + Children = new Drawable[] + { + background = new Box + { + Name = @"dim", + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black.Opacity(60), + }, + outterSpin = new Sprite + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(DISC_SIZE + 500), + Alpha = 0f, + }, + backgroundStrip = new FillFlowContainer + { + Name = @"background strip", + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Width = 0f, + Height = border_width, + Alpha = 0f, + Direction = FillDirection.Horizontal, + Children = new[] + { + leftStrip = new BackgroundStrip(0f, 1f), + rightStrip = new BackgroundStrip(1f, 0f), + }, + }, + disc = new CircularContainer + { + Name = @"content", + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Alpha = 0f, + Masking = true, + BorderColour = Color4.White, + BorderThickness = border_width, + Size = new Vector2(DISC_SIZE), + Scale = new Vector2(0.8f), + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = OsuColour.FromHex(@"05262f"), + }, + new Triangles + { + RelativeSizeAxes = Axes.Both, + TriangleScale = 2, + ColourDark = OsuColour.FromHex(@"04222b"), + ColourLight = OsuColour.FromHex(@"052933"), + }, + innerSpin = new Sprite + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Size = new Vector2(1.05f), + Alpha = 0.25f, + }, + drawableMedal = new DrawableMedal(medal) + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + }, + }, + }, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours, TextureStore textures, AudioManager audio) + { + getSample = audio.Sample.Get(@"MedalSplash/medal-get"); + innerSpin.Texture = outterSpin.Texture = textures.Get(@"MedalSplash/disc-spin"); + + disc.EdgeEffect = leftStrip.EdgeEffect = rightStrip.EdgeEffect = new EdgeEffect + { + Type = EdgeEffectType.Glow, + Colour = colours.Blue.Opacity(0.5f), + Radius = 50, + }; + } + + protected override void PopIn() + { + base.PopIn(); + + FadeIn(200); + background.FlashColour(Color4.White.Opacity(0.25f), 400); + + double duration1 = 400; + double duration2 = 900; + double duration3 = 900; + double duration4 = 1000; + + getSample.Play(); + Delay(200, true); + + innerSpin.Transforms.Add(new TransformRotation + { + StartValue = 0, + EndValue = 359, + StartTime = Clock.TimeInfo.Current, + EndTime = Clock.TimeInfo.Current + 20000, + LoopCount = -1, + }); + + outterSpin.Transforms.Add(new TransformRotation + { + StartValue = 0, + EndValue = 359, + StartTime = Clock.TimeInfo.Current, + EndTime = Clock.TimeInfo.Current + 40000, + LoopCount = -1, + }); + + disc.FadeIn(duration1); + backgroundStrip.FadeIn(duration1); + backgroundStrip.ResizeWidthTo(1f, duration1 * 2, EasingTypes.OutQuint); + outterSpin.FadeTo(0.1f, duration1 * 2); + disc.ScaleTo(1f, duration1 * 2, EasingTypes.OutElastic); + + Delay(duration1 + 200, true); + drawableMedal.ChangeState(DrawableMedal.DisplayState.Icon, duration2); + + Delay(duration2, true); + drawableMedal.ChangeState(DrawableMedal.DisplayState.MedalUnlocked, duration3); + + Delay(duration3, true); + drawableMedal.ChangeState(DrawableMedal.DisplayState.Full, duration4); + } + + protected override void PopOut() + { + base.PopOut(); + + FadeOut(200); + } + + private class BackgroundStrip : Container + { + public BackgroundStrip(float start, float end) + { + RelativeSizeAxes = Axes.Both; + Width = 0.5f; + ColourInfo = ColourInfo.GradientHorizontal(Color4.White.Opacity(start), Color4.White.Opacity(end)); + Masking = true; + + Children = new[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.White, + } + }; + } + } + } +} diff --git a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs new file mode 100644 index 0000000000..c85adc4f2a --- /dev/null +++ b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs @@ -0,0 +1,147 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using OpenTK; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Game.Graphics; +using osu.Game.Graphics.Backgrounds; +using osu.Game.Graphics.Sprites; +using osu.Game.Users; + +namespace osu.Game.Overlays.MedalSplash +{ + public class DrawableMedal : Container + { + private const float scale_when_unlocked = 0.76f; + private const float scale_when_full = 0.6f; + + private readonly Container medal; + private readonly Sprite medalGlow; + private readonly OsuSpriteText unlocked, name; + private readonly Paragraph description; + private readonly FillFlowContainer infoFlow; + private readonly IEnumerable descriptionSprites; + + public DrawableMedal(Medal medal) + { + Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2); + + Children = new Drawable[] + { + this.medal = new Container + { + Anchor = Anchor.TopCentre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, + Alpha = 0f, + Children = new[] + { + medalGlow = new Sprite + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }, + }, + }, + unlocked = new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = "Medal Unlocked".ToUpper(), + TextSize = 24, + Font = @"Exo2.0-Light", + Alpha = 0f, + Scale = new Vector2(1 / scale_when_unlocked), + }, + infoFlow = new FillFlowContainer + { + Anchor = Anchor.TopCentre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Width = 0.6f, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0f, 5f), + Children = new Drawable[] + { + name = new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = medal.Name, + TextSize = 20, + Font = @"Exo2.0-Bold", + Alpha = 0f, + Scale = new Vector2(1 / scale_when_full), + }, + description = new Paragraph + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Alpha = 0f, + Scale = new Vector2(1 / scale_when_full), + }, + }, + }, + }; + + descriptionSprites = description.AddText(medal.Description, s => + { + s.Anchor = Anchor.TopCentre; + s.Origin = Anchor.TopCentre; + s.TextSize = 16; + }); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours, TextureStore textures) + { + medalGlow.Texture = textures.Get(@"MedalSplash/medal-glow"); + + foreach (var s in descriptionSprites) + s.Colour = colours.BlueLight; + + var pos = new Vector2(0f, medal.Size.Y / 2 + 10); + unlocked.Position = pos; + pos.Y += 90; + infoFlow.Position = pos; + } + + public void ChangeState(DisplayState newState, double duration) + { + switch (newState) + { + case DisplayState.Icon: + medal.Scale = Vector2.Zero; + medal.ScaleTo(1, duration, EasingTypes.OutElastic); + medal.FadeInFromZero(duration); + break; + case DisplayState.MedalUnlocked: + ScaleTo(scale_when_unlocked, duration, EasingTypes.OutExpo); + MoveToY(MedalOverlay.DISC_SIZE / 2 - 30, duration, EasingTypes.OutExpo); + unlocked.FadeInFromZero(duration); + break; + case DisplayState.Full: + ScaleTo(scale_when_full, duration, EasingTypes.OutExpo); + MoveToY(MedalOverlay.DISC_SIZE / 2 - 60, duration, EasingTypes.OutExpo); + name.FadeInFromZero(duration); + description.FadeInFromZero(duration * 2); + break; + } + } + + public enum DisplayState + { + Icon, + MedalUnlocked, + Full, + } + } +} diff --git a/osu.Game/Users/Medal.cs b/osu.Game/Users/Medal.cs new file mode 100644 index 0000000000..5ac6eceddc --- /dev/null +++ b/osu.Game/Users/Medal.cs @@ -0,0 +1,11 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Users +{ + public class Medal + { + public string Name { get; set; } + public string Description { get; set; } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 0ec0624978..93d0652aa9 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -452,6 +452,9 @@ + + + From 15cd4f77b2eb40506f985860d18c5084e2f74efd Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Fri, 23 Jun 2017 22:35:06 -0300 Subject: [PATCH 02/18] Proper dismissing. --- osu.Game/Overlays/MedalOverlay.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 2d2a32fa4f..a796da82b9 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -19,6 +19,7 @@ using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Transforms; using osu.Framework.Input; using OpenTK.Input; +using System.Linq; namespace osu.Game.Overlays { @@ -37,7 +38,16 @@ namespace osu.Game.Overlays private SampleChannel getSample; - protected override bool BlockPassThroughKeyboard => true; + protected override bool OnClick(InputState state) + { + dismiss(); + return true; + } + + protected override void OnFocusLost(InputState state) + { + if (state.Keyboard.Keys.Contains(Key.Escape)) dismiss(); + } public MedalOverlay(Medal medal) { @@ -189,6 +199,12 @@ namespace osu.Game.Overlays FadeOut(200); } + private void dismiss() + { + if (drawableMedal.Transforms.Count != 0) return; + Hide(); + } + private class BackgroundStrip : Container { public BackgroundStrip(float start, float end) From 3c97f0482655b2cb049ee5447c04db1e0618630a Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Fri, 23 Jun 2017 23:18:44 -0300 Subject: [PATCH 03/18] Particles. --- osu.Game/Overlays/MedalOverlay.cs | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index a40d9bffda..6cb7e7662b 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -21,6 +21,8 @@ using osu.Framework.Input; using OpenTK.Input; using System.Linq; using osu.Framework.Graphics.Shapes; +using System; +using osu.Framework.MathUtils; namespace osu.Game.Overlays { @@ -144,6 +146,13 @@ namespace osu.Game.Overlays }; } + protected override void Update() + { + base.Update(); + + Add(new MedalParticle(RNG.Next(0, 359))); + } + protected override void PopIn() { base.PopIn(); @@ -225,5 +234,36 @@ namespace osu.Game.Overlays }; } } + + private class MedalParticle : CircularContainer + { + private readonly float direction; + + private Vector2 positionForOffset(float offset) => new Vector2((float)(offset * Math.Sin(direction)), (float)(offset * Math.Cos(direction))); + + public MedalParticle(float direction) + { + this.direction = direction; + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + Position = positionForOffset(DISC_SIZE / 2); + Masking = true; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + EdgeEffect = new EdgeEffectParameters + { + Type = EdgeEffectType.Glow, + Colour = colours.Blue.Opacity(0.5f), + Radius = 5, + }; + + MoveTo(positionForOffset(DISC_SIZE / 2 + 200), 500); + FadeOut(500); + Expire(); + } + } } } From c71f34c50796eea717378dede6cb101dd31f6e4a Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Fri, 23 Jun 2017 23:51:28 -0300 Subject: [PATCH 04/18] Make the background strip expand from the disc edges. --- osu.Game/Overlays/MedalOverlay.cs | 43 ++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 6cb7e7662b..ecd9a0af2f 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -33,7 +33,7 @@ namespace osu.Game.Overlays private const float border_width = 5; private readonly Box background; - private readonly FillFlowContainer backgroundStrip; + private readonly Container backgroundStrip; private readonly BackgroundStrip leftStrip, rightStrip; private readonly CircularContainer disc; private readonly Sprite innerSpin, outterSpin; @@ -72,20 +72,44 @@ namespace osu.Game.Overlays Size = new Vector2(DISC_SIZE + 500), Alpha = 0f, }, - backgroundStrip = new FillFlowContainer + backgroundStrip = new Container { Name = @"background strip", Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.X, - Width = 0f, Height = border_width, Alpha = 0f, - Direction = FillDirection.Horizontal, Children = new[] { - leftStrip = new BackgroundStrip(0f, 1f), - rightStrip = new BackgroundStrip(1f, 0f), + new Container + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.CentreRight, + Width = 0.5f, + Padding = new MarginPadding { Right = DISC_SIZE / 2 }, + Children = new[] + { + leftStrip = new BackgroundStrip(0f, 1f) + { + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + }, + }, + }, + new Container + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.CentreLeft, + Width = 0.5f, + Padding = new MarginPadding { Left = DISC_SIZE / 2 }, + Children = new[] + { + rightStrip = new BackgroundStrip(1f, 0f), + }, + }, }, }, disc = new CircularContainer @@ -187,12 +211,13 @@ namespace osu.Game.Overlays }); disc.FadeIn(duration1); - backgroundStrip.FadeIn(duration1); - backgroundStrip.ResizeWidthTo(1f, duration1 * 2, EasingTypes.OutQuint); outterSpin.FadeTo(0.1f, duration1 * 2); disc.ScaleTo(1f, duration1 * 2, EasingTypes.OutElastic); Delay(duration1 + 200, true); + backgroundStrip.FadeIn(duration2); + leftStrip.ResizeWidthTo(1f, duration2, EasingTypes.OutQuint); + rightStrip.ResizeWidthTo(1f, duration2, EasingTypes.OutQuint); drawableMedal.ChangeState(DrawableMedal.DisplayState.Icon, duration2); Delay(duration2, true); @@ -220,7 +245,7 @@ namespace osu.Game.Overlays public BackgroundStrip(float start, float end) { RelativeSizeAxes = Axes.Both; - Width = 0.5f; + Width = 0f; ColourInfo = ColourInfo.GradientHorizontal(Color4.White.Opacity(start), Color4.White.Opacity(end)); Masking = true; From 0133f9c0869d4ff7123d049a1c1623f9a2c0acee Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Sat, 24 Jun 2017 01:19:44 -0300 Subject: [PATCH 05/18] Medal sprite, make MedalOverlay auto-show when loaded. --- .../Tests/TestCaseMedalOverlay.cs | 6 ++--- osu.Game/Overlays/MedalOverlay.cs | 2 ++ .../Overlays/MedalSplash/DrawableMedal.cs | 23 +++++++++++++------ osu.Game/Users/Medal.cs | 2 ++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs index 581675e66a..ac983277a4 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs @@ -15,14 +15,12 @@ namespace osu.Desktop.VisualTests.Tests { base.Reset(); - MedalOverlay overlay; - Add(overlay = new MedalOverlay(new Medal + Add(new MedalOverlay(new Medal { Name = @"Animations", + InternalName = @"all-intro-doubletime", Description = @"More complex than you think.", })); - - AddStep(@"show", overlay.Show); } } } diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index ecd9a0af2f..d9c949a0da 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -168,6 +168,8 @@ namespace osu.Game.Overlays Colour = colours.Blue.Opacity(0.5f), Radius = 50, }; + + Show(); } protected override void Update() diff --git a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs index ba2e3964a4..e230b9de9b 100644 --- a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs +++ b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs @@ -19,8 +19,9 @@ namespace osu.Game.Overlays.MedalSplash private const float scale_when_unlocked = 0.76f; private const float scale_when_full = 0.6f; - private readonly Container medal; - private readonly Sprite medalGlow; + private readonly Medal medal; + private readonly Container medalContainer; + private readonly Sprite medalGlow, medalSprite; private readonly OsuSpriteText unlocked, name; private readonly TextFlowContainer description; private readonly FillFlowContainer infoFlow; @@ -28,11 +29,12 @@ namespace osu.Game.Overlays.MedalSplash public DrawableMedal(Medal medal) { + this.medal = medal; Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2); Children = new Drawable[] { - this.medal = new Container + this.medalContainer = new Container { Anchor = Anchor.TopCentre, Origin = Anchor.Centre, @@ -40,6 +42,12 @@ namespace osu.Game.Overlays.MedalSplash Alpha = 0f, Children = new[] { + medalSprite = new Sprite + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(0.81f), + }, medalGlow = new Sprite { Anchor = Anchor.Centre, @@ -102,12 +110,13 @@ namespace osu.Game.Overlays.MedalSplash [BackgroundDependencyLoader] private void load(OsuColour colours, TextureStore textures) { + medalSprite.Texture = textures.Get(medal.ImageUrl); medalGlow.Texture = textures.Get(@"MedalSplash/medal-glow"); foreach (var s in descriptionSprites) s.Colour = colours.BlueLight; - var pos = new Vector2(0f, medal.Size.Y / 2 + 10); + var pos = new Vector2(0f, medalContainer.Size.Y / 2 + 10); unlocked.Position = pos; pos.Y += 90; infoFlow.Position = pos; @@ -118,9 +127,9 @@ namespace osu.Game.Overlays.MedalSplash switch (newState) { case DisplayState.Icon: - medal.Scale = Vector2.Zero; - medal.ScaleTo(1, duration, EasingTypes.OutElastic); - medal.FadeInFromZero(duration); + medalContainer.Scale = Vector2.Zero; + medalContainer.ScaleTo(1, duration, EasingTypes.OutElastic); + medalContainer.FadeInFromZero(duration); break; case DisplayState.MedalUnlocked: ScaleTo(scale_when_unlocked, duration, EasingTypes.OutExpo); diff --git a/osu.Game/Users/Medal.cs b/osu.Game/Users/Medal.cs index 5ac6eceddc..aa7382b457 100644 --- a/osu.Game/Users/Medal.cs +++ b/osu.Game/Users/Medal.cs @@ -6,6 +6,8 @@ namespace osu.Game.Users public class Medal { public string Name { get; set; } + public string InternalName { get; set; } + public string ImageUrl => $@"https://s.ppy.sh/images/medals-client/{InternalName}@2x.png"; public string Description { get; set; } } } From b2c516238e70f4b19950dbde62701df3eb4dd3e2 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Sat, 24 Jun 2017 01:48:55 -0300 Subject: [PATCH 06/18] Cleanup. --- osu.Game/Overlays/MedalOverlay.cs | 15 ++++++++++----- osu.Game/Overlays/MedalSplash/DrawableMedal.cs | 14 ++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index d9c949a0da..617a5f7d0b 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -33,7 +33,7 @@ namespace osu.Game.Overlays private const float border_width = 5; private readonly Box background; - private readonly Container backgroundStrip; + private readonly Container backgroundStrip, particleContainer; private readonly BackgroundStrip leftStrip, rightStrip; private readonly CircularContainer disc; private readonly Sprite innerSpin, outterSpin; @@ -61,7 +61,6 @@ namespace osu.Game.Overlays { background = new Box { - Name = @"dim", RelativeSizeAxes = Axes.Both, Colour = Color4.Black.Opacity(60), }, @@ -74,7 +73,6 @@ namespace osu.Game.Overlays }, backgroundStrip = new Container { - Name = @"background strip", Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.X, @@ -112,9 +110,12 @@ namespace osu.Game.Overlays }, }, }, + particleContainer = new Container + { + RelativeSizeAxes = Axes.Both, + }, disc = new CircularContainer { - Name = @"content", Anchor = Anchor.Centre, Origin = Anchor.Centre, Alpha = 0f, @@ -168,7 +169,11 @@ namespace osu.Game.Overlays Colour = colours.Blue.Opacity(0.5f), Radius = 50, }; + } + protected override void LoadComplete() + { + base.LoadComplete(); Show(); } @@ -176,7 +181,7 @@ namespace osu.Game.Overlays { base.Update(); - Add(new MedalParticle(RNG.Next(0, 359))); + particleContainer.Add(new MedalParticle(RNG.Next(0, 359))); } protected override void PopIn() diff --git a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs index e230b9de9b..e385601f6d 100644 --- a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs +++ b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs @@ -34,7 +34,7 @@ namespace osu.Game.Overlays.MedalSplash Children = new Drawable[] { - this.medalContainer = new Container + medalContainer = new Container { Anchor = Anchor.TopCentre, Origin = Anchor.Centre, @@ -63,7 +63,7 @@ namespace osu.Game.Overlays.MedalSplash TextSize = 24, Font = @"Exo2.0-Light", Alpha = 0f, - Scale = new Vector2(1 / scale_when_unlocked), + Scale = new Vector2(1f / scale_when_unlocked), }, infoFlow = new FillFlowContainer { @@ -84,7 +84,7 @@ namespace osu.Game.Overlays.MedalSplash TextSize = 20, Font = @"Exo2.0-Bold", Alpha = 0f, - Scale = new Vector2(1 / scale_when_full), + Scale = new Vector2(1f / scale_when_full), }, description = new TextFlowContainer { @@ -93,7 +93,7 @@ namespace osu.Game.Overlays.MedalSplash RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Alpha = 0f, - Scale = new Vector2(1 / scale_when_full), + Scale = new Vector2(1f / scale_when_full), }, }, }, @@ -116,10 +116,8 @@ namespace osu.Game.Overlays.MedalSplash foreach (var s in descriptionSprites) s.Colour = colours.BlueLight; - var pos = new Vector2(0f, medalContainer.Size.Y / 2 + 10); - unlocked.Position = pos; - pos.Y += 90; - infoFlow.Position = pos; + unlocked.Position = new Vector2(0f, medalContainer.Size.Y / 2 + 10); + infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90); } public void ChangeState(DisplayState newState, double duration) From 2ee0f3f5f6606818dc297e7ce20bb8f2177a4bc4 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Tue, 11 Jul 2017 02:11:08 -0300 Subject: [PATCH 07/18] Update with framework changes. --- .../Tests/TestCaseMedalOverlay.cs | 4 +--- osu.Game/Overlays/MedalOverlay.cs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs index ac983277a4..e00b2beac4 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs @@ -11,10 +11,8 @@ namespace osu.Desktop.VisualTests.Tests { public override string Description => @"medal get!"; - public override void Reset() + public TestCaseMedalOverlay() { - base.Reset(); - Add(new MedalOverlay(new Medal { Name = @"Animations", diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 617a5f7d0b..cc6f23ccdb 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -199,23 +199,25 @@ namespace osu.Game.Overlays getSample.Play(); Delay(200, true); - innerSpin.Transforms.Add(new TransformRotation + var innerRotate = new TransformRotation { - StartValue = 0, EndValue = 359, StartTime = Clock.TimeInfo.Current, EndTime = Clock.TimeInfo.Current + 20000, - LoopCount = -1, - }); + }; - outterSpin.Transforms.Add(new TransformRotation + innerRotate.Loop(0); + innerSpin.Transforms.Add(innerRotate); + + var outerRotate = new TransformRotation { - StartValue = 0, EndValue = 359, StartTime = Clock.TimeInfo.Current, EndTime = Clock.TimeInfo.Current + 40000, - LoopCount = -1, - }); + }; + + outerRotate.Loop(0); + outterSpin.Transforms.Add(outerRotate); disc.FadeIn(duration1); outterSpin.FadeTo(0.1f, duration1 * 2); From 16bb96e6aa8d1353aab868e093e0238e5773b7be Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Tue, 11 Jul 2017 22:12:49 -0300 Subject: [PATCH 08/18] Async medal sprite loading. --- osu.Game/Overlays/MedalOverlay.cs | 11 +++---- .../Overlays/MedalSplash/DrawableMedal.cs | 33 ++++++++++++++++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index cc6f23ccdb..f4260a946f 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -56,6 +56,7 @@ namespace osu.Game.Overlays { RelativeSizeAxes = Axes.Both; Alpha = 0f; + AlwaysPresent = true; Children = new Drawable[] { @@ -120,6 +121,7 @@ namespace osu.Game.Overlays Origin = Anchor.Centre, Alpha = 0f, Masking = true, + AlwaysPresent = true, BorderColour = Color4.White, BorderThickness = border_width, Size = new Vector2(DISC_SIZE), @@ -151,6 +153,8 @@ namespace osu.Game.Overlays Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.X, + AlwaysPresent = true, + OnSpriteLoadComplete = drawable => Show(), }, }, }, @@ -171,12 +175,6 @@ namespace osu.Game.Overlays }; } - protected override void LoadComplete() - { - base.LoadComplete(); - Show(); - } - protected override void Update() { base.Update(); @@ -247,6 +245,7 @@ namespace osu.Game.Overlays { if (drawableMedal.Transforms.Count != 0) return; Hide(); + Expire(); } private class BackgroundStrip : Container diff --git a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs index e385601f6d..a62f6fd0f8 100644 --- a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs +++ b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Collections.Generic; using OpenTK; using osu.Framework.Allocation; @@ -21,16 +22,19 @@ namespace osu.Game.Overlays.MedalSplash private readonly Medal medal; private readonly Container medalContainer; - private readonly Sprite medalGlow, medalSprite; + private readonly Sprite medalGlow; private readonly OsuSpriteText unlocked, name; private readonly TextFlowContainer description; private readonly FillFlowContainer infoFlow; private readonly IEnumerable descriptionSprites; + public Action OnSpriteLoadComplete; + public DrawableMedal(Medal medal) { this.medal = medal; Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2); + AlwaysPresent = true; Children = new Drawable[] { @@ -40,12 +44,17 @@ namespace osu.Game.Overlays.MedalSplash Origin = Anchor.Centre, AutoSizeAxes = Axes.Both, Alpha = 0f, - Children = new[] + AlwaysPresent = true, + Children = new Drawable[] { - medalSprite = new Sprite + new AsyncLoadWrapper(new MedalSprite(medal) + { + OnLoadComplete = drawable => OnSpriteLoadComplete?.Invoke(drawable), + }) { Anchor = Anchor.Centre, Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, Scale = new Vector2(0.81f), }, medalGlow = new Sprite @@ -110,7 +119,6 @@ namespace osu.Game.Overlays.MedalSplash [BackgroundDependencyLoader] private void load(OsuColour colours, TextureStore textures) { - medalSprite.Texture = textures.Get(medal.ImageUrl); medalGlow.Texture = textures.Get(@"MedalSplash/medal-glow"); foreach (var s in descriptionSprites) @@ -149,5 +157,22 @@ namespace osu.Game.Overlays.MedalSplash MedalUnlocked, Full, } + + private class MedalSprite : Sprite + { + private readonly Medal medal; + + public MedalSprite(Medal medal) + { + this.medal = medal; + } + + [BackgroundDependencyLoader] + private void load(TextureStore textures) + { + if (medal?.InternalName != null) + Texture = textures.Get(medal.ImageUrl); + } + } } } From aef2a3bddadf372e494202740f2a19ba282e8529 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Tue, 11 Jul 2017 22:26:58 -0300 Subject: [PATCH 09/18] Cleanup. --- osu.Game/Overlays/MedalOverlay.cs | 22 +++++++++---------- .../Overlays/MedalSplash/DrawableMedal.cs | 7 ++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index f4260a946f..5758097ec2 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -41,17 +41,6 @@ namespace osu.Game.Overlays private SampleChannel getSample; - protected override bool OnClick(InputState state) - { - dismiss(); - return true; - } - - protected override void OnFocusLost(InputState state) - { - if (state.Keyboard.Keys.Contains(Key.Escape)) dismiss(); - } - public MedalOverlay(Medal medal) { RelativeSizeAxes = Axes.Both; @@ -182,6 +171,17 @@ namespace osu.Game.Overlays particleContainer.Add(new MedalParticle(RNG.Next(0, 359))); } + protected override bool OnClick(InputState state) + { + dismiss(); + return true; + } + + protected override void OnFocusLost(InputState state) + { + if (state.Keyboard.Keys.Contains(Key.Escape)) dismiss(); + } + protected override void PopIn() { base.PopIn(); diff --git a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs index a62f6fd0f8..c24fe9799c 100644 --- a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs +++ b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs @@ -26,7 +26,6 @@ namespace osu.Game.Overlays.MedalSplash private readonly OsuSpriteText unlocked, name; private readonly TextFlowContainer description; private readonly FillFlowContainer infoFlow; - private readonly IEnumerable descriptionSprites; public Action OnSpriteLoadComplete; @@ -108,7 +107,7 @@ namespace osu.Game.Overlays.MedalSplash }, }; - descriptionSprites = description.AddText(medal.Description, s => + description.AddText(medal.Description, s => { s.Anchor = Anchor.TopCentre; s.Origin = Anchor.TopCentre; @@ -120,9 +119,7 @@ namespace osu.Game.Overlays.MedalSplash private void load(OsuColour colours, TextureStore textures) { medalGlow.Texture = textures.Get(@"MedalSplash/medal-glow"); - - foreach (var s in descriptionSprites) - s.Colour = colours.BlueLight; + description.Colour = colours.BlueLight; unlocked.Position = new Vector2(0f, medalContainer.Size.Y / 2 + 10); infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90); From 29cdbc65bc456ef22a8198dc63331b1a96477be6 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Tue, 11 Jul 2017 22:38:13 -0300 Subject: [PATCH 10/18] CI fixes. --- osu.Game/Overlays/MedalOverlay.cs | 8 ++++---- osu.Game/Overlays/MedalSplash/DrawableMedal.cs | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 5758097ec2..17e557b194 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -189,10 +189,10 @@ namespace osu.Game.Overlays FadeIn(200); background.FlashColour(Color4.White.Opacity(0.25f), 400); - double duration1 = 400; - double duration2 = 900; - double duration3 = 900; - double duration4 = 1000; + var duration1 = 400; + var duration2 = 900; + var duration3 = 900; + var duration4 = 1000; getSample.Play(); Delay(200, true); diff --git a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs index c24fe9799c..8d4b567c27 100644 --- a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs +++ b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Collections.Generic; using OpenTK; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -20,7 +19,6 @@ namespace osu.Game.Overlays.MedalSplash private const float scale_when_unlocked = 0.76f; private const float scale_when_full = 0.6f; - private readonly Medal medal; private readonly Container medalContainer; private readonly Sprite medalGlow; private readonly OsuSpriteText unlocked, name; @@ -31,7 +29,6 @@ namespace osu.Game.Overlays.MedalSplash public DrawableMedal(Medal medal) { - this.medal = medal; Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2); AlwaysPresent = true; From 204d2ee43d76198e30dd3d7fcb46a13ea7acf79b Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Tue, 11 Jul 2017 22:43:16 -0300 Subject: [PATCH 11/18] Convert MedalOverlay animation durations to constants. --- osu.Game/Overlays/MedalOverlay.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 17e557b194..bb06ec5362 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -182,6 +182,10 @@ namespace osu.Game.Overlays if (state.Keyboard.Keys.Contains(Key.Escape)) dismiss(); } + private const double duration1 = 400; + private const double duration2 = 900; + private const double duration3 = 900; + private const double duration4 = 1000; protected override void PopIn() { base.PopIn(); @@ -189,11 +193,6 @@ namespace osu.Game.Overlays FadeIn(200); background.FlashColour(Color4.White.Opacity(0.25f), 400); - var duration1 = 400; - var duration2 = 900; - var duration3 = 900; - var duration4 = 1000; - getSample.Play(); Delay(200, true); From ca12fd304220a6e9279e967da63f8109eb10bb6a Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Thu, 13 Jul 2017 00:13:18 -0300 Subject: [PATCH 12/18] Better medal sprite loading, fade in particles, visual test update. --- .../Tests/TestCaseMedalOverlay.cs | 13 +++++--- osu.Game/Overlays/MedalOverlay.cs | 21 +++++++----- .../Overlays/MedalSplash/DrawableMedal.cs | 33 +++---------------- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs index e00b2beac4..f069f089bf 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs @@ -13,12 +13,15 @@ namespace osu.Desktop.VisualTests.Tests public TestCaseMedalOverlay() { - Add(new MedalOverlay(new Medal + AddStep(@"display", () => { - Name = @"Animations", - InternalName = @"all-intro-doubletime", - Description = @"More complex than you think.", - })); + Add(new MedalOverlay(new Medal + { + Name = @"Animations", + InternalName = @"all-intro-doubletime", + Description = @"More complex than you think.", + })); + }); } } } diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index bb06ec5362..e58dd2aa40 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -32,17 +32,19 @@ namespace osu.Game.Overlays private const float border_width = 5; + private readonly Medal medal; private readonly Box background; private readonly Container backgroundStrip, particleContainer; private readonly BackgroundStrip leftStrip, rightStrip; private readonly CircularContainer disc; private readonly Sprite innerSpin, outterSpin; - private readonly DrawableMedal drawableMedal; + private DrawableMedal drawableMedal; private SampleChannel getSample; public MedalOverlay(Medal medal) { + this.medal = medal; RelativeSizeAxes = Axes.Both; Alpha = 0f; AlwaysPresent = true; @@ -103,6 +105,7 @@ namespace osu.Game.Overlays particleContainer = new Container { RelativeSizeAxes = Axes.Both, + Alpha = 0f, }, disc = new CircularContainer { @@ -137,14 +140,6 @@ namespace osu.Game.Overlays Size = new Vector2(1.05f), Alpha = 0.25f, }, - drawableMedal = new DrawableMedal(medal) - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - RelativeSizeAxes = Axes.X, - AlwaysPresent = true, - OnSpriteLoadComplete = drawable => Show(), - }, }, }, }; @@ -162,6 +157,13 @@ namespace osu.Game.Overlays Colour = colours.Blue.Opacity(0.5f), Radius = 50, }; + + LoadComponentAsync(drawableMedal = new DrawableMedal(medal) + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + }, m => { disc.Add(m); Show(); }); } protected override void Update() @@ -217,6 +219,7 @@ namespace osu.Game.Overlays outterSpin.Transforms.Add(outerRotate); disc.FadeIn(duration1); + particleContainer.FadeIn(duration1); outterSpin.FadeTo(0.1f, duration1 * 2); disc.ScaleTo(1f, duration1 * 2, EasingTypes.OutElastic); diff --git a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs index 8d4b567c27..cdc352eff0 100644 --- a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs +++ b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using OpenTK; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -19,18 +18,17 @@ namespace osu.Game.Overlays.MedalSplash private const float scale_when_unlocked = 0.76f; private const float scale_when_full = 0.6f; + private readonly Medal medal; private readonly Container medalContainer; - private readonly Sprite medalGlow; + private readonly Sprite medalSprite, medalGlow; private readonly OsuSpriteText unlocked, name; private readonly TextFlowContainer description; private readonly FillFlowContainer infoFlow; - public Action OnSpriteLoadComplete; - public DrawableMedal(Medal medal) { + this.medal = medal; Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2); - AlwaysPresent = true; Children = new Drawable[] { @@ -40,17 +38,12 @@ namespace osu.Game.Overlays.MedalSplash Origin = Anchor.Centre, AutoSizeAxes = Axes.Both, Alpha = 0f, - AlwaysPresent = true, Children = new Drawable[] { - new AsyncLoadWrapper(new MedalSprite(medal) - { - OnLoadComplete = drawable => OnSpriteLoadComplete?.Invoke(drawable), - }) + medalSprite = new Sprite { Anchor = Anchor.Centre, Origin = Anchor.Centre, - AutoSizeAxes = Axes.Both, Scale = new Vector2(0.81f), }, medalGlow = new Sprite @@ -115,6 +108,7 @@ namespace osu.Game.Overlays.MedalSplash [BackgroundDependencyLoader] private void load(OsuColour colours, TextureStore textures) { + medalSprite.Texture = textures.Get(medal.ImageUrl); medalGlow.Texture = textures.Get(@"MedalSplash/medal-glow"); description.Colour = colours.BlueLight; @@ -151,22 +145,5 @@ namespace osu.Game.Overlays.MedalSplash MedalUnlocked, Full, } - - private class MedalSprite : Sprite - { - private readonly Medal medal; - - public MedalSprite(Medal medal) - { - this.medal = medal; - } - - [BackgroundDependencyLoader] - private void load(TextureStore textures) - { - if (medal?.InternalName != null) - Texture = textures.Get(medal.ImageUrl); - } - } } } From 931adcf6774ae71c74251c7100471e2aef9ae1b4 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Thu, 13 Jul 2017 00:13:56 -0300 Subject: [PATCH 13/18] Typo. --- osu.Game/Overlays/MedalOverlay.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index e58dd2aa40..8d24b116ab 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -37,7 +37,7 @@ namespace osu.Game.Overlays private readonly Container backgroundStrip, particleContainer; private readonly BackgroundStrip leftStrip, rightStrip; private readonly CircularContainer disc; - private readonly Sprite innerSpin, outterSpin; + private readonly Sprite innerSpin, outerSpin; private DrawableMedal drawableMedal; private SampleChannel getSample; @@ -56,7 +56,7 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Both, Colour = Color4.Black.Opacity(60), }, - outterSpin = new Sprite + outerSpin = new Sprite { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -149,7 +149,7 @@ namespace osu.Game.Overlays private void load(OsuColour colours, TextureStore textures, AudioManager audio) { getSample = audio.Sample.Get(@"MedalSplash/medal-get"); - innerSpin.Texture = outterSpin.Texture = textures.Get(@"MedalSplash/disc-spin"); + innerSpin.Texture = outerSpin.Texture = textures.Get(@"MedalSplash/disc-spin"); disc.EdgeEffect = leftStrip.EdgeEffect = rightStrip.EdgeEffect = new EdgeEffectParameters { @@ -216,11 +216,11 @@ namespace osu.Game.Overlays }; outerRotate.Loop(0); - outterSpin.Transforms.Add(outerRotate); + outerSpin.Transforms.Add(outerRotate); disc.FadeIn(duration1); particleContainer.FadeIn(duration1); - outterSpin.FadeTo(0.1f, duration1 * 2); + outerSpin.FadeTo(0.1f, duration1 * 2); disc.ScaleTo(1f, duration1 * 2, EasingTypes.OutElastic); Delay(duration1 + 200, true); From 321ae423512ae02b57c6db2207b77673fe906d93 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Thu, 13 Jul 2017 00:27:41 -0300 Subject: [PATCH 14/18] Formatting. --- osu.Game/Overlays/MedalOverlay.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 8d24b116ab..3677c89727 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -163,7 +163,11 @@ namespace osu.Game.Overlays Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.X, - }, m => { disc.Add(m); Show(); }); + }, m => + { + disc.Add(m); + Show(); + }); } protected override void Update() From 20052b060cea6f8d1599bfc32036aeff972ae7d2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 13:25:31 +0900 Subject: [PATCH 15/18] Nest delays and implement IStateful, allowing for flushing on early dismiss Note that this will break rotation loops until https://github.com/ppy/osu-framework/issues/900 is addressed. --- osu.Game/Overlays/MedalOverlay.cs | 85 ++++++++++--------- .../Overlays/MedalSplash/DrawableMedal.cs | 60 ++++++++++--- 2 files changed, 92 insertions(+), 53 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 3677c89727..666cccea82 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -16,7 +16,6 @@ using osu.Framework.Allocation; using osu.Framework.Audio.Sample; using osu.Framework.Audio; using osu.Framework.Graphics.Textures; -using osu.Framework.Graphics.Transforms; using osu.Framework.Input; using OpenTK.Input; using System.Linq; @@ -188,10 +187,9 @@ namespace osu.Game.Overlays if (state.Keyboard.Keys.Contains(Key.Escape)) dismiss(); } - private const double duration1 = 400; - private const double duration2 = 900; - private const double duration3 = 900; - private const double duration4 = 1000; + private const double initial_duration = 400; + private const double step_duration = 900; + protected override void PopIn() { base.PopIn(); @@ -200,56 +198,63 @@ namespace osu.Game.Overlays background.FlashColour(Color4.White.Opacity(0.25f), 400); getSample.Play(); - Delay(200, true); - var innerRotate = new TransformRotation + using (innerSpin.BeginLoopedSequence()) + innerSpin.RotateTo(360, 20000); + + using (outerSpin.BeginLoopedSequence()) + outerSpin.RotateTo(360, 40000); + + using (BeginDelayedSequence(200, true)) { - EndValue = 359, - StartTime = Clock.TimeInfo.Current, - EndTime = Clock.TimeInfo.Current + 20000, - }; + disc.FadeIn(initial_duration); + particleContainer.FadeIn(initial_duration); + outerSpin.FadeTo(0.1f, initial_duration * 2); + disc.ScaleTo(1f, initial_duration * 2, EasingTypes.OutElastic); - innerRotate.Loop(0); - innerSpin.Transforms.Add(innerRotate); + using (BeginDelayedSequence(initial_duration + 200, true)) + { + backgroundStrip.FadeIn(step_duration); + leftStrip.ResizeWidthTo(1f, step_duration, EasingTypes.OutQuint); + rightStrip.ResizeWidthTo(1f, step_duration, EasingTypes.OutQuint); + Schedule(() => + { + if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.Icon; + }); - var outerRotate = new TransformRotation - { - EndValue = 359, - StartTime = Clock.TimeInfo.Current, - EndTime = Clock.TimeInfo.Current + 40000, - }; + using (BeginDelayedSequence(step_duration, true)) + { + Schedule(() => + { + if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.MedalUnlocked; + }); - outerRotate.Loop(0); - outerSpin.Transforms.Add(outerRotate); - - disc.FadeIn(duration1); - particleContainer.FadeIn(duration1); - outerSpin.FadeTo(0.1f, duration1 * 2); - disc.ScaleTo(1f, duration1 * 2, EasingTypes.OutElastic); - - Delay(duration1 + 200, true); - backgroundStrip.FadeIn(duration2); - leftStrip.ResizeWidthTo(1f, duration2, EasingTypes.OutQuint); - rightStrip.ResizeWidthTo(1f, duration2, EasingTypes.OutQuint); - drawableMedal.ChangeState(DrawableMedal.DisplayState.Icon, duration2); - - Delay(duration2, true); - drawableMedal.ChangeState(DrawableMedal.DisplayState.MedalUnlocked, duration3); - - Delay(duration3, true); - drawableMedal.ChangeState(DrawableMedal.DisplayState.Full, duration4); + using (BeginDelayedSequence(step_duration, true)) + Schedule(() => + { + if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.Full; + }); + } + } + } } protected override void PopOut() { base.PopOut(); - FadeOut(200); } private void dismiss() { - if (drawableMedal.Transforms.Count != 0) return; + if (drawableMedal.State != DisplayState.Full) + { + // if we haven't yet, play out the animation fully + drawableMedal.State = DisplayState.Full; + Flush(true); + return; + } + Hide(); Expire(); } diff --git a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs index cdc352eff0..7d7ffbd12a 100644 --- a/osu.Game/Overlays/MedalSplash/DrawableMedal.cs +++ b/osu.Game/Overlays/MedalSplash/DrawableMedal.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework; using OpenTK; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -13,7 +14,7 @@ using osu.Game.Users; namespace osu.Game.Overlays.MedalSplash { - public class DrawableMedal : Container + public class DrawableMedal : Container, IStateful { private const float scale_when_unlocked = 0.76f; private const float scale_when_full = 0.6f; @@ -24,7 +25,7 @@ namespace osu.Game.Overlays.MedalSplash private readonly OsuSpriteText unlocked, name; private readonly TextFlowContainer description; private readonly FillFlowContainer infoFlow; - + private DisplayState state; public DrawableMedal(Medal medal) { this.medal = medal; @@ -116,34 +117,67 @@ namespace osu.Game.Overlays.MedalSplash infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90); } - public void ChangeState(DisplayState newState, double duration) + protected override void LoadComplete() { - switch (newState) + base.LoadComplete(); + updateState(); + } + + public DisplayState State + { + get { return state; } + set { + if (state == value) return; + + state = value; + updateState(); + } + } + + private void updateState() + { + if (!IsLoaded) return; + + const double duration = 900; + + switch (state) + { + case DisplayState.None: + medalContainer.ScaleTo(0); + break; case DisplayState.Icon: - medalContainer.Scale = Vector2.Zero; medalContainer.ScaleTo(1, duration, EasingTypes.OutElastic); - medalContainer.FadeInFromZero(duration); + medalContainer.FadeIn(duration); break; case DisplayState.MedalUnlocked: + medalContainer.ScaleTo(1); + medalContainer.Show(); + ScaleTo(scale_when_unlocked, duration, EasingTypes.OutExpo); MoveToY(MedalOverlay.DISC_SIZE / 2 - 30, duration, EasingTypes.OutExpo); unlocked.FadeInFromZero(duration); break; case DisplayState.Full: + medalContainer.ScaleTo(1); + medalContainer.Show(); + ScaleTo(scale_when_full, duration, EasingTypes.OutExpo); MoveToY(MedalOverlay.DISC_SIZE / 2 - 60, duration, EasingTypes.OutExpo); - name.FadeInFromZero(duration); + name.FadeInFromZero(duration + 100); description.FadeInFromZero(duration * 2); break; } - } - public enum DisplayState - { - Icon, - MedalUnlocked, - Full, + } } + + public enum DisplayState + { + None, + Icon, + MedalUnlocked, + Full, + } } From 980fb18ed60eefa613ca2272a8503232ce23a8d2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 14:30:35 +0900 Subject: [PATCH 16/18] Remove unnecessary alpha/alwayspresent changes --- osu.Game/Overlays/MedalOverlay.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 666cccea82..3222d492e9 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -45,8 +45,6 @@ namespace osu.Game.Overlays { this.medal = medal; RelativeSizeAxes = Axes.Both; - Alpha = 0f; - AlwaysPresent = true; Children = new Drawable[] { From 133bcdec7a91cd8a4e85a0cd906a799637b9c170 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 14:39:15 +0900 Subject: [PATCH 17/18] Move async loading to a higher level to simplify logic --- .../Tests/TestCaseMedalOverlay.cs | 4 ++-- osu.Game/Overlays/MedalOverlay.cs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs index f069f089bf..1533f2141e 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMedalOverlay.cs @@ -15,12 +15,12 @@ namespace osu.Desktop.VisualTests.Tests { AddStep(@"display", () => { - Add(new MedalOverlay(new Medal + LoadComponentAsync(new MedalOverlay(new Medal { Name = @"Animations", InternalName = @"all-intro-doubletime", Description = @"More complex than you think.", - })); + }), Add); }); } } diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index 3222d492e9..ccde414d37 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -155,18 +155,20 @@ namespace osu.Game.Overlays Radius = 50, }; - LoadComponentAsync(drawableMedal = new DrawableMedal(medal) + disc.Add(drawableMedal = new DrawableMedal(medal) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.X, - }, m => - { - disc.Add(m); - Show(); }); } + protected override void LoadComplete() + { + base.LoadComplete(); + Show(); + } + protected override void Update() { base.Update(); From bce4b838d88fbe0ecc878ebc4369b0d0a0d1a2bc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 14:40:50 +0900 Subject: [PATCH 18/18] Formatting --- osu.Game/Overlays/MedalOverlay.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/osu.Game/Overlays/MedalOverlay.cs b/osu.Game/Overlays/MedalOverlay.cs index ccde414d37..5f85474ede 100644 --- a/osu.Game/Overlays/MedalOverlay.cs +++ b/osu.Game/Overlays/MedalOverlay.cs @@ -217,23 +217,14 @@ namespace osu.Game.Overlays backgroundStrip.FadeIn(step_duration); leftStrip.ResizeWidthTo(1f, step_duration, EasingTypes.OutQuint); rightStrip.ResizeWidthTo(1f, step_duration, EasingTypes.OutQuint); - Schedule(() => - { - if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.Icon; - }); + Schedule(() => { if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.Icon; }); using (BeginDelayedSequence(step_duration, true)) { - Schedule(() => - { - if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.MedalUnlocked; - }); + Schedule(() => { if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.MedalUnlocked; }); using (BeginDelayedSequence(step_duration, true)) - Schedule(() => - { - if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.Full; - }); + Schedule(() => { if (drawableMedal.State != DisplayState.Full) drawableMedal.State = DisplayState.Full; }); } } }