osu/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs

296 lines
13 KiB
C#
Raw Normal View History

2019-03-04 04:24:19 +00: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 01:13:17 +00:00
using System;
2018-11-11 01:13:17 +00:00
using System.Linq;
using osu.Framework.Allocation;
2019-03-02 04:40:43 +00:00
using osu.Framework.Bindables;
2018-11-11 01:13:17 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2018-11-17 05:55:27 +00:00
using osu.Game.Graphics;
using osu.Game.Tournament.Components;
2019-06-18 05:51:48 +00:00
using osu.Game.Tournament.Models;
2018-11-11 01:13:17 +00:00
using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK;
using osuTK.Graphics;
2018-11-11 01:13:17 +00:00
namespace osu.Game.Tournament.Screens.Schedule
{
public class ScheduleScreen : TournamentScreen // IProvidesVideo
2018-11-11 01:13:17 +00:00
{
2019-06-18 05:57:05 +00:00
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
2018-11-11 01:13:17 +00:00
private Container mainContainer;
private LadderInfo ladder;
[BackgroundDependencyLoader]
2022-01-15 00:06:39 +00:00
private void load(LadderInfo ladder)
2018-11-11 01:13:17 +00:00
{
this.ladder = ladder;
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new TourneyVideo("schedule")
2018-11-11 01:13:17 +00:00
{
RelativeSizeAxes = Axes.Both,
Loop = true,
},
new Container
2018-11-11 01:13:17 +00: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 04:29:09 +00: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 01:13:17 +00:00
};
}
protected override void LoadComplete()
{
base.LoadComplete();
2018-11-11 01:13:17 +00:00
currentMatch.BindTo(ladder.CurrentMatch);
currentMatch.BindValueChanged(matchChanged, true);
2018-11-11 01:13:17 +00:00
}
2019-06-18 05:57:05 +00:00
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
2018-11-11 01:13:17 +00:00
{
2019-06-18 05:57:05 +00:00
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);
2019-03-02 04:52:56 +00:00
var conditionals = ladder
2019-06-18 05:57:05 +00:00
.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))));
2018-12-01 06:32:11 +00:00
upcoming = upcoming.Concat(conditionals);
2020-03-07 07:31:28 +00:00
upcoming = upcoming.OrderBy(p => p.Date.Value).Take(8);
2018-12-01 06:32:11 +00:00
ScheduleContainer comingUpNext;
2018-11-11 01:13:17 +00:00
mainContainer.Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
2020-03-07 04:26:54 +00:00
Height = 0.74f,
2018-11-11 01:13:17 +00:00
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
new ScheduleContainer("recent matches")
{
RelativeSizeAxes = Axes.Both,
Width = 0.4f,
2019-06-18 05:57:05 +00:00
ChildrenEnumerable = ladder.Matches
2018-12-01 06:32:11 +00:00
.Where(p => p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null
&& Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4)
2018-11-11 01:13:17 +00:00
.OrderByDescending(p => p.Date.Value)
.Take(8)
2019-06-18 05:57:05 +00:00
.Select(p => new ScheduleMatch(p))
2018-11-11 01:13:17 +00:00
},
new ScheduleContainer("upcoming matches")
2018-11-11 01:13:17 +00:00
{
RelativeSizeAxes = Axes.Both,
Width = 0.6f,
2019-06-18 05:57:05 +00:00
ChildrenEnumerable = upcoming.Select(p => new ScheduleMatch(p))
2018-11-11 01:13:17 +00:00
},
}
}
},
comingUpNext = new ScheduleContainer("coming up next")
2018-11-11 01:13:17 +00:00
{
RelativeSizeAxes = Axes.Both,
Height = 0.25f,
}
}
};
if (match.NewValue != null)
{
comingUpNext.Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(30),
Children = new Drawable[]
{
new ScheduleMatch(match.NewValue, false)
2018-11-11 01:13:17 +00:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
new TournamentSpriteTextWithBackground(match.NewValue.Round.Value?.Name.Value)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Scale = new Vector2(0.5f)
},
new TournamentSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = match.NewValue.Team1.Value?.FullName + " vs " + match.NewValue.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 01:13:17 +00:00
{
new ScheduleMatchDate(match.NewValue.Date.Value)
{
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular)
}
}
},
2018-11-11 01:13:17 +00:00
}
};
}
2018-11-11 01:13:17 +00:00
}
2019-06-18 05:57:05 +00:00
public class ScheduleMatch : DrawableTournamentMatch
2018-11-11 01:13:17 +00:00
{
2019-06-18 05:57:05 +00:00
public ScheduleMatch(TournamentMatch match, bool showTimestamp = true)
: base(match)
2018-11-11 01:13:17 +00:00
{
Flow.Direction = FillDirection.Horizontal;
2018-11-17 05:55:27 +00:00
2020-03-07 04:26:54 +00:00
Scale = new Vector2(0.8f);
2020-03-07 07:38:50 +00:00
CurrentMatchSelectionBox.Scale = new Vector2(1.02f, 1.15f);
2019-06-18 05:57:05 +00:00
bool conditional = match is ConditionalTournamentMatch;
2018-12-01 06:32:11 +00:00
if (conditional)
Colour = OsuColour.Gray(0.5f);
2018-11-17 05:55:27 +00:00
if (showTimestamp)
{
2019-06-18 05:57:05 +00:00
AddInternal(new DrawableDate(Match.Date.Value)
2018-11-17 05:55:27 +00:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopLeft,
2020-03-07 04:26:54 +00:00
Colour = OsuColour.Gray(0.7f),
2019-03-02 04:52:56 +00:00
Alpha = conditional ? 0.6f : 1,
2020-03-07 04:26:54 +00:00
Font = OsuFont.Torus,
2018-11-17 05:55:27 +00:00
Margin = new MarginPadding { Horizontal = 10, Vertical = 5 },
});
AddInternal(new TournamentSpriteText
2018-11-17 05:55:27 +00:00
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomLeft,
2020-03-07 04:26:54 +00:00
Colour = OsuColour.Gray(0.7f),
2019-03-02 04:52:56 +00:00
Alpha = conditional ? 0.6f : 1,
2018-11-17 05:55:27 +00:00
Margin = new MarginPadding { Horizontal = 10, Vertical = 5 },
2019-06-18 05:57:05 +00:00
Text = match.Date.Value.ToUniversalTime().ToString("HH:mm UTC") + (conditional ? " (conditional)" : "")
2018-11-17 05:55:27 +00:00
});
}
2018-11-11 01:13:17 +00:00
}
}
public 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()}";
}
2018-11-11 01:13:17 +00:00
public class ScheduleContainer : Container
{
protected override Container<Drawable> Content => content;
private readonly FillFlowContainer content;
public ScheduleContainer(string title)
{
2020-03-07 04:26:54 +00:00
Padding = new MarginPadding { Left = 60, Top = 10 };
2018-11-11 01:13:17 +00:00
InternalChildren = new Drawable[]
{
2020-03-07 04:26:54 +00:00
new FillFlowContainer
2018-11-11 01:13:17 +00:00
{
RelativeSizeAxes = Axes.Both,
2020-03-07 04:26:54 +00: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,
Margin = new MarginPadding(10)
},
}
2018-11-11 01:13:17 +00:00
},
};
}
}
}
}