Merge pull request #23563 from timiimit/organize-room-pills

Add common `OnlinePlayPill` for all online room pills
This commit is contained in:
Dean Herbert 2023-05-25 23:12:16 +09:00 committed by GitHub
commit 30c31d7418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 148 deletions

View File

@ -3,39 +3,14 @@
#nullable disable #nullable disable
using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{ {
public partial class MatchTypePill : OnlinePlayComposite public partial class MatchTypePill : OnlinePlayPill
{ {
private OsuTextFlowContainer textFlow;
public MatchTypePill()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new PillContainer
{
Child = textFlow = new OsuTextFlowContainer(s => s.Font = OsuFont.GetFont(size: 12))
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
}
};
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -45,8 +20,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
private void onMatchTypeChanged(ValueChangedEvent<MatchType> type) private void onMatchTypeChanged(ValueChangedEvent<MatchType> type)
{ {
textFlow.Clear(); TextFlow.Text = type.NewValue.GetLocalisableDescription();
textFlow.AddText(type.NewValue.GetLocalisableDescription());
} }
} }
} }

View File

@ -0,0 +1,37 @@
// 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.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public abstract partial class OnlinePlayPill : OnlinePlayComposite
{
protected PillContainer Pill { get; private set; } = null!;
protected OsuTextFlowContainer TextFlow { get; private set; } = null!;
protected virtual FontUsage Font => OsuFont.GetFont(size: 12);
protected OnlinePlayPill()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = Pill = new PillContainer
{
Child = TextFlow = new OsuTextFlowContainer(s => s.Font = Font)
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
}
};
}
}
}

View File

@ -5,40 +5,16 @@
using System.Linq; using System.Linq;
using Humanizer; using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{ {
/// <summary> /// <summary>
/// A pill that displays the playlist item count. /// A pill that displays the playlist item count.
/// </summary> /// </summary>
public partial class PlaylistCountPill : OnlinePlayComposite public partial class PlaylistCountPill : OnlinePlayPill
{ {
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() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -55,10 +31,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
? Playlist.Count(i => !i.Expired) ? Playlist.Count(i => !i.Expired)
: PlaylistItemStats.Value.CountActive; : PlaylistItemStats.Value.CountActive;
count.Clear(); TextFlow.Clear();
count.AddText(activeItems.ToLocalisableString(), s => s.Font = s.Font.With(weight: FontWeight.Bold)); TextFlow.AddText(activeItems.ToLocalisableString(), s => s.Font = s.Font.With(weight: FontWeight.Bold));
count.AddText(" "); TextFlow.AddText(" ");
count.AddText("Beatmap".ToQuantity(activeItems, ShowQuantityAs.None)); TextFlow.AddText("Beatmap".ToQuantity(activeItems, ShowQuantityAs.None));
} }
} }
} }

View File

@ -3,39 +3,14 @@
#nullable disable #nullable disable
using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{ {
public partial class QueueModePill : OnlinePlayComposite public partial class QueueModePill : OnlinePlayPill
{ {
private OsuTextFlowContainer textFlow;
public QueueModePill()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new PillContainer
{
Child = textFlow = new OsuTextFlowContainer(s => s.Font = OsuFont.GetFont(size: 12))
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
}
};
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -45,8 +20,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
private void onQueueModeChanged(ValueChangedEvent<QueueMode> mode) private void onQueueModeChanged(ValueChangedEvent<QueueMode> mode)
{ {
textFlow.Clear(); TextFlow.Text = mode.NewValue.GetLocalisableDescription();
textFlow.AddText(mode.NewValue.GetLocalisableDescription());
} }
} }
} }

View File

@ -5,58 +5,30 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{ {
public partial class RoomSpecialCategoryPill : OnlinePlayComposite public partial class RoomSpecialCategoryPill : OnlinePlayPill
{ {
private SpriteText text;
private PillContainer pill;
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
public RoomSpecialCategoryPill() protected override FontUsage Font => base.Font.With(weight: FontWeight.SemiBold);
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = pill = new PillContainer
{
Background =
{
Colour = colours.Pink,
Alpha = 1
},
Child = text = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12),
Colour = Color4.Black
}
};
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Pill.Background.Alpha = 1;
TextFlow.Colour = Color4.Black;
Category.BindValueChanged(c => Category.BindValueChanged(c =>
{ {
text.Text = c.NewValue.GetLocalisableDescription(); TextFlow.Text = c.NewValue.GetLocalisableDescription();
Pill.Background.Colour = colours.ForRoomCategory(c.NewValue) ?? colours.Pink;
var backgroundColour = colours.ForRoomCategory(Category.Value);
if (backgroundColour != null)
pill.Background.Colour = backgroundColour.Value;
}, true); }, true);
} }
} }

View File

@ -8,43 +8,20 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Online.Rooms.RoomStatuses;
using osuTK.Graphics;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{ {
/// <summary> /// <summary>
/// A pill that displays the room's current status. /// A pill that displays the room's current status.
/// </summary> /// </summary>
public partial class RoomStatusPill : OnlinePlayComposite public partial class RoomStatusPill : OnlinePlayPill
{ {
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
private PillContainer pill; protected override FontUsage Font => base.Font.With(weight: FontWeight.SemiBold);
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() protected override void LoadComplete()
{ {
@ -54,15 +31,17 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
Status.BindValueChanged(_ => updateDisplay(), true); Status.BindValueChanged(_ => updateDisplay(), true);
FinishTransforms(true); FinishTransforms(true);
TextFlow.Colour = Colour4.Black;
Pill.Background.Alpha = 1;
} }
private void updateDisplay() private void updateDisplay()
{ {
RoomStatus status = getDisplayStatus(); RoomStatus status = getDisplayStatus();
pill.Background.Alpha = 1; Pill.Background.FadeColour(status.GetAppropriateColour(colours), 100);
pill.Background.FadeColour(status.GetAppropriateColour(colours), 100); TextFlow.Text = status.Message;
statusText.Text = status.Message;
} }
private RoomStatus getDisplayStatus() private RoomStatus getDisplayStatus()