1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 15:53:00 +08:00
osu-lazer/osu.Game.Tournament/Screens/Schedule/ScheduleScreen.cs

297 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;
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;
using osu.Framework.Platform;
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
{
public class ScheduleScreen : TournamentScreen // IProvidesVideo
2018-11-11 09:13:17 +08:00
{
2019-06-18 13:57:05 +08:00
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
2018-11-11 09:13:17 +08:00
private Container mainContainer;
private LadderInfo ladder;
[BackgroundDependencyLoader]
private void load(LadderInfo ladder, Storage storage)
{
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
currentMatch.BindTo(ladder.CurrentMatch);
currentMatch.BindValueChanged(matchChanged, true);
2018-11-11 09:13:17 +08:00
}
2019-06-18 13:57:05 +08:00
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
2018-11-11 09:13:17 +08:00
{
2019-06-18 13:57:05 +08: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 12:52:56 +08:00
var conditionals = ladder
2019-06-18 13:57:05 +08: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 14:32:11 +08:00
upcoming = upcoming.Concat(conditionals);
2020-03-07 15:31:28 +08:00
upcoming = upcoming.OrderBy(p => p.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,
2019-06-18 13:57:05 +08:00
ChildrenEnumerable = ladder.Matches
2018-12-01 14:32:11 +08: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 09:13:17 +08:00
.OrderByDescending(p => p.Date.Value)
.Take(8)
2019-06-18 13:57:05 +08:00
.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 (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 09:13:17 +08: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 09:13:17 +08:00
{
new ScheduleMatchDate(match.NewValue.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
}
2019-06-18 13:57:05 +08:00
public 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);
2020-03-07 15:38:50 +08:00
CurrentMatchSelectionBox.Scale = new Vector2(1.02f, 1.15f);
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
}
}
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 09:13:17 +08:00
public class ScheduleContainer : Container
{
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,
Margin = new MarginPadding(10)
},
}
2018-11-11 09:13:17 +08:00
},
};
}
}
}
}