1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-05 04:52:53 +08:00

Fix schedule screen not responding to new matches being added

This commit is contained in:
Dean Herbert 2023-08-31 18:05:34 +09:00
parent 91c3ae4fef
commit 5fa31b7b35

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -19,6 +20,7 @@ namespace osu.Game.Tournament.Screens.Schedule
{ {
public partial class ScheduleScreen : TournamentScreen public partial class ScheduleScreen : TournamentScreen
{ {
private readonly BindableList<TournamentMatch> allMatches = new BindableList<TournamentMatch>();
private readonly Bindable<TournamentMatch?> currentMatch = new Bindable<TournamentMatch?>(); private readonly Bindable<TournamentMatch?> currentMatch = new Bindable<TournamentMatch?>();
private Container mainContainer = null!; private Container mainContainer = null!;
private LadderInfo ladder = null!; private LadderInfo ladder = null!;
@ -101,15 +103,22 @@ namespace osu.Game.Tournament.Screens.Schedule
{ {
base.LoadComplete(); base.LoadComplete();
allMatches.BindTo(ladder.Matches);
allMatches.BindCollectionChanged((_, _) => refresh());
currentMatch.BindTo(ladder.CurrentMatch); currentMatch.BindTo(ladder.CurrentMatch);
currentMatch.BindValueChanged(matchChanged, true); currentMatch.BindValueChanged(_ => refresh(), true);
} }
private void matchChanged(ValueChangedEvent<TournamentMatch?> match) private void refresh()
{ {
var upcoming = ladder.Matches.Where(p => !p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4); IEnumerable<TournamentMatch> upcoming =
var conditionals = ladder allMatches
.Matches.Where(p => !p.Completed.Value && (p.Team1.Value == null || p.Team2.Value == null) && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4) .Where(p => !p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4);
IEnumerable<ConditionalTournamentMatch> conditionals =
allMatches
.Where(p => !p.Completed.Value && (p.Team1.Value == null || p.Team2.Value == null) && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4)
.SelectMany(m => m.ConditionalMatches.Where(cp => m.Acronyms.TrueForAll(a => cp.Acronyms.Contains(a)))); .SelectMany(m => m.ConditionalMatches.Where(cp => m.Acronyms.TrueForAll(a => cp.Acronyms.Contains(a))));
upcoming = upcoming.Concat(conditionals); upcoming = upcoming.Concat(conditionals);
@ -137,7 +146,7 @@ namespace osu.Game.Tournament.Screens.Schedule
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Width = 0.4f, Width = 0.4f,
ChildrenEnumerable = ladder.Matches ChildrenEnumerable = allMatches
.Where(p => p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null .Where(p => p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null
&& Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4) && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4)
.OrderByDescending(p => p.Date.Value) .OrderByDescending(p => p.Date.Value)
@ -161,7 +170,7 @@ namespace osu.Game.Tournament.Screens.Schedule
} }
}; };
if (match.NewValue != null) if (currentMatch.Value != null)
{ {
comingUpNext.Child = new FillFlowContainer comingUpNext.Child = new FillFlowContainer
{ {
@ -170,12 +179,12 @@ namespace osu.Game.Tournament.Screens.Schedule
Spacing = new Vector2(30), Spacing = new Vector2(30),
Children = new Drawable[] Children = new Drawable[]
{ {
new ScheduleMatch(match.NewValue, false) new ScheduleMatch(currentMatch.Value, false)
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
}, },
new TournamentSpriteTextWithBackground(match.NewValue.Round.Value?.Name.Value ?? string.Empty) new TournamentSpriteTextWithBackground(currentMatch.Value.Round.Value?.Name.Value ?? string.Empty)
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
@ -185,7 +194,7 @@ namespace osu.Game.Tournament.Screens.Schedule
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Text = match.NewValue.Team1.Value?.FullName + " vs " + match.NewValue.Team2.Value?.FullName, Text = currentMatch.Value.Team1.Value?.FullName + " vs " + currentMatch.Value.Team2.Value?.FullName,
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.SemiBold) Font = OsuFont.Torus.With(size: 24, weight: FontWeight.SemiBold)
}, },
new FillFlowContainer new FillFlowContainer
@ -196,7 +205,7 @@ namespace osu.Game.Tournament.Screens.Schedule
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Children = new Drawable[] Children = new Drawable[]
{ {
new ScheduleMatchDate(match.NewValue.Date.Value) new ScheduleMatchDate(currentMatch.Value.Date.Value)
{ {
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular) Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular)
} }