1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 04:27:34 +08:00
osu-lazer/osu.Game.Tournament/Screens/Ladder/LadderScreen.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

186 lines
6.6 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Specialized;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Caching;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Lines;
using osu.Game.Tournament.Components;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors;
using osu.Game.Tournament.Screens.Ladder.Components;
using osuTK.Graphics;
namespace osu.Game.Tournament.Screens.Ladder
{
public class LadderScreen : TournamentScreen
{
2019-06-18 13:57:05 +08:00
protected Container<DrawableTournamentMatch> MatchesContainer;
private Container<Path> paths;
private Container headings;
2019-06-13 15:11:15 +08:00
protected LadderDragContainer ScrollContent;
2019-06-13 16:04:57 +08:00
protected Container Content;
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load()
{
normalPathColour = Color4Extensions.FromHex("#66D1FF");
losersPathColour = Color4Extensions.FromHex("#FFC700");
RelativeSizeAxes = Axes.Both;
2019-06-13 16:04:57 +08:00
InternalChild = Content = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new TourneyVideo("ladder")
2018-11-17 13:59:37 +08:00
{
RelativeSizeAxes = Axes.Both,
Loop = true,
},
2020-03-12 12:29:09 +08:00
new DrawableTournamentHeaderText
{
Y = 100,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
2019-06-13 15:11:15 +08:00
ScrollContent = new LadderDragContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
paths = new Container<Path> { RelativeSizeAxes = Axes.Both },
headings = new Container { RelativeSizeAxes = Axes.Both },
2019-06-18 13:57:05 +08:00
MatchesContainer = new Container<DrawableTournamentMatch> { RelativeSizeAxes = Axes.Both },
}
},
}
};
2019-06-18 13:57:05 +08:00
void addMatch(TournamentMatch match) =>
MatchesContainer.Add(new DrawableTournamentMatch(match, this is LadderEditorScreen)
{
Changed = () => layout.Invalidate()
});
2019-06-18 13:57:05 +08:00
foreach (var match in LadderInfo.Matches)
addMatch(match);
2022-06-24 20:25:23 +08:00
LadderInfo.Rounds.CollectionChanged += (_, _) => layout.Invalidate();
LadderInfo.Matches.CollectionChanged += (_, args) =>
{
switch (args.Action)
2019-11-11 19:53:22 +08:00
{
case NotifyCollectionChangedAction.Add:
foreach (var p in args.NewItems.Cast<TournamentMatch>())
addMatch(p);
break;
case NotifyCollectionChangedAction.Remove:
foreach (var p in args.OldItems.Cast<TournamentMatch>())
{
foreach (var d in MatchesContainer.Where(d => d.Match == p))
d.Expire();
}
break;
2019-11-11 19:53:22 +08:00
}
layout.Invalidate();
};
}
private readonly Cached layout = new Cached();
protected override void Update()
{
base.Update();
if (!layout.IsValid)
UpdateLayout();
}
private Color4 normalPathColour;
private Color4 losersPathColour;
protected virtual bool DrawLoserPaths => false;
protected virtual void UpdateLayout()
{
paths.Clear();
headings.Clear();
int id = 1;
2019-06-18 13:57:05 +08:00
foreach (var match in MatchesContainer.OrderBy(d => d.Y).ThenBy(d => d.X))
{
2019-06-18 13:57:05 +08:00
match.Match.ID = id++;
2019-06-18 13:57:05 +08:00
if (match.Match.Progression.Value != null)
{
2019-06-18 13:57:05 +08:00
var dest = MatchesContainer.FirstOrDefault(p => p.Match == match.Match.Progression.Value);
if (dest == null)
// clean up outdated progressions.
2019-06-18 13:57:05 +08:00
match.Match.Progression.Value = null;
else
2019-06-18 13:57:05 +08:00
paths.Add(new ProgressionPath(match, dest) { Colour = match.Match.Losers.Value ? losersPathColour : normalPathColour });
}
if (DrawLoserPaths)
{
2019-06-18 13:57:05 +08:00
if (match.Match.LosersProgression.Value != null)
{
2019-06-18 13:57:05 +08:00
var dest = MatchesContainer.FirstOrDefault(p => p.Match == match.Match.LosersProgression.Value);
if (dest == null)
// clean up outdated progressions.
2019-06-18 13:57:05 +08:00
match.Match.LosersProgression.Value = null;
else
2019-06-18 13:57:05 +08:00
paths.Add(new ProgressionPath(match, dest) { Colour = losersPathColour.Opacity(0.1f) });
}
}
}
2019-06-18 13:44:15 +08:00
foreach (var round in LadderInfo.Rounds)
{
2019-06-18 13:57:05 +08:00
var topMatch = MatchesContainer.Where(p => !p.Match.Losers.Value && p.Match.Round.Value == round).OrderBy(p => p.Y).FirstOrDefault();
2019-06-18 13:57:05 +08:00
if (topMatch == null) continue;
2019-06-18 13:44:15 +08:00
headings.Add(new DrawableTournamentRound(round)
{
2019-06-18 13:57:05 +08:00
Position = headings.ToLocalSpace((topMatch.ScreenSpaceDrawQuad.TopLeft + topMatch.ScreenSpaceDrawQuad.TopRight) / 2),
Margin = new MarginPadding { Bottom = 10 },
Origin = Anchor.BottomCentre,
});
}
2019-06-18 13:44:15 +08:00
foreach (var round in LadderInfo.Rounds)
{
2019-06-18 13:57:05 +08:00
var topMatch = MatchesContainer.Where(p => p.Match.Losers.Value && p.Match.Round.Value == round).OrderBy(p => p.Y).FirstOrDefault();
2019-06-18 13:57:05 +08:00
if (topMatch == null) continue;
2019-06-18 13:44:15 +08:00
headings.Add(new DrawableTournamentRound(round, true)
{
2019-06-18 13:57:05 +08:00
Position = headings.ToLocalSpace((topMatch.ScreenSpaceDrawQuad.TopLeft + topMatch.ScreenSpaceDrawQuad.TopRight) / 2),
Margin = new MarginPadding { Bottom = 10 },
Origin = Anchor.BottomCentre,
});
}
layout.Validate();
}
}
}