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-09-25 09:27:54 +08:00
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2018-09-21 17:51:37 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Lines;
|
2018-11-22 09:25:30 +08:00
|
|
|
using osuTK;
|
2018-09-21 17:51:37 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Ladder.Components
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class ProgressionPath : Path
|
2018-09-21 17:51:37 +08:00
|
|
|
{
|
2020-01-20 12:50:27 +08:00
|
|
|
public DrawableTournamentMatch Source { get; }
|
|
|
|
public DrawableTournamentMatch Destination { get; }
|
2018-09-21 17:51:37 +08:00
|
|
|
|
2019-06-18 13:57:05 +08:00
|
|
|
public ProgressionPath(DrawableTournamentMatch source, DrawableTournamentMatch destination)
|
2018-09-21 17:51:37 +08:00
|
|
|
{
|
|
|
|
Source = source;
|
|
|
|
Destination = destination;
|
|
|
|
|
2019-04-03 15:22:41 +08:00
|
|
|
PathRadius = 3;
|
2018-09-21 17:51:37 +08:00
|
|
|
BypassAutoSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2019-06-13 17:06:24 +08:00
|
|
|
|
2019-11-12 18:37:20 +08:00
|
|
|
static Vector2 getCenteredVector(Vector2 top, Vector2 bottom) => new Vector2(top.X, top.Y + (bottom.Y - top.Y) / 2);
|
2018-09-21 17:51:37 +08:00
|
|
|
|
|
|
|
var q1 = Source.ScreenSpaceDrawQuad;
|
|
|
|
var q2 = Destination.ScreenSpaceDrawQuad;
|
|
|
|
|
2018-09-25 03:51:40 +08:00
|
|
|
float padding = q1.Width / 20;
|
|
|
|
|
2018-09-21 17:51:37 +08:00
|
|
|
bool progressionToRight = q2.TopLeft.X > q1.TopLeft.X;
|
|
|
|
|
|
|
|
if (!progressionToRight)
|
2022-04-14 12:11:11 +08:00
|
|
|
(q2, q1) = (q1, q2);
|
2018-09-21 17:51:37 +08:00
|
|
|
|
|
|
|
var c1 = getCenteredVector(q1.TopRight, q1.BottomRight) + new Vector2(padding, 0);
|
|
|
|
var c2 = getCenteredVector(q2.TopLeft, q2.BottomLeft) - new Vector2(padding, 0);
|
|
|
|
|
|
|
|
var p1 = c1;
|
|
|
|
var p2 = p1 + new Vector2(padding, 0);
|
|
|
|
|
|
|
|
if (p2.X > c2.X)
|
|
|
|
{
|
|
|
|
c2 = getCenteredVector(q2.TopRight, q2.BottomRight) + new Vector2(padding, 0);
|
|
|
|
p2.X = c2.X + padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
var p3 = new Vector2(p2.X, c2.Y);
|
|
|
|
var p4 = new Vector2(c2.X, p3.Y);
|
|
|
|
|
2019-06-13 17:06:24 +08:00
|
|
|
var points = new[] { p1, p2, p3, p4 };
|
|
|
|
|
|
|
|
float minX = points.Min(p => p.X);
|
|
|
|
float minY = points.Min(p => p.Y);
|
|
|
|
|
|
|
|
var topLeft = new Vector2(minX, minY);
|
|
|
|
|
|
|
|
Position = Parent.ToLocalSpace(topLeft);
|
|
|
|
Vertices = points.Select(p => Parent.ToLocalSpace(p) - Parent.ToLocalSpace(topLeft)).ToList();
|
2018-09-21 17:51:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|