1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:03:08 +08:00

Merge pull request #13963 from peppy/tidy-mod-display

Tidy up `ModDisplay`
This commit is contained in:
Dan Balasescu 2021-07-21 17:26:39 +09:00 committed by GitHub
commit b556d6d382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 45 deletions

View File

@ -11,10 +11,8 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
public class TestSceneModDisplay : OsuTestScene public class TestSceneModDisplay : OsuTestScene
{ {
[TestCase(ExpansionMode.ExpandOnHover)] [Test]
[TestCase(ExpansionMode.AlwaysExpanded)] public void TestMode([Values] ExpansionMode mode)
[TestCase(ExpansionMode.AlwaysContracted)]
public void TestMode(ExpansionMode mode)
{ {
AddStep("create mod display", () => AddStep("create mod display", () =>
{ {

View File

@ -416,7 +416,6 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Position = new Vector2(-5, 25), Position = new Vector2(-5, 25),
Current = { BindTarget = modSelect.SelectedMods } Current = { BindTarget = modSelect.SelectedMods }
} }

View File

@ -172,7 +172,6 @@ namespace osu.Game.Screens.Play
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Top = 20 }, Margin = new MarginPadding { Top = 20 },
Current = mods Current = mods
}, },

View File

@ -15,24 +15,26 @@ using osuTK;
namespace osu.Game.Screens.Play.HUD namespace osu.Game.Screens.Play.HUD
{ {
public class ModDisplay : Container, IHasCurrentValue<IReadOnlyList<Mod>> /// <summary>
/// Displays a single-line horizontal auto-sized flow of mods.
/// </summary>
public class ModDisplay : CompositeDrawable, IHasCurrentValue<IReadOnlyList<Mod>>
{ {
private const int fade_duration = 1000; private const int fade_duration = 1000;
public ExpansionMode ExpansionMode = ExpansionMode.ExpandOnHover; public ExpansionMode ExpansionMode = ExpansionMode.ExpandOnHover;
private readonly Bindable<IReadOnlyList<Mod>> current = new Bindable<IReadOnlyList<Mod>>(); private readonly BindableWithCurrent<IReadOnlyList<Mod>> current = new BindableWithCurrent<IReadOnlyList<Mod>>();
public Bindable<IReadOnlyList<Mod>> Current public Bindable<IReadOnlyList<Mod>> Current
{ {
get => current; get => current.Current;
set set
{ {
if (value == null) if (value == null)
throw new ArgumentNullException(nameof(value)); throw new ArgumentNullException(nameof(value));
current.UnbindBindings(); current.Current = value;
current.BindTo(value);
} }
} }
@ -42,51 +44,34 @@ namespace osu.Game.Screens.Play.HUD
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Child = new FillFlowContainer InternalChild = iconsContainer = new ReverseChildIDFillFlowContainer<ModIcon>
{ {
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical, Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
iconsContainer = new ReverseChildIDFillFlowContainer<ModIcon>
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
},
},
}; };
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
Current.UnbindAll();
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Current.BindValueChanged(mods => Current.BindValueChanged(updateDisplay, true);
{
iconsContainer.Clear();
if (mods.NewValue != null)
{
foreach (Mod mod in mods.NewValue)
iconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) });
appearTransform();
}
}, true);
iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint); iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
} }
private void updateDisplay(ValueChangedEvent<IReadOnlyList<Mod>> mods)
{
iconsContainer.Clear();
if (mods.NewValue == null) return;
foreach (Mod mod in mods.NewValue)
iconsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.6f) });
appearTransform();
}
private void appearTransform() private void appearTransform()
{ {
expand(); expand();

View File

@ -282,7 +282,6 @@ namespace osu.Game.Screens.Play
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
}; };
protected PlayerSettingsOverlay CreatePlayerSettingsOverlay() => new PlayerSettingsOverlay(); protected PlayerSettingsOverlay CreatePlayerSettingsOverlay() => new PlayerSettingsOverlay();

View File

@ -135,7 +135,6 @@ namespace osu.Game.Screens.Ranking.Contracted
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
ExpansionMode = ExpansionMode.AlwaysExpanded, ExpansionMode = ExpansionMode.AlwaysExpanded,
Current = { Value = score.Mods }, Current = { Value = score.Mods },
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),