1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:12:54 +08:00

Display avatars rather than full scores

This commit is contained in:
Dean Herbert 2019-01-09 15:15:54 +09:00
parent 0bf9e9b86b
commit 2dc185f249

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -13,9 +14,10 @@ using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components; using osu.Game.Screens.Multi.Components;
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -36,11 +38,10 @@ namespace osu.Game.Screens.Multi.Lounge.Components
private Box statusStrip; private Box statusStrip;
private UpdateableBeatmapBackgroundSprite background; private UpdateableBeatmapBackgroundSprite background;
private ParticipantCountDisplay participantCount; private ParticipantCountDisplay participantCount;
private FillFlowContainer topFlow;
private OsuSpriteText name, status; private OsuSpriteText name, status;
private BeatmapTypeInfo beatmapTypeInfo; private BeatmapTypeInfo beatmapTypeInfo;
private ParticipantInfo participantInfo; private ParticipantInfo participantInfo;
private MatchLeaderboard leaderboard; private MatchParticipants participants;
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }
@ -57,127 +58,138 @@ namespace osu.Game.Screens.Multi.Lounge.Components
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"343138"), Colour = OsuColour.FromHex(@"343138"),
}, },
topFlow = new FillFlowContainer new GridContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
AutoSizeAxes = Axes.Y, RowDimensions = new[]
Direction = FillDirection.Vertical,
Children = new Drawable[]
{ {
new Container new Dimension(GridSizeMode.AutoSize),
{ new Dimension(GridSizeMode.Distributed),
RelativeSizeAxes = Axes.X,
Height = 200,
Masking = true,
Children = new Drawable[]
{
background = new UpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both },
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.5f), Color4.Black.Opacity(0)),
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(20),
Children = new Drawable[]
{
participantCount = new ParticipantCountDisplay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
name = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
TextSize = 30,
},
},
},
},
},
statusStrip = new Box
{
RelativeSizeAxes = Axes.X,
Height = 5,
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"28242d"),
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
LayoutDuration = transition_duration,
Padding = contentPadding,
Spacing = new Vector2(0f, 5f),
Children = new Drawable[]
{
status = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-Bold",
},
beatmapTypeInfo = new BeatmapTypeInfo(),
},
},
},
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = contentPadding,
Children = new Drawable[]
{
participantInfo = new ParticipantInfo(),
},
},
}, },
}, Content = new[]
leaderboard = new MatchLeaderboard {
{ new Drawable[]
Anchor = Anchor.BottomLeft, {
Origin = Anchor.BottomLeft, new FillFlowContainer
RelativeSizeAxes = Axes.X, {
Padding = new MarginPadding { Top = contentPadding.Top, Left = 38, Right = 37 }, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
Height = 200,
Masking = true,
Children = new Drawable[]
{
background = new UpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both },
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.5f), Color4.Black.Opacity(0)),
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(20),
Children = new Drawable[]
{
participantCount = new ParticipantCountDisplay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
name = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
TextSize = 30,
},
},
},
},
},
statusStrip = new Box
{
RelativeSizeAxes = Axes.X,
Height = 5,
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"28242d"),
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
LayoutDuration = transition_duration,
Padding = contentPadding,
Spacing = new Vector2(0f, 5f),
Children = new Drawable[]
{
status = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-Bold",
},
beatmapTypeInfo = new BeatmapTypeInfo(),
},
},
},
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = contentPadding,
Children = new Drawable[]
{
participantInfo = new ParticipantInfo(),
},
},
},
},
},
new Drawable[]
{
participants = new MatchParticipants
{
RelativeSizeAxes = Axes.Both,
}
}
}
} }
}; };
participantInfo.Host.BindTo(bindings.Host); participantInfo.Host.BindTo(bindings.Host);
participantInfo.ParticipantCount.BindTo(bindings.ParticipantCount); participantInfo.ParticipantCount.BindTo(bindings.ParticipantCount);
participantInfo.Participants.BindTo(bindings.Participants); participantInfo.Participants.BindTo(bindings.Participants);
participantCount.Participants.BindTo(bindings.Participants); participantCount.Participants.BindTo(bindings.Participants);
participantCount.ParticipantCount.BindTo(bindings.ParticipantCount); participantCount.ParticipantCount.BindTo(bindings.ParticipantCount);
participantCount.MaxParticipants.BindTo(bindings.MaxParticipants); participantCount.MaxParticipants.BindTo(bindings.MaxParticipants);
beatmapTypeInfo.Beatmap.BindTo(bindings.CurrentBeatmap); beatmapTypeInfo.Beatmap.BindTo(bindings.CurrentBeatmap);
beatmapTypeInfo.Ruleset.BindTo(bindings.CurrentRuleset); beatmapTypeInfo.Ruleset.BindTo(bindings.CurrentRuleset);
beatmapTypeInfo.Type.BindTo(bindings.Type); beatmapTypeInfo.Type.BindTo(bindings.Type);
background.Beatmap.BindTo(bindings.CurrentBeatmap); background.Beatmap.BindTo(bindings.CurrentBeatmap);
bindings.Status.BindValueChanged(displayStatus); bindings.Status.BindValueChanged(displayStatus);
bindings.Name.BindValueChanged(n => name.Text = n); bindings.Name.BindValueChanged(n => name.Text = n);
Room.BindValueChanged(updateRoom, true); Room.BindValueChanged(updateRoom, true);
} }
private void updateRoom(Room room) private void updateRoom(Room room)
{ {
bindings.Room = room; bindings.Room = room;
leaderboard.Room = room; participants.Room = room;
if (room != null) if (room != null)
{ {
@ -197,13 +209,6 @@ namespace osu.Game.Screens.Multi.Lounge.Components
} }
} }
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
leaderboard.Height = DrawHeight - topFlow.DrawHeight;
}
private void displayStatus(RoomStatus s) private void displayStatus(RoomStatus s)
{ {
status.Text = s.Message; status.Text = s.Message;
@ -213,39 +218,113 @@ namespace osu.Game.Screens.Multi.Lounge.Components
status.FadeColour(c, transition_duration); status.FadeColour(c, transition_duration);
} }
private class UserTile : Container, IHasTooltip
{
private readonly User user;
public string TooltipText => user.Username;
public UserTile(User user)
{
this.user = user;
Size = new Vector2(70f);
CornerRadius = 5f;
Masking = true;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"27252d"),
},
new UpdateableAvatar
{
RelativeSizeAxes = Axes.Both,
User = user,
},
};
}
}
private class RoomStatusNoneSelected : RoomStatus private class RoomStatusNoneSelected : RoomStatus
{ {
public override string Message => @"No Room Selected"; public override string Message => @"No Room Selected";
public override Color4 GetAppropriateColour(OsuColour colours) => colours.Gray8; public override Color4 GetAppropriateColour(OsuColour colours) => colours.Gray8;
} }
private class MatchParticipants : CompositeDrawable
{
private Room room;
private readonly FillFlowContainer fill;
public Room Room
{
get { return room; }
set
{
if (room == value)
return;
room = value;
updateParticipants();
}
}
public MatchParticipants()
{
Padding = new MarginPadding { Horizontal = 10 };
InternalChild = new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = fill = new FillFlowContainer
{
Spacing = new Vector2(10),
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
}
};
}
[Resolved]
private APIAccess api { get; set; }
private GetRoomScoresRequest request;
private void updateParticipants()
{
var roomId = room.RoomID.Value ?? 0;
request?.Cancel();
// nice little progressive fade
int time = 500;
foreach (var c in fill.Children)
{
c.Delay(500 - time).FadeOut(time, Easing.Out);
time = Math.Max(20, time - 20);
c.Expire();
}
if (roomId == 0) return;
request = new GetRoomScoresRequest(roomId);
request.Success += scores =>
{
if (roomId != room.RoomID.Value)
return;
fill.Clear();
foreach (var s in scores)
fill.Add(new UserTile(s.User));
fill.FadeInFromZero(1000, Easing.OutQuint);
};
api.Queue(request);
}
private class UserTile : CompositeDrawable, IHasTooltip
{
private readonly User user;
public string TooltipText => user.Username;
public UserTile(User user)
{
this.user = user;
Size = new Vector2(70f);
CornerRadius = 5f;
Masking = true;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"27252d"),
},
new UpdateableAvatar
{
RelativeSizeAxes = Axes.Both,
User = user,
},
};
}
}
}
} }
} }