Add basic ladder manager and state retention

This commit is contained in:
Dean Herbert
2018-09-10 04:51:38 +09:00
parent e6baf418fb
commit 234b04dfc5
10 changed files with 199 additions and 24 deletions

View File

@ -7,8 +7,12 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Lines;
using osu.Framework.Input.EventArgs;
using osu.Framework.Input.States;
using osu.Framework.MathUtils;
using OpenTK;
using OpenTK.Input;
using SixLabors.Primitives;
namespace osu.Game.Tournament.Screens.Ladder.Components
{
@ -46,6 +50,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
{
Pairing = pairing;
Position = new Vector2(pairing.Position.X, pairing.Position.Y);
AutoSizeAxes = Axes.Both;
Margin = new MarginPadding(5);
@ -103,15 +109,19 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
var end = getCenteredVector(progression.ScreenSpaceDrawQuad.TopLeft, progression.ScreenSpaceDrawQuad.BottomLeft);
bool progressionAbove = progression.ScreenSpaceDrawQuad.TopLeft.Y < ScreenSpaceDrawQuad.TopLeft.Y;
bool progressionToRight = progression.ScreenSpaceDrawQuad.TopLeft.X > ScreenSpaceDrawQuad.TopLeft.X;
if (!Precision.AlmostEquals(progressionStart, start) || !Precision.AlmostEquals(progressionEnd, end))
{
progressionStart = start;
progressionEnd = end;
path.Origin = progressionAbove ? Anchor.BottomLeft : Anchor.TopLeft;
path.Origin = progressionAbove ? Anchor.y2 : Anchor.y0;
path.Y = progressionAbove ? line_width : -line_width;
path.Origin |= progressionToRight ? Anchor.x0 : Anchor.x2;
//path.X = progressionToRight ? line_width : -line_width;
Vector2 startPosition = path.ToLocalSpace(start) + new Vector2(padding, 0);
Vector2 endPosition = path.ToLocalSpace(end) + new Vector2(-padding, 0);
Vector2 intermediate1 = startPosition + new Vector2(padding, 0);
@ -131,6 +141,12 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
destinationForWinner.Value = Pairing.Winner;
}
protected override void UpdateAfterAutoSize()
{
base.UpdateAfterAutoSize();
updateProgression();
}
private void updateWinConditions()
{
if (conditions.Value == null) return;
@ -163,5 +179,20 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
SchedulerAfterChildren.Add(() => Scheduler.Add(updateProgression));
updateWinConditions();
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => args.Button == MouseButton.Left;
protected override bool OnDragStart(InputState state) => true;
protected override bool OnDrag(InputState state)
{
if (base.OnDrag(state)) return true;
this.MoveToOffset(state.Mouse.Delta);
var pos = Position;
Pairing.Position = new Point((int)pos.X, (int)pos.Y);
return true;
}
}
}