From 9c27c33e18742a514a04c20500437cc1e55d88b1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 26 Oct 2016 12:49:16 -0400 Subject: [PATCH] Use IStateful and improve collapse logic --- osu.Game/GameModes/Play/BeatmapGroup.cs | 38 +++++++++++--------- osu.Game/GameModes/Play/PlaySongSelect.cs | 42 +++++++---------------- 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/osu.Game/GameModes/Play/BeatmapGroup.cs b/osu.Game/GameModes/Play/BeatmapGroup.cs index 63aa65b832..826f8e3b0c 100644 --- a/osu.Game/GameModes/Play/BeatmapGroup.cs +++ b/osu.Game/GameModes/Play/BeatmapGroup.cs @@ -17,11 +17,18 @@ using OpenTK.Graphics; using osu.Game.Beatmaps.IO; using osu.Framework.Graphics.Textures; using System.Threading.Tasks; - +using osu.Framework; + namespace osu.Game.GameModes.Play { - class BeatmapGroup : Container + class BeatmapGroup : Container, IStateful { + public enum GroupState + { + Collapsed, + Expanded, + } + private const float collapsedAlpha = 0.5f; private const float collapsedWidth = 0.8f; @@ -35,21 +42,20 @@ namespace osu.Game.GameModes.Play } } - public Action SetSelected; - public Action BeatmapSelected; + public Action BeatmapSelected; public BeatmapSetInfo BeatmapSet; - private BeatmapSetBox setBox; - private FlowContainer topContainer; + private BeatmapSetHeader setBox; private FlowContainer difficulties; private bool collapsed; - public bool Collapsed + public GroupState State { - get { return collapsed; } + get { return collapsed ? GroupState.Collapsed : GroupState.Expanded; } set { - if (collapsed == value) + bool val = value == GroupState.Collapsed; + if (collapsed == val) return; - collapsed = value; + collapsed = val; ClearTransformations(); const float uncollapsedAlpha = 1; FadeTo(collapsed ? collapsedAlpha : uncollapsedAlpha, 250); @@ -78,14 +84,14 @@ namespace osu.Game.GameModes.Play float difficultyWidth = 1; Children = new[] { - topContainer = new FlowContainer + new FlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Direction = FlowDirection.VerticalOnly, Children = new Drawable[] { - setBox = new BeatmapSetBox(beatmapSet) + setBox = new BeatmapSetHeader(beatmapSet) { RelativeSizeAxes = Axes.X, Width = collapsedWidth, @@ -127,19 +133,19 @@ namespace osu.Game.GameModes.Play { foreach (BeatmapPanel panel in difficulties.Children) panel.Selected = panel.Beatmap == map; - BeatmapSelected?.Invoke(BeatmapSet, map); + BeatmapSelected?.Invoke(this, map); } protected override bool OnClick(InputState state) { - SetSelected?.Invoke(BeatmapSet); + BeatmapSelected?.Invoke(this, selectedBeatmap); return true; } } - class BeatmapSetBox : Container + class BeatmapSetHeader : Container { - public BeatmapSetBox(BeatmapSetInfo beatmapSet) + public BeatmapSetHeader(BeatmapSetInfo beatmapSet) { AutoSizeAxes = Axes.Y; Masking = true; diff --git a/osu.Game/GameModes/Play/PlaySongSelect.cs b/osu.Game/GameModes/Play/PlaySongSelect.cs index 3f23b362f3..d988ab79ce 100644 --- a/osu.Game/GameModes/Play/PlaySongSelect.cs +++ b/osu.Game/GameModes/Play/PlaySongSelect.cs @@ -2,13 +2,10 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Collections.Generic; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; -using osu.Game.Beatmaps; -using osu.Game.Beatmaps.IO; using osu.Game.GameModes.Backgrounds; using osu.Framework; using osu.Game.Database; @@ -16,10 +13,8 @@ using osu.Framework.Graphics.Primitives; using System.Linq; using OpenTK; using OpenTK.Graphics; -using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.UserInterface; using System.Threading.Tasks; -using System.Diagnostics; namespace osu.Game.GameModes.Play { @@ -27,7 +22,7 @@ namespace osu.Game.GameModes.Play { private Bindable playMode; private BeatmapDatabase beatmaps; - private BeatmapSetInfo selectedBeatmapSet; + private BeatmapGroup selectedBeatmapGroup; private BeatmapInfo selectedBeatmap; // TODO: use currently selected track as bg protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4"); @@ -141,29 +136,20 @@ namespace osu.Game.GameModes.Play { } - private void selectBeatmapSet(BeatmapSetInfo beatmapSet) + private void selectBeatmapSet(BeatmapGroup group) { - if (selectedBeatmapSet == beatmapSet) + if (selectedBeatmapGroup == group) return; - selectedBeatmapSet = beatmapSet; - foreach (var child in setList.Children) - { - var childGroup = child as BeatmapGroup; - if (childGroup.BeatmapSet == beatmapSet) - { - childGroup.Collapsed = false; - selectedBeatmap = childGroup.SelectedBeatmap; - } - else - childGroup.Collapsed = true; - } + selectedBeatmapGroup.State = BeatmapGroup.GroupState.Collapsed; + selectedBeatmapGroup = group; + selectedBeatmapGroup.State = BeatmapGroup.GroupState.Expanded; } - private void selectBeatmap(BeatmapSetInfo set, BeatmapInfo beatmap) + private void selectBeatmap(BeatmapGroup group, BeatmapInfo beatmap) { if (selectedBeatmap == beatmap) return; - selectBeatmapSet(set); + selectBeatmapSet(group); selectedBeatmap = beatmap; } @@ -173,19 +159,15 @@ namespace osu.Game.GameModes.Play beatmapSet.Beatmaps.ForEach(b => beatmaps.GetChildren(b)); beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty) .ToList(); - Scheduler.Add(() => + Schedule(() => { - var group = new BeatmapGroup(beatmapSet) - { - SetSelected = selectBeatmapSet, - BeatmapSelected = selectBeatmap, - }; + var group = new BeatmapGroup(beatmapSet) { BeatmapSelected = selectBeatmap }; setList.Add(group); if (setList.Children.Count() == 1) { - selectedBeatmapSet = group.BeatmapSet; + selectedBeatmapGroup = group; selectedBeatmap = group.SelectedBeatmap; - group.Collapsed = false; + group.State = BeatmapGroup.GroupState.Expanded; } }); }