1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 03:22:57 +08:00
osu-lazer/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs

307 lines
13 KiB
C#
Raw Normal View History

2019-03-04 12:24:19 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-11-11 09:13:17 +08:00
using System;
using System.Collections.Generic;
2018-11-11 09:13:17 +08:00
using System.Linq;
using osu.Framework.Allocation;
2019-03-02 12:40:43 +08:00
using osu.Framework.Bindables;
2018-11-11 09:13:17 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2018-11-17 13:55:27 +08:00
using osu.Game.Graphics;
using osu.Game.Tournament.Components;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Models;
2018-11-11 09:13:17 +08:00
using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK;
using osuTK.Graphics;
2018-11-11 09:13:17 +08:00
namespace osu.Game.Tournament.Screens.Schedule
{
2022-11-24 13:32:20 +08:00
public partial class ScheduleScreen : TournamentScreen
2018-11-11 09:13:17 +08:00
{
private readonly BindableList<TournamentMatch> allMatches = new BindableList<TournamentMatch>();
2023-07-25 19:50:55 +08:00
private readonly Bindable<TournamentMatch?> currentMatch = new Bindable<TournamentMatch?>();
private Container mainContainer = null!;
private LadderInfo ladder = null!;
2018-11-11 09:13:17 +08:00
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load(LadderInfo ladder)
2018-11-11 09:13:17 +08:00
{
this.ladder = ladder;
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new TourneyVideo("schedule")
2018-11-11 09:13:17 +08:00
{
RelativeSizeAxes = Axes.Both,
Loop = true,
},
new Container
2018-11-11 09:13:17 +08:00
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(100) { Bottom = 50 },
Children = new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
},
Content = new[]
{
new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
2020-03-12 12:29:09 +08:00
new DrawableTournamentHeaderText(),
new Container
{
Margin = new MarginPadding { Top = 40 },
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
Colour = Color4.White,
Size = new Vector2(50, 10),
},
new TournamentSpriteTextWithBackground("Schedule")
{
X = 60,
Scale = new Vector2(0.8f)
}
}
},
}
},
},
new Drawable[]
{
mainContainer = new Container
{
RelativeSizeAxes = Axes.Both,
}
}
}
}
}
},
2018-11-11 09:13:17 +08:00
};
}
protected override void LoadComplete()
{
base.LoadComplete();
2018-11-11 09:13:17 +08:00
allMatches.BindTo(ladder.Matches);
allMatches.BindCollectionChanged((_, _) => refresh());
2018-11-11 09:13:17 +08:00
currentMatch.BindTo(ladder.CurrentMatch);
currentMatch.BindValueChanged(_ => refresh(), true);
2018-11-11 09:13:17 +08:00
}
private void refresh()
2018-11-11 09:13:17 +08:00
{
const int days_for_displays = 4;
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))));
2018-12-01 14:32:11 +08:00
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);
2018-12-01 14:32:11 +08:00
ScheduleContainer comingUpNext;
2018-11-11 09:13:17 +08:00
mainContainer.Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
2020-03-07 12:26:54 +08:00
Height = 0.74f,
2018-11-11 09:13:17 +08:00
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
new ScheduleContainer("recent matches")
{
RelativeSizeAxes = Axes.Both,
Width = 0.4f,
ChildrenEnumerable = recent.Select(p => new ScheduleMatch(p))
2018-11-11 09:13:17 +08:00
},
new ScheduleContainer("upcoming matches")
2018-11-11 09:13:17 +08:00
{
RelativeSizeAxes = Axes.Both,
Width = 0.6f,
2019-06-18 13:57:05 +08:00
ChildrenEnumerable = upcoming.Select(p => new ScheduleMatch(p))
2018-11-11 09:13:17 +08:00
},
}
}
},
comingUpNext = new ScheduleContainer("coming up next")
2018-11-11 09:13:17 +08:00
{
RelativeSizeAxes = Axes.Both,
Height = 0.25f,
}
}
};
if (currentMatch.Value != null)
{
comingUpNext.Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(30),
Children = new Drawable[]
{
new ScheduleMatch(currentMatch.Value, false)
2018-11-11 09:13:17 +08:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
new TournamentSpriteTextWithBackground(currentMatch.Value.Round.Value?.Name.Value ?? string.Empty)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Scale = new Vector2(0.5f)
},
new TournamentSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = currentMatch.Value.Team1.Value?.FullName + " vs " + currentMatch.Value.Team2.Value?.FullName,
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.SemiBold)
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
2018-11-11 09:13:17 +08:00
{
new ScheduleMatchDate(currentMatch.Value.Date.Value)
{
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular)
}
}
},
2018-11-11 09:13:17 +08:00
}
};
}
2018-11-11 09:13:17 +08:00
}
2022-11-24 13:32:20 +08:00
public partial class ScheduleMatch : DrawableTournamentMatch
2018-11-11 09:13:17 +08:00
{
2019-06-18 13:57:05 +08:00
public ScheduleMatch(TournamentMatch match, bool showTimestamp = true)
: base(match)
2018-11-11 09:13:17 +08:00
{
Flow.Direction = FillDirection.Horizontal;
2018-11-17 13:55:27 +08:00
2020-03-07 12:26:54 +08:00
Scale = new Vector2(0.8f);
2019-06-18 13:57:05 +08:00
bool conditional = match is ConditionalTournamentMatch;
2018-12-01 14:32:11 +08:00
if (conditional)
Colour = OsuColour.Gray(0.5f);
2018-11-17 13:55:27 +08:00
if (showTimestamp)
{
2019-06-18 13:57:05 +08:00
AddInternal(new DrawableDate(Match.Date.Value)
2018-11-17 13:55:27 +08:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopLeft,
2020-03-07 12:26:54 +08:00
Colour = OsuColour.Gray(0.7f),
2019-03-02 12:52:56 +08:00
Alpha = conditional ? 0.6f : 1,
2020-03-07 12:26:54 +08:00
Font = OsuFont.Torus,
2018-11-17 13:55:27 +08:00
Margin = new MarginPadding { Horizontal = 10, Vertical = 5 },
});
AddInternal(new TournamentSpriteText
2018-11-17 13:55:27 +08:00
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomLeft,
2020-03-07 12:26:54 +08:00
Colour = OsuColour.Gray(0.7f),
2019-03-02 12:52:56 +08:00
Alpha = conditional ? 0.6f : 1,
2018-11-17 13:55:27 +08:00
Margin = new MarginPadding { Horizontal = 10, Vertical = 5 },
2019-06-18 13:57:05 +08:00
Text = match.Date.Value.ToUniversalTime().ToString("HH:mm UTC") + (conditional ? " (conditional)" : "")
2018-11-17 13:55:27 +08:00
});
}
2018-11-11 09:13:17 +08:00
}
}
2022-11-24 13:32:20 +08:00
public partial class ScheduleMatchDate : DrawableDate
{
public ScheduleMatchDate(DateTimeOffset date, float textSize = OsuFont.DEFAULT_FONT_SIZE, bool italic = true)
: base(date, textSize, italic)
{
}
protected override string Format() => Date < DateTimeOffset.Now
? $"Started {base.Format()}"
: $"Starting {base.Format()}";
}
2022-11-24 13:32:20 +08:00
public partial class ScheduleContainer : Container
2018-11-11 09:13:17 +08:00
{
protected override Container<Drawable> Content => content;
private readonly FillFlowContainer content;
public ScheduleContainer(string title)
{
2020-03-07 12:26:54 +08:00
Padding = new MarginPadding { Left = 60, Top = 10 };
2018-11-11 09:13:17 +08:00
InternalChildren = new Drawable[]
{
2020-03-07 12:26:54 +08:00
new FillFlowContainer
2018-11-11 09:13:17 +08:00
{
RelativeSizeAxes = Axes.Both,
2020-03-07 12:26:54 +08:00
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new TournamentSpriteTextWithBackground(title.ToUpperInvariant())
{
Scale = new Vector2(0.5f)
},
content = new FillFlowContainer
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.Both,
Spacing = new Vector2(0, -6),
2020-03-07 12:26:54 +08:00
Margin = new MarginPadding(10)
},
}
2018-11-11 09:13:17 +08:00
},
};
}
}
}
}