1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 07:27:51 +08:00
osu-lazer/osu.Game/Screens/Select/BeatmapInfoWedge.cs

235 lines
9.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-12-06 17:56:20 +08:00
using System;
using System.Collections.Generic;
2016-11-24 12:48:48 +08:00
using osu.Framework.Allocation;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Framework.Graphics.Colour;
2016-11-24 12:48:48 +08:00
using osu.Game.Beatmaps.Drawables;
2016-12-16 11:25:28 +08:00
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
2017-01-30 15:03:45 +08:00
using osu.Framework.MathUtils;
2016-12-16 11:25:28 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Modes;
namespace osu.Game.Screens.Select
{
2016-11-24 12:48:48 +08:00
class BeatmapInfoWedge : Container
{
private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0);
2017-02-27 14:55:34 +08:00
private BufferedContainer beatmapInfoContainer;
2017-01-30 14:15:56 +08:00
private OsuGameBase game;
2016-11-24 12:48:48 +08:00
public BeatmapInfoWedge()
{
Shear = wedged_container_shear;
Masking = true;
BorderColour = new Color4(221, 255, 255, 255);
BorderThickness = 2.5f;
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Glow,
Colour = new Color4(130, 204, 255, 150),
Radius = 20,
Roundness = 15,
};
}
2016-11-24 12:48:48 +08:00
[BackgroundDependencyLoader]
2017-01-30 14:15:56 +08:00
private void load(OsuGameBase game)
2016-11-24 12:48:48 +08:00
{
this.game = game;
}
public void UpdateBeatmap(WorkingBeatmap beatmap)
{
if (beatmap == null)
return;
2016-11-24 12:48:48 +08:00
var lastContainer = beatmapInfoContainer;
2016-11-30 03:50:12 +08:00
float newDepth = lastContainer?.Depth + 1 ?? 0;
BeatmapInfo beatmapInfo = beatmap.BeatmapInfo;
2017-02-27 19:39:04 +08:00
BeatmapMetadata metadata = beatmap.BeatmapInfo?.Metadata ?? beatmap.BeatmapSetInfo?.Metadata ?? new BeatmapMetadata();
2016-11-24 12:48:48 +08:00
2017-01-30 14:15:56 +08:00
List<InfoLabel> labels = new List<InfoLabel>();
2017-01-30 14:15:56 +08:00
if (beatmap.Beatmap != null)
{
2017-01-30 14:15:56 +08:00
labels.Add(new InfoLabel(new BeatmapStatistic
{
Name = "Length",
Icon = FontAwesome.fa_clock_o,
Content = beatmap.Beatmap.HitObjects.Count == 0 ? "-" : TimeSpan.FromMilliseconds(beatmap.Beatmap.HitObjects.Last().EndTime - beatmap.Beatmap.HitObjects.First().StartTime).ToString(@"m\:ss"),
2017-01-30 14:15:56 +08:00
}));
labels.Add(new InfoLabel(new BeatmapStatistic
{
Name = "BPM",
Icon = FontAwesome.fa_circle,
Content = getBPMRange(beatmap.Beatmap),
}));
2017-01-30 14:15:56 +08:00
//get statistics fromt he current ruleset.
Ruleset.GetRuleset(beatmap.BeatmapInfo.Mode).GetBeatmapStatistics(beatmap).ForEach(s => labels.Add(new InfoLabel(s)));
}
2016-12-17 22:53:26 +08:00
2016-11-24 12:48:48 +08:00
(beatmapInfoContainer = new BufferedContainer
{
Depth = newDepth,
PixelSnapping = true,
CacheDrawnFrameBuffer = true,
Shear = -Shear,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
// We will create the white-to-black gradient by modulating transparency and having
// a black backdrop. This results in an sRGB-space gradient and not linear space,
// transitioning from white to black more perceptually uniformly.
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
// We use a container, such that we can set the colour gradient to go across the
// vertices of the masked container instead of the vertices of the (larger) sprite.
2016-11-24 12:48:48 +08:00
new Container
{
RelativeSizeAxes = Axes.Both,
2017-01-11 02:44:40 +08:00
ColourInfo = ColourInfo.GradientVertical(Color4.White, Color4.White.Opacity(0.3f)),
Children = new []
{
2016-12-17 22:53:26 +08:00
// Zoomed-in and cropped beatmap background
2016-11-24 12:48:48 +08:00
new BeatmapBackgroundSprite(beatmap)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
},
},
},
// Text for beatmap info
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical,
Margin = new MarginPadding { Top = 10, Left = 25, Right = 10, Bottom = 20 },
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
2017-02-27 19:39:04 +08:00
Text = metadata.Artist + " -- " + metadata.Title,
TextSize = 28,
Shadow = true,
},
new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
Text = beatmapInfo.Version,
TextSize = 17,
Shadow = true,
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
Margin = new MarginPadding { Top = 10 },
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Children = new []
{
new OsuSpriteText
{
Font = @"Exo2.0-Medium",
Text = "mapped by ",
TextSize = 15,
Shadow = true,
},
new OsuSpriteText
{
Font = @"Exo2.0-Bold",
2017-02-27 19:39:04 +08:00
Text = metadata.Author,
TextSize = 15,
Shadow = true,
},
}
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
Margin = new MarginPadding { Top = 20 },
2017-03-02 02:33:01 +08:00
Spacing = new Vector2(40, 0),
AutoSizeAxes = Axes.Both,
Children = labels
},
}
2016-12-17 22:53:26 +08:00
},
}
}).LoadAsync(game, delegate (Drawable d)
2016-11-24 12:48:48 +08:00
{
FadeIn(250);
2016-11-24 12:48:48 +08:00
lastContainer?.FadeOut(250);
lastContainer?.Expire();
Add(d);
});
}
2016-12-18 02:57:58 +08:00
private string getBPMRange(Beatmap beatmap)
2016-12-18 02:57:58 +08:00
{
2017-01-30 15:03:45 +08:00
double bpmMax = beatmap.BPMMaximum;
double bpmMin = beatmap.BPMMinimum;
if (Precision.AlmostEquals(bpmMin, bpmMax)) return Math.Round(bpmMin) + "bpm";
return Math.Round(bpmMin) + "-" + Math.Round(bpmMax) + "bpm (mostly " + Math.Round(beatmap.BPMMode) + "bpm)";
2016-12-18 02:57:58 +08:00
}
2017-01-29 14:06:44 +08:00
public class InfoLabel : Container
2016-12-17 22:53:26 +08:00
{
public InfoLabel(BeatmapStatistic statistic)
2016-12-17 22:53:26 +08:00
{
2017-01-29 14:06:44 +08:00
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
2016-12-17 22:53:26 +08:00
new TextAwesome
{
2016-12-18 23:53:52 +08:00
Icon = FontAwesome.fa_square,
2017-01-29 14:15:04 +08:00
Colour = new Color4(68, 17, 136, 255),
2016-12-18 23:53:52 +08:00
Rotation = 45
2016-12-17 22:53:26 +08:00
},
new TextAwesome
{
Icon = statistic.Icon,
2017-01-29 14:15:04 +08:00
Colour = new Color4(255, 221, 85, 255),
Scale = new Vector2(0.8f)
2016-12-17 22:53:26 +08:00
},
new OsuSpriteText
{
2017-01-29 14:15:04 +08:00
Margin = new MarginPadding { Left = 13 },
Font = @"Exo2.0-Bold",
2017-01-29 14:15:04 +08:00
Colour = new Color4(255, 221, 85, 255),
Text = statistic.Content,
TextSize = 17,
Origin = Anchor.CentreLeft
2016-12-17 22:53:26 +08:00
},
2017-01-29 14:06:44 +08:00
};
}
2016-12-17 22:53:26 +08:00
}
}
}