From aa9dfcc082da5c372dd093b7055ff5fca6786ef0 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Sat, 9 Sep 2017 19:05:22 -0300 Subject: [PATCH] BeatmapPicker logic. --- .../Visual/TestCaseOnlineBeatmapSetOverlay.cs | 13 +++- .../OnlineBeatmapSet/BeatmapPicker.cs | 59 +++++++++++++++---- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseOnlineBeatmapSetOverlay.cs b/osu.Desktop.Tests/Visual/TestCaseOnlineBeatmapSetOverlay.cs index c939bc002c..2bbe6ea952 100644 --- a/osu.Desktop.Tests/Visual/TestCaseOnlineBeatmapSetOverlay.cs +++ b/osu.Desktop.Tests/Visual/TestCaseOnlineBeatmapSetOverlay.cs @@ -1,9 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Overlays; using osu.Game.Rulesets; +using osu.Game.Users; namespace osu.Desktop.VisualTests.Tests { @@ -41,6 +43,13 @@ namespace osu.Desktop.VisualTests.Tests Preview = @"https://b.ppy.sh/preview/415886.mp3", PlayCount = 681380, FavouriteCount = 356, + Submitted = new DateTime(2016, 2, 10), + Ranked = new DateTime(2016, 6, 19), + Author = new User + { + Username = @"Fresh Chicken", + Id = 3984370, + }, Covers = new BeatmapSetOnlineCovers { Cover = @"https://assets.ppy.sh/beatmaps/415886/covers/cover.jpg?1465651778", @@ -107,7 +116,7 @@ namespace osu.Desktop.VisualTests.Tests new BeatmapInfo { OnlineBeatmapID = 901050, - StarDifficulty = 901050, + StarDifficulty = 5.26, Version = @"GRAVITY", Ruleset = r, Difficulty = new BeatmapDifficulty diff --git a/osu.Game/Overlays/OnlineBeatmapSet/BeatmapPicker.cs b/osu.Game/Overlays/OnlineBeatmapSet/BeatmapPicker.cs index fa02754d80..2a0e137a4e 100644 --- a/osu.Game/Overlays/OnlineBeatmapSet/BeatmapPicker.cs +++ b/osu.Game/Overlays/OnlineBeatmapSet/BeatmapPicker.cs @@ -6,6 +6,7 @@ using System.Linq; using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -26,12 +27,14 @@ namespace osu.Game.Overlays.OnlineBeatmapSet private readonly OsuSpriteText version, starRating; + public readonly Bindable Beatmap = new Bindable(); + public BeatmapPicker(BeatmapSetInfo set) { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - FillFlowContainer tileContainer; + TilesFillFlowContainer tileContainer; Children = new Drawable[] { new FillFlowContainer @@ -41,11 +44,15 @@ namespace osu.Game.Overlays.OnlineBeatmapSet Direction = FillDirection.Vertical, Children = new Drawable[] { - tileContainer = new FillFlowContainer + tileContainer = new TilesFillFlowContainer { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, + AutoSizeAxes = Axes.Both, Margin = new MarginPadding { Left = -(tile_icon_padding + tile_spacing / 2) }, + OnLostHover = () => + { + showBeatmap(Beatmap.Value); + starRating.FadeOut(100); + }, }, new FillFlowContainer { @@ -60,7 +67,6 @@ namespace osu.Game.Overlays.OnlineBeatmapSet Origin = Anchor.BottomLeft, TextSize = 20, Font = @"Exo2.0-Bold", - Text = "BASIC", }, starRating = new OsuSpriteText { @@ -68,7 +74,8 @@ namespace osu.Game.Overlays.OnlineBeatmapSet Origin = Anchor.BottomLeft, TextSize = 13, Font = @"Exo2.0-Bold", - Text = "Star Difficulty 1.36", + Text = "Star Difficulty", + Alpha = 0, Margin = new MarginPadding { Bottom = 1 }, }, }, @@ -89,12 +96,19 @@ namespace osu.Game.Overlays.OnlineBeatmapSet }, }; - tileContainer.ChildrenEnumerable = set.Beatmaps.Select(b => new BeatmapTile(b) + Beatmap.Value = set.Beatmaps.First(); + Beatmap.ValueChanged += showBeatmap; + tileContainer.ChildrenEnumerable = set.Beatmaps.Select(b => new BeatmapTile(b, Beatmap) { OnHovered = beatmap => { + showBeatmap(beatmap); + starRating.Text = string.Format("Star Difficulty {0:N2}", beatmap.StarDifficulty); + starRating.FadeIn(100); }, }); + + Beatmap.TriggerChange(); } [BackgroundDependencyLoader] @@ -103,21 +117,36 @@ namespace osu.Game.Overlays.OnlineBeatmapSet starRating.Colour = colours.Yellow; } + private void showBeatmap(BeatmapInfo beatmap) => version.Text = beatmap.Version; + + private class TilesFillFlowContainer : FillFlowContainer + { + public Action OnLostHover; + + protected override void OnHoverLost(InputState state) + { + base.OnHoverLost(state); + OnLostHover?.Invoke(); + } + } + private class BeatmapTile : OsuClickableContainer { private const float transition_duration = 100; private const float size = 52; private readonly BeatmapInfo beatmap; + private readonly Bindable bindable = new Bindable(); private readonly Container bg; private readonly DifficultyIcon icon; public Action OnHovered; - public BeatmapTile(BeatmapInfo beatmap) + public BeatmapTile(BeatmapInfo beatmap, Bindable bindable) { this.beatmap = beatmap; + this.bindable.BindTo(bindable); Size = new Vector2(size); Margin = new MarginPadding { Horizontal = tile_spacing / 2 }; @@ -143,7 +172,8 @@ namespace osu.Game.Overlays.OnlineBeatmapSet }, }; - fadeOut(); + Action = () => this.bindable.Value = beatmap; + this.bindable.ValueChanged += bindable_ValueChanged; } protected override bool OnHover(InputState state) @@ -155,7 +185,16 @@ namespace osu.Game.Overlays.OnlineBeatmapSet protected override void OnHoverLost(InputState state) { - fadeOut(); + if (bindable.Value != beatmap) + fadeOut(); + } + + private void bindable_ValueChanged(BeatmapInfo value) + { + if (value == beatmap) + fadeIn(); + else + fadeOut(); } private void fadeIn()