1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 15:27:26 +08:00
osu-lazer/osu.Game.Tournament/Screens/Ladder/LadderManager.cs

139 lines
4.5 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2018-09-16 04:35:51 +08:00
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-09-16 04:35:51 +08:00
using osu.Framework.Graphics.Lines;
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;
using SixLabors.Primitives;
2018-09-21 17:51:37 +08:00
namespace osu.Game.Tournament.Screens.Ladder
{
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;
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-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-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);
foreach (var pairing in info.Pairings)
addPairing(pairing);
}
2018-09-16 04:35:51 +08:00
public LadderInfo CreateInfo()
{
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-16 04:35:51 +08:00
private void addPairing(MatchPairing pairing) => pairingsContainer.Add(new DrawableMatchPairing(pairing));
protected override bool OnClick(InputState state)
{
2018-09-16 04:35:51 +08:00
addPairing(new MatchPairing
{
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
}
}
}
}