2018-09-10 03:51:38 +08:00
|
|
|
using System.Collections.Generic;
|
2018-09-16 04:35:51 +08:00
|
|
|
using System.Linq;
|
2018-09-10 03:51:38 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-09-16 04:35:51 +08:00
|
|
|
using osu.Framework.Graphics.Lines;
|
2018-09-10 03:51:38 +08:00
|
|
|
using osu.Framework.Input.States;
|
|
|
|
using osu.Game.Graphics.Cursor;
|
|
|
|
using osu.Game.Tournament.Components;
|
2018-09-21 17:51:37 +08:00
|
|
|
using osu.Game.Tournament.Screens.Ladder.Components;
|
2018-09-10 03:51:38 +08:00
|
|
|
using SixLabors.Primitives;
|
|
|
|
|
2018-09-21 17:51:37 +08:00
|
|
|
namespace osu.Game.Tournament.Screens.Ladder
|
2018-09-10 03:51:38 +08:00
|
|
|
{
|
|
|
|
public class LadderManager : CompositeDrawable
|
|
|
|
{
|
|
|
|
public readonly List<TournamentTeam> Teams;
|
2018-09-16 04:35:51 +08:00
|
|
|
private readonly Container<DrawableMatchPairing> pairingsContainer;
|
|
|
|
private readonly Container<Path> paths;
|
2018-09-10 03:51:38 +08:00
|
|
|
|
|
|
|
public LadderManager(LadderInfo info, List<TournamentTeam> teams)
|
|
|
|
{
|
|
|
|
Teams = teams;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2018-09-16 04:35:51 +08:00
|
|
|
InternalChild = new OsuContextMenuContainer
|
2018-09-10 03:51:38 +08:00
|
|
|
{
|
2018-09-16 04:35:51 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
pairingsContainer = new Container<DrawableMatchPairing> { RelativeSizeAxes = Axes.Both },
|
|
|
|
paths = new Container<Path> { RelativeSizeAxes = Axes.Both },
|
|
|
|
}
|
2018-09-10 03:51:38 +08:00
|
|
|
};
|
|
|
|
|
2018-09-16 04:35:51 +08:00
|
|
|
foreach (var pair in info.Progressions)
|
|
|
|
info.Pairings.Single(p => p.ID == pair.Item1).Progression.Value = info.Pairings.Single(p => p.ID == pair.Item2);
|
|
|
|
|
2018-09-10 03:51:38 +08:00
|
|
|
foreach (var pairing in info.Pairings)
|
|
|
|
addPairing(pairing);
|
|
|
|
}
|
|
|
|
|
2018-09-16 04:35:51 +08:00
|
|
|
public LadderInfo CreateInfo()
|
2018-09-10 03:51:38 +08:00
|
|
|
{
|
2018-09-16 04:35:51 +08:00
|
|
|
var pairings = pairingsContainer.Select(p => p.Pairing).ToList();
|
|
|
|
|
|
|
|
return new LadderInfo
|
|
|
|
{
|
|
|
|
Pairings = pairings,
|
|
|
|
Progressions = pairings
|
|
|
|
.Where(p => p.Progression.Value != null)
|
|
|
|
.Select(p => (p.ID, p.Progression.Value.ID))
|
|
|
|
.ToList()
|
|
|
|
};
|
2018-09-10 03:51:38 +08:00
|
|
|
}
|
|
|
|
|
2018-09-16 04:35:51 +08:00
|
|
|
private void addPairing(MatchPairing pairing) => pairingsContainer.Add(new DrawableMatchPairing(pairing));
|
2018-09-10 03:51:38 +08:00
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
{
|
2018-09-16 04:35:51 +08:00
|
|
|
addPairing(new MatchPairing
|
2018-09-10 03:51:38 +08:00
|
|
|
{
|
|
|
|
Position = new Point((int)state.Mouse.Position.X, (int)state.Mouse.Position.Y)
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-16 04:35:51 +08:00
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
paths.Clear();
|
|
|
|
|
|
|
|
int id = 0;
|
|
|
|
foreach (var pairing in pairingsContainer.OrderBy(d => d.Y).ThenBy(d => d.X))
|
|
|
|
{
|
|
|
|
pairing.Pairing.ID = id++;
|
|
|
|
|
|
|
|
if (pairing.Pairing.Progression.Value != null)
|
2018-09-21 17:51:37 +08:00
|
|
|
paths.Add(new ProgressionPath(pairing, pairingsContainer.Single(p => p.Pairing == pairing.Pairing.Progression.Value)));
|
2018-09-16 04:35:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 17:51:37 +08:00
|
|
|
public void JoinRequest(MatchPairing pairing) => AddInternal(new JoinRequestHandler(pairingsContainer, pairing));
|
2018-09-16 04:35:51 +08:00
|
|
|
|
|
|
|
private class JoinRequestHandler : CompositeDrawable
|
|
|
|
{
|
2018-09-19 01:00:16 +08:00
|
|
|
private readonly Container<DrawableMatchPairing> pairingsContainer;
|
2018-09-16 04:35:51 +08:00
|
|
|
public readonly MatchPairing Source;
|
|
|
|
|
2018-09-21 17:51:37 +08:00
|
|
|
private ProgressionPath path;
|
|
|
|
|
2018-09-19 01:00:16 +08:00
|
|
|
public JoinRequestHandler(Container<DrawableMatchPairing> pairingsContainer, MatchPairing source)
|
2018-09-16 04:35:51 +08:00
|
|
|
{
|
2018-09-19 01:00:16 +08:00
|
|
|
this.pairingsContainer = pairingsContainer;
|
2018-09-16 04:35:51 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-09-21 17:51:37 +08:00
|
|
|
|
|
|
|
Source = source;
|
|
|
|
Source.Progression.Value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private DrawableMatchPairing findTarget(InputState state) => pairingsContainer.FirstOrDefault(d => d.ReceiveMouseInputAt(state.Mouse.NativeState.Position));
|
|
|
|
|
|
|
|
protected override bool OnMouseMove(InputState state)
|
|
|
|
{
|
|
|
|
var found = findTarget(state);
|
|
|
|
|
|
|
|
if (found == path?.Destination)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
path?.Expire();
|
|
|
|
path = null;
|
|
|
|
|
|
|
|
if (found == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AddInternal(path = new ProgressionPath(pairingsContainer.First(c => c.Pairing == Source), found) { Alpha = 0.4f });
|
|
|
|
|
|
|
|
return base.OnMouseMove(state);
|
2018-09-16 04:35:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
{
|
2018-09-21 17:51:37 +08:00
|
|
|
var found = findTarget(state);
|
2018-09-19 01:00:16 +08:00
|
|
|
|
|
|
|
if (found != null)
|
|
|
|
{
|
|
|
|
Source.Progression.Value = found.Pairing;
|
2018-09-16 04:35:51 +08:00
|
|
|
Expire();
|
2018-09-19 01:00:16 +08:00
|
|
|
return true;
|
|
|
|
}
|
2018-09-16 04:35:51 +08:00
|
|
|
|
2018-09-19 01:00:16 +08:00
|
|
|
return false;
|
2018-09-16 04:35:51 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-10 03:51:38 +08:00
|
|
|
}
|
|
|
|
}
|