1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 14:32:55 +08:00

Merge pull request #18021 from frenzibyte/overlay-ruleset-selector-redesign

Update overlay ruleset selector inline with osu-web design
This commit is contained in:
Dean Herbert 2022-05-02 17:53:01 +09:00 committed by GitHub
commit 53d65e8215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 76 deletions

View File

@ -4,11 +4,11 @@
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapSet; using osu.Game.Overlays.BeatmapSet;
using osu.Game.Rulesets;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -17,79 +17,86 @@ namespace osu.Game.Tests.Visual.Online
[Cached] [Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private readonly TestRulesetSelector selector; private BeatmapRulesetSelector selector;
public TestSceneBeatmapRulesetSelector() [SetUp]
public void SetUp() => Schedule(() => Child = selector = new BeatmapRulesetSelector
{ {
Add(selector = new TestRulesetSelector()); Anchor = Anchor.Centre,
} Origin = Anchor.Centre,
BeatmapSet = new APIBeatmapSet(),
});
[Resolved] [Test]
private IRulesetStore rulesets { get; set; } public void TestDisplay()
{
AddSliderStep("osu", 0, 100, 0, v => updateBeatmaps(0, v));
AddSliderStep("taiko", 0, 100, 0, v => updateBeatmaps(1, v));
AddSliderStep("fruits", 0, 100, 0, v => updateBeatmaps(2, v));
AddSliderStep("mania", 0, 100, 0, v => updateBeatmaps(3, v));
void updateBeatmaps(int ruleset, int count)
{
if (selector == null)
return;
selector.BeatmapSet = new APIBeatmapSet
{
Beatmaps = selector.BeatmapSet.Beatmaps
.Where(b => b.Ruleset.OnlineID != ruleset)
.Concat(Enumerable.Range(0, count).Select(_ => new APIBeatmap { RulesetID = ruleset }))
.ToArray(),
};
}
}
[Test] [Test]
public void TestMultipleRulesetsBeatmapSet() public void TestMultipleRulesetsBeatmapSet()
{ {
var enabledRulesets = rulesets.AvailableRulesets.Skip(1).Take(2);
AddStep("load multiple rulesets beatmapset", () => AddStep("load multiple rulesets beatmapset", () =>
{
selector.BeatmapSet = new APIBeatmapSet
{
Beatmaps = enabledRulesets.Select(r => new APIBeatmap { RulesetID = r.OnlineID }).ToArray()
};
});
var tabItems = selector.TabContainer.TabItems;
AddAssert("other rulesets disabled", () => tabItems.Except(tabItems.Where(t => enabledRulesets.Any(r => r.Equals(t.Value)))).All(t => !t.Enabled.Value));
AddAssert("left-most ruleset selected", () => tabItems.First(t => t.Enabled.Value).Active.Value);
}
[Test]
public void TestSingleRulesetBeatmapSet()
{
var enabledRuleset = rulesets.AvailableRulesets.Last();
AddStep("load single ruleset beatmapset", () =>
{ {
selector.BeatmapSet = new APIBeatmapSet selector.BeatmapSet = new APIBeatmapSet
{ {
Beatmaps = new[] Beatmaps = new[]
{ {
new APIBeatmap new APIBeatmap { RulesetID = 1 },
{ new APIBeatmap { RulesetID = 2 },
RulesetID = enabledRuleset.OnlineID
}
} }
}; };
}); });
AddAssert("single ruleset selected", () => selector.SelectedTab.Value.Equals(enabledRuleset)); AddAssert("osu disabled", () => !selector.ChildrenOfType<BeatmapRulesetTabItem>().Single(t => t.Value.OnlineID == 0).Enabled.Value);
AddAssert("mania disabled", () => !selector.ChildrenOfType<BeatmapRulesetTabItem>().Single(t => t.Value.OnlineID == 3).Enabled.Value);
AddAssert("taiko selected", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().Single(t => t.Active.Value).Value.OnlineID == 1);
}
[Test]
public void TestSingleRulesetBeatmapSet()
{
AddStep("load single ruleset beatmapset", () =>
{
selector.BeatmapSet = new APIBeatmapSet
{
Beatmaps = new[] { new APIBeatmap { RulesetID = 3 } }
};
});
AddAssert("single ruleset selected", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().Single(t => t.Active.Value).Value.OnlineID == 3);
} }
[Test] [Test]
public void TestEmptyBeatmapSet() public void TestEmptyBeatmapSet()
{ {
AddStep("load empty beatmapset", () => selector.BeatmapSet = new APIBeatmapSet()); AddStep("load empty beatmapset", () => selector.BeatmapSet = new APIBeatmapSet());
AddAssert("all rulesets disabled", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().All(t => !t.Active.Value && !t.Enabled.Value));
AddAssert("no ruleset selected", () => selector.SelectedTab == null);
AddAssert("all rulesets disabled", () => selector.TabContainer.TabItems.All(t => !t.Enabled.Value));
} }
[Test] [Test]
public void TestNullBeatmapSet() public void TestNullBeatmapSet()
{ {
AddStep("load null beatmapset", () => selector.BeatmapSet = null); AddStep("load null beatmapset", () => selector.BeatmapSet = null);
AddAssert("all rulesets disabled", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().All(t => !t.Active.Value && !t.Enabled.Value));
AddAssert("no ruleset selected", () => selector.SelectedTab == null);
AddAssert("all rulesets disabled", () => selector.TabContainer.TabItems.All(t => !t.Enabled.Value));
}
private class TestRulesetSelector : BeatmapRulesetSelector
{
public new TabItem<RulesetInfo> SelectedTab => base.SelectedTab;
public new TabFillFlowContainer TabContainer => base.TabContainer;
} }
} }
} }

