From ba5b2f2d73fcb3285d0c45a49399e6c7361c8455 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 27 Oct 2016 12:31:45 +0900 Subject: [PATCH] Remove difficulty width offsets and tidy up flow of information. --- osu.Game/Beatmaps/Drawable/BeatmapGroup.cs | 120 +++++++++++---------- osu.Game/Beatmaps/Drawable/BeatmapPanel.cs | 6 +- osu.Game/GameModes/Play/PlaySongSelect.cs | 26 ++--- 3 files changed, 74 insertions(+), 78 deletions(-) diff --git a/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs b/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs index f94d267475..9baa393854 100644 --- a/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs +++ b/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs @@ -9,7 +9,6 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Input; using osu.Game.Database; -using osu.Game.Graphics; using OpenTK; using OpenTK.Graphics; @@ -22,60 +21,61 @@ namespace osu.Game.Beatmaps.Drawable Collapsed, Expanded, } - + private const float collapsedAlpha = 0.5f; private const float collapsedWidth = 0.8f; - - private BeatmapInfo selectedBeatmap; - public BeatmapInfo SelectedBeatmap - { - get { return selectedBeatmap; } - set - { - selectedBeatmap = value; - } - } - public Action BeatmapSelected; + private BeatmapInfo selectedBeatmap; + + /// + /// Fires when one of our difficulties was selected. Will fire on first expand. + /// + public Action SelectionChanged; + public BeatmapSetInfo BeatmapSet; private BeatmapSetHeader header; private FlowContainer difficulties; - private bool collapsed; + private GroupState state; public GroupState State { - get { return collapsed ? GroupState.Collapsed : GroupState.Expanded; } + get { return state; } set { - bool val = value == GroupState.Collapsed; - if (collapsed == val) - return; - collapsed = val; - ClearTransformations(); - const float uncollapsedAlpha = 1; - FadeTo(collapsed ? collapsedAlpha : uncollapsedAlpha, 250); - if (collapsed) - difficulties.Hide(); - else - difficulties.Show(); - header.ClearTransformations(); - header.Width = collapsed ? collapsedWidth : 1; // TODO: Transform - header.BorderColour = new Color4( - header.BorderColour.R, - header.BorderColour.G, - header.BorderColour.B, - collapsed ? 0 : 255); - header.GlowRadius = collapsed ? 0 : 5; + state = value; + switch (state) + { + case GroupState.Expanded: + FadeTo(1, 250); + difficulties.Show(); + + //todo: header should probably have a state, with this logic moved inside it. + header.Width = 1; + header.GlowRadius = 5; + header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 255); + + if (selectedBeatmap == null) + (difficulties.Children.FirstOrDefault() as BeatmapPanel).Selected = true; + SelectionChanged?.Invoke(this, selectedBeatmap); + break; + case GroupState.Collapsed: + FadeTo(collapsedAlpha, 250); + difficulties.Hide(); + + //todo: header should probably have a state, with this logic moved inside it. + header.Width = collapsedWidth; + header.GlowRadius = 0; + header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 0); + break; + } } } public BeatmapGroup(BeatmapSetInfo beatmapSet) { BeatmapSet = beatmapSet; - selectedBeatmap = beatmapSet.Beatmaps[0]; - Alpha = collapsedAlpha; + Alpha = 0; AutoSizeAxes = Axes.Y; RelativeSizeAxes = Axes.X; - float difficultyWidth = 1; Children = new[] { new FlowContainer @@ -101,38 +101,40 @@ namespace osu.Game.Beatmaps.Drawable Spacing = new Vector2(0, 5), Direction = FlowDirection.VerticalOnly, Alpha = 0, - Children = BeatmapSet.Beatmaps.Select( - b => { - float width = difficultyWidth; - if (difficultyWidth > 0.8f) difficultyWidth -= 0.025f; - return new BeatmapPanel(BeatmapSet, b) - { - MapSelected = updateSelected, - Selected = width == 1, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - RelativeSizeAxes = Axes.X, - Width = width, - }; - }) + Children = BeatmapSet.Beatmaps.Select(b => + new BeatmapPanel(BeatmapSet, b) + { + GainedSelection = panelGainedSelection, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + RelativeSizeAxes = Axes.X, + } + ) } } } }; - - collapsed = true; } - - private void updateSelected(BeatmapInfo map) + + public override void Load(BaseGame game) + { + base.Load(game); + State = GroupState.Collapsed; + } + + private void panelGainedSelection(BeatmapInfo map) { + selectedBeatmap = map; + foreach (BeatmapPanel panel in difficulties.Children) - panel.Selected = panel.Beatmap == map; - BeatmapSelected?.Invoke(this, map); + if (panel.Beatmap != map) panel.Selected = false; + + SelectionChanged?.Invoke(this, map); } - + protected override bool OnClick(InputState state) { - BeatmapSelected?.Invoke(this, selectedBeatmap); + State = GroupState.Expanded; return true; } } diff --git a/osu.Game/Beatmaps/Drawable/BeatmapPanel.cs b/osu.Game/Beatmaps/Drawable/BeatmapPanel.cs index fc658f5fd7..2283a0ce69 100644 --- a/osu.Game/Beatmaps/Drawable/BeatmapPanel.cs +++ b/osu.Game/Beatmaps/Drawable/BeatmapPanel.cs @@ -19,7 +19,7 @@ namespace osu.Game.Beatmaps.Drawable { public BeatmapInfo Beatmap; - public Action MapSelected; + public Action GainedSelection; private bool selected; @@ -37,6 +37,8 @@ namespace osu.Game.Beatmaps.Drawable BorderColour.B, selected ? 255 : 0); GlowRadius = selected ? 3 : 0; + + if (selected) GainedSelection?.Invoke(Beatmap); } } @@ -101,7 +103,7 @@ namespace osu.Game.Beatmaps.Drawable protected override bool OnClick(InputState state) { - MapSelected?.Invoke(Beatmap); + Selected = true; return true; } } diff --git a/osu.Game/GameModes/Play/PlaySongSelect.cs b/osu.Game/GameModes/Play/PlaySongSelect.cs index 410d3b1e2a..ae7204d0d8 100644 --- a/osu.Game/GameModes/Play/PlaySongSelect.cs +++ b/osu.Game/GameModes/Play/PlaySongSelect.cs @@ -120,7 +120,7 @@ namespace osu.Game.GameModes.Play // Temporary: scrollContainer.Padding = new MarginPadding { Top = osuGame.Toolbar.Height }; } - + beatmaps = (game as OsuGameBase).Beatmaps; beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset)); Task.Factory.StartNew(addBeatmapSets); @@ -136,21 +136,16 @@ namespace osu.Game.GameModes.Play private void PlayMode_ValueChanged(object sender, EventArgs e) { } - - private void selectBeatmapSet(BeatmapGroup group) + + private void selectBeatmap(BeatmapGroup group, BeatmapInfo beatmap) { if (selectedBeatmapGroup == group) return; - selectedBeatmapGroup.State = BeatmapGroup.GroupState.Collapsed; + + if (selectedBeatmapGroup != null) + selectedBeatmapGroup.State = BeatmapGroup.GroupState.Collapsed; + selectedBeatmapGroup = group; - selectedBeatmapGroup.State = BeatmapGroup.GroupState.Expanded; - } - - private void selectBeatmap(BeatmapGroup group, BeatmapInfo beatmap) - { - if (selectedBeatmap == beatmap) - return; - selectBeatmapSet(group); selectedBeatmap = beatmap; } @@ -158,16 +153,13 @@ namespace osu.Game.GameModes.Play { beatmapSet = beatmaps.GetWithChildren(beatmapSet.BeatmapSetID); beatmapSet.Beatmaps.ForEach(b => beatmaps.GetChildren(b)); - beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty) - .ToList(); + beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty).ToList(); Schedule(() => { - var group = new BeatmapGroup(beatmapSet) { BeatmapSelected = selectBeatmap }; + var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectBeatmap }; setList.Add(group); if (setList.Children.Count() == 1) { - selectedBeatmapGroup = group; - selectedBeatmap = group.SelectedBeatmap; group.State = BeatmapGroup.GroupState.Expanded; } });