1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 03:22:57 +08:00
osu-lazer/osu.Game/Overlays/MedalSplash/DrawableMedal.cs

200 lines
6.7 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
using System;
using osu.Framework;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
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.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Users;
namespace osu.Game.Overlays.MedalSplash
{
[LongRunningLoad]
2018-04-13 17:19:50 +08:00
public class DrawableMedal : Container, IStateful<DisplayState>
{
private const float scale_when_unlocked = 0.76f;
private const float scale_when_full = 0.6f;
public event Action<DisplayState> StateChanged;
private readonly Medal medal;
private readonly Container medalContainer;
private readonly Sprite medalSprite, medalGlow;
private readonly OsuSpriteText unlocked, name;
private readonly TextFlowContainer description;
private DisplayState state;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
public DrawableMedal(Medal medal)
{
this.medal = medal;
Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2);
FillFlowContainer infoFlow;
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,
2019-12-29 08:01:14 +08:00
Scale = new Vector2(0.41f),
2018-04-13 17:19:50 +08:00
},
medalGlow = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
},
},
unlocked = new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
2018-07-24 20:42:06 +08:00
Text = "Medal Unlocked".ToUpperInvariant(),
Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light),
2018-04-13 17:19:50 +08:00
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,
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold),
2018-04-13 17:19:50 +08:00
Alpha = 0f,
Scale = new Vector2(1f / scale_when_full),
},
description = new OsuTextFlowContainer
{
TextAnchor = Anchor.TopCentre,
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.Font = s.Font.With(size: 16);
2018-04-13 17:19:50 +08:00
});
2019-03-17 12:43:23 +08:00
medalContainer.OnLoadComplete += d =>
2018-04-13 17:19:50 +08:00
{
unlocked.Position = new Vector2(0f, medalContainer.DrawSize.Y / 2 + 10);
infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90);
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, TextureStore textures, LargeTextureStore largeTextures)
2018-04-13 17:19:50 +08:00
{
medalSprite.Texture = largeTextures.Get(medal.ImageUrl);
2018-08-31 06:04:40 +08:00
medalGlow.Texture = textures.Get(@"MedalSplash/medal-glow");
2018-04-13 17:19:50 +08:00
description.Colour = colours.BlueLight;
}
protected override void LoadComplete()
{
base.LoadComplete();
updateState();
}
public DisplayState State
{
get => state;
2018-04-13 17:19:50 +08:00
set
{
if (state == value) return;
state = value;
updateState();
StateChanged?.Invoke(State);
}
}
private void updateState()
{
if (!IsLoaded) return;
const double duration = 900;
switch (state)
{
case DisplayState.None:
medalContainer.ScaleTo(0);
break;
2019-04-01 11:44:46 +08:00
2018-04-13 17:19:50 +08:00
case DisplayState.Icon:
medalContainer
.FadeIn(duration)
.ScaleTo(1, duration, Easing.OutElastic);
break;
2019-04-01 11:44:46 +08:00
2018-04-13 17:19:50 +08:00
case DisplayState.MedalUnlocked:
medalContainer
.FadeTo(1)
.ScaleTo(1);
this.ScaleTo(scale_when_unlocked, duration, Easing.OutExpo);
this.MoveToY(MedalOverlay.DISC_SIZE / 2 - 30, duration, Easing.OutExpo);
unlocked.FadeInFromZero(duration);
break;
2019-04-01 11:44:46 +08:00
2018-04-13 17:19:50 +08:00
case DisplayState.Full:
medalContainer
.FadeTo(1)
.ScaleTo(1);
this.ScaleTo(scale_when_full, duration, Easing.OutExpo);
this.MoveToY(MedalOverlay.DISC_SIZE / 2 - 60, duration, Easing.OutExpo);
unlocked.Show();
name.FadeInFromZero(duration + 100);
description.FadeInFromZero(duration * 2);
break;
}
}
}
public enum DisplayState
{
None,
Icon,
MedalUnlocked,
Full,
}
}