osu/osu.Game/Screens/Select/BeatmapInfoWedge.cs

226 lines
9.3 KiB
C#
Raw Normal View History

2016-12-06 09:56:20 +00: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;
2016-11-24 04:48:48 +00:00
using osu.Framework;
using osu.Framework.Allocation;
using OpenTK;
using OpenTK.Graphics;
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 04:48:48 +00:00
using osu.Game.Beatmaps.Drawables;
2016-12-16 03:25:28 +00:00
using System.Linq;
using osu.Game.Graphics;
2016-12-17 18:31:34 +00:00
using osu.Game.Beatmaps.Timing;
namespace osu.Game.Screens.Select
{
2016-11-24 04:48:48 +00:00
class BeatmapInfoWedge : Container
{
private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0);
private Container beatmapInfoContainer;
2016-11-24 04:48:48 +00:00
private BaseGame game;
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 04:48:48 +00:00
[BackgroundDependencyLoader]
2016-12-17 10:30:30 +00:00
private void load(BaseGame game)
2016-11-24 04:48:48 +00:00
{
this.game = game;
}
public void UpdateBeatmap(WorkingBeatmap beatmap)
{
if (beatmap == null)
return;
2016-11-24 04:48:48 +00:00
var lastContainer = beatmapInfoContainer;
2016-11-29 19:50:12 +00:00
float newDepth = lastContainer?.Depth + 1 ?? 0;
BeatmapSetInfo beatmapSetInfo = beatmap.BeatmapSetInfo;
BeatmapInfo beatmapInfo = beatmap.BeatmapInfo;
2016-11-24 04:48:48 +00:00
string bpm = getBPMRange(beatmap.Beatmap);
2016-12-18 15:53:52 +00:00
string length = TimeSpan.FromMilliseconds((beatmap.Beatmap.HitObjects.Last().EndTime - beatmap.Beatmap.HitObjects.First().StartTime)).ToString(@"m\:ss");
string hitCircles = beatmap.Beatmap.HitObjects.Count(h => h.Duration == 0).ToString();
string sliders = beatmap.Beatmap.HitObjects.Count(h => h.Duration > 0).ToString();
2016-12-17 14:53:26 +00:00
2016-11-24 04:48:48 +00: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 04:48:48 +00:00
new Container
{
RelativeSizeAxes = Axes.Both,
2017-01-10 18:44:40 +00:00
ColourInfo = ColourInfo.GradientVertical(Color4.White, Color4.White.Opacity(0.3f)),
Children = new []
{
2016-12-17 14:53:26 +00:00
// Zoomed-in and cropped beatmap background
2016-11-24 04:48:48 +00:00
new BeatmapBackgroundSprite(beatmap)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
},
},
},
// Text for beatmap info
new FlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Direction = FlowDirection.VerticalOnly,
Margin = new MarginPadding { Top = 10, Left = 25, Right = 10, Bottom = 20 },
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new SpriteText
{
Font = @"Exo2.0-MediumItalic",
Text = beatmapSetInfo.Metadata.Artist + " -- " + beatmapSetInfo.Metadata.Title,
TextSize = 28,
Shadow = true,
},
new SpriteText
{
Font = @"Exo2.0-MediumItalic",
Text = beatmapInfo.Version,
TextSize = 17,
Shadow = true,
},
new FlowContainer
{
Margin = new MarginPadding { Top = 10 },
Direction = FlowDirection.HorizontalOnly,
AutoSizeAxes = Axes.Both,
Children = new []
{
new SpriteText
{
Font = @"Exo2.0-Medium",
Text = "mapped by ",
TextSize = 15,
Shadow = true,
},
new SpriteText
{
Font = @"Exo2.0-Bold",
Text = beatmapSetInfo.Metadata.Author,
TextSize = 15,
Shadow = true,
},
}
},
new FlowContainer
{
Margin = new MarginPadding { Top = 20 },
Spacing = new Vector2(40,0),
AutoSizeAxes = Axes.Both,
2017-01-29 06:06:44 +00:00
Children = new []
2016-12-17 00:58:39 +00:00
{
2017-01-29 06:06:44 +00:00
new InfoLabel(FontAwesome.fa_clock_o, length),
new InfoLabel(FontAwesome.fa_circle, bpm),
new InfoLabel(FontAwesome.fa_dot_circle_o, hitCircles),
new InfoLabel(FontAwesome.fa_circle_o, sliders),
}
},
}
2016-12-17 14:53:26 +00:00
},
}
2017-01-29 06:06:44 +00:00
}).Preload(game, delegate (Drawable d)
2016-11-24 04:48:48 +00:00
{
FadeIn(250);
2016-11-24 04:48:48 +00:00
lastContainer?.FadeOut(250);
lastContainer?.Expire();
Add(d);
});
}
2016-12-17 18:57:58 +00:00
private string getBPMRange(Beatmap beatmap)
2016-12-17 18:57:58 +00:00
{
double bpmMax = double.MinValue;
double bpmMin = double.MaxValue;
double bpmMost = beatmap.BPMAt(beatmap.ControlPoints.Where(c => c.BeatLength != 0).GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).First().First().Time);
foreach (ControlPoint a in beatmap.ControlPoints)
2016-12-17 18:57:58 +00:00
{
if (a.BeatLength == 0) continue;
double tmp = beatmap.BPMAt(a.Time);
2016-12-17 18:57:58 +00:00
if (bpmMax < tmp) bpmMax = tmp;
if (bpmMin > tmp) bpmMin = tmp;
}
2016-12-18 02:53:26 +00:00
if (bpmMax == bpmMin) return Math.Round(bpmMin) + "bpm";
2017-01-29 06:16:38 +00:00
return Math.Round(bpmMin) + "-" + Math.Round(bpmMax) + "bpm (mostly " + Math.Round(bpmMost) + "bpm)";
2016-12-17 18:57:58 +00:00
}
2017-01-29 06:06:44 +00:00
public class InfoLabel : Container
2016-12-17 14:53:26 +00:00
{
2017-01-29 06:06:44 +00:00
public InfoLabel(FontAwesome icon, string text)
2016-12-17 14:53:26 +00:00
{
2017-01-29 06:06:44 +00:00
AutoSizeAxes = Axes.Both;
Children = new[]
{
2016-12-17 14:53:26 +00:00
new TextAwesome
{
2016-12-18 15:53:52 +00:00
Icon = FontAwesome.fa_square,
2017-01-29 06:15:04 +00:00
Colour = new Color4(68, 17, 136, 255),
2016-12-18 15:53:52 +00:00
Rotation = 45
2016-12-17 14:53:26 +00:00
},
new TextAwesome
{
2016-12-18 15:53:52 +00:00
Icon = icon,
2017-01-29 06:15:04 +00:00
Colour = new Color4(255, 221, 85, 255),
Scale = new Vector2(0.8f)
2016-12-17 14:53:26 +00:00
},
new SpriteText
{
2017-01-29 06:15:04 +00:00
Margin = new MarginPadding { Left = 13 },
Font = @"Exo2.0-Bold",
2017-01-29 06:15:04 +00:00
Colour = new Color4(255, 221, 85, 255),
Text = text,
TextSize = 17,
Origin = Anchor.CentreLeft
2016-12-17 14:53:26 +00:00
},
2017-01-29 06:06:44 +00:00
};
}
2016-12-17 14:53:26 +00:00
}
}
}