1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00

Merge branch 'master' into showcase-video

This commit is contained in:
Dean Herbert 2020-04-27 08:57:50 +09:00
commit 07513eb171
15 changed files with 117 additions and 28 deletions

View File

@ -5,13 +5,17 @@ using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Overlays.Toolbar;
using osu.Game.Rulesets;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Menus
{
[TestFixture]
public class TestSceneToolbar : OsuTestScene
public class TestSceneToolbar : OsuManualInputManagerTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
@ -21,24 +25,62 @@ namespace osu.Game.Tests.Visual.Menus
typeof(ToolbarNotificationButton),
};
public TestSceneToolbar()
private Toolbar toolbar;
[Resolved]
private RulesetStore rulesets { get; set; }
[SetUp]
public void SetUp() => Schedule(() =>
{
Child = toolbar = new Toolbar { State = { Value = Visibility.Visible } };
});
[Test]
public void TestNotificationCounter()
{
var toolbar = new Toolbar { State = { Value = Visibility.Visible } };
ToolbarNotificationButton notificationButton = null;
AddStep("create toolbar", () =>
{
Add(toolbar);
notificationButton = toolbar.Children.OfType<FillFlowContainer>().Last().Children.OfType<ToolbarNotificationButton>().First();
});
void setNotifications(int count) => AddStep($"set notification count to {count}", () => notificationButton.NotificationCount.Value = count);
AddStep("retrieve notification button", () => notificationButton = toolbar.ChildrenOfType<ToolbarNotificationButton>().Single());
setNotifications(1);
setNotifications(2);
setNotifications(3);
setNotifications(0);
setNotifications(144);
void setNotifications(int count)
=> AddStep($"set notification count to {count}",
() => notificationButton.NotificationCount.Value = count);
}
[TestCase(false)]
[TestCase(true)]
public void TestRulesetSwitchingShortcut(bool toolbarHidden)
{
ToolbarRulesetSelector rulesetSelector = null;
if (toolbarHidden)
AddStep("hide toolbar", () => toolbar.Hide());
AddStep("retrieve ruleset selector", () => rulesetSelector = toolbar.ChildrenOfType<ToolbarRulesetSelector>().Single());
for (int i = 0; i < 4; i++)
{
var expected = rulesets.AvailableRulesets.ElementAt(i);
var numberKey = Key.Number1 + i;
AddStep($"switch to ruleset {i} via shortcut", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.PressKey(numberKey);
InputManager.ReleaseKey(Key.ControlLeft);
InputManager.ReleaseKey(numberKey);
});
AddUntilStep("ruleset switched", () => rulesetSelector.Current.Value.Equals(expected));
}
}
}
}

View File

