diff --git a/osu.Game/Screens/Multiplayer/DrawableRoom.cs b/osu.Game/Screens/Multiplayer/DrawableRoom.cs index bd58fafd12..507e0039e1 100644 --- a/osu.Game/Screens/Multiplayer/DrawableRoom.cs +++ b/osu.Game/Screens/Multiplayer/DrawableRoom.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Linq; using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; @@ -33,11 +32,7 @@ namespace osu.Game.Screens.Multiplayer private readonly Box sideStrip; private readonly Container coverContainer, rulesetContainer, gameTypeContainer; private readonly OsuSpriteText name; - private readonly Container flagContainer; - private readonly OsuSpriteText host; - private readonly FillFlowContainer levelRangeContainer; - private readonly OsuSpriteText levelRangeLower; - private readonly OsuSpriteText levelRangeHigher; + private readonly ParticipantInfo participantInfo; private readonly OsuSpriteText status; private readonly FillFlowContainer beatmapInfoFlow; private readonly OsuSpriteText beatmapTitle; @@ -121,93 +116,7 @@ namespace osu.Game.Screens.Multiplayer { TextSize = 18, }, - new Container - { - RelativeSizeAxes = Axes.X, - Height = 20f, - Children = new Drawable[] - { - new FillFlowContainer - { - AutoSizeAxes = Axes.X, - Height = 15f, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(5f, 0f), - Children = new Drawable[] - { - flagContainer = new Container - { - Width = 22f, - RelativeSizeAxes = Axes.Y, - }, - new Container //todo: team banners - { - Width = 38f, - RelativeSizeAxes = Axes.Y, - CornerRadius = 2f, - Masking = true, - Children = new[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = OsuColour.FromHex(@"ad387e"), - }, - }, - }, - new OsuSpriteText - { - Text = "hosted by", - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - TextSize = 14, - }, - host = new OsuSpriteText - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - TextSize = 14, - Font = @"Exo2.0-BoldItalic", - }, - }, - }, - levelRangeContainer = new FillFlowContainer - { - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Children = new[] - { - new OsuSpriteText - { - Text = "#", - TextSize = 14, - }, - levelRangeLower = new OsuSpriteText - { - TextSize = 14, - Font = @"Exo2.0-Bold", - }, - new OsuSpriteText - { - Text = " - ", - TextSize = 14, - }, - new OsuSpriteText - { - Text = "#", - TextSize = 14, - }, - levelRangeHigher = new OsuSpriteText - { - TextSize = 14, - Font = @"Exo2.0-Bold", - }, - }, - }, - }, - }, + participantInfo = new ParticipantInfo(), }, }, new FillFlowContainer @@ -297,8 +206,7 @@ namespace osu.Game.Screens.Multiplayer this.textures = textures; this.colours = colours; - beatmapInfoFlow.Colour = levelRangeContainer.Colour = colours.Gray9; - host.Colour = colours.Blue; + beatmapInfoFlow.Colour = colours.Gray9; //binded here instead of ctor because dependencies are needed statusBind.ValueChanged += displayStatus; @@ -317,8 +225,7 @@ namespace osu.Game.Screens.Multiplayer private void displayUser(User value) { - host.Text = value.Username; - flagContainer.Children = new[] { new DrawableFlag(value.Country?.FlagName ?? @"__") { RelativeSizeAxes = Axes.Both } }; + participantInfo.Host = value; } private void displayStatus(RoomStatus value) @@ -385,9 +292,7 @@ namespace osu.Game.Screens.Multiplayer private void displayParticipants(User[] value) { - var ranks = value.Select(u => u.GlobalRank); - levelRangeLower.Text = ranks.Min().ToString(); - levelRangeHigher.Text = ranks.Max().ToString(); + participantInfo.Participants = value; } } } diff --git a/osu.Game/Screens/Multiplayer/ParticipantInfo.cs b/osu.Game/Screens/Multiplayer/ParticipantInfo.cs new file mode 100644 index 0000000000..cd9101d5ad --- /dev/null +++ b/osu.Game/Screens/Multiplayer/ParticipantInfo.cs @@ -0,0 +1,142 @@ +using System.Collections.Generic; +using System.Linq; +using OpenTK; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Users; + +namespace osu.Game.Screens.Multiplayer +{ + public class ParticipantInfo : Container + { + private readonly Container flagContainer; + private readonly OsuSpriteText host; + private readonly FillFlowContainer levelRangeContainer; + private readonly OsuSpriteText levelRangeLower; + private readonly OsuSpriteText levelRangeHigher; + + public User Host + { + set + { + host.Text = value.Username; + flagContainer.Children = new[] { new DrawableFlag(value.Country?.FlagName ?? @"__") { RelativeSizeAxes = Axes.Both } }; + } + } + + public IEnumerable Participants + { + set + { + var ranks = value.Select(u => u.GlobalRank); + levelRangeLower.Text = ranks.Min().ToString(); + levelRangeHigher.Text = ranks.Max().ToString(); + } + } + + public ParticipantInfo(string rankPrefix = null) + { + RelativeSizeAxes = Axes.X; + Height = 15f; + + Children = new Drawable[] + { + new FillFlowContainer + { + AutoSizeAxes = Axes.X, + RelativeSizeAxes = Axes.Y, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5f, 0f), + Children = new Drawable[] + { + flagContainer = new Container + { + Width = 22f, + RelativeSizeAxes = Axes.Y, + }, + new Container //todo: team banners + { + Width = 38f, + RelativeSizeAxes = Axes.Y, + CornerRadius = 2f, + Masking = true, + Children = new[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = OsuColour.FromHex(@"ad387e"), + }, + }, + }, + new OsuSpriteText + { + Text = "hosted by", + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + TextSize = 14, + }, + host = new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + TextSize = 14, + Font = @"Exo2.0-BoldItalic", + }, + }, + }, + levelRangeContainer = new FillFlowContainer + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Children = new[] + { + new OsuSpriteText + { + Text = rankPrefix, + TextSize = 14, + }, + new OsuSpriteText + { + Text = "#", + TextSize = 14, + }, + levelRangeLower = new OsuSpriteText + { + TextSize = 14, + Font = @"Exo2.0-Bold", + }, + new OsuSpriteText + { + Text = " - ", + TextSize = 14, + }, + new OsuSpriteText + { + Text = "#", + TextSize = 14, + }, + levelRangeHigher = new OsuSpriteText + { + TextSize = 14, + Font = @"Exo2.0-Bold", + }, + }, + }, + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + levelRangeContainer.Colour = colours.Gray9; + host.Colour = colours.Blue; + } + } +} diff --git a/osu.Game/Screens/Multiplayer/RoomInspector.cs b/osu.Game/Screens/Multiplayer/RoomInspector.cs index 508128c749..d840495765 100644 --- a/osu.Game/Screens/Multiplayer/RoomInspector.cs +++ b/osu.Game/Screens/Multiplayer/RoomInspector.cs @@ -30,9 +30,10 @@ namespace osu.Game.Screens.Multiplayer private const float ruleset_height = 30; private readonly Box statusStrip; - private readonly Container coverContainer, rulesetContainer, gameTypeContainer, flagContainer; - private readonly FillFlowContainer topFlow, levelRangeContainer, participantsFlow; - private readonly OsuSpriteText participants, participantsSlash, maxParticipants, name, status, beatmapTitle, beatmapDash, beatmapArtist, beatmapAuthor, host, levelRangeLower, levelRangeHigher; + private readonly Container coverContainer, rulesetContainer, gameTypeContainer; + private readonly FillFlowContainer topFlow, participantsFlow; + private readonly OsuSpriteText participants, participantsSlash, maxParticipants, name, status, beatmapTitle, beatmapDash, beatmapArtist, beatmapAuthor; + private readonly ParticipantInfo participantInfo; private readonly ScrollContainer participantsScroll; private readonly Bindable nameBind = new Bindable(); @@ -252,90 +253,7 @@ namespace osu.Game.Screens.Multiplayer Padding = contentPadding, Children = new Drawable[] { - new FillFlowContainer - { - AutoSizeAxes = Axes.X, - Height = 15f, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(5f, 0f), - Children = new Drawable[] - { - flagContainer = new Container - { - Width = 22f, - RelativeSizeAxes = Axes.Y, - }, - new Container //todo: team banners - { - Width = 38f, - RelativeSizeAxes = Axes.Y, - CornerRadius = 2f, - Masking = true, - Children = new[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = OsuColour.FromHex(@"ad387e"), - }, - }, - }, - new OsuSpriteText - { - Text = "hosted by", - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - TextSize = 14, - }, - host = new OsuSpriteText - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - TextSize = 14, - Font = @"Exo2.0-BoldItalic", - }, - }, - }, - levelRangeContainer = new FillFlowContainer - { - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Children = new[] - { - new OsuSpriteText - { - Text = "Rank Range ", - TextSize = 14, - }, - new OsuSpriteText - { - Text = "#", - TextSize = 14, - }, - levelRangeLower = new OsuSpriteText - { - TextSize = 14, - Font = @"Exo2.0-Bold", - }, - new OsuSpriteText - { - Text = " - ", - TextSize = 14, - }, - new OsuSpriteText - { - Text = "#", - TextSize = 14, - }, - levelRangeHigher = new OsuSpriteText - { - TextSize = 14, - Font = @"Exo2.0-Bold", - }, - }, - }, + participantInfo = new ParticipantInfo(@"Rank Range "), }, }, }, @@ -372,8 +290,7 @@ namespace osu.Game.Screens.Multiplayer this.colours = colours; this.textures = textures; - beatmapAuthor.Colour = levelRangeContainer.Colour = colours.Gray9; - host.Colour = colours.Blue; + beatmapAuthor.Colour = colours.Gray9; //binded here instead of ctor because dependencies are needed statusBind.ValueChanged += displayStatus; @@ -399,14 +316,7 @@ namespace osu.Game.Screens.Multiplayer private void displayUser(User value) { - host.Text = value.Username; - flagContainer.Children = new[] - { - new DrawableFlag(value.Country?.FlagName ?? @"__") - { - RelativeSizeAxes = Axes.Both, - }, - }; + participantInfo.Host = value; } private void displayStatus(RoomStatus value) @@ -489,11 +399,7 @@ namespace osu.Game.Screens.Multiplayer private void displayParticipants(User[] value) { participants.Text = value.Length.ToString(); - - var ranks = value.Select(u => u.GlobalRank); - levelRangeLower.Text = ranks.Min().ToString(); - levelRangeHigher.Text = ranks.Max().ToString(); - + participantInfo.Participants = value; participantsFlow.Children = value.Select(u => new UserTile(u)); } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 64b81ddc6a..4e015242e2 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -490,6 +490,7 @@ +