From b2bbdfa2847e71c7e465e9322337cece9ab69f9b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 7 Nov 2016 18:04:49 -0500 Subject: [PATCH] Refactor how the sidebar buttons are created/used --- osu.Game/Overlays/Options/AudioOptions.cs | 2 + osu.Game/Overlays/Options/EditorOptions.cs | 2 + osu.Game/Overlays/Options/GameplayOptions.cs | 2 + osu.Game/Overlays/Options/GeneralOptions.cs | 2 + osu.Game/Overlays/Options/GraphicsOptions.cs | 2 + osu.Game/Overlays/Options/InputOptions.cs | 2 + .../Overlays/Options/MaintenanceOptions.cs | 2 + osu.Game/Overlays/Options/OnlineOptions.cs | 2 + osu.Game/Overlays/Options/OptionsSection.cs | 2 + osu.Game/Overlays/Options/OptionsSideNav.cs | 124 +++++++----------- osu.Game/Overlays/Options/SkinOptions.cs | 2 + osu.Game/Overlays/OptionsOverlay.cs | 59 ++++----- 12 files changed, 98 insertions(+), 105 deletions(-) diff --git a/osu.Game/Overlays/Options/AudioOptions.cs b/osu.Game/Overlays/Options/AudioOptions.cs index f0d2eeebd0..61067f4ca4 100644 --- a/osu.Game/Overlays/Options/AudioOptions.cs +++ b/osu.Game/Overlays/Options/AudioOptions.cs @@ -1,11 +1,13 @@ using System; using osu.Framework.Graphics; +using osu.Game.Graphics; namespace osu.Game.Overlays.Options { public class AudioOptions : OptionsSection { protected override string Header => "Audio"; + public override FontAwesome Icon => FontAwesome.fa_headphones; public AudioOptions() { diff --git a/osu.Game/Overlays/Options/EditorOptions.cs b/osu.Game/Overlays/Options/EditorOptions.cs index 2b3f1a9743..7d3a87c0be 100644 --- a/osu.Game/Overlays/Options/EditorOptions.cs +++ b/osu.Game/Overlays/Options/EditorOptions.cs @@ -2,12 +2,14 @@ using OpenTK; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; +using osu.Game.Graphics; namespace osu.Game.Overlays.Options { public class EditorOptions : OptionsSection { protected override string Header => "Editor"; + public override FontAwesome Icon => FontAwesome.fa_pencil; public EditorOptions() { diff --git a/osu.Game/Overlays/Options/GameplayOptions.cs b/osu.Game/Overlays/Options/GameplayOptions.cs index 41f811708a..aca9b8ee51 100644 --- a/osu.Game/Overlays/Options/GameplayOptions.cs +++ b/osu.Game/Overlays/Options/GameplayOptions.cs @@ -1,11 +1,13 @@ using System; using osu.Framework.Graphics; +using osu.Game.Graphics; namespace osu.Game.Overlays.Options { public class GameplayOptions : OptionsSection { protected override string Header => "Gameplay"; + public override FontAwesome Icon => FontAwesome.fa_circle_o; public GameplayOptions() { diff --git a/osu.Game/Overlays/Options/GeneralOptions.cs b/osu.Game/Overlays/Options/GeneralOptions.cs index 46adbe53d6..9ffd1065b2 100644 --- a/osu.Game/Overlays/Options/GeneralOptions.cs +++ b/osu.Game/Overlays/Options/GeneralOptions.cs @@ -4,6 +4,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Platform; +using osu.Game.Graphics; using osu.Game.Online.API; namespace osu.Game.Overlays.Options @@ -11,6 +12,7 @@ namespace osu.Game.Overlays.Options public class GeneralOptions : OptionsSection { protected override string Header => "General"; + public override FontAwesome Icon => FontAwesome.fa_gear; public GeneralOptions() { diff --git a/osu.Game/Overlays/Options/GraphicsOptions.cs b/osu.Game/Overlays/Options/GraphicsOptions.cs index 8051a815aa..58eba7de70 100644 --- a/osu.Game/Overlays/Options/GraphicsOptions.cs +++ b/osu.Game/Overlays/Options/GraphicsOptions.cs @@ -1,11 +1,13 @@ using System; using osu.Framework.Graphics; +using osu.Game.Graphics; namespace osu.Game.Overlays.Options { public class GraphicsOptions : OptionsSection { protected override string Header => "Graphics"; + public override FontAwesome Icon => FontAwesome.fa_laptop; public GraphicsOptions() { diff --git a/osu.Game/Overlays/Options/InputOptions.cs b/osu.Game/Overlays/Options/InputOptions.cs index 189beb86c9..c038daac16 100644 --- a/osu.Game/Overlays/Options/InputOptions.cs +++ b/osu.Game/Overlays/Options/InputOptions.cs @@ -1,11 +1,13 @@ using System; using osu.Framework.Graphics; +using osu.Game.Graphics; namespace osu.Game.Overlays.Options { public class InputOptions : OptionsSection { protected override string Header => "Input"; + public override FontAwesome Icon => FontAwesome.fa_keyboard_o; public InputOptions() { diff --git a/osu.Game/Overlays/Options/MaintenanceOptions.cs b/osu.Game/Overlays/Options/MaintenanceOptions.cs index c139804f4c..a8d19fe06e 100644 --- a/osu.Game/Overlays/Options/MaintenanceOptions.cs +++ b/osu.Game/Overlays/Options/MaintenanceOptions.cs @@ -2,6 +2,7 @@ using OpenTK; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options @@ -9,6 +10,7 @@ namespace osu.Game.Overlays.Options public class MaintenanceOptions : OptionsSection { protected override string Header => "Maintenance"; + public override FontAwesome Icon => FontAwesome.fa_wrench; public MaintenanceOptions() { diff --git a/osu.Game/Overlays/Options/OnlineOptions.cs b/osu.Game/Overlays/Options/OnlineOptions.cs index a22d416ab5..96ecfe67b6 100644 --- a/osu.Game/Overlays/Options/OnlineOptions.cs +++ b/osu.Game/Overlays/Options/OnlineOptions.cs @@ -1,11 +1,13 @@ using System; using osu.Framework.Graphics; +using osu.Game.Graphics; namespace osu.Game.Overlays.Options { public class OnlineOptions : OptionsSection { protected override string Header => "Online"; + public override FontAwesome Icon => FontAwesome.fa_globe; public OnlineOptions() { diff --git a/osu.Game/Overlays/Options/OptionsSection.cs b/osu.Game/Overlays/Options/OptionsSection.cs index c362e0326c..3fdd098b18 100644 --- a/osu.Game/Overlays/Options/OptionsSection.cs +++ b/osu.Game/Overlays/Options/OptionsSection.cs @@ -5,6 +5,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; namespace osu.Game.Overlays.Options { @@ -13,6 +14,7 @@ namespace osu.Game.Overlays.Options protected FlowContainer content; protected override Container Content => content; + public abstract FontAwesome Icon { get; } protected abstract string Header { get; } public OptionsSection() diff --git a/osu.Game/Overlays/Options/OptionsSideNav.cs b/osu.Game/Overlays/Options/OptionsSideNav.cs index fab2562332..0863423114 100644 --- a/osu.Game/Overlays/Options/OptionsSideNav.cs +++ b/osu.Game/Overlays/Options/OptionsSideNav.cs @@ -5,83 +5,29 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input; +using osu.Game.Graphics; namespace osu.Game.Overlays.Options { public class OptionsSideNav : Container { - public Action GeneralAction; - public Action GraphicsAction; - public Action GameplayAction; - public Action AudioAction; - public Action SkinAction; - public Action InputAction; - public Action EditorAction; - public Action OnlineAction; - public Action MaintenanceAction; - + private FlowContainer content; + protected override Container Content => content; + public OptionsSideNav() { RelativeSizeAxes = Axes.Y; - Children = new Drawable[] + InternalChildren = new Drawable[] { - new FlowContainer + content = new FlowContainer { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, - 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(), - } - } + Direction = FlowDirection.VerticalOnly }, 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; } - set { button.Action = value; } - } - - public Graphics.FontAwesome Icon - { - get { return button.Icon; } - set { button.Icon = value; } + get { return drawableIcon.Icon; } + set { drawableIcon.Icon = value; } } public SidebarButton() { 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); } } } diff --git a/osu.Game/Overlays/Options/SkinOptions.cs b/osu.Game/Overlays/Options/SkinOptions.cs index ae7ae3f2ab..c89253abfb 100644 --- a/osu.Game/Overlays/Options/SkinOptions.cs +++ b/osu.Game/Overlays/Options/SkinOptions.cs @@ -3,6 +3,7 @@ using OpenTK; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; +using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; namespace osu.Game.Overlays.Options @@ -10,6 +11,7 @@ namespace osu.Game.Overlays.Options public class SkinOptions : OptionsSection { protected override string Header => "Skin"; + public override FontAwesome Icon => FontAwesome.fa_paint_brush; public SkinOptions() { diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index 3116495109..c72399c5fb 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -2,6 +2,7 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Diagnostics; +using System.Linq; using OpenTK; using OpenTK.Graphics; using OpenTK.Input; @@ -29,16 +30,6 @@ namespace osu.Game.Overlays private ScrollContainer scrollContainer; 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() { @@ -47,6 +38,19 @@ namespace osu.Game.Overlays Size = new Vector2(width, 1); 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[] { new Box @@ -61,10 +65,9 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Y, Width = width - (sideNavWidth + sideNavPadding * 2), Position = new Vector2(sideNavWidth + sideNavPadding * 2, 0), - // Note: removing this comment causes... compiler bugs? It's weird.2 Children = new[] { - flowContainer = new FlowContainer + new FlowContainer { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, @@ -84,15 +87,12 @@ namespace osu.Game.Overlays TextSize = 18, Margin = new MarginPadding { Left = SideMargins, Bottom = 30 }, }, - generalOptions = new GeneralOptions(), - graphicsOptions = new GraphicsOptions(), - gameplayOptions = new GameplayOptions(), - audioOptions = new AudioOptions(), - skinOptions = new SkinOptions(), - inputOptions = new InputOptions(), - editorOptions = new EditorOptions(), - onlineOptions = new OnlineOptions(), - maintenanceOptions = new MaintenanceOptions(), + flowContainer = new FlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FlowDirection.VerticalOnly, + } } } } @@ -101,17 +101,16 @@ namespace osu.Game.Overlays { Padding = new MarginPadding { Left = sideNavPadding, Right = sideNavPadding }, Width = sideNavWidth + sideNavPadding * 2, - GeneralAction = () => scrollContainer.ScrollIntoView(generalOptions), - GraphicsAction = () => scrollContainer.ScrollIntoView(graphicsOptions), - GameplayAction = () => scrollContainer.ScrollIntoView(gameplayOptions), - AudioAction = () => scrollContainer.ScrollIntoView(audioOptions), - SkinAction = () => scrollContainer.ScrollIntoView(skinOptions), - InputAction = () => scrollContainer.ScrollIntoView(inputOptions), - EditorAction = () => scrollContainer.ScrollIntoView(editorOptions), - OnlineAction = () => scrollContainer.ScrollIntoView(onlineOptions), - MaintenanceAction = () => scrollContainer.ScrollIntoView(maintenanceOptions), + Children = sections.Select(section => + new OptionsSideNav.SidebarButton + { + Icon = section.Icon, + Action = () => scrollContainer.ScrollIntoView(section) + } + ) } }; + flowContainer.Add(sections); } protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;