mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 16:32:54 +08:00
Implement incompatibility-displaying variant of mod panel
This commit is contained in:
parent
bbe2dfa458
commit
713f89a59c
@ -1,14 +1,17 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
@ -38,5 +41,41 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIncompatibilityDisplay()
|
||||
{
|
||||
IncompatibilityDisplayingModPanel panel = null;
|
||||
|
||||
AddStep("create panel with DT", () => Child = panel = new IncompatibilityDisplayingModPanel(new OsuModDoubleTime())
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Width = 300
|
||||
});
|
||||
|
||||
clickPanel();
|
||||
AddAssert("panel active", () => panel.Active.Value);
|
||||
|
||||
clickPanel();
|
||||
AddAssert("panel not active", () => !panel.Active.Value);
|
||||
|
||||
AddStep("set incompatible mod", () => SelectedMods.Value = new[] { new OsuModHalfTime() });
|
||||
|
||||
clickPanel();
|
||||
AddAssert("panel not active", () => !panel.Active.Value);
|
||||
|
||||
AddStep("reset mods", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||
|
||||
clickPanel();
|
||||
AddAssert("panel active", () => panel.Active.Value);
|
||||
|
||||
void clickPanel() => AddStep("click panel", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(panel);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
88
osu.Game/Overlays/Mods/IncompatibilityDisplayingModPanel.cs
Normal file
88
osu.Game/Overlays/Mods/IncompatibilityDisplayingModPanel.cs
Normal file
@ -0,0 +1,88 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
public class IncompatibilityDisplayingModPanel : ModPanel, IHasCustomTooltip<Mod>
|
||||
{
|
||||
private readonly BindableBool incompatible = new BindableBool();
|
||||
|
||||
[Resolved]
|
||||
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; }
|
||||
|
||||
public IncompatibilityDisplayingModPanel(Mod mod)
|
||||
: base(mod)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
selectedMods.BindValueChanged(_ => updateIncompatibility(), true);
|
||||
incompatible.BindValueChanged(_ => Scheduler.AddOnce(UpdateState));
|
||||
// base call will run `UpdateState()` first time and finish transforms.
|
||||
base.LoadComplete();
|
||||
}
|
||||
|
||||
private void updateIncompatibility()
|
||||
{
|
||||
incompatible.Value = selectedMods.Value.Count > 0 && !selectedMods.Value.Contains(Mod) && !ModUtils.CheckCompatibleSet(selectedMods.Value.Append(Mod));
|
||||
}
|
||||
|
||||
protected override void UpdateState()
|
||||
{
|
||||
Action = incompatible.Value ? () => { } : (Action)Active.Toggle;
|
||||
|
||||
if (incompatible.Value)
|
||||
{
|
||||
Colour4 backgroundColour = ColourProvider.Background5;
|
||||
Colour4 textBackgroundColour = ColourProvider.Background4;
|
||||
|
||||
Content.TransformTo(nameof(BorderColour), ColourInfo.GradientVertical(backgroundColour, textBackgroundColour), TRANSITION_DURATION, Easing.OutQuint);
|
||||
Background.FadeColour(backgroundColour, TRANSITION_DURATION, Easing.OutQuint);
|
||||
|
||||
SwitchContainer.ResizeWidthTo(IDLE_SWITCH_WIDTH, TRANSITION_DURATION, Easing.OutQuint);
|
||||
SwitchContainer.FadeColour(Colour4.Gray, TRANSITION_DURATION, Easing.OutQuint);
|
||||
MainContentContainer.TransformTo(nameof(Padding), new MarginPadding
|
||||
{
|
||||
Left = IDLE_SWITCH_WIDTH,
|
||||
Right = CORNER_RADIUS
|
||||
}, TRANSITION_DURATION, Easing.OutQuint);
|
||||
|
||||
TextBackground.FadeColour(textBackgroundColour, TRANSITION_DURATION, Easing.OutQuint);
|
||||
TextFlow.FadeColour(Colour4.White.Opacity(0.5f), TRANSITION_DURATION, Easing.OutQuint);
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchContainer.FadeColour(Colour4.White, TRANSITION_DURATION, Easing.OutQuint);
|
||||
base.UpdateState();
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
if (incompatible.Value)
|
||||
return true; // bypasses base call purposely in order to not play out the intermediate state animation.
|
||||
|
||||
return base.OnMouseDown(e);
|
||||
}
|
||||
|
||||
#region IHasCustomTooltip
|
||||
|
||||
public ITooltip<Mod> GetCustomTooltip() => new IncompatibilityDisplayingTooltip();
|
||||
|
||||
public Mod TooltipContent => Mod;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user