View File

@ -17,7 +17,7 @@ namespace osu.Game.Tests.Visual.Online
public class TestSceneProfileRulesetSelector : OsuTestScene public class TestSceneProfileRulesetSelector : OsuTestScene
{ {
[Cached] [Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green); private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Pink);
public TestSceneProfileRulesetSelector() public TestSceneProfileRulesetSelector()
{ {
@ -32,14 +32,14 @@ namespace osu.Game.Tests.Visual.Online
}; };
AddStep("set osu! as default", () => selector.SetDefaultRuleset(new OsuRuleset().RulesetInfo)); AddStep("set osu! as default", () => selector.SetDefaultRuleset(new OsuRuleset().RulesetInfo));
AddStep("set mania as default", () => selector.SetDefaultRuleset(new ManiaRuleset().RulesetInfo));
AddStep("set taiko as default", () => selector.SetDefaultRuleset(new TaikoRuleset().RulesetInfo)); AddStep("set taiko as default", () => selector.SetDefaultRuleset(new TaikoRuleset().RulesetInfo));
AddStep("set catch as default", () => selector.SetDefaultRuleset(new CatchRuleset().RulesetInfo)); AddStep("set catch as default", () => selector.SetDefaultRuleset(new CatchRuleset().RulesetInfo));
AddStep("set mania as default", () => selector.SetDefaultRuleset(new ManiaRuleset().RulesetInfo));
AddStep("User with osu as default", () => user.Value = new APIUser { PlayMode = "osu" }); AddStep("User with osu as default", () => user.Value = new APIUser { Id = 0, PlayMode = "osu" });
AddStep("User with mania as default", () => user.Value = new APIUser { PlayMode = "mania" }); AddStep("User with taiko as default", () => user.Value = new APIUser { Id = 1, PlayMode = "taiko" });
AddStep("User with taiko as default", () => user.Value = new APIUser { PlayMode = "taiko" }); AddStep("User with catch as default", () => user.Value = new APIUser { Id = 2, PlayMode = "fruits" });
AddStep("User with catch as default", () => user.Value = new APIUser { PlayMode = "fruits" }); AddStep("User with mania as default", () => user.Value = new APIUser { Id = 3, PlayMode = "mania" });
AddStep("null user", () => user.Value = null); AddStep("null user", () => user.Value = null);
} }
} }

