Remove pill inheritance

This commit is contained in:
smoogipoo 2021-07-12 15:18:38 +09:00
parent a8cbffa57e
commit 435b4b0e6e
3 changed files with 57 additions and 34 deletions

View File

@ -5,21 +5,27 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osuTK.Graphics;
namespace osu.Game.Screens.OnlinePlay.Components
{
/// <summary>
/// Abstract class for "pill" components displayed as part of <see cref="DrawableRoom"/>s.
/// Displays contents in a "pill".
/// </summary>
public abstract class RoomInfoPill : OnlinePlayComposite
public class PillContainer : Container
{
private const float padding = 8;
protected Drawable Background { get; private set; }
public Drawable Background { get; private set; }
protected RoomInfoPill()
protected override Container<Drawable> Content { get; } = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
};
public PillContainer()
{
AutoSizeAxes = Axes.X;
Height = 16;
@ -58,21 +64,12 @@ namespace osu.Game.Screens.OnlinePlay.Components
},
Content = new[]
{
new[]
{
CreateContent().With(d =>
{
d.Anchor = Anchor.Centre;
d.Origin = Anchor.Centre;
})
}
new[] { Content }
}
}
}
}
};
}
protected abstract Drawable CreateContent();
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Specialized;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
@ -11,10 +12,29 @@ namespace osu.Game.Screens.OnlinePlay.Components
/// <summary>
/// A pill that displays the playlist item count.
/// </summary>
public class PlaylistCountPill : RoomInfoPill
public class PlaylistCountPill : OnlinePlayComposite
{
private OsuTextFlowContainer count;
public PlaylistCountPill()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new PillContainer
{
Child = count = new OsuTextFlowContainer(s => s.Font = OsuFont.GetFont(size: 12))
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -28,12 +48,5 @@ namespace osu.Game.Screens.OnlinePlay.Components
count.AddText(Playlist.Count.ToString(), s => s.Font = s.Font.With(weight: FontWeight.Bold));
count.AddText(" Maps");
}
protected override Drawable CreateContent() => count = new OsuTextFlowContainer(s => s.Font = OsuFont.GetFont(size: 12))
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
}
}

View File

@ -16,14 +16,35 @@ namespace osu.Game.Screens.OnlinePlay.Components
/// <summary>
/// A pill that displays the room's current status.
/// </summary>
public class RoomStatusPill : RoomInfoPill
public class RoomStatusPill : OnlinePlayComposite
{
[Resolved]
private OsuColour colours { get; set; }
private bool firstDisplay = true;
private PillContainer pill;
private SpriteText statusText;
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
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -36,19 +57,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
{
RoomStatus status = EndDate.Value < DateTimeOffset.Now ? new RoomStatusEnded() : Status.Value ?? new RoomStatusOpen();
Background.Alpha = 1;
Background.FadeColour(status.GetAppropriateColour(colours), firstDisplay ? 0 : 100);
pill.Background.Alpha = 1;
pill.Background.FadeColour(status.GetAppropriateColour(colours), firstDisplay ? 0 : 100);
statusText.Text = status.Message;
firstDisplay = false;
}
protected override Drawable CreateContent() => statusText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12),
Colour = Color4.Black
};
}
}