Make settings more modular

This commit is contained in:
Dean Herbert
2017-08-10 22:21:22 +09:00
parent 384b8c0600
commit 66fa84a451
8 changed files with 101 additions and 21 deletions

View File

@ -0,0 +1,44 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Overlays;
using osu.Game.Overlays.Settings;
using System.Collections.Generic;
using osu.Game.Graphics;
namespace osu.Desktop.Tests.Visual
{
public class TestCaseKeyConfiguration : OsuTestCase
{
private readonly KeyConfiguration configuration;
public override string Description => @"Key configuration";
public TestCaseKeyConfiguration()
{
Child = configuration = new KeyConfiguration();
}
protected override void LoadComplete()
{
base.LoadComplete();
configuration.Show();
}
}
public class KeyConfiguration : SettingsOverlay
{
protected override IEnumerable<SettingsSection> CreateSections() => new[]
{
new BindingsSection(),
new BindingsSection()
};
}
public class BindingsSection : SettingsSection
{
public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail;
public override string Header => "Header";
}
}

View File

@ -13,7 +13,7 @@ namespace osu.Desktop.Tests.Visual
public TestCaseSettings() public TestCaseSettings()
{ {
Children = new[] { settings = new SettingsOverlay() }; Children = new[] { settings = new MainSettings() };
} }
protected override void LoadComplete() protected override void LoadComplete()

View File

@ -81,6 +81,7 @@
<Compile Include="Visual\TestCaseGamefield.cs" /> <Compile Include="Visual\TestCaseGamefield.cs" />
<Compile Include="Visual\TestCaseGraph.cs" /> <Compile Include="Visual\TestCaseGraph.cs" />
<Compile Include="Visual\TestCaseHitObjects.cs" /> <Compile Include="Visual\TestCaseHitObjects.cs" />
<Compile Include="Visual\TestCaseKeyConfiguration.cs" />
<Compile Include="Visual\TestCaseKeyCounter.cs" /> <Compile Include="Visual\TestCaseKeyCounter.cs" />
<Compile Include="Visual\TestCaseLeaderboard.cs" /> <Compile Include="Visual\TestCaseLeaderboard.cs" />
<Compile Include="Visual\TestCaseManiaHitObjects.cs" /> <Compile Include="Visual\TestCaseManiaHitObjects.cs" />

View File

