mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 05:52:54 +08:00
Add animation, selection indicator to difficulties
This commit is contained in:
parent
4b6a1486a6
commit
910a079bda
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ using osu.Framework.Input;
|
|||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Game.Beatmaps.IO;
|
using osu.Game.Beatmaps.IO;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace osu.Game.GameModes.Play
|
namespace osu.Game.GameModes.Play
|
||||||
{
|
{
|
||||||
class BeatmapGroup : AutoSizeContainer
|
class BeatmapGroup : AutoSizeContainer
|
||||||
@ -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,
|
||||||
@ -77,6 +79,27 @@ namespace osu.Game.GameModes.Play
|
|||||||
setBox.GlowRadius = collapsed ? 0 : 5;
|
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)
|
public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources)
|
||||||
{
|
{
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
@ -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);
|
base.Load(game);
|
||||||
if (beatmapSet.Metadata.BackgroundFile != null)
|
if (beatmapSet.Metadata.BackgroundFile != null)
|
||||||
{
|
{
|
||||||
Task.Factory.StartNew(() =>
|
Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
beatmapStore.AddBeatmap(beatmapSet);
|
beatmapStore.AddBeatmap(beatmapSet);
|
||||||
var texture = resources.Get($@"{beatmapSet.BeatmapSetID}:{beatmapSet.Metadata.BackgroundFile}");
|
var texture = resources.Get($@"{beatmapSet.BeatmapSetID}:{beatmapSet.Metadata.BackgroundFile}");
|
||||||
Scheduler.Add(() => backgroundImage.Texture = texture);
|
Scheduler.Add(() => backgroundImage.Texture = texture);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user