1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 07:42:52 +08:00
osu-lazer/osu.Game/Overlays/MedalSplash/DrawableMedal.cs

192 lines
6.6 KiB
C#
Raw Normal View History

2017-06-01 15:45:46 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-09-04 08:10:04 +08:00
using System;
using osu.Framework;
2017-06-01 15:45:46 +08:00
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>
2017-06-01 15:45:46 +08:00
{
private const float scale_when_unlocked = 0.76f;
private const float scale_when_full = 0.6f;
2017-09-04 08:10:04 +08:00
public event Action<DisplayState> StateChanged;
private readonly Medal medal;
private readonly Container medalContainer;
private readonly Sprite medalSprite, medalGlow;
2017-06-01 15:45:46 +08:00
private readonly OsuSpriteText unlocked, name;
private readonly TextFlowContainer description;
2017-06-01 15:45:46 +08:00
private readonly FillFlowContainer infoFlow;
private DisplayState state;
2017-06-01 15:45:46 +08:00
public DrawableMedal(Medal medal)
{
this.medal = medal;
2017-06-01 15:45:46 +08:00
Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2);
Children = new Drawable[]
{
2017-06-24 12:48:55 +08:00
medalContainer = new Container
2017-06-01 15:45:46 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Alpha = 0f,
2017-07-12 09:12:49 +08:00
Children = new Drawable[]
2017-06-01 15:45:46 +08:00
{
medalSprite = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.81f),
},
2017-06-01 15:45:46 +08:00
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,
2017-06-24 12:48:55 +08:00
Scale = new Vector2(1f / scale_when_unlocked),
2017-06-01 15:45:46 +08:00
},
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,
2017-06-24 12:48:55 +08:00
Scale = new Vector2(1f / scale_when_full),
2017-06-01 15:45:46 +08:00
},
description = new TextFlowContainer
2017-06-01 15:45:46 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Alpha = 0f,
2017-06-24 12:48:55 +08:00
Scale = new Vector2(1f / scale_when_full),
2017-06-01 15:45:46 +08:00
},
},
},
};
2017-07-12 09:26:58 +08:00
description.AddText(medal.Description, s =>
2017-06-01 15:45:46 +08:00
{
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);
2017-06-01 15:45:46 +08:00
medalGlow.Texture = textures.Get(@"MedalSplash/medal-glow");
2017-07-12 09:26:58 +08:00
description.Colour = colours.BlueLight;
2017-06-01 15:45:46 +08:00
2017-06-24 12:48:55 +08:00
unlocked.Position = new Vector2(0f, medalContainer.Size.Y / 2 + 10);
infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90);
2017-06-01 15:45:46 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
updateState();
}
public DisplayState State
2017-06-01 15:45:46 +08:00
{
get { return state; }
set
2017-06-01 15:45:46 +08:00
{
if (state == value) return;
state = value;
updateState();
2017-09-04 08:10:04 +08:00
StateChanged?.Invoke(State);
}
}
private void updateState()
{
if (!IsLoaded) return;
const double duration = 900;
switch (state)
{
case DisplayState.None:
medalContainer.ScaleTo(0);
break;
2017-06-01 15:45:46 +08:00
case DisplayState.Icon:
2017-07-16 23:28:20 +08:00
medalContainer
.FadeIn(duration)
2017-07-23 02:50:25 +08:00
.ScaleTo(1, duration, Easing.OutElastic);
2017-06-01 15:45:46 +08:00
break;
case DisplayState.MedalUnlocked:
2017-07-16 23:28:20 +08:00
medalContainer
.FadeTo(1)
.ScaleTo(1);
2017-07-23 02:50:25 +08:00
this.ScaleTo(scale_when_unlocked, duration, Easing.OutExpo);
this.MoveToY(MedalOverlay.DISC_SIZE / 2 - 30, duration, Easing.OutExpo);
2017-06-01 15:45:46 +08:00
unlocked.FadeInFromZero(duration);
break;
case DisplayState.Full:
2017-07-16 23:28:20 +08:00
medalContainer
.FadeTo(1)
.ScaleTo(1);
2017-07-23 02:50:25 +08:00
this.ScaleTo(scale_when_full, duration, Easing.OutExpo);
this.MoveToY(MedalOverlay.DISC_SIZE / 2 - 60, duration, Easing.OutExpo);
name.FadeInFromZero(duration + 100);
2017-06-01 15:45:46 +08:00
description.FadeInFromZero(duration * 2);
break;
}
2017-06-01 15:45:46 +08:00
}
}
public enum DisplayState
{
None,
Icon,
MedalUnlocked,
Full,
}
2017-06-01 15:45:46 +08:00
}