Merge branch 'master' into improve-alternate-after-break

This commit is contained in:
Bartłomiej Dach 2022-05-02 11:38:44 +02:00 committed by GitHub
commit b1056e5582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 76 deletions

View File

@ -4,11 +4,11 @@
using System.Linq;
using NUnit.Framework;
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.Overlays;
using osu.Game.Overlays.BeatmapSet;
using osu.Game.Rulesets;
namespace osu.Game.Tests.Visual.Online
{
@ -17,79 +17,86 @@ namespace osu.Game.Tests.Visual.Online
[Cached]
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]
private IRulesetStore rulesets { get; set; }
[Test]
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]
public void TestMultipleRulesetsBeatmapSet()
{
var enabledRulesets = rulesets.AvailableRulesets.Skip(1).Take(2);
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
{
Beatmaps = new[]
{
new APIBeatmap
{
RulesetID = enabledRuleset.OnlineID
}
new APIBeatmap { RulesetID = 1 },
new APIBeatmap { RulesetID = 2 },
}
};
});
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]
public void TestEmptyBeatmapSet()
{
AddStep("load empty beatmapset", () => selector.BeatmapSet = new APIBeatmapSet());
AddAssert("no ruleset selected", () => selector.SelectedTab == null);
AddAssert("all rulesets disabled", () => selector.TabContainer.TabItems.All(t => !t.Enabled.Value));
AddAssert("all rulesets disabled", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().All(t => !t.Active.Value && !t.Enabled.Value));
}
[Test]
public void TestNullBeatmapSet()
{
AddStep("load null beatmapset", () => selector.BeatmapSet = null);
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;
AddAssert("all rulesets disabled", () => selector.ChildrenOfType<BeatmapRulesetTabItem>().All(t => !t.Active.Value && !t.Enabled.Value));
}
}
}

View File

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

View File

@ -99,6 +99,8 @@ namespace osu.Game.Overlays.FirstRunSetup
private class NestedSongSelect : PlaySongSelect
{
protected override bool ControlGlobalMusic => false;
public override bool? AllowTrackAdjustments => false;
}
private class PinnedMainMenu : MainMenu

View File

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

View File

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