2019-01-24 08:43:03 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
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;
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using System;
|
2019-04-02 05:51:28 +00:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-10-02 03:02:47 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2020-01-09 04:43:44 +00:00
|
|
|
using osu.Framework.Utils;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
{
|
|
|
|
public class MedalOverlay : FocusedOverlayContainer
|
|
|
|
{
|
|
|
|
public const float DISC_SIZE = 400;
|
|
|
|
|
|
|
|
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, outerSpin;
|
|
|
|
private DrawableMedal drawableMedal;
|
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
private Sample getSample;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-01-07 04:39:30 +00:00
|
|
|
private readonly Container content;
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
public MedalOverlay(Medal medal)
|
|
|
|
{
|
|
|
|
this.medal = medal;
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2020-01-07 04:39:30 +00:00
|
|
|
Child = content = new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
Alpha = 0,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black.Opacity(60),
|
|
|
|
},
|
|
|
|
outerSpin = new Sprite
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(DISC_SIZE + 500),
|
|
|
|
Alpha = 0f,
|
|
|
|
},
|
|
|
|
backgroundStrip = new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = border_width,
|
|
|
|
Alpha = 0f,
|
|
|
|
Children = new[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Width = 0.5f,
|
|
|
|
Padding = new MarginPadding { Right = DISC_SIZE / 2 },
|
|
|
|
Children = new[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
leftStrip = new BackgroundStrip(0f, 1f)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
},
|
|
|
|
},
|
2020-01-07 04:39:30 +00:00
|
|
|
new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
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),
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-07 04:39:30 +00:00
|
|
|
particleContainer = new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0f,
|
|
|
|
},
|
|
|
|
disc = new CircularContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Alpha = 0f,
|
|
|
|
Masking = true,
|
|
|
|
AlwaysPresent = true,
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
BorderThickness = border_width,
|
|
|
|
Size = new Vector2(DISC_SIZE),
|
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
Children = new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-11 01:18:41 +00:00
|
|
|
Colour = Color4Extensions.FromHex(@"05262f"),
|
2020-01-07 04:39:30 +00:00
|
|
|
},
|
|
|
|
new Triangles
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
TriangleScale = 2,
|
2020-03-11 01:18:41 +00:00
|
|
|
ColourDark = Color4Extensions.FromHex(@"04222b"),
|
|
|
|
ColourLight = Color4Extensions.FromHex(@"052933"),
|
2020-01-07 04:39:30 +00:00
|
|
|
},
|
|
|
|
innerSpin = new Sprite
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Size = new Vector2(1.05f),
|
|
|
|
Alpha = 0.25f,
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
},
|
|
|
|
},
|
2020-01-07 04:39:30 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
};
|
2020-01-07 04:39:30 +00:00
|
|
|
|
|
|
|
Show();
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-08-30 22:04:40 +00:00
|
|
|
private void load(OsuColour colours, TextureStore textures, AudioManager audio)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2019-05-28 08:06:01 +00:00
|
|
|
getSample = audio.Samples.Get(@"MedalSplash/medal-get");
|
2018-08-30 22:04:40 +00:00
|
|
|
innerSpin.Texture = outerSpin.Texture = textures.Get(@"MedalSplash/disc-spin");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
disc.EdgeEffect = leftStrip.EdgeEffect = rightStrip.EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
Colour = colours.Blue.Opacity(0.5f),
|
|
|
|
Radius = 50,
|
|
|
|
};
|
2020-01-04 15:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-12-29 00:01:14 +00:00
|
|
|
LoadComponentAsync(drawableMedal = new DrawableMedal(medal)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-01-04 15:45:34 +00:00
|
|
|
}, loaded =>
|
|
|
|
{
|
|
|
|
disc.Add(loaded);
|
2020-01-07 04:39:30 +00:00
|
|
|
startAnimation();
|
2020-01-04 15:45:34 +00:00
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
particleContainer.Add(new MedalParticle(RNG.Next(0, 359)));
|
|
|
|
}
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
dismiss();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
protected override void OnFocusLost(FocusLostEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2018-10-02 03:44:14 +00:00
|
|
|
if (e.CurrentState.Keyboard.Keys.IsPressed(Key.Escape)) dismiss();
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private const double initial_duration = 400;
|
|
|
|
private const double step_duration = 900;
|
|
|
|
|
2020-01-07 04:39:30 +00:00
|
|
|
private void startAnimation()
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-07 04:39:30 +00:00
|
|
|
content.Show();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
background.FlashColour(Color4.White.Opacity(0.25f), 400);
|
|
|
|
|
|
|
|
getSample.Play();
|
|
|
|
|
|
|
|
innerSpin.Spin(20000, RotationDirection.Clockwise);
|
|
|
|
outerSpin.Spin(40000, RotationDirection.Clockwise);
|
|
|
|
|
|
|
|
using (BeginDelayedSequence(200, true))
|
|
|
|
{
|
|
|
|
disc.FadeIn(initial_duration)
|
|
|
|
.ScaleTo(1f, initial_duration * 2, Easing.OutElastic);
|
|
|
|
|
|
|
|
particleContainer.FadeIn(initial_duration);
|
|
|
|
outerSpin.FadeTo(0.1f, initial_duration * 2);
|
|
|
|
|
|
|
|
using (BeginDelayedSequence(initial_duration + 200, true))
|
|
|
|
{
|
|
|
|
backgroundStrip.FadeIn(step_duration);
|
|
|
|
leftStrip.ResizeWidthTo(1f, step_duration, Easing.OutQuint);
|
|
|
|
rightStrip.ResizeWidthTo(1f, step_duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
this.Animate().Schedule(() =>
|
2019-02-28 05:45:59 +00:00
|
|
|
{
|
|
|
|
if (drawableMedal.State != DisplayState.Full)
|
|
|
|
drawableMedal.State = DisplayState.Icon;
|
|
|
|
}).Delay(step_duration).Schedule(() =>
|
|
|
|
{
|
|
|
|
if (drawableMedal.State != DisplayState.Full)
|
|
|
|
drawableMedal.State = DisplayState.MedalUnlocked;
|
|
|
|
}).Delay(step_duration).Schedule(() =>
|
|
|
|
{
|
|
|
|
if (drawableMedal.State != DisplayState.Full)
|
|
|
|
drawableMedal.State = DisplayState.Full;
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
base.PopOut();
|
|
|
|
this.FadeOut(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dismiss()
|
|
|
|
{
|
|
|
|
if (drawableMedal.State != DisplayState.Full)
|
|
|
|
{
|
|
|
|
// if we haven't yet, play out the animation fully
|
|
|
|
drawableMedal.State = DisplayState.Full;
|
|
|
|
FinishTransforms(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Hide();
|
|
|
|
Expire();
|
|
|
|
}
|
|
|
|
|
|
|
|
private class BackgroundStrip : Container
|
|
|
|
{
|
|
|
|
public BackgroundStrip(float start, float end)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Width = 0f;
|
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.White.Opacity(start), Color4.White.Opacity(end));
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.White,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.MoveTo(positionForOffset(DISC_SIZE / 2 + 200), 500);
|
|
|
|
this.FadeOut(500);
|
|
|
|
Expire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|