From ddcd5ec286577b06c162d8985af3326af344494d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 3 Oct 2016 20:39:32 +0900 Subject: [PATCH 1/8] Add basic layout for toolbar. --- osu.Game/GameModes/Menu/ButtonSystem.cs | 2 - osu.Game/Overlays/Toolbar.cs | 132 +++++++++++++++++++++++- 2 files changed, 127 insertions(+), 7 deletions(-) diff --git a/osu.Game/GameModes/Menu/ButtonSystem.cs b/osu.Game/GameModes/Menu/ButtonSystem.cs index a4fbf37886..0b01965394 100644 --- a/osu.Game/GameModes/Menu/ButtonSystem.cs +++ b/osu.Game/GameModes/Menu/ButtonSystem.cs @@ -701,6 +701,4 @@ namespace osu.Game.GameModes.Menu { } } - - } diff --git a/osu.Game/Overlays/Toolbar.cs b/osu.Game/Overlays/Toolbar.cs index 2db9f1ba96..cd1c65915a 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -1,22 +1,23 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Drawables; using OpenTK; using OpenTK.Graphics; +using osu.Game.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Game.Configuration; namespace osu.Game.Overlays { public class Toolbar : Container { const float height = 50; + private FlowContainer leftFlow; + private FlowContainer rightFlow; public override void Load() { @@ -31,8 +32,129 @@ namespace osu.Game.Overlays { RelativeSizeAxes = Axes.Both, Colour = new Color4(0.1f, 0.1f, 0.1f, 0.9f) + }, + leftFlow = new FlowContainer + { + Direction = FlowDirection.HorizontalOnly, + RelativeSizeAxes = Axes.Y, + Size = new Vector2(0, 1), + Children = new [] + { + new ToolbarButton(FontAwesome.gear), + new ToolbarButton(FontAwesome.home), + new ToolbarModeButton(FontAwesome.fa_osu_osu_o, @"osu!"), + new ToolbarModeButton(FontAwesome.fa_osu_taiko_o, @"taiko"), + new ToolbarModeButton(FontAwesome.fa_osu_fruits_o, @"catch"), + new ToolbarModeButton(FontAwesome.fa_osu_mania_o, @"mania"), + } + }, + rightFlow = new FlowContainer + { + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + Direction = FlowDirection.HorizontalOnly, + RelativeSizeAxes = Axes.Y, + Size = new Vector2(0, 1), + Children = new [] + { + new ToolbarButton(FontAwesome.search), + new ToolbarButton(FontAwesome.user, ((OsuGame)Game).Config.Get(OsuConfig.Username)), + new ToolbarButton(FontAwesome.bars), + } } }; } + + public class ToolbarModeButton : ToolbarButton + { + public ToolbarModeButton(FontAwesome icon, string text = null) : base(icon, text) + { + } + + public override void Load() + { + base.Load(); + Icon.TextSize = height * 0.7f; + } + } + + public class ToolbarButton : FlowContainer + { + public TextAwesome Icon; + public SpriteText Text; + private Box background; + private Drawable paddingLeft; + private Drawable paddingRight; + private Drawable paddingIcon; + + public new float Padding + { + get { return paddingLeft.Size.X; } + set + { + paddingLeft.Size = new Vector2(value, 1); + paddingRight.Size = new Vector2(value, 1); + } + } + + public ToolbarButton(FontAwesome icon, string text = null) + { + background = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = new Color4(20, 20, 20, 140), + }; + + this.Icon = new TextAwesome() + { + Icon = icon, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }; + + this.Text = new SpriteText + { + Text = text, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }; + + paddingLeft = new Container { RelativeSizeAxes = Axes.Y }; + paddingRight = new Container { RelativeSizeAxes = Axes.Y }; + paddingIcon = new Container { Size = new Vector2(string.IsNullOrEmpty(text) ? 0 : 5, 0) }; + + Padding = 10; + } + + protected override bool OnHover(InputState state) + { + background.FadeColour(new Color4(130, 130, 130, 160), 100); + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + background.FadeColour(new Color4(20, 20, 20, 140), 100); + base.OnHoverLost(state); + } + + public override void Load() + { + base.Load(); + + RelativeSizeAxes = Axes.Y; + Direction = FlowDirection.HorizontalOnly; + + Children = new Drawable[] + { + background, + paddingLeft, + Icon, + paddingIcon, + Text, + paddingRight, + }; + } + } } } From 51cf13460fcd053d05cbbebb6318fa6edbfb7d68 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 3 Oct 2016 23:56:25 +0900 Subject: [PATCH 2/8] Remove performance overlay. --- osu.Game/OsuGame.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 9ba587a195..c26627d1c4 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -29,8 +29,6 @@ namespace osu.Game { base.Load(); - ShowPerformanceOverlay = true; - Add(new Drawable[] { new ParallaxContainer { From 11403a922a2eb24971e5193c72faf672134cc569 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Oct 2016 17:15:03 +0900 Subject: [PATCH 3/8] Make Home, Settings and PlayMode buttons work. --- osu.Game/Configuration/OsuConfigManager.cs | 6 +- osu.Game/GameModes/Menu/MainMenu.cs | 2 +- osu.Game/GameModes/Play/PlayMode.cs | 20 +++ osu.Game/OsuGame.cs | 17 ++- osu.Game/Overlays/Toolbar.cs | 170 +++++++++++++++++---- osu.Game/osu.Game.csproj | 1 + 6 files changed, 185 insertions(+), 31 deletions(-) create mode 100644 osu.Game/GameModes/Play/PlayMode.cs diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 0873669399..9991394913 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -2,6 +2,7 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Configuration; +using osu.Game.GameModes.Play; using osu.Game.Online.API; namespace osu.Game.Configuration @@ -17,6 +18,8 @@ namespace osu.Game.Configuration Set(OsuConfig.Username, string.Empty); Set(OsuConfig.Password, string.Empty); Set(OsuConfig.Token, string.Empty); + + Set(OsuConfig.PlayMode, PlayMode.Osu); } } @@ -27,6 +30,7 @@ namespace osu.Game.Configuration MouseSensitivity, Username, Password, - Token + Token, + PlayMode } } diff --git a/osu.Game/GameModes/Menu/MainMenu.cs b/osu.Game/GameModes/Menu/MainMenu.cs index e4c66a27a4..fa99abed91 100644 --- a/osu.Game/GameModes/Menu/MainMenu.cs +++ b/osu.Game/GameModes/Menu/MainMenu.cs @@ -17,7 +17,7 @@ using OpenTK; namespace osu.Game.GameModes.Menu { - internal class MainMenu : GameMode + public class MainMenu : GameMode { private ButtonSystem buttons; public override string Name => @"Main Menu"; diff --git a/osu.Game/GameModes/Play/PlayMode.cs b/osu.Game/GameModes/Play/PlayMode.cs new file mode 100644 index 0000000000..bf7c141ca4 --- /dev/null +++ b/osu.Game/GameModes/Play/PlayMode.cs @@ -0,0 +1,20 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + + +using System.ComponentModel; + +namespace osu.Game.GameModes.Play +{ + public enum PlayMode + { + [Description(@"osu!")] + Osu = 0, + [Description(@"taiko")] + Taiko = 1, + [Description(@"catch")] + Catch = 2, + [Description(@"mania")] + Mania = 3 + } +} diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index c26627d1c4..4148854513 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -1,6 +1,7 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Configuration; using osu.Game.Configuration; using osu.Game.GameModes.Menu; using OpenTK; @@ -17,6 +18,9 @@ namespace osu.Game public class OsuGame : OsuGameBase { public Toolbar Toolbar; + public MainMenu MainMenu; + + public Bindable PlayMode; public override void SetHost(BasicGameHost host) { @@ -36,9 +40,18 @@ namespace osu.Game new Background() } }, - new MainMenu(), - Toolbar = new Toolbar(), + MainMenu = new MainMenu(), + Toolbar = new Toolbar + { + OnHome = delegate { MainMenu.MakeCurrent(); }, + OnSettings = delegate { Options.PoppedOut = !Options.PoppedOut; }, + OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, + }, }); + + PlayMode = Config.GetBindable(OsuConfig.PlayMode); + PlayMode.ValueChanged += delegate { Toolbar.SetGameMode(PlayMode.Value); }; + PlayMode.TriggerChange(); } public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true) diff --git a/osu.Game/Overlays/Toolbar.cs b/osu.Game/Overlays/Toolbar.cs index cd1c65915a..b953f455e9 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -10,6 +10,10 @@ using osu.Game.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Input; using osu.Game.Configuration; +using System; +using System.Linq; +using osu.Game.GameModes.Play; +using osu.Framework.Extensions; namespace osu.Game.Overlays { @@ -18,6 +22,12 @@ namespace osu.Game.Overlays const float height = 50; private FlowContainer leftFlow; private FlowContainer rightFlow; + private FlowContainer modeButtons; + + public Action OnSettings; + public Action OnHome; + public Action OnPlayModeChange; + public override void Load() { @@ -26,6 +36,27 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.X; Size = new Vector2(1, height); + modeButtons = new FlowContainer + { + RelativeSizeAxes = Axes.Y, + Direction = FlowDirection.HorizontalOnly + }; + + foreach (PlayMode m in Enum.GetValues(typeof(PlayMode))) + { + var localMode = m; + modeButtons.Add(new ToolbarModeButton + { + Mode = m, + Action = delegate + { + SetGameMode(localMode); + OnPlayModeChange?.Invoke(localMode); + } + }); + } + + Children = new Drawable[] { new Box @@ -37,15 +68,19 @@ namespace osu.Game.Overlays { Direction = FlowDirection.HorizontalOnly, RelativeSizeAxes = Axes.Y, - Size = new Vector2(0, 1), Children = new [] { - new ToolbarButton(FontAwesome.gear), - new ToolbarButton(FontAwesome.home), - new ToolbarModeButton(FontAwesome.fa_osu_osu_o, @"osu!"), - new ToolbarModeButton(FontAwesome.fa_osu_taiko_o, @"taiko"), - new ToolbarModeButton(FontAwesome.fa_osu_fruits_o, @"catch"), - new ToolbarModeButton(FontAwesome.fa_osu_mania_o, @"mania"), + new ToolbarButton + { + Icon = FontAwesome.gear, + Action = OnSettings + }, + new ToolbarButton + { + Icon = FontAwesome.home, + Action = OnHome + }, + modeButtons } }, rightFlow = new FlowContainer @@ -57,32 +92,96 @@ namespace osu.Game.Overlays Size = new Vector2(0, 1), Children = new [] { - new ToolbarButton(FontAwesome.search), - new ToolbarButton(FontAwesome.user, ((OsuGame)Game).Config.Get(OsuConfig.Username)), - new ToolbarButton(FontAwesome.bars), + new ToolbarButton + { + Icon = FontAwesome.search + }, + new ToolbarButton + { + Icon = FontAwesome.user, + Text = ((OsuGame)Game).Config.Get(OsuConfig.Username) + }, + new ToolbarButton + { + Icon = FontAwesome.bars + }, } } }; } + public void SetGameMode(PlayMode mode) + { + foreach (var m in modeButtons.Children.Cast()) + { + m.Active = m.Mode == mode; + } + } + public class ToolbarModeButton : ToolbarButton { - public ToolbarModeButton(FontAwesome icon, string text = null) : base(icon, text) + private PlayMode mode; + public PlayMode Mode { + get { return mode; } + set + { + mode = value; + Text = mode.GetDescription(); + Icon = getModeIcon(mode); + } + } + + public bool Active + { + set + { + Background.Colour = value ? new Color4(100, 100, 100, 140) : new Color4(20, 20, 20, 140); + } + } + + private FontAwesome getModeIcon(PlayMode mode) + { + switch (mode) + { + default: return FontAwesome.fa_osu_osu_o; + case PlayMode.Taiko: return FontAwesome.fa_osu_taiko_o; + case PlayMode.Catch: return FontAwesome.fa_osu_fruits_o; + case PlayMode.Mania: return FontAwesome.fa_osu_mania_o; + } } public override void Load() { base.Load(); - Icon.TextSize = height * 0.7f; + DrawableIcon.TextSize = height * 0.7f; } } public class ToolbarButton : FlowContainer { - public TextAwesome Icon; - public SpriteText Text; - private Box background; + public FontAwesome Icon + { + get { return DrawableIcon.Icon; } + set { DrawableIcon.Icon = value; } + } + + public string Text + { + get { return DrawableText.Text; } + set + { + DrawableText.Text = value; + paddingIcon.Alpha = string.IsNullOrEmpty(value) ? 0 : 1; + } + } + + public Action Action; + + protected TextAwesome DrawableIcon; + protected SpriteText DrawableText; + protected Box Background; + protected Box HoverBackground; private Drawable paddingLeft; private Drawable paddingRight; private Drawable paddingIcon; @@ -97,44 +196,60 @@ namespace osu.Game.Overlays } } - public ToolbarButton(FontAwesome icon, string text = null) + public ToolbarButton() { - background = new Box + Background = new Box { RelativeSizeAxes = Axes.Both, Colour = new Color4(20, 20, 20, 140), }; - this.Icon = new TextAwesome() + HoverBackground = new Box + { + RelativeSizeAxes = Axes.Both, + Additive = true, + Colour = new Color4(20, 20, 20, 0), + Alpha = 0, + }; + + DrawableIcon = new TextAwesome() { - Icon = icon, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, }; - this.Text = new SpriteText + DrawableText = new SpriteText { - Text = text, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, }; paddingLeft = new Container { RelativeSizeAxes = Axes.Y }; paddingRight = new Container { RelativeSizeAxes = Axes.Y }; - paddingIcon = new Container { Size = new Vector2(string.IsNullOrEmpty(text) ? 0 : 5, 0) }; + paddingIcon = new Container + { + Size = new Vector2(5, 0), + Alpha = 0 + }; Padding = 10; } + protected override bool OnClick(InputState state) + { + Action?.Invoke(); + return base.OnClick(state); + } + protected override bool OnHover(InputState state) { - background.FadeColour(new Color4(130, 130, 130, 160), 100); + HoverBackground.FadeTo(0.4f, 200); return base.OnHover(state); } protected override void OnHoverLost(InputState state) { - background.FadeColour(new Color4(20, 20, 20, 140), 100); + HoverBackground.FadeTo(0, 200); base.OnHoverLost(state); } @@ -147,11 +262,12 @@ namespace osu.Game.Overlays Children = new Drawable[] { - background, + Background, + HoverBackground, paddingLeft, - Icon, + DrawableIcon, paddingIcon, - Text, + DrawableText, paddingRight, }; } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 513a101744..d0143ac3da 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -81,6 +81,7 @@ + From c2d4672b8deadc8ddfc471b31cada648cbf837ed Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Oct 2016 19:40:56 +0900 Subject: [PATCH 4/8] Add osu! prefix to mode descriptions. --- osu.Game/GameModes/Play/PlayMode.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/GameModes/Play/PlayMode.cs b/osu.Game/GameModes/Play/PlayMode.cs index bf7c141ca4..8234baa523 100644 --- a/osu.Game/GameModes/Play/PlayMode.cs +++ b/osu.Game/GameModes/Play/PlayMode.cs @@ -10,11 +10,11 @@ namespace osu.Game.GameModes.Play { [Description(@"osu!")] Osu = 0, - [Description(@"taiko")] + [Description(@"osu!taiko")] Taiko = 1, - [Description(@"catch")] + [Description(@"osu!catch")] Catch = 2, - [Description(@"mania")] + [Description(@"osu!mania")] Mania = 3 } } From cc525805685536e51e5cfd305c3cd0ff3b23da44 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Oct 2016 19:41:18 +0900 Subject: [PATCH 5/8] Implement mode selector highlight line. --- osu.Game/Overlays/Toolbar.cs | 201 ++--------------------- osu.Game/Overlays/ToolbarButton.cs | 177 ++++++++++++++++++++ osu.Game/Overlays/ToolbarModeButton.cs | 51 ++++++ osu.Game/Overlays/ToolbarModeSelector.cs | 105 ++++++++++++ osu.Game/osu.Game.csproj | 3 + 5 files changed, 348 insertions(+), 189 deletions(-) create mode 100644 osu.Game/Overlays/ToolbarButton.cs create mode 100644 osu.Game/Overlays/ToolbarModeButton.cs create mode 100644 osu.Game/Overlays/ToolbarModeSelector.cs diff --git a/osu.Game/Overlays/Toolbar.cs b/osu.Game/Overlays/Toolbar.cs index b953f455e9..569de8d208 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -17,17 +17,17 @@ using osu.Framework.Extensions; namespace osu.Game.Overlays { - public class Toolbar : Container + public partial class Toolbar : Container { const float height = 50; private FlowContainer leftFlow; private FlowContainer rightFlow; - private FlowContainer modeButtons; public Action OnSettings; public Action OnHome; public Action OnPlayModeChange; + private ToolbarModeSelector modeSelector; public override void Load() { @@ -36,51 +36,35 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.X; Size = new Vector2(1, height); - modeButtons = new FlowContainer - { - RelativeSizeAxes = Axes.Y, - Direction = FlowDirection.HorizontalOnly - }; - - foreach (PlayMode m in Enum.GetValues(typeof(PlayMode))) - { - var localMode = m; - modeButtons.Add(new ToolbarModeButton - { - Mode = m, - Action = delegate - { - SetGameMode(localMode); - OnPlayModeChange?.Invoke(localMode); - } - }); - } - - Children = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both, - Colour = new Color4(0.1f, 0.1f, 0.1f, 0.9f) + Colour = new Color4(0.1f, 0.1f, 0.1f, 0.4f) }, leftFlow = new FlowContainer { Direction = FlowDirection.HorizontalOnly, RelativeSizeAxes = Axes.Y, - Children = new [] + Children = new Drawable[] { new ToolbarButton { Icon = FontAwesome.gear, - Action = OnSettings + Action = OnSettings, + TooltipMain = "Settings" }, new ToolbarButton { Icon = FontAwesome.home, + TooltipMain = "Home", Action = OnHome }, - modeButtons + modeSelector = new ToolbarModeSelector + { + OnPlayModeChange = this.OnPlayModeChange + } } }, rightFlow = new FlowContainer @@ -110,167 +94,6 @@ namespace osu.Game.Overlays }; } - public void SetGameMode(PlayMode mode) - { - foreach (var m in modeButtons.Children.Cast()) - { - m.Active = m.Mode == mode; - } - } - - public class ToolbarModeButton : ToolbarButton - { - private PlayMode mode; - public PlayMode Mode - { - get { return mode; } - set - { - mode = value; - Text = mode.GetDescription(); - Icon = getModeIcon(mode); - } - } - - public bool Active - { - set - { - Background.Colour = value ? new Color4(100, 100, 100, 140) : new Color4(20, 20, 20, 140); - } - } - - private FontAwesome getModeIcon(PlayMode mode) - { - switch (mode) - { - default: return FontAwesome.fa_osu_osu_o; - case PlayMode.Taiko: return FontAwesome.fa_osu_taiko_o; - case PlayMode.Catch: return FontAwesome.fa_osu_fruits_o; - case PlayMode.Mania: return FontAwesome.fa_osu_mania_o; - } - } - - public override void Load() - { - base.Load(); - DrawableIcon.TextSize = height * 0.7f; - } - } - - public class ToolbarButton : FlowContainer - { - public FontAwesome Icon - { - get { return DrawableIcon.Icon; } - set { DrawableIcon.Icon = value; } - } - - public string Text - { - get { return DrawableText.Text; } - set - { - DrawableText.Text = value; - paddingIcon.Alpha = string.IsNullOrEmpty(value) ? 0 : 1; - } - } - - public Action Action; - - protected TextAwesome DrawableIcon; - protected SpriteText DrawableText; - protected Box Background; - protected Box HoverBackground; - private Drawable paddingLeft; - private Drawable paddingRight; - private Drawable paddingIcon; - - public new float Padding - { - get { return paddingLeft.Size.X; } - set - { - paddingLeft.Size = new Vector2(value, 1); - paddingRight.Size = new Vector2(value, 1); - } - } - - public ToolbarButton() - { - Background = new Box - { - RelativeSizeAxes = Axes.Both, - Colour = new Color4(20, 20, 20, 140), - }; - - HoverBackground = new Box - { - RelativeSizeAxes = Axes.Both, - Additive = true, - Colour = new Color4(20, 20, 20, 0), - Alpha = 0, - }; - - DrawableIcon = new TextAwesome() - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - }; - - DrawableText = new SpriteText - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - }; - - paddingLeft = new Container { RelativeSizeAxes = Axes.Y }; - paddingRight = new Container { RelativeSizeAxes = Axes.Y }; - paddingIcon = new Container - { - Size = new Vector2(5, 0), - Alpha = 0 - }; - - Padding = 10; - } - - protected override bool OnClick(InputState state) - { - Action?.Invoke(); - return base.OnClick(state); - } - - protected override bool OnHover(InputState state) - { - HoverBackground.FadeTo(0.4f, 200); - return base.OnHover(state); - } - - protected override void OnHoverLost(InputState state) - { - HoverBackground.FadeTo(0, 200); - base.OnHoverLost(state); - } - - public override void Load() - { - base.Load(); - - RelativeSizeAxes = Axes.Y; - Direction = FlowDirection.HorizontalOnly; - - Children = new Drawable[] - { - Background, - HoverBackground, - paddingLeft, - DrawableIcon, - paddingIcon, - DrawableText, - paddingRight, - }; - } - } + public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode); } } diff --git a/osu.Game/Overlays/ToolbarButton.cs b/osu.Game/Overlays/ToolbarButton.cs new file mode 100644 index 0000000000..8a09747ee6 --- /dev/null +++ b/osu.Game/Overlays/ToolbarButton.cs @@ -0,0 +1,177 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Drawables; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Game.Graphics; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Overlays +{ + public class ToolbarButton : Container + { + public const float WIDTH = 60; + + public FontAwesome Icon + { + get { return DrawableIcon.Icon; } + set { DrawableIcon.Icon = value; } + } + + public string Text + { + get { return DrawableText.Text; } + set + { + DrawableText.Text = value; + paddingIcon.Alpha = string.IsNullOrEmpty(value) ? 0 : 1; + } + } + + public string TooltipMain + { + get { return tooltip1.Text; } + set + { + tooltip1.Text = value; + } + } + + public string TooltipSub + { + get { return tooltip2.Text; } + set + { + tooltip2.Text = value; + } + } + + public Action Action; + protected TextAwesome DrawableIcon; + protected SpriteText DrawableText; + protected Box HoverBackground; + private Drawable paddingLeft; + private Drawable paddingRight; + private Drawable paddingIcon; + private FlowContainer tooltipContainer; + private SpriteText tooltip1; + private SpriteText tooltip2; + + public new float Padding + { + get { return paddingLeft.Size.X; } + set + { + paddingLeft.Size = new Vector2(value, 1); + paddingRight.Size = new Vector2(value, 1); + tooltipContainer.Position = new Vector2(value, tooltipContainer.Position.Y); + } + } + + public ToolbarButton() + { + HoverBackground = new Box + { + RelativeSizeAxes = Axes.Both, + Additive = true, + Colour = new Color4(60, 60, 60, 255), + Alpha = 0, + }; + + DrawableIcon = new TextAwesome + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }; + + DrawableText = new SpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }; + + tooltipContainer = new FlowContainer + { + Direction = FlowDirection.VerticalOnly, + Anchor = Anchor.BottomLeft, + Position = new Vector2(0, -5), + Alpha = 0, + Children = new[] + { + tooltip1 = new SpriteText() + { + TextSize = 22, + }, + tooltip2 = new SpriteText + { + TextSize = 15 + } + } + }; + + paddingLeft = new Container { RelativeSizeAxes = Axes.Y }; + paddingRight = new Container { RelativeSizeAxes = Axes.Y }; + paddingIcon = new Container + { + Size = new Vector2(5, 0), + Alpha = 0 + }; + + Padding = 10; + RelativeSizeAxes = Axes.Y; + Size = new Vector2(WIDTH, 1); + } + + public override void Load() + { + base.Load(); + + Children = new Drawable[] + { + HoverBackground, + new FlowContainer + { + Direction = FlowDirection.HorizontalOnly, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.Y, + Children = new Drawable[] + { + paddingLeft, + DrawableIcon, + paddingIcon, + DrawableText, + paddingRight + }, + }, + tooltipContainer + }; + } + + protected override bool OnClick(InputState state) + { + Action?.Invoke(); + HoverBackground.FlashColour(Color4.White, 400); + return base.OnClick(state); + } + + protected override bool OnHover(InputState state) + { + HoverBackground.FadeTo(0.4f, 200); + tooltipContainer.FadeIn(100); + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + HoverBackground.FadeTo(0, 200); + tooltipContainer.FadeOut(100); + base.OnHoverLost(state); + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/ToolbarModeButton.cs b/osu.Game/Overlays/ToolbarModeButton.cs new file mode 100644 index 0000000000..a8519e3436 --- /dev/null +++ b/osu.Game/Overlays/ToolbarModeButton.cs @@ -0,0 +1,51 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Extensions; +using osu.Game.GameModes.Play; +using osu.Game.Graphics; +using OpenTK.Graphics; + +namespace osu.Game.Overlays +{ + public class ToolbarModeButton : ToolbarButton + { + private PlayMode mode; + public PlayMode Mode + { + get { return mode; } + set + { + mode = value; + TooltipMain = mode.GetDescription(); + TooltipSub = $"Play some {mode.GetDescription()}"; + Icon = getModeIcon(mode); + } + } + + public bool Active + { + set + { + //Background.Colour = value ? new Color4(100, 100, 100, 255) : new Color4(20, 20, 20, 255); + } + } + + private FontAwesome getModeIcon(PlayMode mode) + { + switch (mode) + { + default: return FontAwesome.fa_osu_osu_o; + case PlayMode.Taiko: return FontAwesome.fa_osu_taiko_o; + case PlayMode.Catch: return FontAwesome.fa_osu_fruits_o; + case PlayMode.Mania: return FontAwesome.fa_osu_mania_o; + } + } + + public override void Load() + { + base.Load(); + DrawableIcon.TextSize *= 1.4f; + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/ToolbarModeSelector.cs b/osu.Game/Overlays/ToolbarModeSelector.cs new file mode 100644 index 0000000000..8dbd5e5f2f --- /dev/null +++ b/osu.Game/Overlays/ToolbarModeSelector.cs @@ -0,0 +1,105 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Framework.Cached; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Drawables; +using osu.Framework.Graphics.Transformations; +using osu.Game.GameModes.Play; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Overlays +{ + class ToolbarModeSelector : Container + { + const float padding = 10; + + private FlowContainer modeButtons; + private Box modeButtonLine; + private ToolbarModeButton activeButton; + + public Action OnPlayModeChange; + + + public ToolbarModeSelector() + { + RelativeSizeAxes = Axes.Y; + } + + public override void Load() + { + base.Load(); + + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = new Color4(20, 20, 20, 255) + }, + modeButtons = new FlowContainer + { + RelativeSizeAxes = Axes.Y, + Direction = FlowDirection.HorizontalOnly, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + }, + modeButtonLine = new Box + { + RelativeSizeAxes = Axes.X, + Size = new Vector2(0.3f, 3), + Anchor = Anchor.BottomLeft, + Origin = Anchor.TopCentre, + Colour = Color4.White + } + }; + + foreach (PlayMode m in Enum.GetValues(typeof(PlayMode))) + { + var localMode = m; + modeButtons.Add(new ToolbarModeButton + { + Mode = m, + Action = delegate + { + SetGameMode(localMode); + OnPlayModeChange?.Invoke(localMode); + } + }); + } + + RelativeSizeAxes = Axes.Y; + Size = new Vector2(modeButtons.Children.Count() * ToolbarButton.WIDTH + padding * 2, 1); + } + + public void SetGameMode(PlayMode mode) + { + foreach (ToolbarModeButton m in modeButtons.Children.Cast()) + { + bool isActive = m.Mode == mode; + m.Active = isActive; + if (isActive) + activeButton = m; + } + + activeMode.Invalidate(); + } + + Cached activeMode = new Cached(); + + protected override void UpdateLayout() + { + base.UpdateLayout(); + + if (!activeMode.EnsureValid()) + activeMode.Refresh(() => modeButtonLine.MoveToX(activeButton.Position.X + activeButton.Size.X / 2 + padding, 200, EasingTypes.OutQuint)); + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d0143ac3da..8ef0f07fa7 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -120,6 +120,9 @@ + + + From 836083667f20a3fa6e6f07ac43b99739fd6a4b75 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Oct 2016 19:57:32 +0900 Subject: [PATCH 6/8] Clean up a bit. --- osu.Game/Overlays/Toolbar.cs | 19 +++++++------------ osu.Game/Overlays/ToolbarModeSelector.cs | 6 +----- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/osu.Game/Overlays/Toolbar.cs b/osu.Game/Overlays/Toolbar.cs index 569de8d208..f30105beab 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -7,21 +7,15 @@ using osu.Framework.Graphics.Drawables; using OpenTK; using OpenTK.Graphics; using osu.Game.Graphics; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Input; using osu.Game.Configuration; using System; -using System.Linq; using osu.Game.GameModes.Play; -using osu.Framework.Extensions; namespace osu.Game.Overlays { - public partial class Toolbar : Container + public class Toolbar : Container { const float height = 50; - private FlowContainer leftFlow; - private FlowContainer rightFlow; public Action OnSettings; public Action OnHome; @@ -43,7 +37,7 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Both, Colour = new Color4(0.1f, 0.1f, 0.1f, 0.4f) }, - leftFlow = new FlowContainer + new FlowContainer { Direction = FlowDirection.HorizontalOnly, RelativeSizeAxes = Axes.Y, @@ -53,27 +47,28 @@ namespace osu.Game.Overlays { Icon = FontAwesome.gear, Action = OnSettings, - TooltipMain = "Settings" + TooltipMain = "Settings", + TooltipSub = "Change your settings", }, new ToolbarButton { Icon = FontAwesome.home, TooltipMain = "Home", + TooltipSub = "Return to the main menu", Action = OnHome }, modeSelector = new ToolbarModeSelector { - OnPlayModeChange = this.OnPlayModeChange + OnPlayModeChange = OnPlayModeChange } } }, - rightFlow = new FlowContainer + new FlowContainer { Anchor = Anchor.TopRight, Origin = Anchor.TopRight, Direction = FlowDirection.HorizontalOnly, RelativeSizeAxes = Axes.Y, - Size = new Vector2(0, 1), Children = new [] { new ToolbarButton diff --git a/osu.Game/Overlays/ToolbarModeSelector.cs b/osu.Game/Overlays/ToolbarModeSelector.cs index 8dbd5e5f2f..c429dd5a24 100644 --- a/osu.Game/Overlays/ToolbarModeSelector.cs +++ b/osu.Game/Overlays/ToolbarModeSelector.cs @@ -2,10 +2,7 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using osu.Framework.Cached; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -27,7 +24,6 @@ namespace osu.Game.Overlays public Action OnPlayModeChange; - public ToolbarModeSelector() { RelativeSizeAxes = Axes.Y; @@ -92,7 +88,7 @@ namespace osu.Game.Overlays activeMode.Invalidate(); } - Cached activeMode = new Cached(); + private Cached activeMode = new Cached(); protected override void UpdateLayout() { From 3891f467a34562d2d921fe996654802d0b29ab0b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 4 Oct 2016 20:00:55 +0900 Subject: [PATCH 7/8] Fix being able to click two toolbar buttons at once. --- osu.Game/Overlays/ToolbarButton.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/ToolbarButton.cs b/osu.Game/Overlays/ToolbarButton.cs index 8a09747ee6..46e99f2699 100644 --- a/osu.Game/Overlays/ToolbarButton.cs +++ b/osu.Game/Overlays/ToolbarButton.cs @@ -157,21 +157,20 @@ namespace osu.Game.Overlays { Action?.Invoke(); HoverBackground.FlashColour(Color4.White, 400); - return base.OnClick(state); + return true; } protected override bool OnHover(InputState state) { HoverBackground.FadeTo(0.4f, 200); tooltipContainer.FadeIn(100); - return base.OnHover(state); + return true; } protected override void OnHoverLost(InputState state) { HoverBackground.FadeTo(0, 200); tooltipContainer.FadeOut(100); - base.OnHoverLost(state); } } } \ No newline at end of file From a768e4ec16b7d1bf4c8be14d2b8d5d779adbc1e4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 5 Oct 2016 03:27:29 +0900 Subject: [PATCH 8/8] Framework update. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 4d78fdfbe0..7c15499b5e 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 4d78fdfbe01e3ecb213c19a3f3243c80a71bb668 +Subproject commit 7c15499b5ef49bed580b2ee851952826b9c5d39a