1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 06:47:24 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/ModDisplay.cs

124 lines
3.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;
2018-04-13 17:19:50 +08:00
using System.Collections.Generic;
using System.Linq;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
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;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.Containers;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Play.HUD
{
public class ModDisplay : Container, IHasCurrentValue<IReadOnlyList<Mod>>
2018-04-13 17:19:50 +08:00
{
private const int fade_duration = 1000;
2018-12-12 13:38:03 +08:00
public bool DisplayUnrankedText = true;
private readonly Bindable<IReadOnlyList<Mod>> current = new Bindable<IReadOnlyList<Mod>>();
public Bindable<IReadOnlyList<Mod>> Current
{
get => current;
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
2018-04-13 17:19:50 +08:00
current.UnbindBindings();
current.BindTo(value);
}
}
2018-04-13 17:19:50 +08:00
private readonly FillFlowContainer<ModIcon> iconsContainer;
private readonly OsuSpriteText unrankedText;
public ModDisplay()
{
2018-12-12 13:38:03 +08:00
AutoSizeAxes = Axes.Both;
2018-04-13 17:19:50 +08:00
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
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.TopCentre,
Text = @"/ UNRANKED /",
Font = OsuFont.Numeric.With(size: 12)
2018-04-13 17:19:50 +08:00
}
};
Current.ValueChanged += mods =>
2018-04-13 17:19:50 +08:00
{
iconsContainer.Clear();
foreach (Mod mod in mods.NewValue)
2018-04-13 17:19:50 +08:00
{
iconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) });
}
if (IsLoaded)
appearTransform();
};
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
Current.UnbindAll();
}
2018-04-13 17:19:50 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
appearTransform();
}
private void appearTransform()
{
if (DisplayUnrankedText && Current.Value.Any(m => !m.Ranked))
2018-04-13 17:19:50 +08:00
unrankedText.FadeInFromZero(fade_duration, Easing.OutQuint);
else
unrankedText.Hide();
iconsContainer.FinishTransforms();
iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
expand();
using (iconsContainer.BeginDelayedSequence(1200))
contract();
}
private void expand() => iconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
private void contract() => iconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
2018-04-13 17:19:50 +08:00
{
expand();
2018-10-02 11:02:47 +08:00
return base.OnHover(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override void OnHoverLost(HoverLostEvent e)
2018-04-13 17:19:50 +08:00
{
contract();
2018-10-02 11:02:47 +08:00
base.OnHoverLost(e);
2018-04-13 17:19:50 +08:00
}
}
}