2019-01-24 08:43:03 +00:00
|
|
|
|
// 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
|
|
|
|
|
2018-12-20 12:06:40 +00:00
|
|
|
|
using System;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-12-20 12:06:40 +00:00
|
|
|
|
using System.Linq;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00: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 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-02-12 04:04:46 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
|
{
|
2019-04-10 08:13:12 +00:00
|
|
|
|
public class ModDisplay : Container, IHasCurrentValue<IReadOnlyList<Mod>>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
private const int fade_duration = 1000;
|
|
|
|
|
|
2018-12-12 05:38:03 +00:00
|
|
|
|
public bool DisplayUnrankedText = true;
|
|
|
|
|
|
2020-02-13 09:05:53 +00:00
|
|
|
|
public ExpansionMode ExpansionMode = ExpansionMode.ExpandOnHover;
|
2019-05-08 09:42:26 +00:00
|
|
|
|
|
2019-04-10 08:13:12 +00:00
|
|
|
|
private readonly Bindable<IReadOnlyList<Mod>> current = new Bindable<IReadOnlyList<Mod>>();
|
2018-12-20 12:06:40 +00:00
|
|
|
|
|
2019-04-10 08:13:12 +00:00
|
|
|
|
public Bindable<IReadOnlyList<Mod>> Current
|
2018-12-20 12:06:40 +00:00
|
|
|
|
{
|
|
|
|
|
get => current;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(value));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-20 12:06:40 +00:00
|
|
|
|
current.UnbindBindings();
|
|
|
|
|
current.BindTo(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-29 17:59:51 +00:00
|
|
|
|
protected readonly FillFlowContainer<ModIcon> IconsContainer;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private readonly OsuSpriteText unrankedText;
|
|
|
|
|
|
|
|
|
|
public ModDisplay()
|
|
|
|
|
{
|
2018-12-12 05:38:03 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-01-29 17:59:51 +00:00
|
|
|
|
IconsContainer = new ReverseChildIDFillFlowContainer<ModIcon>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
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 /",
|
2019-02-22 10:42:09 +00:00
|
|
|
|
Font = OsuFont.Numeric.With(size: 12)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-20 12:06:40 +00:00
|
|
|
|
Current.ValueChanged += mods =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-01-29 17:59:51 +00:00
|
|
|
|
IconsContainer.Clear();
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2019-02-22 08:51:39 +00:00
|
|
|
|
foreach (Mod mod in mods.NewValue)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-01-29 17:59:51 +00:00
|
|
|
|
IconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) });
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
appearTransform();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 15:15:51 +00:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
2018-12-20 12:06:40 +00:00
|
|
|
|
Current.UnbindAll();
|
2018-08-20 15:15:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2019-05-08 09:42:26 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
appearTransform();
|
2020-01-29 17:59:51 +00:00
|
|
|
|
IconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appearTransform()
|
|
|
|
|
{
|
2018-12-22 05:02:45 +00:00
|
|
|
|
if (DisplayUnrankedText && Current.Value.Any(m => !m.Ranked))
|
2018-04-13 09:19:50 +00:00
|
|
|
|
unrankedText.FadeInFromZero(fade_duration, Easing.OutQuint);
|
|
|
|
|
else
|
|
|
|
|
unrankedText.Hide();
|
|
|
|
|
|
|
|
|
|
expand();
|
2019-05-08 09:42:26 +00:00
|
|
|
|
|
2020-01-29 17:59:51 +00:00
|
|
|
|
using (IconsContainer.BeginDelayedSequence(1200))
|
2018-04-13 09:19:50 +00:00
|
|
|
|
contract();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-08 09:42:26 +00:00
|
|
|
|
private void expand()
|
|
|
|
|
{
|
2020-02-13 09:05:53 +00:00
|
|
|
|
if (ExpansionMode != ExpansionMode.AlwaysContracted)
|
2020-01-29 17:59:51 +00:00
|
|
|
|
IconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
|
2019-05-08 09:42:26 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-02-13 09:05:53 +00:00
|
|
|
|
private void contract()
|
|
|
|
|
{
|
|
|
|
|
if (ExpansionMode != ExpansionMode.AlwaysExpanded)
|
|
|
|
|
IconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
expand();
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnHover(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
contract();
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnHoverLost(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-13 09:05:53 +00:00
|
|
|
|
|
|
|
|
|
public enum ExpansionMode
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The <see cref="ModDisplay"/> will expand only when hovered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
ExpandOnHover,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The <see cref="ModDisplay"/> will always be expanded.
|
|
|
|
|
/// </summary>
|
|
|
|
|
AlwaysExpanded,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The <see cref="ModDisplay"/> will always be contracted.
|
|
|
|
|
/// </summary>
|
|
|
|
|
AlwaysContracted
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|