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

Combine implementations of status + end date info

This commit is contained in:
smoogipoo 2018-12-27 16:18:48 +09:00
parent a3b6a3981c
commit 50201e602e
4 changed files with 122 additions and 102 deletions

View File

@ -1,32 +0,0 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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()}";
}
}
}

View File

@ -0,0 +1,111 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<DateTimeOffset> EndDate = new Bindable<DateTimeOffset>();
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<RoomStatus> Status = new Bindable<RoomStatus>();
public readonly IBindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
[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}";
}
}
}
}

View File

@ -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);
}

View File

@ -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}";
}
}
}
}