View File

@ -5,18 +5,18 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osuTK.Graphics; using osuTK.Graphics;
using osuTK; using osuTK;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class OverlayRulesetTabItem : TabItem<RulesetInfo> public class OverlayRulesetTabItem : TabItem<RulesetInfo>, IHasTooltip
{ {
private Color4 accentColour; private Color4 accentColour;
@ -26,7 +26,7 @@ namespace osu.Game.Overlays
set set
{ {
accentColour = value; accentColour = value;
text.FadeColour(value, 120, Easing.OutQuint); icon.FadeColour(value, 120, Easing.OutQuint);
} }
} }
@ -35,7 +35,9 @@ namespace osu.Game.Overlays
[Resolved] [Resolved]
private OverlayColourProvider colourProvider { get; set; } private OverlayColourProvider colourProvider { get; set; }
private readonly OsuSpriteText text; private readonly Drawable icon;
public LocalisableString TooltipText => Value.Name;
public OverlayRulesetTabItem(RulesetInfo value) public OverlayRulesetTabItem(RulesetInfo value)
: base(value) : base(value)
@ -48,15 +50,14 @@ namespace osu.Game.Overlays
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(3, 0), Spacing = new Vector2(4, 0),
Child = text = new OsuSpriteText Child = icon = new ConstrainedIconContainer
{ {
Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Text = value.Name, Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 14), Size = new Vector2(20f),
ShadowColour = Color4.Black.Opacity(0.75f) Icon = value.CreateInstance().CreateIcon(),
} },
}, },
new HoverClickSounds() new HoverClickSounds()
}); });
@ -70,7 +71,7 @@ namespace osu.Game.Overlays
Enabled.BindValueChanged(_ => updateState(), true); Enabled.BindValueChanged(_ => updateState(), true);
} }
public override bool PropagatePositionalInputSubTree => Enabled.Value && !Active.Value && base.PropagatePositionalInputSubTree; public override bool PropagatePositionalInputSubTree => Enabled.Value && base.PropagatePositionalInputSubTree;
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
@ -91,7 +92,6 @@ namespace osu.Game.Overlays
private void updateState() private void updateState()
{ {
text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium);
AccentColour = Enabled.Value ? getActiveColour() : colourProvider.Foreground1; AccentColour = Enabled.Value ? getActiveColour() : colourProvider.Foreground1;
} }

View File

@ -2,7 +2,10 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -23,7 +26,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
isDefault = value; isDefault = value;
icon.FadeTo(isDefault ? 1 : 0, 200, Easing.OutQuint); icon.Alpha = isDefault ? 1 : 0;
} }
} }
@ -42,15 +45,20 @@ namespace osu.Game.Overlays.Profile.Header.Components
public ProfileRulesetTabItem(RulesetInfo value) public ProfileRulesetTabItem(RulesetInfo value)
: base(value) : base(value)
{ {
Add(icon = new SpriteIcon Add(icon = new DefaultRulesetIcon { Alpha = 0 });
}
public class DefaultRulesetIcon : SpriteIcon, IHasTooltip
{ {
Origin = Anchor.Centre, public LocalisableString TooltipText => UsersStrings.ShowEditDefaultPlaymodeIsDefaultTooltip;
Anchor = Anchor.Centre,
Alpha = 0, public DefaultRulesetIcon()
AlwaysPresent = true, {
Icon = FontAwesome.Solid.Star, Origin = Anchor.Centre;
Size = new Vector2(12), Anchor = Anchor.Centre;
}); Icon = FontAwesome.Solid.Star;
Size = new Vector2(12);
}
} }
} }
} }