1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:47:24 +08:00

Merge pull request #24690 from peppy/tournament-schedule-screen-layout-fix

Fix regression in spacing on tournament schedule screen
This commit is contained in:
Bartłomiej Dach 2023-08-31 18:14:14 +02:00 committed by GitHub
commit ab8a032928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 20 deletions

View File

@ -12,6 +12,13 @@ namespace osu.Game.Tournament.Tests.Screens
{
public partial class TestSceneScheduleScreen : TournamentScreenTestScene
{
public override void SetUpSteps()
{
AddStep("clear matches", () => Ladder.Matches.Clear());
base.SetUpSteps();
}
[BackgroundDependencyLoader]
private void load()
{
@ -34,6 +41,36 @@ namespace osu.Game.Tournament.Tests.Screens
AddStep("Set null current match", () => Ladder.CurrentMatch.Value = null);
}
[Test]
public void TestUpcomingMatches()
{
AddStep("Add upcoming match", () =>
{
var tournamentMatch = CreateSampleMatch();
tournamentMatch.Date.Value = DateTimeOffset.UtcNow.AddMinutes(5);
tournamentMatch.Completed.Value = false;
Ladder.Matches.Add(tournamentMatch);
});
}
[Test]
public void TestRecentMatches()
{
AddStep("Add recent match", () =>
{
var tournamentMatch = CreateSampleMatch();
tournamentMatch.Date.Value = DateTimeOffset.UtcNow;
tournamentMatch.Completed.Value = true;
tournamentMatch.Team1Score.Value = tournamentMatch.PointsToWin;
tournamentMatch.Team2Score.Value = tournamentMatch.PointsToWin / 2;
Ladder.Matches.Add(tournamentMatch);
});
}
private void setMatchDate(TimeSpan relativeTime)
// Humanizer cannot handle negative timespans.
=> AddStep($"start time is {relativeTime}", () =>

View File

@ -23,7 +23,7 @@ namespace osu.Game.Tournament.Tests
{
public TournamentScalingContainer()
{
TargetDrawSize = new Vector2(1920, 1080);
TargetDrawSize = new Vector2(1024, 768);
RelativeSizeAxes = Axes.Both;
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -19,6 +20,7 @@ namespace osu.Game.Tournament.Screens.Schedule
{
public partial class ScheduleScreen : TournamentScreen
{
private readonly BindableList<TournamentMatch> allMatches = new BindableList<TournamentMatch>();
private readonly Bindable<TournamentMatch?> currentMatch = new Bindable<TournamentMatch?>();
private Container mainContainer = null!;
private LadderInfo ladder = null!;
@ -101,19 +103,34 @@ namespace osu.Game.Tournament.Screens.Schedule
{
base.LoadComplete();
allMatches.BindTo(ladder.Matches);
allMatches.BindCollectionChanged((_, _) => refresh());
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);
var conditionals = 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)
.SelectMany(m => m.ConditionalMatches.Where(cp => m.Acronyms.TrueForAll(a => cp.Acronyms.Contains(a))));
const int days_for_displays = 4;
upcoming = upcoming.Concat(conditionals);
upcoming = upcoming.OrderBy(p => p.Date.Value).Take(8);
IEnumerable<ConditionalTournamentMatch> conditionals =
allMatches
.Where(m => !m.Completed.Value && (m.Team1.Value == null || m.Team2.Value == null) && Math.Abs(m.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < days_for_displays)
.SelectMany(m => m.ConditionalMatches.Where(cp => m.Acronyms.TrueForAll(a => cp.Acronyms.Contains(a))));
IEnumerable<TournamentMatch> upcoming =
allMatches
.Where(m => !m.Completed.Value && m.Team1.Value != null && m.Team2.Value != null && Math.Abs(m.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < days_for_displays)
.Concat(conditionals)
.OrderBy(m => m.Date.Value)
.Take(8);
var recent =
allMatches
.Where(m => m.Completed.Value && m.Team1.Value != null && m.Team2.Value != null && Math.Abs(m.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < days_for_displays)
.OrderByDescending(m => m.Date.Value)
.Take(8);
ScheduleContainer comingUpNext;
@ -137,12 +154,7 @@ namespace osu.Game.Tournament.Screens.Schedule
{
RelativeSizeAxes = Axes.Both,
Width = 0.4f,
ChildrenEnumerable = 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)
.OrderByDescending(p => p.Date.Value)
.Take(8)
.Select(p => new ScheduleMatch(p))
ChildrenEnumerable = recent.Select(p => new ScheduleMatch(p))
},
new ScheduleContainer("upcoming matches")
{
@ -161,7 +173,7 @@ namespace osu.Game.Tournament.Screens.Schedule
}
};
if (match.NewValue != null)
if (currentMatch.Value != null)
{
comingUpNext.Child = new FillFlowContainer
{
@ -170,12 +182,12 @@ namespace osu.Game.Tournament.Screens.Schedule
Spacing = new Vector2(30),
Children = new Drawable[]
{
new ScheduleMatch(match.NewValue, false)
new ScheduleMatch(currentMatch.Value, false)
{
Anchor = 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,
Origin = Anchor.CentreLeft,
@ -185,7 +197,7 @@ namespace osu.Game.Tournament.Screens.Schedule
{
Anchor = 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)
},
new FillFlowContainer
@ -196,7 +208,7 @@ namespace osu.Game.Tournament.Screens.Schedule
Origin = Anchor.CentreLeft,
Children = new Drawable[]
{
new ScheduleMatchDate(match.NewValue.Date.Value)
new ScheduleMatchDate(currentMatch.Value.Date.Value)
{
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular)
}
@ -282,6 +294,7 @@ namespace osu.Game.Tournament.Screens.Schedule
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.Both,
Spacing = new Vector2(0, -6),
Margin = new MarginPadding(10)
},
}