osu/osu.Game/Overlays/MedalSplash/DrawableMedal.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

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