1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +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;
using osu.Game.Graphics;
using osu.Framework.Graphics.Transformations;
namespace osu.Game.GameModes.Play
{
@ -24,14 +25,36 @@ namespace osu.Game.GameModes.Play
private BeatmapSetInfo beatmapSet;
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)
{
this.beatmapSet = set;
this.beatmap = beatmap;
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, -1);
Masking = true;
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[]
{
new Box
@ -72,7 +95,7 @@ namespace osu.Game.GameModes.Play
protected override bool OnClick(InputState state)
{
Selected?.Invoke(beatmap);
MapSelected?.Invoke(beatmap);
return true;
}
}

View File

@ -16,8 +16,8 @@ using osu.Framework.Input;
using OpenTK.Graphics;
using osu.Game.Beatmaps.IO;
using osu.Framework.Graphics.Textures;
using System.Threading.Tasks;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Play
{
class BeatmapGroup : AutoSizeContainer
@ -60,15 +60,17 @@ namespace osu.Game.GameModes.Play
EndTime = Time + 250,
});
if (collapsed)
{
topContainer.Remove(difficulties);
setBox.Size = new Vector2(collapsedWidth, -1);
}
else
{
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.R,
setBox.BorderColour.G,
@ -77,6 +79,27 @@ namespace osu.Game.GameModes.Play
setBox.GlowRadius = collapsed ? 0 : 5;
}
}
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)
{
@ -85,6 +108,7 @@ namespace osu.Game.GameModes.Play
Alpha = collapsedAlpha;
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, -1);
float difficultyWidth = 1;
Children = new[]
{
topContainer = new FlowContainer
@ -109,11 +133,23 @@ namespace osu.Game.GameModes.Play
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, -1),
Margin = new MarginPadding { Top = 5 },
Padding = new MarginPadding { Left = 25 },
Padding = new MarginPadding { Left = 75 },
Spacing = new Vector2(0, 5),
Direction = FlowDirection.VerticalOnly,
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;
}
@ -202,18 +238,18 @@ namespace osu.Game.GameModes.Play
};
}
public override void Load(Framework.BaseGame game)
{
public override void Load(Framework.BaseGame game)
{
base.Load(game);
if (beatmapSet.Metadata.BackgroundFile != null)
{
Task.Factory.StartNew(() =>
{
beatmapStore.AddBeatmap(beatmapSet);
var texture = resources.Get($@"{beatmapSet.BeatmapSetID}:{beatmapSet.Metadata.BackgroundFile}");
Scheduler.Add(() => backgroundImage.Texture = texture);
{
Task.Factory.StartNew(() =>
{
beatmapStore.AddBeatmap(beatmapSet);
var texture = resources.Get($@"{beatmapSet.BeatmapSetID}:{beatmapSet.Metadata.BackgroundFile}");
Scheduler.Add(() => backgroundImage.Texture = texture);
});
}
}
}
}

View File

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