2019-01-24 17:43:03 +09: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 18:19:50 +09:00
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-12-20 21:06:40 +09:00
|
|
|
|
using System;
|
2017-05-05 13:00:05 +09:00
|
|
|
|
using System.Collections.Generic;
|
2019-02-21 19:04:31 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-05-05 13:00:05 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-06-09 13:45:09 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-05-05 13:00:05 +09:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-05 13:00:05 +09:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
|
{
|
2021-07-21 15:55:51 +09:00
|
|
|
|
/// <summary>
|
2021-07-21 16:38:18 +09:00
|
|
|
|
/// Displays a single-line horizontal auto-sized flow of mods. For cases where wrapping is required, use <see cref="ModFlowDisplay"/> instead.
|
2021-07-21 15:55:51 +09:00
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class ModDisplay : CompositeDrawable, IHasCurrentValue<IReadOnlyList<Mod>>
|
2017-05-05 13:00:05 +09:00
|
|
|
|
{
|
2017-06-27 05:17:21 +03:00
|
|
|
|
private const int fade_duration = 1000;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-02-13 18:05:53 +09:00
|
|
|
|
public ExpansionMode ExpansionMode = ExpansionMode.ExpandOnHover;
|
2019-05-08 18:42:26 +09:00
|
|
|
|
|
2021-07-21 15:55:51 +09:00
|
|
|
|
private readonly BindableWithCurrent<IReadOnlyList<Mod>> current = new BindableWithCurrent<IReadOnlyList<Mod>>();
|
2018-12-20 21:06:40 +09:00
|
|
|
|
|
2019-04-10 17:13:12 +09:00
|
|
|
|
public Bindable<IReadOnlyList<Mod>> Current
|
2018-12-20 21:06:40 +09:00
|
|
|
|
{
|
2021-07-21 15:55:51 +09:00
|
|
|
|
get => current.Current;
|
2018-12-20 21:06:40 +09:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(value));
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-07-21 15:55:51 +09:00
|
|
|
|
current.Current = value;
|
2018-12-20 21:06:40 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-04-05 14:53:49 -07:00
|
|
|
|
private readonly FillFlowContainer<ModIcon> iconsContainer;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-05 13:00:05 +09:00
|
|
|
|
public ModDisplay()
|
|
|
|
|
{
|
2018-12-12 14:38:03 +09:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
2021-07-21 15:55:51 +09:00
|
|
|
|
InternalChild = iconsContainer = new ReverseChildIDFillFlowContainer<ModIcon>
|
2017-05-05 13:00:05 +09:00
|
|
|
|
{
|
2020-10-15 17:10:35 +09:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2021-07-21 15:55:51 +09:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
2017-05-05 13:00:05 +09:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-05 13:00:05 +09:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2019-05-08 18:42:26 +09:00
|
|
|
|
|
2021-07-21 15:55:51 +09:00
|
|
|
|
Current.BindValueChanged(updateDisplay, true);
|
2021-02-17 21:09:20 +09:00
|
|
|
|
|
2021-07-21 15:55:51 +09:00
|
|
|
|
iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
|
|
|
|
|
}
|
2021-02-17 21:09:20 +09:00
|
|
|
|
|
2021-07-21 15:55:51 +09:00
|
|
|
|
private void updateDisplay(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
|
|
|
|
{
|
|
|
|
|
iconsContainer.Clear();
|
2021-02-17 21:09:20 +09:00
|
|
|
|
|
2021-07-21 15:55:51 +09:00
|
|
|
|
if (mods.NewValue == null) return;
|
|
|
|
|
|
|
|
|
|
foreach (Mod mod in mods.NewValue)
|
|
|
|
|
iconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) });
|
|
|
|
|
|
|
|
|
|
appearTransform();
|
2017-05-05 13:00:05 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-05 13:00:05 +09:00
|
|
|
|
private void appearTransform()
|
|
|
|
|
{
|
2017-05-05 13:17:36 +09:00
|
|
|
|
expand();
|
2019-05-08 18:42:26 +09:00
|
|
|
|
|
2020-04-05 14:53:49 -07:00
|
|
|
|
using (iconsContainer.BeginDelayedSequence(1200))
|
2017-05-05 13:17:36 +09:00
|
|
|
|
contract();
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-05-08 18:42:26 +09:00
|
|
|
|
private void expand()
|
|
|
|
|
{
|
2020-02-13 18:05:53 +09:00
|
|
|
|
if (ExpansionMode != ExpansionMode.AlwaysContracted)
|
2020-04-05 14:53:49 -07:00
|
|
|
|
iconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
|
2019-05-08 18:42:26 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-02-13 18:05:53 +09:00
|
|
|
|
private void contract()
|
|
|
|
|
{
|
|
|
|
|
if (ExpansionMode != ExpansionMode.AlwaysExpanded)
|
2020-04-05 14:53:49 -07:00
|
|
|
|
iconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);
|
2020-02-13 18:05:53 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-05-05 13:17:36 +09:00
|
|
|
|
{
|
|
|
|
|
expand();
|
2018-10-02 12:02:47 +09:00
|
|
|
|
return base.OnHover(e);
|
2017-05-05 13:17:36 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2017-05-05 13:17:36 +09:00
|
|
|
|
{
|
|
|
|
|
contract();
|
2018-10-02 12:02:47 +09:00
|
|
|
|
base.OnHoverLost(e);
|
2017-05-05 13:00:05 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-13 18:05:53 +09: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
|
|
|
|
|
}
|
2017-05-05 13:00:05 +09:00
|
|
|
|
}
|