1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +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 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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()

View File

@ -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);
}
}
}

View File

@ -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()
{

View File

@ -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;