From 50201e602eacbdc1a03c99f405c96734e2ab99ed Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 27 Dec 2018 16:18:48 +0900 Subject: [PATCH] Combine implementations of status + end date info --- .../Screens/Multi/Components/EndDateInfo.cs | 32 ----- .../Multi/Components/RoomStatusInfo.cs | 111 ++++++++++++++++++ .../Multi/Lounge/Components/DrawableRoom.cs | 33 +----- .../Screens/Multi/Match/Components/Info.cs | 48 ++------ 4 files changed, 122 insertions(+), 102 deletions(-) delete mode 100644 osu.Game/Screens/Multi/Components/EndDateInfo.cs create mode 100644 osu.Game/Screens/Multi/Components/RoomStatusInfo.cs diff --git a/osu.Game/Screens/Multi/Components/EndDateInfo.cs b/osu.Game/Screens/Multi/Components/EndDateInfo.cs deleted file mode 100644 index c71ec04d33..0000000000 --- a/osu.Game/Screens/Multi/Components/EndDateInfo.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using osu.Game.Graphics; - -namespace osu.Game.Screens.Multi.Components -{ - public class EndDateInfo : DrawableDate - { - public EndDateInfo() - : base(DateTimeOffset.UtcNow) - { - } - - protected override string Format() - { - var diffToNow = Date.Subtract(DateTimeOffset.Now); - - if (diffToNow.TotalSeconds < -5) - return $"Closed {base.Format()}"; - - if (diffToNow.TotalSeconds < 0) - return "Closed"; - - if (diffToNow.TotalSeconds < 5) - return "Closing soon"; - - return $"Closing {base.Format()}"; - } - } -} diff --git a/osu.Game/Screens/Multi/Components/RoomStatusInfo.cs b/osu.Game/Screens/Multi/Components/RoomStatusInfo.cs new file mode 100644 index 0000000000..ca93ea2366 --- /dev/null +++ b/osu.Game/Screens/Multi/Components/RoomStatusInfo.cs @@ -0,0 +1,111 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics; +using osu.Game.Online.Multiplayer; +using osu.Game.Online.Multiplayer.RoomStatuses; + +namespace osu.Game.Screens.Multi.Components +{ + public class RoomStatusInfo : CompositeDrawable + { + private readonly RoomBindings bindings = new RoomBindings(); + + public RoomStatusInfo(Room room) + { + bindings.Room = room; + + AutoSizeAxes = Axes.Both; + + StatusPart statusPart; + EndDatePart endDatePart; + + InternalChild = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + statusPart = new StatusPart + { + TextSize = 14, + Font = "Exo2.0-Bold" + }, + endDatePart = new EndDatePart { TextSize = 14 } + } + }; + + statusPart.EndDate.BindTo(bindings.EndDate); + statusPart.Status.BindTo(bindings.Status); + statusPart.Availability.BindTo(bindings.Availability); + endDatePart.EndDate.BindTo(bindings.EndDate); + } + + private class EndDatePart : DrawableDate + { + public readonly IBindable EndDate = new Bindable(); + + public EndDatePart() + : base(DateTimeOffset.UtcNow) + { + EndDate.BindValueChanged(d => Date = d); + } + + protected override string Format() + { + var diffToNow = Date.Subtract(DateTimeOffset.Now); + + if (diffToNow.TotalSeconds < -5) + return $"Closed {base.Format()}"; + + if (diffToNow.TotalSeconds < 0) + return "Closed"; + + if (diffToNow.TotalSeconds < 5) + return "Closing soon"; + + return $"Closing {base.Format()}"; + } + } + + private class StatusPart : EndDatePart + { + public readonly IBindable Status = new Bindable(); + public readonly IBindable Availability = new Bindable(); + + [Resolved] + private OsuColour colours { get; set; } + + public StatusPart() + { + EndDate.BindValueChanged(_ => Format()); + Status.BindValueChanged(_ => Format()); + Availability.BindValueChanged(_ => Format()); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + Text = Format(); + } + + protected override string Format() + { + if (!IsLoaded) + return string.Empty; + + RoomStatus status = Date < DateTimeOffset.Now ? new RoomStatusEnded() : Status.Value ?? new RoomStatusOpen(); + + this.FadeColour(status.GetAppropriateColour(colours), 100); + return $"{Availability.Value.GetDescription()}, {status.Message}"; + } + } + } +} diff --git a/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs b/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs index 0540eed1aa..fb31864cc5 100644 --- a/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs +++ b/osu.Game/Screens/Multi/Lounge/Components/DrawableRoom.cs @@ -99,10 +99,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components private void load(OsuColour colours) { Box sideStrip; - OsuSpriteText status; ParticipantInfo participantInfo; OsuSpriteText name; - EndDateInfo endDate; Children = new Drawable[] { @@ -172,31 +170,11 @@ namespace osu.Game.Screens.Multi.Lounge.Components RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), Children = new Drawable[] { - status = new OsuSpriteText - { - TextSize = 14, - Font = @"Exo2.0-Bold", - }, - new FillFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 5), - Children = new Drawable[] - { - endDate = new EndDateInfo - { - TextSize = 14, - }, - beatmapTitle = new BeatmapTitle - { - TextSize = 14, - }, - } - } + new RoomStatusInfo(Room), + beatmapTitle = new BeatmapTitle { TextSize = 14 }, }, }, modeTypeInfo = new ModeTypeInfo @@ -220,12 +198,9 @@ namespace osu.Game.Screens.Multi.Lounge.Components participantInfo.ParticipantCount.BindTo(bindings.ParticipantCount); bindings.Name.BindValueChanged(n => name.Text = n, true); - bindings.EndDate.BindValueChanged(d => endDate.Date = d, true); bindings.Status.BindValueChanged(s => { - status.Text = s.Message; - - foreach (Drawable d in new Drawable[] { selectionBox, sideStrip, status }) + foreach (Drawable d in new Drawable[] { selectionBox, sideStrip }) d.FadeColour(s.GetAppropriateColour(colours), transition_duration); }, true); } diff --git a/osu.Game/Screens/Multi/Match/Components/Info.cs b/osu.Game/Screens/Multi/Match/Components/Info.cs index 08ba370282..0aabc014c9 100644 --- a/osu.Game/Screens/Multi/Match/Components/Info.cs +++ b/osu.Game/Screens/Multi/Match/Components/Info.cs @@ -2,8 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using osu.Framework.Allocation; -using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -20,10 +18,6 @@ namespace osu.Game.Screens.Multi.Match.Components { public Action OnStart; - private readonly OsuSpriteText availabilityStatus; - - private OsuColour colours; - private readonly RoomBindings bindings = new RoomBindings(); public Info(Room room) @@ -33,9 +27,8 @@ namespace osu.Game.Screens.Multi.Match.Components ReadyButton readyButton; ViewBeatmapButton viewBeatmapButton; - OsuSpriteText name; - EndDateInfo endDate; HostInfo hostInfo; + RoomStatusInfo statusInfo; Children = new Drawable[] { @@ -65,9 +58,12 @@ namespace osu.Game.Screens.Multi.Match.Components Direction = FillDirection.Vertical, Children = new Drawable[] { - name = new OsuSpriteText { TextSize = 30 }, - availabilityStatus = new OsuSpriteText { TextSize = 14 }, - endDate = new EndDateInfo { TextSize = 14 } + new OsuSpriteText + { + TextSize = 30, + Current = bindings.Name + }, + new RoomStatusInfo(room), } }, hostInfo = new HostInfo(), @@ -98,37 +94,7 @@ namespace osu.Game.Screens.Multi.Match.Components readyButton.Beatmap.BindTo(bindings.CurrentBeatmap); hostInfo.Host.BindTo(bindings.Host); - bindings.Availability.BindValueChanged(_ => updateAvailabilityStatus()); - bindings.Status.BindValueChanged(_ => updateAvailabilityStatus()); - bindings.Name.BindValueChanged(n => name.Text = n); - bindings.EndDate.BindValueChanged(d => endDate.Date = d); - bindings.Room = room; } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - this.colours = colours; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - updateAvailabilityStatus(); - } - - private void updateAvailabilityStatus() - { - if (!IsLoaded) - return; - - if (bindings.Status.Value != null) - { - availabilityStatus.FadeColour(bindings.Status.Value.GetAppropriateColour(colours), 100); - availabilityStatus.Text = $"{bindings.Availability.Value.GetDescription()}, {bindings.Status.Value.Message}"; - } - } } }