1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:07:26 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/ModDisplay.cs

103 lines
3.3 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using OpenTK;
2017-05-05 12:17:36 +08:00
using osu.Framework.Input;
using osu.Game.Graphics.Containers;
using System.Linq;
namespace osu.Game.Screens.Play.HUD
{
public class ModDisplay : Container, IHasCurrentValue<IEnumerable<Mod>>
{
private const int fade_duration = 1000;
private readonly Bindable<IEnumerable<Mod>> mods = new Bindable<IEnumerable<Mod>>();
public Bindable<IEnumerable<Mod>> Current => mods;
private readonly FillFlowContainer<ModIcon> iconsContainer;
private readonly OsuSpriteText unrankedText;
public ModDisplay()
{
Children = new Drawable[]
{
iconsContainer = new ReverseChildIDFillFlowContainer<ModIcon>
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Left = 10, Right = 10 },
},
unrankedText = new OsuSpriteText
{
AlwaysPresent = true,
Anchor = Anchor.BottomCentre,
Origin = Anchor.TopCentre,
Text = @"/ UNRANKED /",
Font = @"Venera",
TextSize = 12,
}
};
mods.ValueChanged += mods =>
{
iconsContainer.Clear();
foreach (Mod mod in mods)
{
2017-11-15 23:15:27 +08:00
iconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) });
}
if (IsLoaded)
appearTransform();
};
}
protected override void LoadComplete()
{
base.LoadComplete();
appearTransform();
}
private void appearTransform()
{
2017-07-12 14:42:38 +08:00
if (mods.Value.Any(m => !m.Ranked))
2017-07-23 02:50:25 +08:00
unrankedText.FadeInFromZero(fade_duration, Easing.OutQuint);
else
2017-07-08 17:34:24 +08:00
unrankedText.Hide();
2017-07-21 23:24:09 +08:00
iconsContainer.FinishTransforms();
2017-07-23 02:50:25 +08:00
iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
2017-05-05 12:17:36 +08:00
expand();
using (iconsContainer.BeginDelayedSequence(1200))
2017-05-05 12:17:36 +08:00
contract();
}
2017-07-23 02:50:25 +08:00
private void expand() => iconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
2017-05-05 12:17:36 +08:00
2017-07-23 02:50:25 +08:00
private void contract() => iconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);
2017-05-05 12:17:36 +08:00
protected override bool OnHover(InputState state)
{
expand();
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
contract();
base.OnHoverLost(state);
}
}
}