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 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/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/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..8234baa523 --- /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(@"osu!taiko")] + Taiko = 1, + [Description(@"osu!catch")] + Catch = 2, + [Description(@"osu!mania")] + Mania = 3 + } +} diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 9ba587a195..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) { @@ -29,8 +33,6 @@ namespace osu.Game { base.Load(); - ShowPerformanceOverlay = true; - Add(new Drawable[] { new ParallaxContainer { @@ -38,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 2db9f1ba96..f30105beab 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -1,16 +1,15 @@ //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.Game.Configuration; +using System; +using osu.Game.GameModes.Play; namespace osu.Game.Overlays { @@ -18,6 +17,12 @@ namespace osu.Game.Overlays { const float height = 50; + public Action OnSettings; + public Action OnHome; + public Action OnPlayModeChange; + + private ToolbarModeSelector modeSelector; + public override void Load() { base.Load(); @@ -30,9 +35,60 @@ namespace osu.Game.Overlays 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) + }, + new FlowContainer + { + Direction = FlowDirection.HorizontalOnly, + RelativeSizeAxes = Axes.Y, + Children = new Drawable[] + { + new ToolbarButton + { + Icon = FontAwesome.gear, + Action = OnSettings, + 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 = OnPlayModeChange + } + } + }, + new FlowContainer + { + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + Direction = FlowDirection.HorizontalOnly, + RelativeSizeAxes = Axes.Y, + Children = new [] + { + 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) => modeSelector.SetGameMode(mode); } } diff --git a/osu.Game/Overlays/ToolbarButton.cs b/osu.Game/Overlays/ToolbarButton.cs new file mode 100644 index 0000000000..46e99f2699 --- /dev/null +++ b/osu.Game/Overlays/ToolbarButton.cs @@ -0,0 +1,176 @@ +//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 true; + } + + protected override bool OnHover(InputState state) + { + HoverBackground.FadeTo(0.4f, 200); + tooltipContainer.FadeIn(100); + return true; + } + + protected override void OnHoverLost(InputState state) + { + HoverBackground.FadeTo(0, 200); + tooltipContainer.FadeOut(100); + } + } +} \ 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..c429dd5a24 --- /dev/null +++ b/osu.Game/Overlays/ToolbarModeSelector.cs @@ -0,0 +1,101 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Linq; +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(); + } + + private 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 513a101744..8ef0f07fa7 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -81,6 +81,7 @@ + @@ -119,6 +120,9 @@ + + +