Split out classes into own files and rename GroupInfoContainer to a flow

This commit is contained in:
Dean Herbert 2023-01-11 16:47:29 +09:00
parent 5441c02a1a
commit e0d58d51b6
3 changed files with 38 additions and 27 deletions

View File

@ -1,9 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -74,7 +73,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
if (group.Playmodes?.Length > 0) if (group.Playmodes?.Length > 0)
{ {
innerContainer.AddRange(group.Playmodes.Select(p => innerContainer.AddRange(group.Playmodes.Select(p =>
(rulesets.GetRuleset(p)?.CreateInstance().CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }).With(icon => (rulesets.GetRuleset((string)p)?.CreateInstance().CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }).With(icon =>
{ {
icon.Size = new Vector2(TextSize - 1); icon.Size = new Vector2(TextSize - 1);
})).ToList() })).ToList()
@ -82,25 +81,4 @@ namespace osu.Game.Overlays.Profile.Header.Components
} }
} }
} }
public partial class GroupInfoContainer : FillFlowContainer
{
public readonly Bindable<APIUser?> User = new Bindable<APIUser?>();
public GroupInfoContainer()
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Spacing = new Vector2(2);
User.BindValueChanged(val =>
{
if (val.NewValue?.Groups?.Length > 0)
{
Clear(true);
Children = val.NewValue?.Groups.Select(g => new GroupBadge(g)).ToList();
}
});
}
}
} }

View File

@ -0,0 +1,33 @@
// 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.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osuTK;
namespace osu.Game.Overlays.Profile.Header.Components
{
public partial class GroupBadgeFlow : FillFlowContainer
{
public readonly Bindable<APIUser?> User = new Bindable<APIUser?>();
public GroupBadgeFlow()
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Spacing = new Vector2(2);
User.BindValueChanged(val =>
{
if (val.NewValue?.Groups?.Length > 0)
{
Clear(true);
Children = val.NewValue?.Groups.Select(g => new GroupBadge(g)).ToList();
}
});
}
}
}

View File

@ -40,7 +40,7 @@ namespace osu.Game.Overlays.Profile.Header
private UpdateableFlag userFlag = null!; private UpdateableFlag userFlag = null!;
private OsuSpriteText userCountryText = null!; private OsuSpriteText userCountryText = null!;
private FillFlowContainer userStats = null!; private FillFlowContainer userStats = null!;
private GroupInfoContainer groupInfoContainer = null!; private GroupBadgeFlow groupBadgeFlow = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
@ -103,7 +103,7 @@ namespace osu.Game.Overlays.Profile.Header
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
}, },
groupInfoContainer = new GroupInfoContainer groupBadgeFlow = new GroupBadgeFlow
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
@ -190,7 +190,7 @@ namespace osu.Game.Overlays.Profile.Header
supporterTag.SupportLevel = user?.SupportLevel ?? 0; supporterTag.SupportLevel = user?.SupportLevel ?? 0;
titleText.Text = user?.Title ?? string.Empty; titleText.Text = user?.Title ?? string.Empty;
titleText.Colour = Color4Extensions.FromHex(user?.Colour ?? "fff"); titleText.Colour = Color4Extensions.FromHex(user?.Colour ?? "fff");
groupInfoContainer.User.Value = user; groupBadgeFlow.User.Value = user;
userStats.Clear(); userStats.Clear();