mirror of
https://github.com/ppy/osu.git
synced 2025-03-06 05:53:11 +08:00
BeatmapPicker logic.
This commit is contained in:
parent
cbd9c07aed
commit
aa9dfcc082
@ -1,9 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Desktop.VisualTests.Tests
|
namespace osu.Desktop.VisualTests.Tests
|
||||||
{
|
{
|
||||||
@ -41,6 +43,13 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
Preview = @"https://b.ppy.sh/preview/415886.mp3",
|
Preview = @"https://b.ppy.sh/preview/415886.mp3",
|
||||||
PlayCount = 681380,
|
PlayCount = 681380,
|
||||||
FavouriteCount = 356,
|
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
|
Covers = new BeatmapSetOnlineCovers
|
||||||
{
|
{
|
||||||
Cover = @"https://assets.ppy.sh/beatmaps/415886/covers/cover.jpg?1465651778",
|
Cover = @"https://assets.ppy.sh/beatmaps/415886/covers/cover.jpg?1465651778",
|
||||||
@ -107,7 +116,7 @@ namespace osu.Desktop.VisualTests.Tests
|
|||||||
new BeatmapInfo
|
new BeatmapInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapID = 901050,
|
OnlineBeatmapID = 901050,
|
||||||
StarDifficulty = 901050,
|
StarDifficulty = 5.26,
|
||||||
Version = @"GRAVITY",
|
Version = @"GRAVITY",
|
||||||
Ruleset = r,
|
Ruleset = r,
|
||||||
Difficulty = new BeatmapDifficulty
|
Difficulty = new BeatmapDifficulty
|
||||||
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -26,12 +27,14 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
|
|||||||
|
|
||||||
private readonly OsuSpriteText version, starRating;
|
private readonly OsuSpriteText version, starRating;
|
||||||
|
|
||||||
|
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
||||||
|
|
||||||
public BeatmapPicker(BeatmapSetInfo set)
|
public BeatmapPicker(BeatmapSetInfo set)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
FillFlowContainer tileContainer;
|
TilesFillFlowContainer tileContainer;
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
@ -41,11 +44,15 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
|
|||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
tileContainer = new FillFlowContainer
|
tileContainer = new TilesFillFlowContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
AutoSizeAxes = Axes.Both,
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
Margin = new MarginPadding { Left = -(tile_icon_padding + tile_spacing / 2) },
|
Margin = new MarginPadding { Left = -(tile_icon_padding + tile_spacing / 2) },
|
||||||
|
OnLostHover = () =>
|
||||||
|
{
|
||||||
|
showBeatmap(Beatmap.Value);
|
||||||
|
starRating.FadeOut(100);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -60,7 +67,6 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
|
|||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
TextSize = 20,
|
TextSize = 20,
|
||||||
Font = @"Exo2.0-Bold",
|
Font = @"Exo2.0-Bold",
|
||||||
Text = "BASIC",
|
|
||||||
},
|
},
|
||||||
starRating = new OsuSpriteText
|
starRating = new OsuSpriteText
|
||||||
{
|
{
|
||||||
@ -68,7 +74,8 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
|
|||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
TextSize = 13,
|
TextSize = 13,
|
||||||
Font = @"Exo2.0-Bold",
|
Font = @"Exo2.0-Bold",
|
||||||
Text = "Star Difficulty 1.36",
|
Text = "Star Difficulty",
|
||||||
|
Alpha = 0,
|
||||||
Margin = new MarginPadding { Bottom = 1 },
|
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 =>
|
OnHovered = beatmap =>
|
||||||
{
|
{
|
||||||
|
showBeatmap(beatmap);
|
||||||
|
starRating.Text = string.Format("Star Difficulty {0:N2}", beatmap.StarDifficulty);
|
||||||
|
starRating.FadeIn(100);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Beatmap.TriggerChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -103,21 +117,36 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
|
|||||||
starRating.Colour = colours.Yellow;
|
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 class BeatmapTile : OsuClickableContainer
|
||||||
{
|
{
|
||||||
private const float transition_duration = 100;
|
private const float transition_duration = 100;
|
||||||
private const float size = 52;
|
private const float size = 52;
|
||||||
|
|
||||||
private readonly BeatmapInfo beatmap;
|
private readonly BeatmapInfo beatmap;
|
||||||
|
private readonly Bindable<BeatmapInfo> bindable = new Bindable<BeatmapInfo>();
|
||||||
|
|
||||||
private readonly Container bg;
|
private readonly Container bg;
|
||||||
private readonly DifficultyIcon icon;
|
private readonly DifficultyIcon icon;
|
||||||
|
|
||||||
public Action<BeatmapInfo> OnHovered;
|
public Action<BeatmapInfo> OnHovered;
|
||||||
|
|
||||||
public BeatmapTile(BeatmapInfo beatmap)
|
public BeatmapTile(BeatmapInfo beatmap, Bindable<BeatmapInfo> bindable)
|
||||||
{
|
{
|
||||||
this.beatmap = beatmap;
|
this.beatmap = beatmap;
|
||||||
|
this.bindable.BindTo(bindable);
|
||||||
Size = new Vector2(size);
|
Size = new Vector2(size);
|
||||||
Margin = new MarginPadding { Horizontal = tile_spacing / 2 };
|
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)
|
protected override bool OnHover(InputState state)
|
||||||
@ -155,6 +185,15 @@ namespace osu.Game.Overlays.OnlineBeatmapSet
|
|||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
protected override void OnHoverLost(InputState state)
|
||||||
{
|
{
|
||||||
|
if (bindable.Value != beatmap)
|
||||||
|
fadeOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindable_ValueChanged(BeatmapInfo value)
|
||||||
|
{
|
||||||
|
if (value == beatmap)
|
||||||
|
fadeIn();
|
||||||
|
else
|
||||||
fadeOut();
|
fadeOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user