1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00
osu-lazer/osu.Game.Tournament/Components/SongBar.cs

216 lines
7.1 KiB
C#
Raw Normal View History

2018-11-06 18:23:03 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
2018-11-11 00:29:42 +08:00
using osu.Framework.Extensions.Color4Extensions;
2018-11-06 18:23:03 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Menu;
using osuTK;
using osuTK.Graphics;
2018-11-06 18:23:03 +08:00
namespace osu.Game.Tournament.Components
{
public class SongBar : CompositeDrawable
{
private BeatmapInfo beatmap;
public BeatmapInfo Beatmap
{
get => beatmap;
set
{
if (beatmap == value)
return;
beatmap = value;
update();
}
}
private LegacyMods mods;
public LegacyMods Mods
{
get => mods;
set
{
mods = value;
update();
}
}
private Container panelContents;
2018-11-11 00:29:42 +08:00
private Container innerPanel;
private Container outerPanel;
2018-11-16 17:14:42 +08:00
private TournamentBeatmapPanel panel;
private float panelWidth => expanded ? 0.6f : 1;
2018-11-11 00:29:42 +08:00
private const float main_width = 0.97f;
2018-11-16 17:14:42 +08:00
private bool expanded;
2018-11-11 00:29:42 +08:00
public bool Expanded
{
2018-11-16 17:14:42 +08:00
get => expanded;
2018-11-11 00:29:42 +08:00
set
{
2018-11-16 17:14:42 +08:00
expanded = value;
panel?.ResizeWidthTo(panelWidth, 800, Easing.OutQuint);
2018-11-16 17:14:42 +08:00
if (expanded)
2018-11-11 00:29:42 +08:00
{
innerPanel.ResizeWidthTo(0.7f, 800, Easing.OutQuint);
outerPanel.ResizeWidthTo(main_width, 800, Easing.OutQuint);
}
else
{
innerPanel.ResizeWidthTo(1, 800, Easing.OutQuint);
outerPanel.ResizeWidthTo(0.25f, 800, Easing.OutQuint);
2018-11-11 00:29:42 +08:00
}
}
}
2018-11-06 18:23:03 +08:00
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
2018-11-11 00:29:42 +08:00
outerPanel = new Container
2018-11-06 18:23:03 +08:00
{
Masking = true,
2018-11-11 00:29:42 +08:00
EdgeEffect = new EdgeEffectParameters
{
Colour = Color4.Black.Opacity(0.2f),
Type = EdgeEffectType.Shadow,
Radius = 5,
},
2018-11-06 18:23:03 +08:00
RelativeSizeAxes = Axes.X,
2018-11-11 00:29:42 +08:00
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
RelativePositionAxes = Axes.X,
X = -(1 - main_width) / 2,
2018-11-06 18:23:03 +08:00
Y = -10,
2018-11-16 17:14:42 +08:00
Width = main_width,
2018-11-06 18:23:03 +08:00
Height = TournamentBeatmapPanel.HEIGHT,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.93f),
},
2018-11-16 17:14:42 +08:00
new OsuLogo
{
Triangles = false,
Colour = OsuColour.Gray(0.33f),
Scale = new Vector2(0.08f),
Margin = new MarginPadding(50),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
},
2018-11-11 00:29:42 +08:00
innerPanel = new Container
2018-11-06 18:23:03 +08:00
{
Masking = true,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Width = 0.7f,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.86f),
},
panelContents = new Container
{
RelativeSizeAxes = Axes.Both,
}
}
}
}
}
};
}
private void update()
{
if (beatmap == null)
{
panelContents.Clear();
return;
}
var bpm = beatmap.BeatmapSet.OnlineInfo.BPM;
var length = beatmap.OnlineInfo.Length;
string extra = "";
var ar = beatmap.BaseDifficulty.ApproachRate;
if ((mods & LegacyMods.HardRock) > 0) extra = "*";
if ((mods & LegacyMods.DoubleTime) > 0)
{
//ar *= 1.5f;
bpm *= 1.5f;
length /= 1.5f;
extra = "*";
}
panelContents.Children = new Drawable[]
{
new OsuSpriteText
{
Text = $"Length {length:0}s",
2018-11-06 18:23:03 +08:00
Margin = new MarginPadding { Horizontal = 15, Vertical = 5 },
Colour = OsuColour.Gray(0.33f),
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
},
new OsuSpriteText
{
Text = $"BPM {bpm:0.#}",
Margin = new MarginPadding { Horizontal = 15, Vertical = 5 },
Colour = OsuColour.Gray(0.33f),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
new OsuSpriteText
{
2018-11-18 11:38:48 +08:00
Text = $"CS {beatmap.BaseDifficulty.CircleSize:0.#} / AR {ar:0.#}{extra}",
2018-11-06 18:23:03 +08:00
Margin = new MarginPadding { Horizontal = 15, Vertical = 5 },
Colour = OsuColour.Gray(0.33f),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight
},
new OsuSpriteText
{
Text = $"Star Rating {beatmap.StarDifficulty:0.#}{extra}",
Margin = new MarginPadding { Horizontal = 15, Vertical = 5 },
Colour = OsuColour.Gray(0.33f),
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight
},
2018-11-16 17:14:42 +08:00
panel = new TournamentBeatmapPanel(beatmap)
2018-11-06 18:23:03 +08:00
{
Anchor = Anchor.Centre,
2018-11-16 17:14:42 +08:00
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(panelWidth, 1)
2018-11-06 18:23:03 +08:00
}
};
}
}
}