From 9bf36418a07324ee6d25cf88112f0a04433ce54e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 2 Dec 2016 18:43:01 +0900 Subject: [PATCH 1/3] Make toolbar buttons more independent logic-wise. Also adds visual toggle state for toggleable buttons. --- osu.Game/OsuGame.cs | 18 ++--- osu.Game/Overlays/Toolbar/Toolbar.cs | 22 +----- osu.Game/Overlays/Toolbar/ToolbarButton.cs | 2 +- .../Overlays/Toolbar/ToolbarHomeButton.cs | 19 +++++ .../Overlays/Toolbar/ToolbarMusicButton.cs | 23 ++++++ .../Overlays/Toolbar/ToolbarSettingsButton.cs | 25 +++++++ .../Overlays/Toolbar/ToolbarToggleButton.cs | 71 +++++++++++++++++++ osu.Game/osu.Game.csproj | 4 ++ 8 files changed, 156 insertions(+), 28 deletions(-) create mode 100644 osu.Game/Overlays/Toolbar/ToolbarHomeButton.cs create mode 100644 osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs create mode 100644 osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs create mode 100644 osu.Game/Overlays/Toolbar/ToolbarToggleButton.cs diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index d481a446b8..c6e07c3a79 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -47,7 +47,7 @@ namespace osu.Game string[] args; - public OptionsOverlay Options; + private OptionsOverlay options; public OsuGame(string[] args = null) { @@ -61,7 +61,7 @@ namespace osu.Game host.Size = new Vector2(Config.Get(OsuConfig.Width), Config.Get(OsuConfig.Height)); } - public void ToggleOptions() => Options.ToggleVisibility(); + public void ToggleOptions() => options.ToggleVisibility(); [BackgroundDependencyLoader] private void load() @@ -118,15 +118,17 @@ namespace osu.Game //overlay elements (chat = new ChatOverlay { Depth = 0 }).Preload(this, overlayContent.Add); - (Options = new OptionsOverlay { Depth = -1 }).Preload(this, overlayContent.Add); + (options = new OptionsOverlay { Depth = -1 }).Preload(this, overlayContent.Add); (musicController = new MusicController() { Depth = -3 }).Preload(this, overlayContent.Add); + + Dependencies.Cache(options); + Dependencies.Cache(musicController); + (Toolbar = new Toolbar { Depth = -2, OnHome = delegate { mainMenu?.MakeCurrent(); }, - OnSettings = Options.ToggleVisibility, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, - OnMusicController = musicController.ToggleVisibility }).Preload(this, t => { PlayMode.ValueChanged += delegate { Toolbar.SetGameMode(PlayMode.Value); }; @@ -134,9 +136,9 @@ namespace osu.Game overlayContent.Add(Toolbar); }); - Options.StateChanged += delegate + options.StateChanged += delegate { - switch (Options.State) + switch (options.State) { case Visibility.Hidden: intro.MoveToX(0, OptionsOverlay.TRANSITION_LENGTH, EasingTypes.OutQuint); @@ -164,7 +166,7 @@ namespace osu.Game switch (args.Key) { case Key.O: - Options.ToggleVisibility(); + options.ToggleVisibility(); return true; } } diff --git a/osu.Game/Overlays/Toolbar/Toolbar.cs b/osu.Game/Overlays/Toolbar/Toolbar.cs index a1af1d3293..df6168b6c5 100644 --- a/osu.Game/Overlays/Toolbar/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar/Toolbar.cs @@ -2,7 +2,6 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; @@ -22,10 +21,8 @@ namespace osu.Game.Overlays.Toolbar { private const float height = 50; - public Action OnSettings; public Action OnHome; public Action OnPlayModeChange; - public Action OnMusicController; private ToolbarModeSelector modeSelector; private Box solidBackground; @@ -87,18 +84,9 @@ namespace osu.Game.Overlays.Toolbar AutoSizeAxes = Axes.X, Children = new Drawable[] { - new ToolbarButton + new ToolbarSettingsButton(), + new ToolbarHomeButton() { - Icon = FontAwesome.fa_gear, - TooltipMain = "Settings", - TooltipSub = "Change your settings", - Action = () => OnSettings?.Invoke() - }, - new ToolbarButton - { - Icon = FontAwesome.fa_home, - TooltipMain = "Home", - TooltipSub = "Return to the main menu", Action = () => OnHome?.Invoke() }, modeSelector = new ToolbarModeSelector @@ -116,11 +104,7 @@ namespace osu.Game.Overlays.Toolbar AutoSizeAxes = Axes.X, Children = new [] { - new ToolbarButton - { - Icon = FontAwesome.fa_music, - Action = () => OnMusicController?.Invoke() - }, + new ToolbarMusicButton(), new ToolbarButton { Icon = FontAwesome.fa_search diff --git a/osu.Game/Overlays/Toolbar/ToolbarButton.cs b/osu.Game/Overlays/Toolbar/ToolbarButton.cs index 9949a81c89..70462fa5fe 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarButton.cs @@ -133,7 +133,7 @@ namespace osu.Game.Overlays.Toolbar protected override bool OnClick(InputState state) { Action?.Invoke(); - HoverBackground.FlashColour(new Color4(255, 255, 255, 180), 800, EasingTypes.OutQuint); + HoverBackground.FlashColour(new Color4(255, 255, 255, 100), 500, EasingTypes.OutQuint); return true; } diff --git a/osu.Game/Overlays/Toolbar/ToolbarHomeButton.cs b/osu.Game/Overlays/Toolbar/ToolbarHomeButton.cs new file mode 100644 index 0000000000..259abc0739 --- /dev/null +++ b/osu.Game/Overlays/Toolbar/ToolbarHomeButton.cs @@ -0,0 +1,19 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Game.Graphics; +using osu.Game.Screens.Menu; + +namespace osu.Game.Overlays.Toolbar +{ + class ToolbarHomeButton : ToolbarButton + { + public ToolbarHomeButton() + { + Icon = FontAwesome.fa_home; + TooltipMain = "Home"; + TooltipSub = "Return to the main menu"; + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs b/osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs new file mode 100644 index 0000000000..9409532df8 --- /dev/null +++ b/osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs @@ -0,0 +1,23 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Game.Graphics; + +namespace osu.Game.Overlays.Toolbar +{ + class ToolbarMusicButton : ToolbarToggleButton + { + public ToolbarMusicButton() + { + Icon = FontAwesome.fa_music; + } + + [BackgroundDependencyLoader] + private void load(MusicController music) + { + StateContainer = music; + Action = music.ToggleVisibility; + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs b/osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs new file mode 100644 index 0000000000..67fb4feb6f --- /dev/null +++ b/osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs @@ -0,0 +1,25 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Game.Graphics; + +namespace osu.Game.Overlays.Toolbar +{ + class ToolbarSettingsButton : ToolbarToggleButton + { + public ToolbarSettingsButton() + { + Icon = FontAwesome.fa_gear; + TooltipMain = "Settings"; + TooltipSub = "Change your settings"; + } + + [BackgroundDependencyLoader] + private void load(OptionsOverlay options) + { + StateContainer = options; + Action = options.ToggleVisibility; + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/Toolbar/ToolbarToggleButton.cs b/osu.Game/Overlays/Toolbar/ToolbarToggleButton.cs new file mode 100644 index 0000000000..72fc87b310 --- /dev/null +++ b/osu.Game/Overlays/Toolbar/ToolbarToggleButton.cs @@ -0,0 +1,71 @@ +//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.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Game.Configuration; +using osu.Game.Online.API; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Overlays.Toolbar +{ + class ToolbarToggleButton : ToolbarButton + { + private Box StateBackground; + + private OverlayContainer stateContainer; + + public OverlayContainer StateContainer + { + get { return stateContainer; } + set + { + stateContainer = value; + stateContainer.StateChanged += stateChanged; + } + } + + public ToolbarToggleButton() + { + Add(StateBackground = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = new Color4(150, 150, 150, 180), + BlendingMode = BlendingMode.Additive, + Depth = 2, + Alpha = 0, + }); + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + if (stateContainer != null) + stateContainer.StateChanged -= stateChanged; + } + + private void stateChanged(OverlayContainer c, Visibility state) + { + switch (state) + { + case Visibility.Hidden: + StateBackground.FadeOut(200); + break; + case Visibility.Visible: + StateBackground.FadeIn(200); + break; + } + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 6f56037026..4478590e42 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -92,6 +92,10 @@ + + + + From ebde5fa97feb10d01e4f044dcde4f2c1342a6f85 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 2 Dec 2016 20:56:05 +0900 Subject: [PATCH 2/3] Update framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index b5efbe6d53..e611e186e3 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit b5efbe6d53cb6895163731e2a934a1c6518d9d7d +Subproject commit e611e186e3c8951d7e58a6c92c75e1b587e825a2 From a80c28ca37a007bca6746cc981b14ab43a0fad24 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 2 Dec 2016 21:28:23 +0900 Subject: [PATCH 3/3] ToolbarOverlayToggleButton --- osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs | 2 +- .../{ToolbarToggleButton.cs => ToolbarOverlayToggleButton.cs} | 4 ++-- osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs | 2 +- osu.Game/osu.Game.csproj | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename osu.Game/Overlays/Toolbar/{ToolbarToggleButton.cs => ToolbarOverlayToggleButton.cs} (91%) diff --git a/osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs b/osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs index 9409532df8..67ec2aed26 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarMusicButton.cs @@ -6,7 +6,7 @@ using osu.Game.Graphics; namespace osu.Game.Overlays.Toolbar { - class ToolbarMusicButton : ToolbarToggleButton + class ToolbarMusicButton : ToolbarOverlayToggleButton { public ToolbarMusicButton() { diff --git a/osu.Game/Overlays/Toolbar/ToolbarToggleButton.cs b/osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs similarity index 91% rename from osu.Game/Overlays/Toolbar/ToolbarToggleButton.cs rename to osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs index 72fc87b310..b72a358456 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarToggleButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs @@ -20,7 +20,7 @@ using OpenTK.Graphics; namespace osu.Game.Overlays.Toolbar { - class ToolbarToggleButton : ToolbarButton + class ToolbarOverlayToggleButton : ToolbarButton { private Box StateBackground; @@ -36,7 +36,7 @@ namespace osu.Game.Overlays.Toolbar } } - public ToolbarToggleButton() + public ToolbarOverlayToggleButton() { Add(StateBackground = new Box { diff --git a/osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs b/osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs index 67fb4feb6f..4bc3964716 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarSettingsButton.cs @@ -6,7 +6,7 @@ using osu.Game.Graphics; namespace osu.Game.Overlays.Toolbar { - class ToolbarSettingsButton : ToolbarToggleButton + class ToolbarSettingsButton : ToolbarOverlayToggleButton { public ToolbarSettingsButton() { diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 4478590e42..c4915b7567 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -95,7 +95,7 @@ - +