1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 19:42:54 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomStatusPill.cs

75 lines
2.0 KiB
C#
Raw Normal View History

2021-07-12 14:11:07 +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 System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses;
using osuTK.Graphics;
2021-07-13 15:02:18 +08:00
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
2021-07-12 14:11:07 +08:00
{
/// <summary>
/// A pill that displays the room's current status.
/// </summary>
2021-07-12 14:18:38 +08:00
public class RoomStatusPill : OnlinePlayComposite
2021-07-12 14:11:07 +08:00
{
[Resolved]
private OsuColour colours { get; set; }
2021-07-12 14:18:38 +08:00
private PillContainer pill;
2021-07-12 14:11:07 +08:00
private SpriteText statusText;
2021-07-12 14:18:38 +08:00
public RoomStatusPill()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = pill = new PillContainer
{
Child = statusText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12),
Colour = Color4.Black
}
};
}
2021-07-12 14:11:07 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
EndDate.BindValueChanged(_ => updateDisplay());
Status.BindValueChanged(_ => updateDisplay(), true);
2021-08-12 08:13:10 +08:00
FinishTransforms(true);
2021-07-12 14:11:07 +08:00
}
private void updateDisplay()
{
RoomStatus status = getDisplayStatus();
2021-07-12 14:11:07 +08:00
2021-07-12 14:18:38 +08:00
pill.Background.Alpha = 1;
2021-08-12 08:13:10 +08:00
pill.Background.FadeColour(status.GetAppropriateColour(colours), 100);
2021-07-12 14:11:07 +08:00
statusText.Text = status.Message;
}
private RoomStatus getDisplayStatus()
{
if (EndDate.Value < DateTimeOffset.Now)
return new RoomStatusEnded();
2021-08-12 08:14:46 +08:00
return Status.Value;
}
2021-07-12 14:11:07 +08:00
}
}