1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 23:23:04 +08:00
osu-lazer/osu.Game/Overlays/MedalSplash/DrawableMedal.cs
2017-07-14 13:25:31 +09:00

184 lines
6.4 KiB
C#

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Users;
namespace osu.Game.Overlays.MedalSplash
{
public class DrawableMedal : Container, IStateful<DisplayState>
{
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 medalSprite, medalGlow;
private readonly OsuSpriteText unlocked, name;
private readonly TextFlowContainer description;
private readonly FillFlowContainer infoFlow;
private DisplayState state;
public DrawableMedal(Medal medal)
{
this.medal = medal;
Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2);
Children = new Drawable[]
{
medalContainer = new Container
{
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Alpha = 0f,
Children = new Drawable[]
{
medalSprite = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.81f),
},
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(1f / 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(1f / scale_when_full),
},
description = new TextFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Alpha = 0f,
Scale = new Vector2(1f / scale_when_full),
},
},
},
};
description.AddText(medal.Description, s =>
{
s.Anchor = Anchor.TopCentre;
s.Origin = Anchor.TopCentre;
s.TextSize = 16;
});
}
[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;
unlocked.Position = new Vector2(0f, medalContainer.Size.Y / 2 + 10);
infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90);
}
protected override void LoadComplete()
{
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.ScaleTo(1, duration, EasingTypes.OutElastic);
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 + 100);
description.FadeInFromZero(duration * 2);
break;
}
}
}
public enum DisplayState
{
None,
Icon,
MedalUnlocked,
Full,
}
}