1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 10:07:25 +08:00
osu-lazer/osu.Game/Screens/Multi/Components/OverlinedDisplay.cs

132 lines
4.2 KiB
C#
Raw Normal View History

2020-02-14 19:42:14 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
namespace osu.Game.Screens.Multi.Components
2020-02-14 19:42:14 +08:00
{
public abstract class OverlinedDisplay : MultiplayerComposite
{
protected readonly Container Content;
public override Axes RelativeSizeAxes
{
get => base.RelativeSizeAxes;
set
{
base.RelativeSizeAxes = value;
updateDimensions();
}
}
public override Axes AutoSizeAxes
{
get => base.AutoSizeAxes;
protected set
{
base.AutoSizeAxes = value;
updateDimensions();
}
}
2020-06-25 19:53:48 +08:00
private bool showLine = true;
public bool ShowLine
{
get => showLine;
set
{
showLine = value;
line.Alpha = value ? 1 : 0;
}
}
2020-02-14 19:42:14 +08:00
protected string Details
{
set => details.Text = value;
}
private readonly Circle line;
private readonly OsuSpriteText details;
private readonly GridContainer grid;
2020-02-14 19:42:14 +08:00
protected OverlinedDisplay(string title)
{
InternalChild = grid = new GridContainer
2020-02-14 19:42:14 +08:00
{
Content = new[]
{
new Drawable[]
{
line = new Circle
{
RelativeSizeAxes = Axes.X,
Height = 2,
Margin = new MarginPadding { Bottom = 2 }
},
},
new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Top = 5 },
Spacing = new Vector2(10, 0),
Children = new Drawable[]
{
new OsuSpriteText
{
Text = title,
2020-06-25 21:06:28 +08:00
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold)
2020-02-14 19:42:14 +08:00
},
details = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold)
},
2020-02-14 19:42:14 +08:00
}
},
},
new Drawable[]
{
2020-06-11 14:07:14 +08:00
Content = new Container { Padding = new MarginPadding { Top = 5 } }
2020-02-14 19:42:14 +08:00
}
}
};
updateDimensions();
2020-02-14 19:42:14 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
line.Colour = colours.Yellow;
details.Colour = colours.Yellow;
}
private void updateDimensions()
{
grid.RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(AutoSizeAxes.HasFlag(Axes.Y) ? GridSizeMode.AutoSize : GridSizeMode.Distributed),
};
// Assigning to none is done so that setting auto and relative size modes doesn't cause exceptions to be thrown
grid.AutoSizeAxes = Content.AutoSizeAxes = Axes.None;
grid.RelativeSizeAxes = Content.RelativeSizeAxes = Axes.None;
// Auto-size when required, otherwise eagerly relative-size
grid.AutoSizeAxes = Content.AutoSizeAxes = AutoSizeAxes;
grid.RelativeSizeAxes = Content.RelativeSizeAxes = ~AutoSizeAxes;
}
2020-02-14 19:42:14 +08:00
}
}