1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 12:42:54 +08:00

Add animation, selection indicator to difficulties

This commit is contained in:
Drew DeVault 2016-10-20 15:16:06 -04:00
parent 4b6a1486a6
commit 910a079bda
3 changed files with 83 additions and 24 deletions

View File

@ -16,6 +16,7 @@ using osu.Framework.Graphics.Primitives;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK; using OpenTK;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Framework.Graphics.Transformations;
namespace osu.Game.GameModes.Play namespace osu.Game.GameModes.Play
{ {
@ -24,14 +25,36 @@ namespace osu.Game.GameModes.Play
private BeatmapSetInfo beatmapSet; private BeatmapSetInfo beatmapSet;
private BeatmapInfo beatmap; private BeatmapInfo beatmap;
public Action<BeatmapInfo> Selected; public Action<BeatmapInfo> MapSelected;
private bool selected;
public bool Selected
{
get { return selected; }
set
{
if (selected == value)
return;
selected = value;
BorderColour = new Color4(
BorderColour.R,
BorderColour.G,
BorderColour.B,
selected ? 255 : 0);
GlowRadius = selected ? 3 : 0;
}
}
public BeatmapButton(BeatmapSetInfo set, BeatmapInfo beatmap) public BeatmapButton(BeatmapSetInfo set, BeatmapInfo beatmap)
{ {
this.beatmapSet = set; this.beatmapSet = set;
this.beatmap = beatmap; this.beatmap = beatmap;
RelativeSizeAxes = Axes.X; Masking = true;
Size = new Vector2(1, -1); CornerRadius = 5;
BorderThickness = 2;
BorderColour = new Color4(221, 255, 255, 0);
GlowColour = new Color4(166, 221, 251, 0.75f); // TODO: Get actual color for this
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -72,7 +95,7 @@ namespace osu.Game.GameModes.Play
protected override bool OnClick(InputState state) protected override bool OnClick(InputState state)
{ {
Selected?.Invoke(beatmap); MapSelected?.Invoke(beatmap);
return true; return true;
} }
} }

View File

@ -60,15 +60,17 @@ namespace osu.Game.GameModes.Play
EndTime = Time + 250, EndTime = Time + 250,
}); });
if (collapsed) if (collapsed)
{
topContainer.Remove(difficulties); topContainer.Remove(difficulties);
setBox.Size = new Vector2(collapsedWidth, -1);
}
else else
{
topContainer.Add(difficulties); topContainer.Add(difficulties);
setBox.Size = new Vector2(1, -1); setBox.ClearTransformations();
} setBox.Transforms.Add(new TransformSize(Clock)
{
StartValue = new Vector2(collapsed ? 1 : collapsedWidth, -1),
EndValue = new Vector2(collapsed ? collapsedWidth : 1, -1),
StartTime = Time,
EndTime = Time + 200,
});
setBox.BorderColour = new Color4( setBox.BorderColour = new Color4(
setBox.BorderColour.R, setBox.BorderColour.R,
setBox.BorderColour.G, setBox.BorderColour.G,
@ -78,6 +80,27 @@ namespace osu.Game.GameModes.Play
} }
} }
private void updateSelected(BeatmapInfo map)
{
int selected = BeatmapSet.Beatmaps.IndexOf(map);
var buttons = difficulties.Children.ToList();
for (int i = 0; i < buttons.Count; i++)
{
var button = buttons[i] as BeatmapButton;
float targetWidth = 1 - Math.Abs((selected - i) * 0.025f);
targetWidth = MathHelper.Clamp(targetWidth, 0.8f, 1);
button.Transforms.Add(new TransformSize(Clock)
{
StartValue = new Vector2(button.Size.X, -1),
EndValue = new Vector2(targetWidth, -1),
StartTime = Time,
EndTime = Time + 100,
});
button.Selected = selected == i;
}
BeatmapSelected?.Invoke(BeatmapSet, map);
}
public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources) public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources)
{ {
BeatmapSet = beatmapSet; BeatmapSet = beatmapSet;
@ -85,6 +108,7 @@ namespace osu.Game.GameModes.Play
Alpha = collapsedAlpha; Alpha = collapsedAlpha;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Size = new Vector2(1, -1); Size = new Vector2(1, -1);
float difficultyWidth = 1;
Children = new[] Children = new[]
{ {
topContainer = new FlowContainer topContainer = new FlowContainer
@ -109,11 +133,23 @@ namespace osu.Game.GameModes.Play
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Size = new Vector2(1, -1), Size = new Vector2(1, -1),
Margin = new MarginPadding { Top = 5 }, Margin = new MarginPadding { Top = 5 },
Padding = new MarginPadding { Left = 25 }, Padding = new MarginPadding { Left = 75 },
Spacing = new Vector2(0, 5), Spacing = new Vector2(0, 5),
Direction = FlowDirection.VerticalOnly, Direction = FlowDirection.VerticalOnly,
Children = this.BeatmapSet.Beatmaps.Select( Children = this.BeatmapSet.Beatmaps.Select(
b => new BeatmapButton(this.BeatmapSet, b) { Selected = beatmap => BeatmapSelected?.Invoke(beatmapSet, beatmap) }) b => {
float width = difficultyWidth;
if (difficultyWidth > 0.8f) difficultyWidth -= 0.025f;
return new BeatmapButton(this.BeatmapSet, b)
{
MapSelected = beatmap => updateSelected(beatmap),
Selected = width == 1,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.X,
Size = new Vector2(width, -1),
};
})
}; };
collapsed = true; collapsed = true;
} }

View File

@ -80,7 +80,7 @@ namespace osu.Game.GameModes.Play
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Size = new Vector2(1), Size = new Vector2(1),
Padding = new MarginPadding { Right = scrollWidth - 100 }, Padding = new MarginPadding { Right = scrollWidth - 200 },
Children = new[] Children = new[]
{ {
new Box new Box