2017-06-01 07:45:46 +00:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// 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.Input;
|
|
|
|
using OpenTK.Input;
|
2017-06-24 01:35:06 +00:00
|
|
|
using System.Linq;
|
2017-06-24 01:42:36 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-06-24 02:18:44 +00:00
|
|
|
using System;
|
|
|
|
using osu.Framework.MathUtils;
|
2017-06-01 07:45:46 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
{
|
|
|
|
public class MedalOverlay : FocusedOverlayContainer
|
|
|
|
{
|
|
|
|
public const float DISC_SIZE = 400;
|
|
|
|
|
|
|
|
private const float border_width = 5;
|
|
|
|
|
2017-07-13 03:13:18 +00:00
|
|
|
private readonly Medal medal;
|
2017-06-01 07:45:46 +00:00
|
|
|
private readonly Box background;
|
2017-06-24 04:48:55 +00:00
|
|
|
private readonly Container backgroundStrip, particleContainer;
|
2017-06-01 07:45:46 +00:00
|
|
|
private readonly BackgroundStrip leftStrip, rightStrip;
|
|
|
|
private readonly CircularContainer disc;
|
2017-07-13 03:13:56 +00:00
|
|
|
private readonly Sprite innerSpin, outerSpin;
|
2017-07-13 03:13:18 +00:00
|
|
|
private DrawableMedal drawableMedal;
|
2017-06-01 07:45:46 +00:00
|
|
|
|
|
|
|
private SampleChannel getSample;
|
|
|
|
|
|
|
|
public MedalOverlay(Medal medal)
|
|
|
|
{
|
2017-07-13 03:13:18 +00:00
|
|
|
this.medal = medal;
|
2017-06-01 07:45:46 +00:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black.Opacity(60),
|
|
|
|
},
|
2017-07-13 03:13:56 +00:00
|
|
|
outerSpin = new Sprite
|
2017-06-01 07:45:46 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(DISC_SIZE + 500),
|
|
|
|
Alpha = 0f,
|
|
|
|
},
|
2017-06-24 02:51:28 +00:00
|
|
|
backgroundStrip = new Container
|
2017-06-01 07:45:46 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = border_width,
|
|
|
|
Alpha = 0f,
|
|
|
|
Children = new[]
|
|
|
|
{
|
2017-06-24 02:51:28 +00:00
|
|
|
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),
|
|
|
|
},
|
|
|
|
},
|
2017-06-01 07:45:46 +00:00
|
|
|
},
|
|
|
|
},
|
2017-06-24 04:48:55 +00:00
|
|
|
particleContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-07-13 03:13:18 +00:00
|
|
|
Alpha = 0f,
|
2017-06-24 04:48:55 +00:00
|
|
|
},
|
2017-06-01 07:45:46 +00:00
|
|
|
disc = new CircularContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Alpha = 0f,
|
|
|
|
Masking = true,
|
2017-07-12 01:12:49 +00:00
|
|
|
AlwaysPresent = true,
|
2017-06-01 07:45:46 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours, TextureStore textures, AudioManager audio)
|
|
|
|
{
|
|
|
|
getSample = audio.Sample.Get(@"MedalSplash/medal-get");
|
2017-07-13 03:13:56 +00:00
|
|
|
innerSpin.Texture = outerSpin.Texture = textures.Get(@"MedalSplash/disc-spin");
|
2017-06-01 07:45:46 +00:00
|
|
|
|
2017-06-24 01:42:36 +00:00
|
|
|
disc.EdgeEffect = leftStrip.EdgeEffect = rightStrip.EdgeEffect = new EdgeEffectParameters
|
2017-06-01 07:45:46 +00:00
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
Colour = colours.Blue.Opacity(0.5f),
|
|
|
|
Radius = 50,
|
|
|
|
};
|
2017-07-13 03:13:18 +00:00
|
|
|
|
2017-07-14 05:39:15 +00:00
|
|
|
disc.Add(drawableMedal = new DrawableMedal(medal)
|
2017-07-13 03:13:18 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-10-09 08:52:48 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-07-13 03:27:41 +00:00
|
|
|
});
|
2017-06-24 04:48:55 +00:00
|
|
|
}
|
2017-06-24 04:19:44 +00:00
|
|
|
|
2017-07-14 05:39:15 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
2017-06-24 02:18:44 +00:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2017-06-24 04:48:55 +00:00
|
|
|
particleContainer.Add(new MedalParticle(RNG.Next(0, 359)));
|
2017-06-24 02:18:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 01:26:58 +00:00
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
{
|
|
|
|
dismiss();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnFocusLost(InputState state)
|
|
|
|
{
|
|
|
|
if (state.Keyboard.Keys.Contains(Key.Escape)) dismiss();
|
|
|
|
}
|
|
|
|
|
2017-07-14 04:25:31 +00:00
|
|
|
private const double initial_duration = 400;
|
|
|
|
private const double step_duration = 900;
|
|
|
|
|
2017-06-01 07:45:46 +00:00
|
|
|
protected override void PopIn()
|
|
|
|
{
|
|
|
|
base.PopIn();
|
|
|
|
|
2017-07-14 16:18:12 +00:00
|
|
|
this.FadeIn(200);
|
2017-06-01 07:45:46 +00:00
|
|
|
background.FlashColour(Color4.White.Opacity(0.25f), 400);
|
|
|
|
|
|
|
|
getSample.Play();
|
|
|
|
|
2017-07-21 16:23:01 +00:00
|
|
|
innerSpin.Spin(20000, RotationDirection.Clockwise);
|
|
|
|
outerSpin.Spin(40000, RotationDirection.Clockwise);
|
2017-06-01 07:45:46 +00:00
|
|
|
|
2017-07-14 04:25:31 +00:00
|
|
|
using (BeginDelayedSequence(200, true))
|
2017-06-01 07:45:46 +00:00
|
|
|
{
|
2017-07-16 15:28:20 +00:00
|
|
|
disc.FadeIn(initial_duration)
|
2017-07-22 18:50:25 +00:00
|
|
|
.ScaleTo(1f, initial_duration * 2, Easing.OutElastic);
|
2017-07-16 15:28:20 +00:00
|
|
|
|
2017-07-14 04:25:31 +00:00
|
|
|
particleContainer.FadeIn(initial_duration);
|
|
|
|
outerSpin.FadeTo(0.1f, initial_duration * 2);
|
2017-06-01 07:45:46 +00:00
|
|
|
|
2017-07-14 04:25:31 +00:00
|
|
|
using (BeginDelayedSequence(initial_duration + 200, true))
|
|
|
|
{
|
|
|
|
backgroundStrip.FadeIn(step_duration);
|
2017-07-22 18:50:25 +00:00
|
|
|
leftStrip.ResizeWidthTo(1f, step_duration, Easing.OutQuint);
|
|
|
|
rightStrip.ResizeWidthTo(1f, step_duration, Easing.OutQuint);
|
2017-06-01 07:45:46 +00:00
|
|
|
|
2017-07-16 14:37:59 +00:00
|
|
|
this.Animate().Schedule(() =>
|
2017-07-14 04:25:31 +00:00
|
|
|
{
|
2017-07-16 14:37: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;
|
|
|
|
});
|
2017-07-14 04:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-01 07:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
base.PopOut();
|
2017-07-14 16:18:12 +00:00
|
|
|
this.FadeOut(200);
|
2017-06-01 07:45:46 +00:00
|
|
|
}
|
|
|
|
|
2017-06-24 01:35:06 +00:00
|
|
|
private void dismiss()
|
|
|
|
{
|
2017-07-14 04:25:31 +00:00
|
|
|
if (drawableMedal.State != DisplayState.Full)
|
|
|
|
{
|
|
|
|
// if we haven't yet, play out the animation fully
|
|
|
|
drawableMedal.State = DisplayState.Full;
|
2017-07-21 15:24:09 +00:00
|
|
|
FinishTransforms(true);
|
2017-07-14 04:25:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-24 01:35:06 +00:00
|
|
|
Hide();
|
2017-07-12 01:12:49 +00:00
|
|
|
Expire();
|
2017-06-24 01:35:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 07:45:46 +00:00
|
|
|
private class BackgroundStrip : Container
|
|
|
|
{
|
|
|
|
public BackgroundStrip(float start, float end)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-06-24 02:51:28 +00:00
|
|
|
Width = 0f;
|
2017-07-23 05:30:50 +00:00
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.White.Opacity(start), Color4.White.Opacity(end));
|
2017-06-01 07:45:46 +00:00
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.White,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 02:18:44 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2017-07-14 16:18:12 +00:00
|
|
|
this.MoveTo(positionForOffset(DISC_SIZE / 2 + 200), 500);
|
|
|
|
this.FadeOut(500);
|
2017-06-24 02:18:44 +00:00
|
|
|
Expire();
|
|
|
|
}
|
|
|
|
}
|
2017-06-01 07:45:46 +00:00
|
|
|
}
|
|
|
|
}
|