1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 22:52:57 +08:00
osu-lazer/osu.Game/Overlays/BeatmapSet/Info.cs

196 lines
7.1 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-09-09 05:32:07 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
2017-09-09 05:32:07 +08:00
using osu.Game.Graphics.Sprites;
2017-09-25 17:26:27 +08:00
using OpenTK;
using OpenTK.Graphics;
2017-09-09 05:32:07 +08:00
2017-09-25 17:26:27 +08:00
namespace osu.Game.Overlays.BeatmapSet
2017-09-09 05:32:07 +08:00
{
public class Info : Container
{
2017-09-13 23:37:18 +08:00
private const float transition_duration = 250;
2017-09-09 05:32:07 +08:00
private const float metadata_width = 225;
private const float spacing = 20;
2017-09-13 23:37:18 +08:00
private readonly MetadataSection description, source, tags;
2017-09-09 05:32:07 +08:00
private readonly Box successRateBackground;
2017-09-11 13:48:48 +08:00
private readonly SuccessRate successRate;
2017-09-13 23:37:18 +08:00
private BeatmapSetInfo beatmapSet;
public BeatmapSetInfo BeatmapSet
{
get { return beatmapSet; }
set
{
if (value == beatmapSet) return;
beatmapSet = value;
source.Text = BeatmapSet.Metadata.Source;
tags.Text = BeatmapSet.Metadata.Tags;
}
}
2017-09-09 05:32:07 +08:00
2017-09-11 13:48:48 +08:00
public BeatmapInfo Beatmap
{
get { return successRate.Beatmap; }
set { successRate.Beatmap = value; }
}
2017-09-13 23:37:18 +08:00
public Info()
2017-09-09 05:32:07 +08:00
{
RelativeSizeAxes = Axes.X;
Height = 220;
Masking = true;
EdgeEffect = new EdgeEffectParameters
{
Colour = Color4.Black.Opacity(0.25f),
Type = EdgeEffectType.Shadow,
Radius = 3,
Offset = new Vector2(0f, 1f),
};
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
},
new Container
{
RelativeSizeAxes = Axes.Both,
2017-09-25 17:26:27 +08:00
Padding = new MarginPadding { Top = 15, Horizontal = BeatmapSetOverlay.X_PADDING },
2017-09-09 05:32:07 +08:00
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
2017-09-25 17:26:27 +08:00
Padding = new MarginPadding { Right = metadata_width + BeatmapSetOverlay.RIGHT_WIDTH + spacing * 2 },
Child = new Container
2017-09-09 05:32:07 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-09-13 23:37:18 +08:00
Child = description = new MetadataSection("Description"),
2017-09-09 05:32:07 +08:00
},
},
new Container
2017-09-09 05:32:07 +08:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Y,
Width = metadata_width,
Padding = new MarginPadding { Horizontal = 10 },
2017-09-25 17:26:27 +08:00
Margin = new MarginPadding { Right = BeatmapSetOverlay.RIGHT_WIDTH + spacing },
2017-09-13 23:37:18 +08:00
Child = new FillFlowContainer
2017-09-09 05:32:07 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
2017-09-13 23:37:18 +08:00
LayoutDuration = transition_duration,
Children = new[]
{
source = new MetadataSection("Source"),
tags = new MetadataSection("Tags"),
},
2017-09-09 05:32:07 +08:00
},
},
new Container
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Y,
2017-09-25 17:26:27 +08:00
Width = BeatmapSetOverlay.RIGHT_WIDTH,
2017-09-11 13:48:48 +08:00
Children = new Drawable[]
2017-09-09 05:32:07 +08:00
{
successRateBackground = new Box
{
RelativeSizeAxes = Axes.Both,
},
2017-09-11 13:48:48 +08:00
successRate = new SuccessRate
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 20, Horizontal = 15 },
},
2017-09-09 05:32:07 +08:00
},
},
},
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
successRateBackground.Colour = colours.GrayE;
2017-09-13 23:37:18 +08:00
source.TextColour = description.TextColour = colours.Gray5;
tags.TextColour = colours.BlueDark;
2017-09-09 05:32:07 +08:00
}
private class MetadataSection : FillFlowContainer
{
private readonly OsuSpriteText header;
2017-09-13 23:37:18 +08:00
private readonly TextFlowContainer textFlow;
public string Text
{
set
{
if (string.IsNullOrEmpty(value))
{
this.FadeOut(transition_duration);
return;
}
this.FadeIn(transition_duration);
textFlow.Clear();
textFlow.AddText(value, s => s.TextSize = 14);
}
}
2017-09-09 05:32:07 +08:00
2017-09-13 23:37:18 +08:00
public Color4 TextColour
{
get { return textFlow.Colour; }
set { textFlow.Colour = value; }
}
public MetadataSection(string title)
2017-09-09 05:32:07 +08:00
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Spacing = new Vector2(5f);
2017-09-13 23:37:18 +08:00
InternalChildren = new Drawable[]
2017-09-09 05:32:07 +08:00
{
header = new OsuSpriteText
{
2017-09-13 23:37:18 +08:00
Text = title,
2017-09-09 05:32:07 +08:00
Font = @"Exo2.0-Bold",
TextSize = 14,
Shadow = false,
2017-09-09 05:32:07 +08:00
Margin = new MarginPadding { Top = 20 },
},
textFlow = new OsuTextFlowContainer
2017-09-09 05:32:07 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
header.Colour = colours.Gray5;
}
}
}
}