1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-08 22:43:21 +08:00
osu-lazer/osu.Game/GameModes/Play/BeatmapGroup.cs

169 lines
5.8 KiB
C#
Raw Normal View History

2016-10-14 03:10:00 +08:00
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
2016-10-14 03:10:00 +08:00
using osu.Game.Beatmaps;
2016-10-19 22:47:23 +08:00
using osu.Game.Database;
2016-10-14 03:10:00 +08:00
using osu.Framework.Graphics.Primitives;
using OpenTK;
using System.Linq;
2016-10-14 04:25:41 +08:00
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using OpenTK.Graphics;
2016-10-14 03:10:00 +08:00
namespace osu.Game.GameModes.Play
{
2016-10-14 04:55:15 +08:00
class BeatmapGroup : AutoSizeContainer
2016-10-14 03:10:00 +08:00
{
private const float collapsedAlpha = 0.3f;
2016-10-14 04:55:15 +08:00
2016-10-19 22:47:23 +08:00
public event Action<BeatmapSetInfo> SetSelected;
public event Action<BeatmapSetInfo, BeatmapInfo> BeatmapSelected;
public BeatmapSetInfo BeatmapSet;
2016-10-20 02:02:03 +08:00
private BeatmapSetBox setBox;
2016-10-14 04:55:15 +08:00
private FlowContainer topContainer;
2016-10-14 04:25:41 +08:00
private FlowContainer difficulties;
2016-10-14 03:10:00 +08:00
private bool collapsed;
public bool Collapsed
{
get { return collapsed; }
set
{
2016-10-14 04:25:41 +08:00
if (collapsed == value)
return;
2016-10-14 03:10:00 +08:00
collapsed = value;
2016-10-14 04:25:41 +08:00
this.ClearTransformations();
const float uncollapsedAlpha = 1;
Transforms.Add(new TransformAlpha(Clock)
{
StartValue = collapsed ? uncollapsedAlpha : collapsedAlpha,
EndValue = collapsed ? collapsedAlpha : uncollapsedAlpha,
StartTime = Time,
EndTime = Time + 250,
});
2016-10-14 03:10:00 +08:00
if (collapsed)
2016-10-14 04:55:15 +08:00
topContainer.Remove(difficulties);
2016-10-14 03:10:00 +08:00
else
2016-10-14 04:55:15 +08:00
topContainer.Add(difficulties);
2016-10-20 02:02:03 +08:00
setBox.BorderColour = new Color4(
setBox.BorderColour.R,
setBox.BorderColour.G,
setBox.BorderColour.B,
collapsed ? 0 : 255);
2016-10-14 03:10:00 +08:00
}
}
2016-10-19 22:47:23 +08:00
public BeatmapGroup(BeatmapSetInfo beatmapSet)
2016-10-14 03:10:00 +08:00
{
2016-10-14 04:25:41 +08:00
BeatmapSet = beatmapSet;
2016-10-14 04:55:15 +08:00
Alpha = collapsedAlpha;
2016-10-14 08:48:36 +08:00
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, 0);
2016-10-14 05:27:08 +08:00
Children = new[]
2016-10-14 03:10:00 +08:00
{
2016-10-14 04:55:15 +08:00
topContainer = new FlowContainer
{
2016-10-14 08:48:36 +08:00
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, 0),
2016-10-14 04:55:15 +08:00
Direction = FlowDirection.VerticalOnly,
2016-10-20 02:02:03 +08:00
Children = new[] { setBox = new BeatmapSetBox(beatmapSet) }
2016-10-14 04:55:15 +08:00
}
2016-10-14 03:10:00 +08:00
};
2016-10-14 04:25:41 +08:00
difficulties = new FlowContainer // Deliberately not added to children
{
2016-10-14 08:48:36 +08:00
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, 0),
Margin = new MarginPadding { Top = 5 },
Padding = new MarginPadding { Left = 25 },
Spacing = new Vector2(0, 5),
2016-10-14 04:25:41 +08:00
Direction = FlowDirection.VerticalOnly,
Children = this.BeatmapSet.Beatmaps.Select(b => new BeatmapButton(this.BeatmapSet, b))
};
collapsed = true;
2016-10-14 03:10:00 +08:00
}
2016-10-14 04:25:41 +08:00
protected override bool OnClick(InputState state)
2016-10-14 03:10:00 +08:00
{
2016-10-14 04:25:41 +08:00
SetSelected?.Invoke(BeatmapSet);
return true;
2016-10-14 03:10:00 +08:00
}
}
class BeatmapSetBox : AutoSizeContainer
{
2016-10-19 22:47:23 +08:00
private BeatmapSetInfo beatmapSet;
2016-10-19 22:47:23 +08:00
public BeatmapSetBox(BeatmapSetInfo beatmapSet)
{
this.beatmapSet = beatmapSet;
2016-10-14 08:48:36 +08:00
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, 0);
2016-10-20 02:02:03 +08:00
Masking = true;
CornerRadius = 5;
BorderThickness = 2;
BorderColour = new Color4(221, 255, 255, 0);
Children = new Drawable[]
{
new Box
{
Colour = new Color4(85, 85, 85, 255), // TODO: Gradient, and beatmap texture
RelativeSizeAxes = Axes.Both,
Size = new Vector2(1),
},
new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0, 2),
Padding = new MarginPadding { Top = 3, Left = 20, Right = 20, Bottom = 3 },
Children = new[]
{
// TODO: Make these italic
new SpriteText
{
Text = this.beatmapSet.Metadata.TitleUnicode ?? this.beatmapSet.Metadata.Title,
TextSize = 20
},
new SpriteText
{
Text = this.beatmapSet.Metadata.ArtistUnicode ?? this.beatmapSet.Metadata.Artist,
TextSize = 16
},
new FlowContainer
{
Children = new[]
{
new DifficultyIcon(FontAwesome.dot_circle_o, new Color4(159, 198, 0, 255)),
new DifficultyIcon(FontAwesome.dot_circle_o, new Color4(246, 101, 166, 255)),
}
}
}
}
};
}
}
class DifficultyIcon : Container
{
public DifficultyIcon(FontAwesome icon, Color4 color)
{
const float size = 20;
Size = new Vector2(size);
Children = new[]
{
new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = size,
Size = new Vector2(size),
Colour = color,
Icon = icon
}
};
}
}
2016-10-14 03:10:00 +08:00
}