@ -1,6 +1,7 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Input.Bindings;
using osu.Game.Overlays.Settings;
@ -9,7 +10,11 @@ namespace osu.Game.Overlays.KeyBinding
{
public class GlobalKeyBindingsSection : SettingsSection
{
public override IconUsage Icon => FontAwesome.Solid.Globe;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.Globe
};
public override string Header => "Global";
public GlobalKeyBindingsSection(GlobalActionContainer manager)

View File

@ -1,6 +1,7 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Overlays.Settings;
@ -10,7 +11,11 @@ namespace osu.Game.Overlays.KeyBinding
{
public class RulesetBindingsSection : SettingsSection
{
public override IconUsage Icon => (ruleset.CreateInstance().CreateIcon() as SpriteIcon)?.Icon ?? OsuIcon.Hot;
public override Drawable CreateIcon() => ruleset?.CreateInstance()?.CreateIcon() ?? new SpriteIcon
{
Icon = OsuIcon.Hot
};
public override string Header => ruleset.Name;
private readonly RulesetInfo ruleset;

View File

@ -13,9 +13,12 @@ namespace osu.Game.Overlays.Settings.Sections
{
public override string Header => "Audio";
public override IEnumerable<string> FilterTerms => base.FilterTerms.Concat(new[] { "sound" });
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.VolumeUp
};
public override IconUsage Icon => FontAwesome.Solid.VolumeUp;
public override IEnumerable<string> FilterTerms => base.FilterTerms.Concat(new[] { "sound" });
public AudioSection()
{

View File

@ -10,7 +10,11 @@ namespace osu.Game.Overlays.Settings.Sections
public class DebugSection : SettingsSection
{
public override string Header => "Debug";
public override IconUsage Icon => FontAwesome.Solid.Bug;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.Bug
};
public DebugSection()
{

View File

@ -13,7 +13,11 @@ namespace osu.Game.Overlays.Settings.Sections
public class GameplaySection : SettingsSection
{
public override string Header => "Gameplay";
public override IconUsage Icon => FontAwesome.Regular.Circle;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Regular.Circle
};
public GameplaySection()
{

View File

@ -10,7 +10,11 @@ namespace osu.Game.Overlays.Settings.Sections
public class GeneralSection : SettingsSection
{
public override string Header => "General";
public override IconUsage Icon => FontAwesome.Solid.Cog;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.Cog
};
public GeneralSection()
{

View File

@ -10,7 +10,11 @@ namespace osu.Game.Overlays.Settings.Sections
public class GraphicsSection : SettingsSection
{
public override string Header => "Graphics";
public override IconUsage Icon => FontAwesome.Solid.Laptop;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.Laptop
};
public GraphicsSection()
{

View File

@ -10,7 +10,11 @@ namespace osu.Game.Overlays.Settings.Sections
public class InputSection : SettingsSection
{
public override string Header => "Input";
public override IconUsage Icon => FontAwesome.Regular.Keyboard;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.Keyboard
};
public InputSection(KeyBindingPanel keyConfig)
{

View File

@ -11,7 +11,11 @@ namespace osu.Game.Overlays.Settings.Sections
public class MaintenanceSection : SettingsSection
{
public override string Header => "Maintenance";
public override IconUsage Icon => FontAwesome.Solid.Wrench;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.Wrench
};
public MaintenanceSection()
{

View File

@ -10,7 +10,11 @@ namespace osu.Game.Overlays.Settings.Sections
public class OnlineSection : SettingsSection
{
public override string Header => "Online";
public override IconUsage Icon => FontAwesome.Solid.GlobeAsia;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.GlobeAsia
};
public OnlineSection()
{

View File

@ -19,7 +19,10 @@ namespace osu.Game.Overlays.Settings.Sections
public override string Header => "Skin";
public override IconUsage Icon => FontAwesome.Solid.PaintBrush;
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.PaintBrush
};
private readonly Bindable<SkinInfo> dropdownBindable = new Bindable<SkinInfo> { Default = SkinInfo.Default };
private readonly Bindable<int> configBindable = new Bindable<int>();

View File

@ -11,7 +11,6 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Overlays.Settings
{
@ -20,7 +19,7 @@ namespace osu.Game.Overlays.Settings
protected FillFlowContainer FlowContent;
protected override Container<Drawable> Content => FlowContent;
public abstract IconUsage Icon { get; }
public abstract Drawable CreateIcon();
public abstract string Header { get; }
public IEnumerable<IFilterable> FilterableChildren => Children.OfType<IFilterable>();

View File

@ -11,12 +11,13 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Settings
{
public class SidebarButton : OsuButton
{
private readonly SpriteIcon drawableIcon;
private readonly ConstrainedIconContainer iconContainer;
private readonly SpriteText headerText;
private readonly Box selectionIndicator;
private readonly Container text;
@ -30,7 +31,7 @@ namespace osu.Game.Overlays.Settings
{
section = value;
headerText.Text = value.Header;
drawableIcon.Icon = value.Icon;
iconContainer.Icon = value.CreateIcon();
}
}
@ -78,7 +79,7 @@ namespace osu.Game.Overlays.Settings
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
drawableIcon = new SpriteIcon
iconContainer = new ConstrainedIconContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -33,6 +33,9 @@ namespace osu.Game.Overlays.Toolbar
private readonly Bindable<OverlayActivation> overlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
// Toolbar components like RulesetSelector should receive keyboard input events even when the toolbar is hidden.
public override bool PropagateNonPositionalInputSubTree => true;
public Toolbar()
{
RelativeSizeAxes = Axes.X;
@ -148,7 +151,7 @@ namespace osu.Game.Overlays.Toolbar
protected override void PopOut()
{
userButton?.StateContainer.Hide();
userButton.StateContainer?.Hide();
this.MoveToY(-DrawSize.Y, transition_time, Easing.OutQuint);
this.FadeOut(transition_time);