1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 03:25:11 +08:00

Add owner avatar to multiplayer items

This commit is contained in:
Dan Balasescu 2021-11-25 23:15:28 +09:00
parent 7c91cd674e
commit 1f5d95666e
2 changed files with 58 additions and 5 deletions

View File

@ -13,6 +13,7 @@ using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Database;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Rooms;
@ -34,6 +35,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
private BeatmapManager manager;
private RulesetStore rulesets;
[Cached(typeof(UserLookupCache))]
private readonly TestUserLookupCache userLookupCache = new TestUserLookupCache();
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
@ -343,6 +347,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
playlist.Items.Add(new PlaylistItem
{
ID = i,
OwnerID = 2,
Beatmap =
{
Value = i % 2 == 1
@ -390,6 +395,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
playlist.Items.Add(new PlaylistItem
{
ID = index++,
OwnerID = 2,
Beatmap = { Value = b },
Ruleset = { Value = new OsuRuleset().RulesetInfo },
RequiredMods =

View File

@ -4,17 +4,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
@ -26,6 +30,7 @@ using osu.Game.Overlays.BeatmapSet;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play.HUD;
using osu.Game.Users.Drawables;
using osuTK;
using osuTK.Graphics;
@ -34,6 +39,7 @@ namespace osu.Game.Screens.OnlinePlay
public class DrawableRoomPlaylistItem : OsuRearrangeableListItem<PlaylistItem>
{
public const float HEIGHT = 50;
public const float ICON_HEIGHT = 34;
public Action<PlaylistItem> RequestDeletion;
@ -45,6 +51,7 @@ namespace osu.Game.Screens.OnlinePlay
private LinkFlowContainer authorText;
private ExplicitContentBeatmapPill explicitContentPill;
private ModDisplay modDisplay;
private UpdateableAvatar ownerAvatar;
private readonly IBindable<bool> valid = new Bindable<bool>();
@ -54,6 +61,12 @@ namespace osu.Game.Screens.OnlinePlay
public readonly PlaylistItem Item;
[Resolved]
private OsuColour colours { get; set; }
[Resolved]
private UserLookupCache userLookupCache { get; set; }
private readonly bool allowEdit;
private readonly bool allowSelection;
@ -79,9 +92,6 @@ namespace osu.Game.Screens.OnlinePlay
Colour = OsuColour.Gray(0.5f);
}
[Resolved]
private OsuColour colours { get; set; }
[BackgroundDependencyLoader]
private void load()
{
@ -132,7 +142,8 @@ namespace osu.Game.Screens.OnlinePlay
maskingContainer.BorderColour = colours.Red;
}
difficultyIconContainer.Child = new DifficultyIcon(Item.Beatmap.Value, ruleset.Value, requiredMods, performBackgroundDifficultyLookup: false) { Size = new Vector2(32) };
userLookupCache.GetUserAsync(Item.OwnerID).ContinueWith(u => Schedule(() => ownerAvatar.User = u.Result), TaskContinuationOptions.OnlyOnRanToCompletion);
difficultyIconContainer.Child = new DifficultyIcon(Item.Beatmap.Value, ruleset.Value, requiredMods, performBackgroundDifficultyLookup: false) { Size = new Vector2(ICON_HEIGHT) };
panelBackground.Beatmap.Value = Item.Beatmap.Value;
@ -183,6 +194,7 @@ namespace osu.Game.Screens.OnlinePlay
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
@ -191,12 +203,21 @@ namespace osu.Game.Screens.OnlinePlay
{
new Drawable[]
{
ownerAvatar = new OwnerAvatar
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(ICON_HEIGHT),
Margin = new MarginPadding { Left = 8, Right = 8, },
Masking = true,
CornerRadius = 4,
},
difficultyIconContainer = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Left = 8, Right = 8, },
Margin = new MarginPadding { Right = 8 },
},
new FillFlowContainer
{
@ -417,5 +438,31 @@ namespace osu.Game.Screens.OnlinePlay
Beatmap.BindValueChanged(beatmap => backgroundSprite.Beatmap.Value = beatmap.NewValue);
}
}
private class OwnerAvatar : UpdateableAvatar, IHasTooltip
{
public OwnerAvatar()
{
AddInternal(new TooltipArea(this)
{
RelativeSizeAxes = Axes.Both,
Depth = -1
});
}
public LocalisableString TooltipText => User == null ? "loading user..." : $"queued by {User.Username}";
private class TooltipArea : Component, IHasTooltip
{
private readonly OwnerAvatar avatar;
public TooltipArea(OwnerAvatar avatar)
{
this.avatar = avatar;
}
public LocalisableString TooltipText => avatar.TooltipText;
}
}
}
}