mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 05:22:54 +08:00
Move editing functionality to its own screen
This commit is contained in:
parent
5801ed7b1a
commit
67bb428aef
@ -16,7 +16,7 @@ namespace osu.Game.Tournament.Tests
|
||||
Add(new OsuContextMenuContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new LadderManager()
|
||||
Child = new LadderScreen()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ 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);
|
||||
@ -69,6 +67,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
Spacing = new Vector2(2)
|
||||
}
|
||||
};
|
||||
|
||||
pairing.Team1.BindValueChanged(_ => updateTeams());
|
||||
pairing.Team2.BindValueChanged(_ => updateTeams());
|
||||
pairing.Team1Score.BindValueChanged(_ => updateWinConditions());
|
||||
@ -79,6 +78,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
pairing.LosersProgression.BindValueChanged(_ => updateProgression());
|
||||
pairing.Losers.BindValueChanged(_ => updateTeams());
|
||||
pairing.Current.BindValueChanged(_ => updateCurrentMatch(), true);
|
||||
pairing.Position.BindValueChanged(pos =>
|
||||
{
|
||||
if (IsDragged) return;
|
||||
Position = new Vector2(pos.X, pos.Y);
|
||||
}, true);
|
||||
|
||||
updateTeams();
|
||||
}
|
||||
@ -205,13 +209,13 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
updateWinConditions();
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e) => e.Button == MouseButton.Left && editorInfo.EditingEnabled;
|
||||
protected override bool OnMouseDown(MouseDownEvent e) => e.Button == MouseButton.Left && editorInfo != null;
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e) => editorInfo.EditingEnabled;
|
||||
protected override bool OnDragStart(DragStartEvent e) => editorInfo != null;
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
if (Selected && editorInfo.EditingEnabled && e.Key == Key.Delete)
|
||||
if (Selected && editorInfo != null && e.Key == Key.Delete)
|
||||
{
|
||||
Remove();
|
||||
return true;
|
||||
@ -222,7 +226,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (!editorInfo.EditingEnabled)
|
||||
if (editorInfo == null)
|
||||
return false;
|
||||
|
||||
Selected = true;
|
||||
@ -237,7 +241,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
this.MoveToOffset(e.Delta);
|
||||
|
||||
var pos = Position;
|
||||
Pairing.Position = new Point((int)pos.X, (int)pos.Y);
|
||||
Pairing.Position.Value = new Point((int)pos.X, (int)pos.Y);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
private Color4 colourNormal;
|
||||
|
||||
private readonly Func<bool> isWinner;
|
||||
private LadderManager manager;
|
||||
private LadderEditorScreen ladderEditor;
|
||||
|
||||
[Resolved]
|
||||
private LadderInfo ladderInfo { get; set; }
|
||||
@ -80,9 +80,9 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(OsuColour colours, LadderManager manager)
|
||||
private void load(OsuColour colours, LadderEditorScreen ladderEditor)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.ladderEditor = ladderEditor;
|
||||
|
||||
colourWinner = losers ? colours.YellowDarker : colours.BlueDarker;
|
||||
colourNormal = OsuColour.Gray(0.2f);
|
||||
@ -141,7 +141,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
//TODO: use OnClick instead once we have per-button clicks.
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (Team == null || editorInfo.EditingEnabled) return false;
|
||||
if (Team == null || editorInfo != null) return false;
|
||||
|
||||
if (!pairing.Current.Value)
|
||||
{
|
||||
@ -190,15 +190,15 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!editorInfo.EditingEnabled)
|
||||
if (editorInfo == null)
|
||||
return new MenuItem[0];
|
||||
|
||||
return new MenuItem[]
|
||||
{
|
||||
new OsuMenuItem("Set as current", MenuItemType.Standard, setCurrent),
|
||||
new OsuMenuItem("Join with", MenuItemType.Standard, () => manager.RequestJoin(pairing, false)),
|
||||
new OsuMenuItem("Join with (loser)", MenuItemType.Standard, () => manager.RequestJoin(pairing, true)),
|
||||
new OsuMenuItem("Remove", MenuItemType.Destructive, () => manager.Remove(pairing)),
|
||||
new OsuMenuItem("Join with", MenuItemType.Standard, () => ladderEditor.RequestJoin(pairing, false)),
|
||||
new OsuMenuItem("Join with (loser)", MenuItemType.Standard, () => ladderEditor.RequestJoin(pairing, true)),
|
||||
new OsuMenuItem("Remove", MenuItemType.Destructive, () => ladderEditor.Remove(pairing)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
{
|
||||
public class LadderEditorInfo
|
||||
{
|
||||
public readonly BindableBool EditingEnabled = new BindableBool();
|
||||
public readonly Bindable<MatchPairing> Selected = new Bindable<MatchPairing>();
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,6 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new PlayerCheckbox
|
||||
{
|
||||
Bindable = editorInfo.EditingEnabled,
|
||||
LabelText = "Enable editing"
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
@ -119,16 +114,6 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
if (editorInfo.Selected.Value != null)
|
||||
editorInfo.Selected.Value.Losers.Value = losers;
|
||||
};
|
||||
|
||||
// sliderBestOf.Bindable.ValueChanged += val =>
|
||||
// {
|
||||
// if (editorInfo.Selected.Value != null) editorInfo.Selected.Value.BestOf.Value = (int)val;
|
||||
// };
|
||||
|
||||
editorInfo.EditingEnabled.ValueChanged += enabled =>
|
||||
{
|
||||
if (!enabled) editorInfo.Selected.Value = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
|
||||
public readonly Bindable<DateTimeOffset> Date = new Bindable<DateTimeOffset>();
|
||||
|
||||
public Point Position;
|
||||
public readonly Bindable<Point> Position = new Bindable<Point>();
|
||||
|
||||
public MatchPairing()
|
||||
{
|
||||
|
166
osu.Game.Tournament/Screens/Ladder/LadderEditorScreen.cs
Normal file
166
osu.Game.Tournament/Screens/Ladder/LadderEditorScreen.cs
Normal file
@ -0,0 +1,166 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SixLabors.Primitives;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Ladder
|
||||
{
|
||||
[Cached]
|
||||
public class LadderEditorScreen : LadderScreen, IHasContextMenu
|
||||
{
|
||||
[Cached]
|
||||
private LadderEditorInfo editorInfo = new LadderEditorInfo();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
((Container)InternalChild).Add(new LadderEditorSettings
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Margin = new MarginPadding(5)
|
||||
});
|
||||
}
|
||||
|
||||
private void updateInfo()
|
||||
{
|
||||
LadderInfo.Pairings = PairingsContainer.Select(p => p.Pairing).ToList();
|
||||
foreach (var g in LadderInfo.Groupings)
|
||||
g.Pairings = LadderInfo.Pairings.Where(p => p.Grouping.Value == g).Select(p => p.ID).ToList();
|
||||
|
||||
LadderInfo.Progressions = LadderInfo.Pairings.Where(p => p.Progression.Value != null).Select(p => new TournamentProgression(p.ID, p.Progression.Value.ID)).Concat(
|
||||
LadderInfo.Pairings.Where(p => p.LosersProgression.Value != null).Select(p => new TournamentProgression(p.ID, p.LosersProgression.Value.ID, true)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
protected override void AddPairing(MatchPairing pairing)
|
||||
{
|
||||
base.AddPairing(pairing);
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
protected override void UpdateLayout()
|
||||
{
|
||||
base.UpdateLayout();
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
public void RequestJoin(MatchPairing pairing, bool losers)
|
||||
{
|
||||
ScrollContent.Add(new JoinRequestHandler(PairingsContainer, pairing, losers, updateInfo));
|
||||
}
|
||||
|
||||
public MenuItem[] ContextMenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
if (editorInfo == null)
|
||||
return new MenuItem[0];
|
||||
|
||||
return new MenuItem[]
|
||||
{
|
||||
new OsuMenuItem("Create new match", MenuItemType.Highlighted, () =>
|
||||
{
|
||||
var pos = PairingsContainer.ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position);
|
||||
AddPairing(new MatchPairing { Position = { Value = new Point((int)pos.X, (int)pos.Y) } });
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(MatchPairing pairing)
|
||||
{
|
||||
PairingsContainer.FirstOrDefault(p => p.Pairing == pairing)?.Remove();
|
||||
}
|
||||
|
||||
private class JoinRequestHandler : CompositeDrawable
|
||||
{
|
||||
private readonly Container<DrawableMatchPairing> pairingsContainer;
|
||||
public readonly MatchPairing Source;
|
||||
private readonly bool losers;
|
||||
private readonly Action complete;
|
||||
|
||||
private ProgressionPath path;
|
||||
|
||||
public JoinRequestHandler(Container<DrawableMatchPairing> pairingsContainer, MatchPairing source, bool losers, Action complete)
|
||||
{
|
||||
this.pairingsContainer = pairingsContainer;
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
Source = source;
|
||||
this.losers = losers;
|
||||
this.complete = complete;
|
||||
if (losers)
|
||||
Source.LosersProgression.Value = null;
|
||||
else
|
||||
Source.Progression.Value = null;
|
||||
}
|
||||
|
||||
private DrawableMatchPairing findTarget(InputState state)
|
||||
{
|
||||
return pairingsContainer.FirstOrDefault(d => d.ReceivePositionalInputAt(state.Mouse.Position));
|
||||
}
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
var found = findTarget(e.CurrentState);
|
||||
|
||||
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)
|
||||
{
|
||||
Colour = Color4.Yellow,
|
||||
});
|
||||
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
var found = findTarget(e.CurrentState);
|
||||
|
||||
if (found != null)
|
||||
{
|
||||
if (found.Pairing != Source)
|
||||
{
|
||||
if (losers)
|
||||
Source.LosersProgression.Value = found.Pairing;
|
||||
else
|
||||
Source.Progression.Value = found.Pairing;
|
||||
}
|
||||
|
||||
complete?.Invoke();
|
||||
Expire();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,259 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
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.Cursor;
|
||||
using osu.Framework.Graphics.Lines;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SixLabors.Primitives;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Ladder
|
||||
{
|
||||
[Cached]
|
||||
public class LadderManager : TournamentScreen, IHasContextMenu
|
||||
{
|
||||
private Container<DrawableMatchPairing> pairingsContainer;
|
||||
private Container<Path> paths;
|
||||
private Container headings;
|
||||
|
||||
private ScrollableContainer scrollContent;
|
||||
|
||||
[Resolved]
|
||||
private LadderEditorInfo editorInfo { get; set;}
|
||||
|
||||
[Resolved]
|
||||
private LadderInfo ladderInfo { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
normalPathColour = colours.BlueDarker.Darken(2);
|
||||
losersPathColour = colours.YellowDarker.Darken(2);
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
InternalChild = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
scrollContent = new ScrollableContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
paths = new Container<Path> { RelativeSizeAxes = Axes.Both },
|
||||
headings = new Container { RelativeSizeAxes = Axes.Both },
|
||||
pairingsContainer = new Container<DrawableMatchPairing> { RelativeSizeAxes = Axes.Both },
|
||||
}
|
||||
},
|
||||
new LadderEditorSettings
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Margin = new MarginPadding(5)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var pairing in ladderInfo.Pairings)
|
||||
addPairing(pairing);
|
||||
|
||||
// todo: fix this
|
||||
Scheduler.AddDelayed(() => layout.Invalidate(), 100, true);
|
||||
}
|
||||
|
||||
private void updateInfo()
|
||||
{
|
||||
ladderInfo.Pairings = pairingsContainer.Select(p => p.Pairing).ToList();
|
||||
foreach (var g in ladderInfo.Groupings)
|
||||
g.Pairings = ladderInfo.Pairings.Where(p => p.Grouping.Value == g).Select(p => p.ID).ToList();
|
||||
|
||||
ladderInfo.Progressions = ladderInfo.Pairings.Where(p => p.Progression.Value != null).Select(p => new TournamentProgression(p.ID, p.Progression.Value.ID)).Concat(
|
||||
ladderInfo.Pairings.Where(p => p.LosersProgression.Value != null).Select(p => new TournamentProgression(p.ID, p.LosersProgression.Value.ID, true)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void addPairing(MatchPairing pairing)
|
||||
{
|
||||
pairingsContainer.Add(new DrawableMatchPairing(pairing));
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
public MenuItem[] ContextMenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!editorInfo.EditingEnabled)
|
||||
return new MenuItem[0];
|
||||
|
||||
return new MenuItem[]
|
||||
{
|
||||
new OsuMenuItem("Create new match", MenuItemType.Highlighted, () =>
|
||||
{
|
||||
var pos = pairingsContainer.ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position);
|
||||
addPairing(new MatchPairing { Position = new Point((int)pos.X, (int)pos.Y) });
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private Cached layout = new Cached();
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (!layout.IsValid)
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
private Color4 normalPathColour;
|
||||
private Color4 losersPathColour;
|
||||
|
||||
private void updateLayout()
|
||||
{
|
||||
paths.Clear();
|
||||
headings.Clear();
|
||||
|
||||
int id = 1;
|
||||
foreach (var pairing in pairingsContainer.OrderBy(d => d.Y).ThenBy(d => d.X))
|
||||
{
|
||||
pairing.Pairing.ID = id++;
|
||||
|
||||
if (pairing.Pairing.Progression.Value != null)
|
||||
{
|
||||
var dest = pairingsContainer.FirstOrDefault(p => p.Pairing == pairing.Pairing.Progression.Value);
|
||||
|
||||
if (dest == null)
|
||||
// clean up outdated progressions.
|
||||
pairing.Pairing.Progression.Value = null;
|
||||
else
|
||||
paths.Add(new ProgressionPath(pairing, dest) { Colour = pairing.Pairing.Losers ? losersPathColour : normalPathColour });
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var group in ladderInfo.Groupings)
|
||||
{
|
||||
var topPairing = pairingsContainer.Where(p => !p.Pairing.Losers && p.Pairing.Grouping.Value == group).OrderBy(p => p.Y).FirstOrDefault();
|
||||
|
||||
if (topPairing == null) continue;
|
||||
|
||||
headings.Add(new DrawableTournamentGrouping(group)
|
||||
{
|
||||
Position = headings.ToLocalSpace((topPairing.ScreenSpaceDrawQuad.TopLeft + topPairing.ScreenSpaceDrawQuad.TopRight) / 2),
|
||||
Margin = new MarginPadding { Bottom = 10 },
|
||||
Origin = Anchor.BottomCentre,
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var group in ladderInfo.Groupings)
|
||||
{
|
||||
var topPairing = pairingsContainer.Where(p => p.Pairing.Losers && p.Pairing.Grouping.Value == group).OrderBy(p => p.Y).FirstOrDefault();
|
||||
|
||||
if (topPairing == null) continue;
|
||||
|
||||
headings.Add(new DrawableTournamentGrouping(group, true)
|
||||
{
|
||||
Position = headings.ToLocalSpace((topPairing.ScreenSpaceDrawQuad.TopLeft + topPairing.ScreenSpaceDrawQuad.TopRight) / 2),
|
||||
Margin = new MarginPadding { Bottom = 10 },
|
||||
Origin = Anchor.BottomCentre,
|
||||
});
|
||||
}
|
||||
|
||||
layout.Validate();
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
public void RequestJoin(MatchPairing pairing, bool losers) => scrollContent.Add(new JoinRequestHandler(pairingsContainer, pairing, losers, updateInfo));
|
||||
|
||||
// todo: remove after ppy/osu-framework#1980 is merged.
|
||||
public override bool HandlePositionalInput => true;
|
||||
|
||||
public void Remove(MatchPairing pairing) => pairingsContainer.FirstOrDefault(p => p.Pairing == pairing)?.Remove();
|
||||
|
||||
private class JoinRequestHandler : CompositeDrawable
|
||||
{
|
||||
private readonly Container<DrawableMatchPairing> pairingsContainer;
|
||||
public readonly MatchPairing Source;
|
||||
private readonly bool losers;
|
||||
private readonly Action complete;
|
||||
|
||||
private ProgressionPath path;
|
||||
|
||||
public JoinRequestHandler(Container<DrawableMatchPairing> pairingsContainer, MatchPairing source, bool losers, Action complete)
|
||||
{
|
||||
this.pairingsContainer = pairingsContainer;
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
Source = source;
|
||||
this.losers = losers;
|
||||
this.complete = complete;
|
||||
if (losers)
|
||||
Source.LosersProgression.Value = null;
|
||||
else
|
||||
Source.Progression.Value = null;
|
||||
}
|
||||
|
||||
private DrawableMatchPairing findTarget(InputState state) => pairingsContainer.FirstOrDefault(d => d.ReceivePositionalInputAt(state.Mouse.Position));
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
var found = findTarget(e.CurrentState);
|
||||
|
||||
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)
|
||||
{
|
||||
Colour = Color4.Yellow,
|
||||
});
|
||||
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
var found = findTarget(e.CurrentState);
|
||||
|
||||
if (found != null)
|
||||
{
|
||||
if (found.Pairing != Source)
|
||||
{
|
||||
if (losers)
|
||||
Source.LosersProgression.Value = found.Pairing;
|
||||
else
|
||||
Source.Progression.Value = found.Pairing;
|
||||
}
|
||||
|
||||
complete?.Invoke();
|
||||
Expire();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
135
osu.Game.Tournament/Screens/Ladder/LadderScreen.cs
Normal file
135
osu.Game.Tournament/Screens/Ladder/LadderScreen.cs
Normal file
@ -0,0 +1,135 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
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.Graphics;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tournament.Screens.Ladder
|
||||
{
|
||||
public class LadderScreen : TournamentScreen
|
||||
{
|
||||
protected Container<DrawableMatchPairing> PairingsContainer;
|
||||
private Container<Path> paths;
|
||||
private Container headings;
|
||||
|
||||
protected ScrollableContainer ScrollContent;
|
||||
|
||||
[Resolved]
|
||||
protected LadderInfo LadderInfo { get; private set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
normalPathColour = colours.BlueDarker.Darken(2);
|
||||
losersPathColour = colours.YellowDarker.Darken(2);
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
InternalChild = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
ScrollContent = new ScrollableContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
paths = new Container<Path> { RelativeSizeAxes = Axes.Both },
|
||||
headings = new Container { RelativeSizeAxes = Axes.Both },
|
||||
PairingsContainer = new Container<DrawableMatchPairing> { RelativeSizeAxes = Axes.Both },
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var pairing in LadderInfo.Pairings)
|
||||
AddPairing(pairing);
|
||||
|
||||
// todo: fix this
|
||||
Scheduler.AddDelayed(() => layout.Invalidate(), 100, true);
|
||||
}
|
||||
|
||||
protected virtual void AddPairing(MatchPairing pairing)
|
||||
{
|
||||
PairingsContainer.Add(new DrawableMatchPairing(pairing));
|
||||
}
|
||||
|
||||
private Cached layout = new Cached();
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (!layout.IsValid)
|
||||
UpdateLayout();
|
||||
}
|
||||
|
||||
private Color4 normalPathColour;
|
||||
private Color4 losersPathColour;
|
||||
|
||||
protected virtual void UpdateLayout()
|
||||
{
|
||||
paths.Clear();
|
||||
headings.Clear();
|
||||
|
||||
int id = 1;
|
||||
foreach (var pairing in PairingsContainer.OrderBy(d => d.Y).ThenBy(d => d.X))
|
||||
{
|
||||
pairing.Pairing.ID = id++;
|
||||
|
||||
if (pairing.Pairing.Progression.Value != null)
|
||||
{
|
||||
var dest = PairingsContainer.FirstOrDefault(p => p.Pairing == pairing.Pairing.Progression.Value);
|
||||
|
||||
if (dest == null)
|
||||
// clean up outdated progressions.
|
||||
pairing.Pairing.Progression.Value = null;
|
||||
else
|
||||
paths.Add(new ProgressionPath(pairing, dest) { Colour = pairing.Pairing.Losers ? losersPathColour : normalPathColour });
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var group in LadderInfo.Groupings)
|
||||
{
|
||||
var topPairing = PairingsContainer.Where(p => !p.Pairing.Losers && p.Pairing.Grouping.Value == group).OrderBy(p => p.Y).FirstOrDefault();
|
||||
|
||||
if (topPairing == null) continue;
|
||||
|
||||
headings.Add(new DrawableTournamentGrouping(group)
|
||||
{
|
||||
Position = headings.ToLocalSpace((topPairing.ScreenSpaceDrawQuad.TopLeft + topPairing.ScreenSpaceDrawQuad.TopRight) / 2),
|
||||
Margin = new MarginPadding { Bottom = 10 },
|
||||
Origin = Anchor.BottomCentre,
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var group in LadderInfo.Groupings)
|
||||
{
|
||||
var topPairing = PairingsContainer.Where(p => p.Pairing.Losers && p.Pairing.Grouping.Value == group).OrderBy(p => p.Y).FirstOrDefault();
|
||||
|
||||
if (topPairing == null) continue;
|
||||
|
||||
headings.Add(new DrawableTournamentGrouping(group, true)
|
||||
{
|
||||
Position = headings.ToLocalSpace((topPairing.ScreenSpaceDrawQuad.TopLeft + topPairing.ScreenSpaceDrawQuad.TopRight) / 2),
|
||||
Margin = new MarginPadding { Bottom = 10 },
|
||||
Origin = Anchor.BottomCentre,
|
||||
});
|
||||
}
|
||||
|
||||
layout.Validate();
|
||||
}
|
||||
|
||||
// todo: remove after ppy/osu-framework#1980 is merged.
|
||||
public override bool HandlePositionalInput => true;
|
||||
}
|
||||
}
|
@ -25,7 +25,8 @@ namespace osu.Game.Tournament.Screens
|
||||
public class TournamentSceneManager : OsuScreen
|
||||
{
|
||||
private ScheduleScreen schedule;
|
||||
private LadderManager bracket;
|
||||
private LadderScreen bracket;
|
||||
private LadderEditorScreen bracketEditor;
|
||||
private MapPoolScreen mapPool;
|
||||
private GameplayScreen gameplay;
|
||||
private TeamWinScreen winner;
|
||||
@ -57,6 +58,8 @@ namespace osu.Game.Tournament.Screens
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuButton { RelativeSizeAxes = Axes.X, Text = "Bracket Editor", Action = () => setScreen(bracketEditor) },
|
||||
new Container { RelativeSizeAxes = Axes.X, Height = 50 },
|
||||
new OsuButton { RelativeSizeAxes = Axes.X, Text = "Drawings", Action = () => setScreen(drawings) },
|
||||
new OsuButton { RelativeSizeAxes = Axes.X, Text = "Showcase", Action = () => setScreen(showcase) },
|
||||
new Container { RelativeSizeAxes = Axes.X, Height = 50 },
|
||||
@ -96,7 +99,8 @@ namespace osu.Game.Tournament.Screens
|
||||
Children = new Drawable[]
|
||||
{
|
||||
schedule = new ScheduleScreen(),
|
||||
bracket = new LadderManager(),
|
||||
bracket = new LadderScreen(),
|
||||
bracketEditor = new LadderEditorScreen(),
|
||||
showcase = new ShowcaseScreen(),
|
||||
mapPool = new MapPoolScreen(),
|
||||
teamIntro = new TeamIntroScreen(),
|
||||
|
@ -19,7 +19,6 @@ using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
|
||||
namespace osu.Game.Tournament
|
||||
{
|
||||
@ -35,9 +34,6 @@ namespace osu.Game.Tournament
|
||||
[Cached]
|
||||
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||
|
||||
[Cached]
|
||||
private LadderEditorInfo editorInfo = new LadderEditorInfo();
|
||||
|
||||
private Bindable<Size> windowSize;
|
||||
private FileBasedIPC ipc;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user