1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/BeatmapSetHeader.cs

178 lines
6.6 KiB
C#
Raw Normal View History

//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.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Game.Configuration;
using osu.Game.Graphics;
using OpenTK;
using OpenTK.Graphics;
2016-11-23 10:59:50 +08:00
namespace osu.Game.Beatmaps.Drawables
2016-10-27 10:55:55 +08:00
{
class BeatmapSetHeader : Panel
{
public Action<BeatmapSetHeader> GainedSelection;
private SpriteText title, artist;
private OsuConfigManager config;
private Bindable<bool> preferUnicode;
private WorkingBeatmap beatmap;
public BeatmapSetHeader(WorkingBeatmap beatmap)
{
this.beatmap = beatmap;
Children = new Drawable[]
{
new PanelBackground(beatmap)
{
RelativeSizeAxes = Axes.Both,
2016-11-05 19:00:14 +08:00
},
new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
Padding = new MarginPadding { Top = 5, Left = 18, Right = 10, Bottom = 10 },
AutoSizeAxes = Axes.Both,
Children = new[]
{
title = new SpriteText
{
Font = @"Exo2.0-BoldItalic",
Text = beatmap.BeatmapSetInfo.Metadata.Title,
TextSize = 22,
Shadow = true,
},
artist = new SpriteText
{
Margin = new MarginPadding { Top = -1 },
Font = @"Exo2.0-SemiBoldItalic",
Text = beatmap.BeatmapSetInfo.Metadata.Artist,
TextSize = 17,
Shadow = true,
},
new FlowContainer
{
Margin = new MarginPadding { Top = 5 },
AutoSizeAxes = Axes.Both,
Children = new[]
{
new DifficultyIcon(FontAwesome.fa_dot_circle_o, new Color4(159, 198, 0, 255)),
new DifficultyIcon(FontAwesome.fa_dot_circle_o, new Color4(246, 101, 166, 255)),
}
}
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
FadeInFromZero(250);
}
protected override void Selected()
{
base.Selected();
GainedSelection?.Invoke(this);
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
this.config = config;
preferUnicode = config.GetBindable<bool>(OsuConfig.ShowUnicode);
preferUnicode.ValueChanged += preferUnicode_changed;
preferUnicode_changed(preferUnicode, null);
}
private void preferUnicode_changed(object sender, EventArgs e)
{
title.Text = config.GetUnicodeString(beatmap.BeatmapSetInfo.Metadata.Title, beatmap.BeatmapSetInfo.Metadata.TitleUnicode);
artist.Text = config.GetUnicodeString(beatmap.BeatmapSetInfo.Metadata.Artist, beatmap.BeatmapSetInfo.Metadata.ArtistUnicode);
}
protected override void Dispose(bool isDisposing)
{
if (preferUnicode != null)
preferUnicode.ValueChanged -= preferUnicode_changed;
base.Dispose(isDisposing);
}
class PanelBackground : BufferedContainer
{
private readonly WorkingBeatmap working;
public PanelBackground(WorkingBeatmap working)
{
this.working = working;
CacheDrawnFrameBuffer = true;
Children = new[]
{
new FlowContainer
{
2016-11-30 03:50:12 +08:00
Depth = -1,
Direction = FlowDirection.HorizontalOnly,
RelativeSizeAxes = Axes.Both,
// This makes the gradient not be perfectly horizontal, but diagonal at a ~40<34> angle
Shear = new Vector2(0.8f, 0),
Alpha = 0.5f,
Children = new[]
{
// The left half with no gradient applied
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Width = 0.4f,
},
// Piecewise-linear gradient with 3 segments to make it appear smoother
new Box
{
RelativeSizeAxes = Axes.Both,
ColourInfo = OsuColor.BeatmapHeaderBackgroundA,
Width = 0.05f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
ColourInfo = OsuColor.BeatmapHeaderBackgroundB,
Width = 0.2f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
ColourInfo = OsuColor.BeatmapHeaderBackgroundC,
Width = 0.05f,
},
}
},
};
}
[BackgroundDependencyLoader]
private void load(OsuGameBase game)
{
2016-11-24 12:48:48 +08:00
new BeatmapBackgroundSprite(working)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2016-11-24 12:48:48 +08:00
FillMode = FillMode.Fill,
}.Preload(game, (bg) =>
{
Add(bg);
ForceRedraw();
});
}
}
2016-10-27 10:55:55 +08:00
}
}