@ -182,7 +182,7 @@ namespace osu.Game
LoadComponentAsync(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(direct = new DirectOverlay { Depth = -1 }, mainContent.Add);
LoadComponentAsync(social = new SocialOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(social = new SocialOverlay { Depth = -1 }, mainContent.Add);
LoadComponentAsync(chat = new ChatOverlay { Depth = -1 }, mainContent.Add); LoadComponentAsync(chat = new ChatOverlay { Depth = -1 }, mainContent.Add);
LoadComponentAsync(settings = new SettingsOverlay { Depth = -1 }, overlayContent.Add); LoadComponentAsync(settings = new MainSettings { Depth = -1 }, overlayContent.Add);
LoadComponentAsync(userProfile = new UserProfileOverlay { Depth = -2 }, mainContent.Add); LoadComponentAsync(userProfile = new UserProfileOverlay { Depth = -2 }, mainContent.Add);
LoadComponentAsync(musicController = new MusicController LoadComponentAsync(musicController = new MusicController
{ {

View File

@ -0,0 +1,29 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
namespace osu.Game.Overlays
{
public class MainSettings : SettingsOverlay
{
protected override IEnumerable<SettingsSection> CreateSections() => new SettingsSection[]
{
new GeneralSection(),
new GraphicsSection(),
new GameplaySection(),
new AudioSection(),
new SkinSection(),
new InputSection(),
new OnlineSection(),
new MaintenanceSection(),
new DebugSection(),
};
protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves");
protected override Drawable CreateFooter() => new SettingsFooter();
}
}

View File

@ -11,6 +11,15 @@ namespace osu.Game.Overlays.Settings
{ {
public class SettingsHeader : Container public class SettingsHeader : Container
{ {
private readonly string heading;
private readonly string subheading;
public SettingsHeader(string heading, string subheading)
{
this.heading = heading;
this.subheading = subheading;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
@ -28,7 +37,7 @@ namespace osu.Game.Overlays.Settings
{ {
new OsuSpriteText new OsuSpriteText
{ {
Text = "settings", Text = heading,
TextSize = 40, TextSize = 40,
Margin = new MarginPadding Margin = new MarginPadding
{ {
@ -39,7 +48,7 @@ namespace osu.Game.Overlays.Settings
new OsuSpriteText new OsuSpriteText
{ {
Colour = colours.Pink, Colour = colours.Pink,
Text = "Change the way osu! behaves", Text = subheading,
TextSize = 18, TextSize = 18,
Margin = new MarginPadding Margin = new MarginPadding
{ {

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -12,11 +13,10 @@ using osu.Framework.Input;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class SettingsOverlay : OsuFocusedOverlayContainer public abstract class SettingsOverlay : OsuFocusedOverlayContainer
{ {
internal const float CONTENT_MARGINS = 10; internal const float CONTENT_MARGINS = 10;
@ -38,27 +38,19 @@ namespace osu.Game.Overlays
private Func<float> getToolbarHeight; private Func<float> getToolbarHeight;
public SettingsOverlay() protected SettingsOverlay()
{ {
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
} }
protected abstract IEnumerable<SettingsSection> CreateSections();
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game) private void load(OsuGame game)
{ {
var sections = new SettingsSection[] var sections = CreateSections().ToList();
{
new GeneralSection(),
new GraphicsSection(),
new GameplaySection(),
new AudioSection(),
new SkinSection(),
new InputSection(),
new OnlineSection(),
new MaintenanceSection(),
new DebugSection(),
};
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -72,7 +64,7 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = width, Width = width,
Margin = new MarginPadding { Left = SIDEBAR_WIDTH }, Margin = new MarginPadding { Left = SIDEBAR_WIDTH },
ExpandableHeader = new SettingsHeader(), ExpandableHeader = CreateHeader(),
FixedHeader = searchTextBox = new SearchTextBox FixedHeader = searchTextBox = new SearchTextBox
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -87,7 +79,7 @@ namespace osu.Game.Overlays
Exit = Hide, Exit = Hide,
}, },
Children = sections, Children = sections,
Footer = new SettingsFooter() Footer = CreateFooter()
}, },
sidebar = new Sidebar sidebar = new Sidebar
{ {
@ -121,6 +113,10 @@ namespace osu.Game.Overlays
getToolbarHeight = () => game?.ToolbarOffset ?? 0; getToolbarHeight = () => game?.ToolbarOffset ?? 0;
} }
protected virtual Drawable CreateHeader() => new Container();
protected virtual Drawable CreateFooter() => new Container();
protected override void PopIn() protected override void PopIn()
{ {
base.PopIn(); base.PopIn();

View File

@ -102,6 +102,7 @@
<Compile Include="Online\API\Requests\PostMessageRequest.cs" /> <Compile Include="Online\API\Requests\PostMessageRequest.cs" />
<Compile Include="Online\Chat\ErrorMessage.cs" /> <Compile Include="Online\Chat\ErrorMessage.cs" />
<Compile Include="Overlays\Chat\ChatTabControl.cs" /> <Compile Include="Overlays\Chat\ChatTabControl.cs" />
<Compile Include="Overlays\MainSettings.cs" />
<Compile Include="Overlays\Music\CollectionsDropdown.cs" /> <Compile Include="Overlays\Music\CollectionsDropdown.cs" />
<Compile Include="Overlays\Music\FilterControl.cs" /> <Compile Include="Overlays\Music\FilterControl.cs" />
<Compile Include="Overlays\Music\PlaylistItem.cs" /> <Compile Include="Overlays\Music\PlaylistItem.cs" />