From 772eb460fbd477fac46d5948bc133e0bc947b433 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 8 May 2019 19:03:26 +0900 Subject: [PATCH] Move button definitions to their respective classes --- osu.Game/Screens/Select/Footer.cs | 57 +++++++------------ osu.Game/Screens/Select/FooterButtonMods.cs | 11 ++++ osu.Game/Screens/Select/FooterButtonRandom.cs | 11 ++++ osu.Game/Screens/Select/SongSelect.cs | 6 +- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/osu.Game/Screens/Select/Footer.cs b/osu.Game/Screens/Select/Footer.cs index 4466fb418c..b5afc7b0ff 100644 --- a/osu.Game/Screens/Select/Footer.cs +++ b/osu.Game/Screens/Select/Footer.cs @@ -30,54 +30,39 @@ namespace osu.Game.Screens.Select private readonly FillFlowContainer buttons; - /// Button to be added. - /// Text on the button. - /// Colour of the button. + private readonly List overlays = new List(); + + /// THe button to be added. + /// The to be toggled by this button. /// Hotkey of the button. - /// Action the button does. - /// - /// Higher depth to be put on the left, and lower to be put on the right. - /// Notice this is different to ! - /// - public void AddButton(FooterButton button, string text, Color4 colour, Action action, Key? hotkey = null, float depth = 0) + public void AddButton(FooterButton button, OverlayContainer overlay, Key? hotkey = null) + { + overlays.Add(overlay); + AddButton(button, () => showOverlay(overlay), hotkey); + } + + /// Button to be added. + /// Action the button does. + /// Hotkey of the button. + public void AddButton(FooterButton button, Action action, Key? hotkey = null) { - button.Text = text; - button.Depth = depth; - button.SelectedColour = colour; - button.DeselectedColour = colour.Opacity(0.5f); button.Hotkey = hotkey; button.Hovered = updateModeLight; button.HoverLost = updateModeLight; button.Action = action; buttons.Add(button); - buttons.SetLayoutPosition(button, -depth); } - private readonly List overlays = new List(); - - /// THe button to be added. - /// Text on the button. - /// Colour of the button. - /// Hotkey of the button. - /// The to be toggled by this button. - /// - /// Higher depth to be put on the left, and lower to be put on the right. - /// Notice this is different to ! - /// - public void AddButton(FooterButton button, string text, Color4 colour, OverlayContainer overlay, Key? hotkey = null, float depth = 0) + private void showOverlay(OverlayContainer overlay) { - overlays.Add(overlay); - AddButton(button, text, colour, () => + foreach (var o in overlays) { - foreach (var o in overlays) - { - if (o == overlay) - o.ToggleVisibility(); - else - o.Hide(); - } - }, hotkey, depth); + if (o == overlay) + o.ToggleVisibility(); + else + o.Hide(); + } } private void updateModeLight() => modeLight.FadeColour(buttons.FirstOrDefault(b => b.IsHovered)?.SelectedColour ?? Color4.Transparent, TRANSITION_LENGTH, Easing.OutQuint); diff --git a/osu.Game/Screens/Select/FooterButtonMods.cs b/osu.Game/Screens/Select/FooterButtonMods.cs index 3de668bbf0..4343ee6cdb 100644 --- a/osu.Game/Screens/Select/FooterButtonMods.cs +++ b/osu.Game/Screens/Select/FooterButtonMods.cs @@ -7,6 +7,9 @@ using osu.Framework.Graphics.Containers; using osu.Game.Screens.Play.HUD; using osu.Game.Rulesets.Mods; using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; +using osu.Game.Graphics; using osuTK; namespace osu.Game.Screens.Select @@ -34,6 +37,14 @@ namespace osu.Game.Screens.Select modDisplay.Current = mods; } + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + SelectedColour = colours.Yellow; + DeselectedColour = SelectedColour.Opacity(0.5f); + Text = @"mods"; + } + private class FooterModDisplay : ModDisplay { public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false; diff --git a/osu.Game/Screens/Select/FooterButtonRandom.cs b/osu.Game/Screens/Select/FooterButtonRandom.cs index a725bfc103..06f2e1ee43 100644 --- a/osu.Game/Screens/Select/FooterButtonRandom.cs +++ b/osu.Game/Screens/Select/FooterButtonRandom.cs @@ -1,9 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; +using osu.Game.Graphics; using osu.Game.Graphics.Sprites; namespace osu.Game.Screens.Select @@ -24,6 +27,14 @@ namespace osu.Game.Screens.Select }); } + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + SelectedColour = colours.Green; + DeselectedColour = SelectedColour.Opacity(0.5f); + Text = @"random"; + } + protected override bool OnKeyDown(KeyDownEvent e) { secondaryActive = e.ShiftPressed; diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index d43ca33ee3..c747fdee60 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -223,9 +223,9 @@ namespace osu.Game.Screens.Select if (Footer != null) { - Footer.AddButton(new FooterButtonMods(mods), @"mods", colours.Yellow, ModSelect, Key.F1); - Footer.AddButton(new FooterButtonRandom(), @"random", colours.Green, triggerRandom, Key.F2); - Footer.AddButton(new FooterButton(), @"options", colours.Blue, BeatmapOptions, Key.F3); + Footer.AddButton(new FooterButtonMods(mods), ModSelect, Key.F1); + Footer.AddButton(new FooterButtonRandom(), triggerRandom, Key.F2); + Footer.AddButton(new FooterButtonOptions(), BeatmapOptions, Key.F3); BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo), Key.Number4, float.MaxValue); BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, colours.Purple, null, Key.Number1);