1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 03:02:54 +08:00

Refactor how the sidebar buttons are created/used

This commit is contained in:
Drew DeVault 2016-11-07 18:04:49 -05:00
parent e6c3fc1091
commit b2bbdfa284
12 changed files with 98 additions and 105 deletions

View File

@ -1,11 +1,13 @@
using System; using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class AudioOptions : OptionsSection public class AudioOptions : OptionsSection
{ {
protected override string Header => "Audio"; protected override string Header => "Audio";
public override FontAwesome Icon => FontAwesome.fa_headphones;
public AudioOptions() public AudioOptions()
{ {

View File

@ -2,12 +2,14 @@
using OpenTK; using OpenTK;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class EditorOptions : OptionsSection public class EditorOptions : OptionsSection
{ {
protected override string Header => "Editor"; protected override string Header => "Editor";
public override FontAwesome Icon => FontAwesome.fa_pencil;
public EditorOptions() public EditorOptions()
{ {

View File

@ -1,11 +1,13 @@
using System; using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class GameplayOptions : OptionsSection public class GameplayOptions : OptionsSection
{ {
protected override string Header => "Gameplay"; protected override string Header => "Gameplay";
public override FontAwesome Icon => FontAwesome.fa_circle_o;
public GameplayOptions() public GameplayOptions()
{ {

View File

@ -4,6 +4,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Graphics;
using osu.Game.Online.API; using osu.Game.Online.API;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
@ -11,6 +12,7 @@ namespace osu.Game.Overlays.Options
public class GeneralOptions : OptionsSection public class GeneralOptions : OptionsSection
{ {
protected override string Header => "General"; protected override string Header => "General";
public override FontAwesome Icon => FontAwesome.fa_gear;
public GeneralOptions() public GeneralOptions()
{ {

View File

@ -1,11 +1,13 @@
using System; using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class GraphicsOptions : OptionsSection public class GraphicsOptions : OptionsSection
{ {
protected override string Header => "Graphics"; protected override string Header => "Graphics";
public override FontAwesome Icon => FontAwesome.fa_laptop;
public GraphicsOptions() public GraphicsOptions()
{ {

View File

@ -1,11 +1,13 @@
using System; using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class InputOptions : OptionsSection public class InputOptions : OptionsSection
{ {
protected override string Header => "Input"; protected override string Header => "Input";
public override FontAwesome Icon => FontAwesome.fa_keyboard_o;
public InputOptions() public InputOptions()
{ {

View File

@ -2,6 +2,7 @@
using OpenTK; using OpenTK;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
@ -9,6 +10,7 @@ namespace osu.Game.Overlays.Options
public class MaintenanceOptions : OptionsSection public class MaintenanceOptions : OptionsSection
{ {
protected override string Header => "Maintenance"; protected override string Header => "Maintenance";
public override FontAwesome Icon => FontAwesome.fa_wrench;
public MaintenanceOptions() public MaintenanceOptions()
{ {

View File

@ -1,11 +1,13 @@
using System; using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class OnlineOptions : OptionsSection public class OnlineOptions : OptionsSection
{ {
protected override string Header => "Online"; protected override string Header => "Online";
public override FontAwesome Icon => FontAwesome.fa_globe;
public OnlineOptions() public OnlineOptions()
{ {

View File

@ -5,6 +5,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
@ -13,6 +14,7 @@ namespace osu.Game.Overlays.Options
protected FlowContainer content; protected FlowContainer content;
protected override Container Content => content; protected override Container Content => content;
public abstract FontAwesome Icon { get; }
protected abstract string Header { get; } protected abstract string Header { get; }
public OptionsSection() public OptionsSection()

View File

@ -5,83 +5,29 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Graphics;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
{ {
public class OptionsSideNav : Container public class OptionsSideNav : Container
{ {
public Action GeneralAction; private FlowContainer content;
public Action GraphicsAction; protected override Container Content => content;
public Action GameplayAction;
public Action AudioAction;
public Action SkinAction;
public Action InputAction;
public Action EditorAction;
public Action OnlineAction;
public Action MaintenanceAction;
public OptionsSideNav() public OptionsSideNav()
{ {
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Children = new Drawable[] InternalChildren = new Drawable[]
{ {
new FlowContainer content = new FlowContainer
{ {
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Direction = FlowDirection.VerticalOnly, Direction = FlowDirection.VerticalOnly
Children = new[]
{
new SidebarButton
{
Icon = Graphics.FontAwesome.gear,
Action = () => GeneralAction(),
},
new SidebarButton
{
Icon = Graphics.FontAwesome.laptop,
Action = () => GraphicsAction(),
},
new SidebarButton
{
Icon = Graphics.FontAwesome.circle_o,
Action = () => GameplayAction(),
},
new SidebarButton
{
Icon = Graphics.FontAwesome.headphones,
Action = () => AudioAction(),
},
new SidebarButton
{
Icon = Graphics.FontAwesome.fa_paint_brush,
Action = () => SkinAction(),
},
new SidebarButton
{
Icon = Graphics.FontAwesome.keyboard_o,
Action = () => InputAction(),
},
new SidebarButton
{
Icon = Graphics.FontAwesome.pencil,
Action = () => EditorAction(),
},
new SidebarButton
{
Icon = Graphics.FontAwesome.globe,
Action = () => {
OnlineAction();
}
},
new SidebarButton
{
Icon = Graphics.FontAwesome.wrench,
Action = () => MaintenanceAction(),
}
}
}, },
new Box new Box
{ {
@ -94,26 +40,54 @@ namespace osu.Game.Overlays.Options
}; };
} }
private class SidebarButton : Container public class SidebarButton : Container
{ {
private ToolbarButton button; private TextAwesome drawableIcon;
private Box backgroundBox;
public Action Action;
public Action Action public FontAwesome Icon
{ {
get { return button.Action; } get { return drawableIcon.Icon; }
set { button.Action = value; } set { drawableIcon.Icon = value; }
}
public Graphics.FontAwesome Icon
{
get { return button.Icon; }
set { button.Icon = value; }
} }
public SidebarButton() public SidebarButton()
{ {
Size = new Vector2(60); Size = new Vector2(60);
Children = new[] { button = new ToolbarButton() }; Children = new Drawable[]
{
backgroundBox = new Box
{
RelativeSizeAxes = Axes.Both,
BlendingMode = BlendingMode.Additive,
Colour = new Color4(60, 60, 60, 255),
Alpha = 0,
},
drawableIcon = new TextAwesome
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
};
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs e)
{
Action?.Invoke();
backgroundBox.FlashColour(Color4.White, 400);
return true;
}
protected override bool OnHover(InputState state)
{
backgroundBox.FadeTo(0.4f, 200);
return true;
}
protected override void OnHoverLost(InputState state)
{
backgroundBox.FadeTo(0, 200);
} }
} }
} }

View File

@ -3,6 +3,7 @@ using OpenTK;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Options namespace osu.Game.Overlays.Options
@ -10,6 +11,7 @@ namespace osu.Game.Overlays.Options
public class SkinOptions : OptionsSection public class SkinOptions : OptionsSection
{ {
protected override string Header => "Skin"; protected override string Header => "Skin";
public override FontAwesome Icon => FontAwesome.fa_paint_brush;
public SkinOptions() public SkinOptions()
{ {

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.Diagnostics; using System.Diagnostics;
using System.Linq;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
@ -29,16 +30,6 @@ namespace osu.Game.Overlays
private ScrollContainer scrollContainer; private ScrollContainer scrollContainer;
private FlowContainer flowContainer; private FlowContainer flowContainer;
private GeneralOptions generalOptions;
private GraphicsOptions graphicsOptions;
private GameplayOptions gameplayOptions;
private AudioOptions audioOptions;
private SkinOptions skinOptions;
private InputOptions inputOptions;
private EditorOptions editorOptions;
private OnlineOptions onlineOptions;
private MaintenanceOptions maintenanceOptions;
public OptionsOverlay() public OptionsOverlay()
{ {
@ -47,6 +38,19 @@ namespace osu.Game.Overlays
Size = new Vector2(width, 1); Size = new Vector2(width, 1);
Position = new Vector2(-width, 0); Position = new Vector2(-width, 0);
var sections = new OptionsSection[]
{
new GeneralOptions(),
new GraphicsOptions(),
new GameplayOptions(),
new AudioOptions(),
new SkinOptions(),
new InputOptions(),
new EditorOptions(),
new OnlineOptions(),
new MaintenanceOptions(),
};
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -61,10 +65,9 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = width - (sideNavWidth + sideNavPadding * 2), Width = width - (sideNavWidth + sideNavPadding * 2),
Position = new Vector2(sideNavWidth + sideNavPadding * 2, 0), Position = new Vector2(sideNavWidth + sideNavPadding * 2, 0),
// Note: removing this comment causes... compiler bugs? It's weird.2
Children = new[] Children = new[]
{ {
flowContainer = new FlowContainer new FlowContainer
{ {
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -84,15 +87,12 @@ namespace osu.Game.Overlays
TextSize = 18, TextSize = 18,
Margin = new MarginPadding { Left = SideMargins, Bottom = 30 }, Margin = new MarginPadding { Left = SideMargins, Bottom = 30 },
}, },
generalOptions = new GeneralOptions(), flowContainer = new FlowContainer
graphicsOptions = new GraphicsOptions(), {
gameplayOptions = new GameplayOptions(), AutoSizeAxes = Axes.Y,
audioOptions = new AudioOptions(), RelativeSizeAxes = Axes.X,
skinOptions = new SkinOptions(), Direction = FlowDirection.VerticalOnly,
inputOptions = new InputOptions(), }
editorOptions = new EditorOptions(),
onlineOptions = new OnlineOptions(),
maintenanceOptions = new MaintenanceOptions(),
} }
} }
} }
@ -101,17 +101,16 @@ namespace osu.Game.Overlays
{ {
Padding = new MarginPadding { Left = sideNavPadding, Right = sideNavPadding }, Padding = new MarginPadding { Left = sideNavPadding, Right = sideNavPadding },
Width = sideNavWidth + sideNavPadding * 2, Width = sideNavWidth + sideNavPadding * 2,
GeneralAction = () => scrollContainer.ScrollIntoView(generalOptions), Children = sections.Select(section =>
GraphicsAction = () => scrollContainer.ScrollIntoView(graphicsOptions), new OptionsSideNav.SidebarButton
GameplayAction = () => scrollContainer.ScrollIntoView(gameplayOptions), {
AudioAction = () => scrollContainer.ScrollIntoView(audioOptions), Icon = section.Icon,
SkinAction = () => scrollContainer.ScrollIntoView(skinOptions), Action = () => scrollContainer.ScrollIntoView(section)
InputAction = () => scrollContainer.ScrollIntoView(inputOptions), }
EditorAction = () => scrollContainer.ScrollIntoView(editorOptions), )
OnlineAction = () => scrollContainer.ScrollIntoView(onlineOptions),
MaintenanceAction = () => scrollContainer.ScrollIntoView(maintenanceOptions),
} }
}; };
flowContainer.Add(sections);
} }
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;