diff --git a/osu.Game/Screens/Multi/Components/BeatmapTitle.cs b/osu.Game/Screens/Multi/Components/BeatmapTitle.cs index 6dc59f5cac..e3ef5eb401 100644 --- a/osu.Game/Screens/Multi/Components/BeatmapTitle.cs +++ b/osu.Game/Screens/Multi/Components/BeatmapTitle.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Localisation; @@ -9,7 +10,7 @@ using osu.Game.Graphics.Sprites; namespace osu.Game.Screens.Multi.Components { - public class BeatmapTitle : FillFlowContainer + public class BeatmapTitle : CompositeDrawable { private readonly OsuSpriteText beatmapTitle, beatmapDash, beatmapArtist; @@ -18,31 +19,25 @@ namespace osu.Game.Screens.Multi.Components set { beatmapTitle.TextSize = beatmapDash.TextSize = beatmapArtist.TextSize = value; } } - private BeatmapInfo beatmap; - - public BeatmapInfo Beatmap - { - set - { - if (value == beatmap) return; - beatmap = value; - - if (IsLoaded) - updateText(); - } - } + public readonly Bindable Beatmap = new Bindable(); public BeatmapTitle() { AutoSizeAxes = Axes.Both; - Direction = FillDirection.Horizontal; - Children = new[] + InternalChild = new FillFlowContainer { - beatmapTitle = new OsuSpriteText { Font = @"Exo2.0-BoldItalic", }, - beatmapDash = new OsuSpriteText { Font = @"Exo2.0-BoldItalic", }, - beatmapArtist = new OsuSpriteText { Font = @"Exo2.0-RegularItalic", }, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Children = new[] + { + beatmapTitle = new OsuSpriteText { Font = @"Exo2.0-BoldItalic", }, + beatmapDash = new OsuSpriteText { Font = @"Exo2.0-BoldItalic", }, + beatmapArtist = new OsuSpriteText { Font = @"Exo2.0-RegularItalic", }, + } }; + + Beatmap.BindValueChanged(v => updateText()); } protected override void LoadComplete() @@ -53,16 +48,19 @@ namespace osu.Game.Screens.Multi.Components private void updateText() { - if (beatmap == null) + if (!IsLoaded) + return; + + if (Beatmap.Value == null) { beatmapTitle.Text = "Changing map"; beatmapDash.Text = beatmapArtist.Text = string.Empty; } else { - beatmapTitle.Text = new LocalisedString((beatmap.Metadata.TitleUnicode, beatmap.Metadata.Title)); + beatmapTitle.Text = new LocalisedString((Beatmap.Value.Metadata.TitleUnicode, Beatmap.Value.Metadata.Title)); beatmapDash.Text = @" - "; - beatmapArtist.Text = new LocalisedString((beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist)); + beatmapArtist.Text = new LocalisedString((Beatmap.Value.Metadata.ArtistUnicode, Beatmap.Value.Metadata.Artist)); } } } diff --git a/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs b/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs index a22e171275..2bd7b19a0a 100644 --- a/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs +++ b/osu.Game/Screens/Multi/Components/BeatmapTypeInfo.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; @@ -12,53 +13,55 @@ using osuTK; namespace osu.Game.Screens.Multi.Components { - public class BeatmapTypeInfo : FillFlowContainer + public class BeatmapTypeInfo : CompositeDrawable { - private readonly ModeTypeInfo modeTypeInfo; - private readonly BeatmapTitle beatmapTitle; private readonly OsuSpriteText beatmapAuthor; - public BeatmapInfo Beatmap - { - set - { - modeTypeInfo.Beatmap = beatmapTitle.Beatmap = value; - beatmapAuthor.Text = value == null ? string.Empty : $"mapped by {value.Metadata.Author}"; - } - } + public readonly Bindable Beatmap = new Bindable(); - public GameType Type - { - set { modeTypeInfo.Type = value; } - } + public readonly Bindable Type = new Bindable(); public BeatmapTypeInfo() { AutoSizeAxes = Axes.Both; - Direction = FillDirection.Horizontal; - LayoutDuration = 100; - Spacing = new Vector2(5f, 0f); - Children = new Drawable[] + BeatmapTitle beatmapTitle; + ModeTypeInfo modeTypeInfo; + + InternalChild = new FillFlowContainer { - modeTypeInfo = new ModeTypeInfo(), - new Container + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + LayoutDuration = 100, + Spacing = new Vector2(5, 0), + Children = new Drawable[] { - AutoSizeAxes = Axes.X, - Height = 30, - Margin = new MarginPadding { Left = 5 }, - Children = new Drawable[] + modeTypeInfo = new ModeTypeInfo(), + new Container { - beatmapTitle = new BeatmapTitle(), - beatmapAuthor = new OsuSpriteText + AutoSizeAxes = Axes.X, + Height = 30, + Margin = new MarginPadding { Left = 5 }, + Children = new Drawable[] { - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - TextSize = 14, + beatmapTitle = new BeatmapTitle(), + beatmapAuthor = new OsuSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + TextSize = 14, + }, }, }, - }, + } }; + + modeTypeInfo.Beatmap.BindTo(Beatmap); + modeTypeInfo.Type.BindTo(Type); + + beatmapTitle.Beatmap.BindTo(Beatmap); + + Beatmap.BindValueChanged(v => beatmapAuthor.Text = v == null ? string.Empty : $"mapped by {v.Metadata.Author}"); } [BackgroundDependencyLoader] diff --git a/osu.Game/Screens/Multi/Components/DrawableRoom.cs b/osu.Game/Screens/Multi/Components/DrawableRoom.cs index 6bdc4c2f2d..43a9b6ad06 100644 --- a/osu.Game/Screens/Multi/Components/DrawableRoom.cs +++ b/osu.Game/Screens/Multi/Components/DrawableRoom.cs @@ -38,10 +38,10 @@ namespace osu.Game.Screens.Multi.Components private readonly Box selectionBox; private readonly Bindable nameBind = new Bindable(); + private readonly Bindable beatmapBind = new Bindable(); private readonly Bindable hostBind = new Bindable(); private readonly Bindable statusBind = new Bindable(); private readonly Bindable typeBind = new Bindable(); - private readonly Bindable roomBeatmap = new Bindable(); private readonly Bindable> participantsBind = new Bindable>(); private readonly Bindable beatmap = new Bindable(); @@ -104,7 +104,7 @@ namespace osu.Game.Screens.Multi.Components { Box sideStrip; UpdateableBeatmapBackgroundSprite background; - OsuSpriteText name, status; + OsuSpriteText status; ParticipantInfo participantInfo; BeatmapTitle beatmapTitle; ModeTypeInfo modeTypeInfo; @@ -166,9 +166,10 @@ namespace osu.Game.Screens.Multi.Components Spacing = new Vector2(5f), Children = new Drawable[] { - name = new OsuSpriteText + new OsuSpriteText { TextSize = 18, + Current = nameBind }, participantInfo = new ParticipantInfo(), }, @@ -206,11 +207,6 @@ namespace osu.Game.Screens.Multi.Components }, }; - nameBind.ValueChanged += n => name.Text = n; - hostBind.ValueChanged += h => participantInfo.Host = h; - typeBind.ValueChanged += m => modeTypeInfo.Type = m; - participantsBind.ValueChanged += p => participantInfo.Participants = p; - statusBind.ValueChanged += s => { status.Text = s.Message; @@ -221,19 +217,22 @@ namespace osu.Game.Screens.Multi.Components background.Beatmap.BindTo(beatmap); - roomBeatmap.ValueChanged += b => - { - beatmap.Value = beatmaps.GetWorkingBeatmap(b); - beatmapTitle.Beatmap = b; - modeTypeInfo.Beatmap = b; - }; + beatmapBind.ValueChanged += b => beatmap.Value = beatmaps.GetWorkingBeatmap(b); nameBind.BindTo(Room.Name); hostBind.BindTo(Room.Host); statusBind.BindTo(Room.Status); typeBind.BindTo(Room.Type); - roomBeatmap.BindTo(Room.Beatmap); + beatmapBind.BindTo(Room.Beatmap); participantsBind.BindTo(Room.Participants); + + modeTypeInfo.Beatmap.BindTo(beatmapBind); + modeTypeInfo.Type.BindTo(typeBind); + + participantInfo.Host.BindTo(hostBind); + participantInfo.Participants.BindTo(participantsBind); + + beatmapTitle.Beatmap.BindTo(beatmapBind); } protected override void LoadComplete() diff --git a/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs b/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs index 95f0c2153d..87d150c5a4 100644 --- a/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs +++ b/osu.Game/Screens/Multi/Components/ModeTypeInfo.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; @@ -10,74 +11,54 @@ using osuTK; namespace osu.Game.Screens.Multi.Components { - public class ModeTypeInfo : Container + public class ModeTypeInfo : CompositeDrawable { private const float height = 30; private const float transition_duration = 100; - private readonly Container rulesetContainer, gameTypeContainer; + private readonly Container rulesetContainer; - public BeatmapInfo Beatmap - { - set - { - if (value != null) - { - rulesetContainer.FadeIn(transition_duration); - rulesetContainer.Children = new[] - { - new DifficultyIcon(value) - { - Size = new Vector2(height), - }, - }; - } - else - { - rulesetContainer.FadeOut(transition_duration); - } - } - } - - public GameType Type - { - set - { - gameTypeContainer.Children = new[] - { - new DrawableGameType(value) - { - Size = new Vector2(height), - }, - }; - } - } + public readonly Bindable Beatmap = new Bindable(); + public readonly Bindable Type = new Bindable(); public ModeTypeInfo() { AutoSizeAxes = Axes.Both; - Children = new[] + Container gameTypeContainer; + + InternalChild = new FillFlowContainer { - new FillFlowContainer + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5f, 0f), + LayoutDuration = 100, + Children = new[] { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(5f, 0f), - LayoutDuration = 100, - Children = new[] + rulesetContainer = new Container { - rulesetContainer = new Container - { - AutoSizeAxes = Axes.Both, - }, - gameTypeContainer = new Container - { - AutoSizeAxes = Axes.Both, - }, + AutoSizeAxes = Axes.Both, + }, + gameTypeContainer = new Container + { + AutoSizeAxes = Axes.Both, }, }, }; + + Beatmap.BindValueChanged(updateBeatmap); + Type.BindValueChanged(v => gameTypeContainer.Child = new DrawableGameType(v) { Size = new Vector2(height) }); + } + + private void updateBeatmap(BeatmapInfo beatmap) + { + if (beatmap != null) + { + rulesetContainer.FadeIn(transition_duration); + rulesetContainer.Child = new DifficultyIcon(beatmap) { Size = new Vector2(height) }; + } + else + rulesetContainer.FadeOut(transition_duration); } } } diff --git a/osu.Game/Screens/Multi/Components/ParticipantCount.cs b/osu.Game/Screens/Multi/Components/ParticipantCount.cs index e7183cbd92..66f13ed683 100644 --- a/osu.Game/Screens/Multi/Components/ParticipantCount.cs +++ b/osu.Game/Screens/Multi/Components/ParticipantCount.cs @@ -1,69 +1,65 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Sprites; +using osu.Game.Users; namespace osu.Game.Screens.Multi.Components { - public class ParticipantCount : FillFlowContainer + public class ParticipantCount : CompositeDrawable { private const float text_size = 30; private const float transition_duration = 100; - private readonly OsuSpriteText count, slash, maxText; + private readonly OsuSpriteText slash, maxText; - public int Count - { - set => count.Text = value.ToString(); - } - - private int? max; - public int? Max - { - get => max; - set - { - if (value == max) return; - max = value; - - updateMax(); - } - } + public readonly Bindable> Participants = new Bindable>(); + public readonly Bindable MaxParticipants = new Bindable(); public ParticipantCount() { AutoSizeAxes = Axes.Both; - Direction = FillDirection.Horizontal; - LayoutDuration = transition_duration; - Children = new[] + OsuSpriteText count; + + InternalChild = new FillFlowContainer { - count = new OsuSpriteText + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + LayoutDuration = transition_duration, + Children = new[] { - TextSize = text_size, - Font = @"Exo2.0-Bold" - }, - slash = new OsuSpriteText - { - Text = @"/", - TextSize = text_size, - Font = @"Exo2.0-Light" - }, - maxText = new OsuSpriteText - { - TextSize = text_size, - Font = @"Exo2.0-Light" - }, + count = new OsuSpriteText + { + TextSize = text_size, + Font = @"Exo2.0-Bold" + }, + slash = new OsuSpriteText + { + Text = @"/", + TextSize = text_size, + Font = @"Exo2.0-Light" + }, + maxText = new OsuSpriteText + { + TextSize = text_size, + Font = @"Exo2.0-Light" + }, + } }; - updateMax(); + Participants.BindValueChanged(v => count.Text = v.Count().ToString()); + MaxParticipants.BindValueChanged(_ => updateMax(), true); } private void updateMax() { - if (Max == null) + if (MaxParticipants.Value == null) { slash.FadeOut(transition_duration); maxText.FadeOut(transition_duration); @@ -71,7 +67,7 @@ namespace osu.Game.Screens.Multi.Components else { slash.FadeIn(transition_duration); - maxText.Text = Max.ToString(); + maxText.Text = MaxParticipants.Value.ToString(); maxText.FadeIn(transition_duration); } } diff --git a/osu.Game/Screens/Multi/Components/ParticipantInfo.cs b/osu.Game/Screens/Multi/Components/ParticipantInfo.cs index b1c77a04af..47aff3f200 100644 --- a/osu.Game/Screens/Multi/Components/ParticipantInfo.cs +++ b/osu.Game/Screens/Multi/Components/ParticipantInfo.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -16,36 +17,21 @@ namespace osu.Game.Screens.Multi.Components { 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) { RelativeSizeAxes = Axes.Both } }; - } - } - - public IEnumerable Participants - { - set - { - var ranks = value.Select(u => u.Statistics.Ranks.Global); - levelRangeLower.Text = ranks.Min().ToString(); - levelRangeHigher.Text = ranks.Max().ToString(); - } - } + public readonly Bindable Host = new Bindable(); + public readonly Bindable> Participants = new Bindable>(); public ParticipantInfo(string rankPrefix = null) { RelativeSizeAxes = Axes.X; Height = 15f; + OsuSpriteText levelRangeHigher; + OsuSpriteText levelRangeLower; + Container flagContainer; + Children = new Drawable[] { new FillFlowContainer @@ -133,6 +119,19 @@ namespace osu.Game.Screens.Multi.Components }, }, }; + + Host.BindValueChanged(v => + { + host.Text = v.Username; + flagContainer.Child = new DrawableFlag(v.Country) { RelativeSizeAxes = Axes.Both }; + }); + + Participants.BindValueChanged(v => + { + var ranks = v.Select(u => u.Statistics.Ranks.Global); + levelRangeLower.Text = ranks.Min().ToString(); + levelRangeHigher.Text = ranks.Max().ToString(); + }); } [BackgroundDependencyLoader] diff --git a/osu.Game/Screens/Multi/Components/RoomInspector.cs b/osu.Game/Screens/Multi/Components/RoomInspector.cs index b7dcb3c8fb..d282264ed6 100644 --- a/osu.Game/Screens/Multi/Components/RoomInspector.cs +++ b/osu.Game/Screens/Multi/Components/RoomInspector.cs @@ -29,10 +29,10 @@ namespace osu.Game.Screens.Multi.Components private readonly MarginPadding contentPadding = new MarginPadding { Horizontal = 20, Vertical = 10 }; private readonly Bindable nameBind = new Bindable(); + private readonly Bindable beatmapBind = new Bindable(); private readonly Bindable hostBind = new Bindable(); private readonly Bindable statusBind = new Bindable(); private readonly Bindable typeBind = new Bindable(); - private readonly Bindable roomBeatmap = new Bindable(); private readonly Bindable maxParticipantsBind = new Bindable(); private readonly Bindable> participantsBind = new Bindable>(); @@ -64,7 +64,7 @@ namespace osu.Game.Screens.Multi.Components hostBind.UnbindBindings(); statusBind.UnbindBindings(); typeBind.UnbindBindings(); - roomBeatmap.UnbindBindings(); + beatmapBind.UnbindBindings(); maxParticipantsBind.UnbindBindings(); participantsBind.UnbindBindings(); @@ -74,7 +74,7 @@ namespace osu.Game.Screens.Multi.Components hostBind.BindTo(room.Host); statusBind.BindTo(room.Status); typeBind.BindTo(room.Type); - roomBeatmap.BindTo(room.Beatmap); + beatmapBind.BindTo(room.Beatmap); maxParticipantsBind.BindTo(room.MaxParticipants); participantsBind.BindTo(room.Participants); } @@ -131,6 +131,7 @@ namespace osu.Game.Screens.Multi.Components Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, TextSize = 30, + Current = nameBind }, }, }, @@ -203,26 +204,20 @@ namespace osu.Game.Screens.Multi.Components }, }; - nameBind.ValueChanged += n => name.Text = n; - hostBind.ValueChanged += h => participantInfo.Host = h; - typeBind.ValueChanged += t => beatmapTypeInfo.Type = t; - maxParticipantsBind.ValueChanged += m => participantCount.Max = m; statusBind.ValueChanged += displayStatus; + beatmapBind.ValueChanged += b => beatmap.Value = beatmaps.GetWorkingBeatmap(b); + participantsBind.ValueChanged += p => participantsFlow.ChildrenEnumerable = p.Select(u => new UserTile(u)); background.Beatmap.BindTo(beatmap); - roomBeatmap.ValueChanged += b => - { - beatmap.Value = beatmaps.GetWorkingBeatmap(b); - beatmapTypeInfo.Beatmap = b; - }; + participantInfo.Host.BindTo(hostBind); + participantInfo.Participants.BindTo(participantsBind); - participantsBind.ValueChanged += p => - { - participantCount.Count = p.Count(); - participantInfo.Participants = p; - participantsFlow.ChildrenEnumerable = p.Select(u => new UserTile(u)); - }; + participantCount.Participants.BindTo(participantsBind); + participantCount.MaxParticipants.BindTo(maxParticipantsBind); + + beatmapTypeInfo.Type.BindTo(typeBind); + beatmapTypeInfo.Beatmap.BindTo(beatmapBind); updateState(); } @@ -265,7 +260,7 @@ namespace osu.Game.Screens.Multi.Components participantInfo.FadeIn(transition_duration); statusBind.TriggerChange(); - roomBeatmap.TriggerChange(); + beatmapBind.TriggerChange(); } } diff --git a/osu.Game/Screens/Multi/Screens/Match/Info.cs b/osu.Game/Screens/Multi/Screens/Match/Info.cs index fc6e84c38a..9600a878a6 100644 --- a/osu.Game/Screens/Multi/Screens/Match/Info.cs +++ b/osu.Game/Screens/Multi/Screens/Match/Info.cs @@ -99,10 +99,11 @@ namespace osu.Game.Screens.Multi.Screens.Match }, }; + beatmapTypeInfo.Beatmap.BindTo(Beatmap); + beatmapTypeInfo.Type.BindTo(Type); + Availability.BindValueChanged(_ => updateAvailabilityStatus()); Status.BindValueChanged(_ => updateAvailabilityStatus()); - Beatmap.BindValueChanged(b => beatmapTypeInfo.Beatmap = b); - Type.BindValueChanged(t => beatmapTypeInfo.Type = t); } [BackgroundDependencyLoader] diff --git a/osu.Game/Screens/Multi/Screens/Match/Participants.cs b/osu.Game/Screens/Multi/Screens/Match/Participants.cs index d40796760b..98ab758f81 100644 --- a/osu.Game/Screens/Multi/Screens/Match/Participants.cs +++ b/osu.Game/Screens/Multi/Screens/Match/Participants.cs @@ -60,6 +60,9 @@ namespace osu.Game.Screens.Multi.Screens.Match }, }; + count.Participants.BindTo(Users); + count.MaxParticipants.BindTo(MaxParticipants); + Users.BindValueChanged(v => { usersFlow.Children = v.Select(u => new UserPanel(u) @@ -69,11 +72,7 @@ namespace osu.Game.Screens.Multi.Screens.Match Width = 300, OnLoadComplete = d => d.FadeInFromZero(60), }).ToList(); - - count.Count = v.Count(); }); - - MaxParticipants.BindValueChanged(v => count.Max = v); } } }