diff --git a/osu.Game.Tests/Visual/TestCaseMatchInfo.cs b/osu.Game.Tests/Visual/TestCaseMatchInfo.cs index 205da6932f..6998ff4c39 100644 --- a/osu.Game.Tests/Visual/TestCaseMatchInfo.cs +++ b/osu.Game.Tests/Visual/TestCaseMatchInfo.cs @@ -19,10 +19,10 @@ namespace osu.Game.Tests.Visual Info info = new Info(); Add(info); - AddStep(@"set name", () => info.Name = @"Room Name?"); - AddStep(@"set availability", () => info.Availability = RoomAvailability.FriendsOnly); - AddStep(@"set status", () => info.Status = new RoomStatusPlaying()); - AddStep(@"set beatmap", () => info.Beatmap = new BeatmapInfo + AddStep(@"set name", () => info.Name.Value = @"Room Name?"); + AddStep(@"set availability", () => info.Availability.Value = RoomAvailability.FriendsOnly); + AddStep(@"set status", () => info.Status.Value = new RoomStatusPlaying()); + AddStep(@"set beatmap", () => info.Beatmap.Value = new BeatmapInfo { StarDifficulty = 2.4, Ruleset = rulesets.GetRuleset(0), @@ -34,14 +34,14 @@ namespace osu.Game.Tests.Visual }, }); - AddStep(@"set type", () => info.Type = new GameTypeTagTeam()); + AddStep(@"set type", () => info.Type.Value = new GameTypeTagTeam()); - AddStep(@"change name", () => info.Name = @"Room Name!"); - AddStep(@"change availability", () => info.Availability = RoomAvailability.InviteOnly); - AddStep(@"change status", () => info.Status = new RoomStatusOpen()); - AddStep(@"null beatmap", () => info.Beatmap = null); - AddStep(@"change type", () => info.Type = new GameTypeTeamVersus()); - AddStep(@"change beatmap", () => info.Beatmap = new BeatmapInfo + AddStep(@"change name", () => info.Name.Value = @"Room Name!"); + AddStep(@"change availability", () => info.Availability.Value = RoomAvailability.InviteOnly); + AddStep(@"change status", () => info.Status.Value = new RoomStatusOpen()); + AddStep(@"null beatmap", () => info.Beatmap.Value = null); + AddStep(@"change type", () => info.Type.Value = new GameTypeTeamVersus()); + AddStep(@"change beatmap", () => info.Beatmap.Value = new BeatmapInfo { StarDifficulty = 4.2, Ruleset = rulesets.GetRuleset(3), diff --git a/osu.Game.Tests/Visual/TestCaseMatchParticipants.cs b/osu.Game.Tests/Visual/TestCaseMatchParticipants.cs index d6ae07252b..6024ec8ea6 100644 --- a/osu.Game.Tests/Visual/TestCaseMatchParticipants.cs +++ b/osu.Game.Tests/Visual/TestCaseMatchParticipants.cs @@ -19,8 +19,8 @@ namespace osu.Game.Tests.Visual RelativeSizeAxes = Axes.Both, }); - AddStep(@"set max to null", () => participants.Max = null); - AddStep(@"set users", () => participants.Users = new[] + AddStep(@"set max to null", () => participants.MaxParticipants.Value = null); + AddStep(@"set users", () => participants.Users.Value = new[] { new User { @@ -48,9 +48,9 @@ namespace osu.Game.Tests.Visual }, }); - AddStep(@"set max", () => participants.Max = 10); - AddStep(@"clear users", () => participants.Users = new User[] { }); - AddStep(@"set max to null", () => participants.Max = null); + AddStep(@"set max", () => participants.MaxParticipants.Value = 10); + AddStep(@"clear users", () => participants.Users.Value = new User[] { }); + AddStep(@"set max to null", () => participants.MaxParticipants.Value = null); } } } diff --git a/osu.Game/Screens/Multi/Screens/Lounge/Lounge.cs b/osu.Game/Screens/Multi/Screens/Lounge/Lounge.cs index f4dd45bdfb..140b3550c1 100644 --- a/osu.Game/Screens/Multi/Screens/Lounge/Lounge.cs +++ b/osu.Game/Screens/Multi/Screens/Lounge/Lounge.cs @@ -27,7 +27,7 @@ namespace osu.Game.Screens.Multi.Screens.Lounge public override string Title => "Lounge"; - protected override Container TransitionContent => content; + protected override Drawable TransitionContent => content; public Lounge() { diff --git a/osu.Game/Screens/Multi/Screens/Match/Info.cs b/osu.Game/Screens/Multi/Screens/Match/Info.cs index a2c056c8bd..fc6e84c38a 100644 --- a/osu.Game/Screens/Multi/Screens/Match/Info.cs +++ b/osu.Game/Screens/Multi/Screens/Match/Info.cs @@ -23,60 +23,26 @@ namespace osu.Game.Screens.Multi.Screens.Match { public const float HEIGHT = 128; - private readonly OsuSpriteText name, availabilityStatus; - private readonly BeatmapTypeInfo beatmapTypeInfo; + private readonly OsuSpriteText availabilityStatus; private readonly ReadyButton readyButton; private OsuColour colours; public Bindable Ready => readyButton.Ready; - public string Name - { - set { name.Text = value; } - } - - private RoomAvailability availability; - public RoomAvailability Availability - { - set - { - if (value == availability) return; - availability = value; - - if (IsLoaded) - updateAvailabilityStatus(); - } - } - - private RoomStatus status; - public RoomStatus Status - { - set - { - if (value == status) return; - status = value; - - if (IsLoaded) - updateAvailabilityStatus(); - } - } - - public BeatmapInfo Beatmap - { - set { beatmapTypeInfo.Beatmap = value; } - } - - public GameType Type - { - set { beatmapTypeInfo.Type = value; } - } + public readonly Bindable Name = new Bindable(); + public readonly Bindable Availability = new Bindable(); + public readonly Bindable Status = new Bindable(); + public readonly Bindable Beatmap = new Bindable(); + public readonly Bindable Type = new Bindable(); public Info() { RelativeSizeAxes = Axes.X; Height = HEIGHT; + BeatmapTypeInfo beatmapTypeInfo; + Children = new Drawable[] { new Box @@ -103,9 +69,10 @@ namespace osu.Game.Screens.Multi.Screens.Match Direction = FillDirection.Vertical, Children = new Drawable[] { - name = new OsuSpriteText + new OsuSpriteText { TextSize = 30, + Current = Name }, availabilityStatus = new OsuSpriteText { @@ -131,6 +98,11 @@ namespace osu.Game.Screens.Multi.Screens.Match }, }, }; + + Availability.BindValueChanged(_ => updateAvailabilityStatus()); + Status.BindValueChanged(_ => updateAvailabilityStatus()); + Beatmap.BindValueChanged(b => beatmapTypeInfo.Beatmap = b); + Type.BindValueChanged(t => beatmapTypeInfo.Type = t); } [BackgroundDependencyLoader] @@ -148,10 +120,13 @@ namespace osu.Game.Screens.Multi.Screens.Match private void updateAvailabilityStatus() { - if (status != null) + if (!IsLoaded) + return; + + if (Status.Value != null) { - availabilityStatus.FadeColour(status.GetAppropriateColour(colours), 100); - availabilityStatus.Text = $"{availability.GetDescription()}, {status.Message}"; + availabilityStatus.FadeColour(Status.Value.GetAppropriateColour(colours), 100); + availabilityStatus.Text = $"{Availability.Value.GetDescription()}, {Status.Value.Message}"; } } diff --git a/osu.Game/Screens/Multi/Screens/Match/Match.cs b/osu.Game/Screens/Multi/Screens/Match/Match.cs index 468390b75b..4f81ffd305 100644 --- a/osu.Game/Screens/Multi/Screens/Match/Match.cs +++ b/osu.Game/Screens/Multi/Screens/Match/Match.cs @@ -20,15 +20,14 @@ namespace osu.Game.Screens.Multi.Screens.Match private readonly Participants participants; private readonly Bindable nameBind = new Bindable(); + private readonly Bindable beatmapBind = new Bindable(); private readonly Bindable statusBind = new Bindable(); private readonly Bindable availabilityBind = new Bindable(); private readonly Bindable typeBind = new Bindable(); private readonly Bindable maxParticipantsBind = new Bindable(); private readonly Bindable> participantsBind = new Bindable>(); - private readonly Bindable roomBeatmap = new Bindable(); - - protected override Container TransitionContent => participants; + protected override Drawable TransitionContent => participants; public override string Title => room.Name.Value; @@ -41,6 +40,14 @@ namespace osu.Game.Screens.Multi.Screens.Match { this.room = room; + nameBind.BindTo(room.Name); + beatmapBind.BindTo(room.Beatmap); + statusBind.BindTo(room.Status); + availabilityBind.BindTo(room.Availability); + typeBind.BindTo(room.Type); + participantsBind.BindTo(room.Participants); + maxParticipantsBind.BindTo(room.MaxParticipants); + Header header; RoomSettingsOverlay settings; Info info; @@ -76,8 +83,6 @@ namespace osu.Game.Screens.Multi.Screens.Match header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect()); header.Beatmap.BindTo(Beatmap); - roomBeatmap.BindValueChanged(b => info.Beatmap = b, true); - header.Tabs.Current.ValueChanged += t => { if (t == MatchHeaderPage.Settings) @@ -94,31 +99,22 @@ namespace osu.Game.Screens.Multi.Screens.Match settings.Applied = () => settings.Hide(); - nameBind.BindTo(room.Name); - nameBind.BindValueChanged(n => info.Name = n, true); + info.Beatmap.BindTo(beatmapBind); + info.Name.BindTo(nameBind); + info.Status.BindTo(statusBind); + info.Availability.BindTo(availabilityBind); + info.Type.BindTo(typeBind); - statusBind.BindTo(room.Status); - statusBind.BindValueChanged(s => info.Status = s, true); - - availabilityBind.BindTo(room.Availability); - availabilityBind.BindValueChanged(a => info.Availability = a, true); - - typeBind.BindTo(room.Type); - typeBind.BindValueChanged(t => info.Type = t, true); - - maxParticipantsBind.BindTo(room.MaxParticipants); - maxParticipantsBind.BindValueChanged(m => { participants.Max = m; }, true); - - participantsBind.BindTo(room.Participants); - participantsBind.BindValueChanged(p => participants.Users = p, true); + participants.Users.BindTo(participantsBind); + participants.MaxParticipants.BindTo(maxParticipantsBind); } [BackgroundDependencyLoader] private void load() { - roomBeatmap.BindTo(room.Beatmap); - roomBeatmap.BindValueChanged(b => Beatmap.Value = beatmapManager.GetWorkingBeatmap(room.Beatmap.Value), true); - Beatmap.BindValueChanged(b => roomBeatmap.Value = b.BeatmapInfo); + beatmapBind.BindTo(room.Beatmap); + beatmapBind.BindValueChanged(b => Beatmap.Value = beatmapManager.GetWorkingBeatmap(room.Beatmap.Value), true); + Beatmap.BindValueChanged(b => beatmapBind.Value = b.BeatmapInfo); } } } diff --git a/osu.Game/Screens/Multi/Screens/Match/Participants.cs b/osu.Game/Screens/Multi/Screens/Match/Participants.cs index a5ac93fffc..d40796760b 100644 --- a/osu.Game/Screens/Multi/Screens/Match/Participants.cs +++ b/osu.Game/Screens/Multi/Screens/Match/Participants.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Overlays.SearchableList; @@ -12,35 +13,23 @@ using osuTK; namespace osu.Game.Screens.Multi.Screens.Match { - public class Participants : Container + public class Participants : CompositeDrawable { - private readonly ParticipantCount count; - private readonly FillFlowContainer usersFlow; + public readonly Bindable> Users = new Bindable>(); + public readonly Bindable MaxParticipants = new Bindable(); - public IEnumerable Users + public new MarginPadding Padding { - set - { - usersFlow.Children = value.Select(u => new UserPanel(u) - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Width = 300, - OnLoadComplete = d => d.FadeInFromZero(60), - }).ToList(); - - count.Count = value.Count(); - } - } - - public int? Max - { - set => count.Max = value; + get => base.Padding; + set => base.Padding = value; } public Participants() { - Child = new Container + FillFlowContainer usersFlow; + ParticipantCount count; + + InternalChild = new Container { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Horizontal = SearchableListOverlay.WIDTH_PADDING }, @@ -70,6 +59,21 @@ namespace osu.Game.Screens.Multi.Screens.Match }, }, }; + + Users.BindValueChanged(v => + { + usersFlow.Children = v.Select(u => new UserPanel(u) + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Width = 300, + OnLoadComplete = d => d.FadeInFromZero(60), + }).ToList(); + + count.Count = v.Count(); + }); + + MaxParticipants.BindValueChanged(v => count.Max = v); } } } diff --git a/osu.Game/Screens/Multi/Screens/MultiplayerScreen.cs b/osu.Game/Screens/Multi/Screens/MultiplayerScreen.cs index fd866a5fef..3184316a33 100644 --- a/osu.Game/Screens/Multi/Screens/MultiplayerScreen.cs +++ b/osu.Game/Screens/Multi/Screens/MultiplayerScreen.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Screens; using osu.Game.Graphics.Containers; @@ -10,7 +9,7 @@ namespace osu.Game.Screens.Multi.Screens { public abstract class MultiplayerScreen : OsuScreen, IMultiplayerScreen { - protected virtual Container TransitionContent => Content; + protected virtual Drawable TransitionContent => Content; public virtual string ShortTitle => Title;