1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 10:22:54 +08:00

Complete editing support

This commit is contained in:
Dean Herbert 2018-09-22 05:52:25 +09:00
parent 36e1517197
commit 2f2dcec8c7
11 changed files with 306 additions and 58 deletions

View File

@ -21,7 +21,7 @@ namespace osu.Game.Tournament.Tests
private readonly LadderManager manager; private readonly LadderManager manager;
[Cached] [Cached]
private Bindable<TournamentConditions> conditions = new Bindable<TournamentConditions>(new TournamentConditions { BestOf = 9 }); private Bindable<TournamentConditions> conditions = new Bindable<TournamentConditions>(new TournamentConditions());
public TestCaseLadderManager() public TestCaseLadderManager()
{ {

View File

@ -24,7 +24,7 @@ namespace osu.Game.Tournament.Tests
}; };
[Cached] [Cached]
private Bindable<TournamentConditions> conditions = new Bindable<TournamentConditions>(new TournamentConditions { BestOf = 9 }); private Bindable<TournamentConditions> conditions = new Bindable<TournamentConditions>(new TournamentConditions());
public TestCaseMatchPairings() public TestCaseMatchPairings()
{ {

View File

@ -29,7 +29,7 @@ namespace osu.Game.Tournament.Components
AcronymText = new OsuSpriteText AcronymText = new OsuSpriteText
{ {
Text = team?.Acronym.ToUpperInvariant() ?? string.Empty, Text = team?.Acronym?.ToUpperInvariant() ?? string.Empty,
Font = @"Exo2.0-Regular" Font = @"Exo2.0-Regular"
}; };
} }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Tournament.Components
/// </summary> /// </summary>
public string FlagName public string FlagName
{ {
get { return flagName ?? Acronym.Substring(0, 2); } get { return flagName ?? Acronym?.Substring(0, 2); }
set { flagName = value; } set { flagName = value; }
} }
@ -31,10 +31,12 @@ namespace osu.Game.Tournament.Components
/// </summary> /// </summary>
public string Acronym public string Acronym
{ {
get { return acronym ?? FullName.Substring(0, 3); } get { return acronym ?? FullName?.Substring(0, 3); }
set { acronym = value; } set { acronym = value; }
} }
public List<User> Players { get; set; } public List<User> Players { get; set; }
public override string ToString() => FullName ?? Acronym;
} }
} }

View File

@ -5,9 +5,11 @@ using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.EventArgs; using osu.Framework.Input.EventArgs;
using osu.Framework.Input.States; using osu.Framework.Input.States;
using OpenTK; using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
using SixLabors.Primitives; using SixLabors.Primitives;
@ -18,6 +20,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
public readonly MatchPairing Pairing; public readonly MatchPairing Pairing;
private readonly FillFlowContainer<DrawableMatchTeam> flow; private readonly FillFlowContainer<DrawableMatchTeam> flow;
private readonly Bindable<TournamentConditions> conditions = new Bindable<TournamentConditions>(); private readonly Bindable<TournamentConditions> conditions = new Bindable<TournamentConditions>();
private readonly Drawable selectionBox;
private Bindable<MatchPairing> globalSelection;
[Resolved(CanBeNull = true)]
private LadderEditorInfo editorInfo { get; set; } = null;
public DrawableMatchPairing(MatchPairing pairing) public DrawableMatchPairing(MatchPairing pairing)
{ {
@ -29,8 +36,20 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
Margin = new MarginPadding(5); Margin = new MarginPadding(5);
InternalChildren = new Drawable[] InternalChildren = new[]
{ {
selectionBox = new Container
{
CornerRadius = 5,
Masking = true,
Scale = new Vector2(1.05f),
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
Colour = Color4.YellowGreen,
Child = new Box { RelativeSizeAxes = Axes.Both }
},
flow = new FillFlowContainer<DrawableMatchTeam> flow = new FillFlowContainer<DrawableMatchTeam>
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -38,13 +57,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
Spacing = new Vector2(2) Spacing = new Vector2(2)
} }
}; };
pairing.Team1.BindValueChanged(_ => updateTeams()); pairing.Team1.BindValueChanged(_ => updateTeams());
pairing.Team2.BindValueChanged(_ => updateTeams()); pairing.Team2.BindValueChanged(_ => updateTeams());
pairing.Team1Score.BindValueChanged(_ => updateWinConditions()); pairing.Team1Score.BindValueChanged(_ => updateWinConditions());
pairing.Team2Score.BindValueChanged(_ => updateWinConditions()); pairing.Team2Score.BindValueChanged(_ => updateWinConditions());
pairing.BestOf.BindValueChanged(_ => updateWinConditions());
pairing.Completed.BindValueChanged(_ => updateProgression()); pairing.Completed.BindValueChanged(_ => updateProgression());
pairing.Progression.BindValueChanged(_ => updateProgression()); pairing.Progression.BindValueChanged(_ => updateProgression());
@ -60,6 +77,27 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
this.conditions.BindTo(conditions); this.conditions.BindTo(conditions);
} }
private bool selected;
public bool Selected
{
get => selected;
set
{
if (value == selected) return;
selected = value;
if (selected)
{
selectionBox.Show();
editorInfo.Selected.Value = Pairing;
}
else
selectionBox.Hide();
}
}
private void updateProgression() private void updateProgression()
{ {
var progression = Pairing.Progression?.Value; var progression = Pairing.Progression?.Value;
@ -76,13 +114,22 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
{ {
if (conditions.Value == null) return; if (conditions.Value == null) return;
Pairing.Completed.Value = Pairing.Team1Score.Value + Pairing.Team2Score.Value >= conditions.Value.BestOf; Pairing.Completed.Value = Pairing.Team1Score.Value + Pairing.Team2Score.Value >= Pairing.BestOf.Value;
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
updateTeams(); updateTeams();
if (editorInfo != null)
{
globalSelection = editorInfo.Selected.GetBoundCopy();
globalSelection.BindValueChanged(s =>
{
if (s != Pairing) Selected = false;
});
}
} }
private void updateTeams() private void updateTeams()
@ -109,10 +156,34 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
protected override bool OnDragStart(InputState state) => true; protected override bool OnDragStart(InputState state) => true;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (Selected && editorInfo.EditingEnabled && args.Key == Key.Delete)
{
Remove();
return true;
}
return base.OnKeyDown(state, args);
}
protected override bool OnClick(InputState state)
{
if (!editorInfo.EditingEnabled)
return false;
Selected = true;
return true;
}
protected override bool OnDrag(InputState state) protected override bool OnDrag(InputState state)
{ {
if (base.OnDrag(state)) return true; if (base.OnDrag(state)) return true;
if (!editorInfo.EditingEnabled)
return false;
Selected = true;
this.MoveToOffset(state.Mouse.Delta); this.MoveToOffset(state.Mouse.Delta);
var pos = Position; var pos = Position;
@ -122,10 +193,9 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
public void Remove() public void Remove()
{ {
if (Pairing.ProgressionSource.Value != null) Selected = false;
Pairing.ProgressionSource.Value.Progression.Value = null;
Pairing.Progression.Value = null; Pairing.Progression.Value = null;
Expire(); Expire();
} }
} }

View File

@ -25,7 +25,6 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
{ {
public class DrawableMatchTeam : DrawableTournamentTeam, IHasContextMenu public class DrawableMatchTeam : DrawableTournamentTeam, IHasContextMenu
{ {
private readonly Bindable<TournamentTeam> team;
private readonly MatchPairing pairing; private readonly MatchPairing pairing;
private OsuSpriteText scoreText; private OsuSpriteText scoreText;
private Box background; private Box background;
@ -39,10 +38,12 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
private readonly Func<bool> isWinner; private readonly Func<bool> isWinner;
private LadderManager manager; private LadderManager manager;
[Resolved(CanBeNull = true)]
private LadderEditorInfo editorInfo { get; set; } = null;
public DrawableMatchTeam(Bindable<TournamentTeam> team, MatchPairing pairing) public DrawableMatchTeam(Bindable<TournamentTeam> team, MatchPairing pairing)
: base(team) : base(team)
{ {
this.team = team.GetBoundCopy();
this.pairing = pairing; this.pairing = pairing;
Size = new Vector2(150, 40); Size = new Vector2(150, 40);
@ -127,7 +128,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{ {
if (Team == null) return false; if (Team == null || editorInfo.EditingEnabled) return false;
if (args.Button == MouseButton.Left) if (args.Button == MouseButton.Left)
{ {
@ -158,12 +159,20 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
scoreText.Font = AcronymText.Font = winner ? "Exo2.0-Bold" : "Exo2.0-Regular"; scoreText.Font = AcronymText.Font = winner ? "Exo2.0-Bold" : "Exo2.0-Regular";
} }
public MenuItem[] ContextMenuItems => new MenuItem[] public MenuItem[] ContextMenuItems
{ {
new OsuMenuItem("Populate team", MenuItemType.Standard, () => team.Value = manager.Teams.Random()), get
new OsuMenuItem("Join with", MenuItemType.Standard, () => manager.RequestJoin(pairing)), {
new OsuMenuItem("Remove", MenuItemType.Destructive, () => manager.Remove(pairing)), if (!editorInfo.EditingEnabled)
}; return new MenuItem[0];
return new MenuItem[]
{
new OsuMenuItem("Join with", MenuItemType.Standard, () => manager.RequestJoin(pairing)),
new OsuMenuItem("Remove", MenuItemType.Destructive, () => manager.Remove(pairing)),
};
}
}
} }
internal static class Extensions internal static class Extensions

View File

@ -0,0 +1,147 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Settings;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Tournament.Components;
namespace osu.Game.Tournament.Screens.Ladder.Components
{
public class LadderEditorSettings : PlayerSettingsGroup
{
private const int padding = 10;
protected override string Title => @"ladder";
private PlayerSliderBar<double> sliderBestOf;
private SettingsDropdown<TournamentTeam> dropdownTeam1;
private SettingsDropdown<TournamentTeam> dropdownTeam2;
[Resolved]
private LadderEditorInfo editorInfo { get; set; } = null;
[BackgroundDependencyLoader]
private void load()
{
var teamEntries = editorInfo.Teams.Select(t => new KeyValuePair<string, TournamentTeam>(t.ToString(), t)).Prepend(new KeyValuePair<string, TournamentTeam>("Empty", new TournamentTeam()));
Children = new Drawable[]
{
new PlayerCheckbox
{
Bindable = editorInfo.EditingEnabled,
LabelText = "Enable editing"
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = padding },
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Team1",
},
},
},
dropdownTeam1 = new SettingsDropdown<TournamentTeam>
{
Items = teamEntries,
Bindable = new Bindable<TournamentTeam>
{
Value = teamEntries.First().Value,
Default = teamEntries.First().Value
}
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = padding },
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Team2",
},
},
},
dropdownTeam2 = new SettingsDropdown<TournamentTeam>
{
Items = teamEntries,
Bindable = new Bindable<TournamentTeam>
{
Value = teamEntries.First().Value,
Default = teamEntries.First().Value
}
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = padding },
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Best of",
},
},
},
sliderBestOf = new PlayerSliderBar<double>
{
Bindable = new BindableDouble
{
Default = 5,
Value = 5,
MinValue = 1,
MaxValue = 20,
Precision = 1,
},
}
};
editorInfo.Selected.ValueChanged += selection =>
{
dropdownTeam1.Bindable.Value = dropdownTeam1.Items.FirstOrDefault(i => i.Value.Acronym == selection?.Team1.Value?.Acronym).Value;
dropdownTeam2.Bindable.Value = dropdownTeam1.Items.FirstOrDefault(i => i.Value.Acronym == selection?.Team2.Value?.Acronym).Value;
sliderBestOf.Bindable.Value = selection?.BestOf ?? sliderBestOf.Bindable.Default;
};
dropdownTeam1.Bindable.ValueChanged += val =>
{
if (editorInfo.Selected.Value != null) editorInfo.Selected.Value.Team1.Value = val.Acronym == null ? null : val;
};
dropdownTeam2.Bindable.ValueChanged += val =>
{
if (editorInfo.Selected.Value != null) editorInfo.Selected.Value.Team2.Value = val.Acronym == null ? null : val;
};
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;
};
}
}
}

View File

@ -25,38 +25,16 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
public readonly Bindable<bool> Completed = new Bindable<bool>(); public readonly Bindable<bool> Completed = new Bindable<bool>();
[JsonIgnore] public readonly BindableInt BestOf = new BindableInt(5);
public readonly Bindable<MatchPairing> Progression = new Bindable<MatchPairing>();
[JsonIgnore] [JsonIgnore]
public readonly Bindable<MatchPairing> ProgressionSource = new Bindable<MatchPairing>(); public readonly Bindable<MatchPairing> Progression = new Bindable<MatchPairing>();
[JsonProperty] [JsonProperty]
public Point Position; public Point Position;
private MatchPairing lastProgression; // todo: fix if we ever get LastValue inside Bindable<>.
public MatchPairing() public MatchPairing()
{ {
Progression.ValueChanged += progression =>
{
if (lastProgression != null)
// clear the source from the previous progression.
lastProgression.ProgressionSource.Value = null;
if (progression != null)
// set the source on the new progression.
progression.ProgressionSource.Value = this;
lastProgression = progression;
};
ProgressionSource.ValueChanged += source =>
{
if (source != null)
// ennsure no two-way progressions.
Progression.Value = null;
};
} }
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null) public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null)

View File

@ -5,9 +5,5 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
/// </summary> /// </summary>
public class TournamentConditions public class TournamentConditions
{ {
/// <summary>
/// How many matches before a winner is decided.
/// </summary>
public int BestOf;
} }
} }

View File

@ -1,5 +1,8 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
@ -13,15 +16,25 @@ using SixLabors.Primitives;
namespace osu.Game.Tournament.Screens.Ladder namespace osu.Game.Tournament.Screens.Ladder
{ {
public class LadderEditorInfo
{
public readonly BindableBool EditingEnabled = new BindableBool();
public List<TournamentTeam> Teams = new List<TournamentTeam>();
public readonly Bindable<MatchPairing> Selected = new Bindable<MatchPairing>();
}
public class LadderManager : CompositeDrawable, IHasContextMenu public class LadderManager : CompositeDrawable, IHasContextMenu
{ {
public readonly List<TournamentTeam> Teams; public readonly List<TournamentTeam> Teams;
private readonly Container<DrawableMatchPairing> pairingsContainer; private readonly Container<DrawableMatchPairing> pairingsContainer;
private readonly Container<Path> paths; private readonly Container<Path> paths;
[Cached]
private readonly LadderEditorInfo editorInfo = new LadderEditorInfo();
public LadderManager(LadderInfo info, List<TournamentTeam> teams) public LadderManager(LadderInfo info, List<TournamentTeam> teams)
{ {
Teams = teams; editorInfo.Teams = Teams = teams;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -32,11 +45,25 @@ namespace osu.Game.Tournament.Screens.Ladder
{ {
paths = new Container<Path> { RelativeSizeAxes = Axes.Both }, paths = new Container<Path> { RelativeSizeAxes = Axes.Both },
pairingsContainer = new Container<DrawableMatchPairing> { RelativeSizeAxes = Axes.Both }, pairingsContainer = new Container<DrawableMatchPairing> { RelativeSizeAxes = Axes.Both },
new LadderEditorSettings
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Margin = new MarginPadding(5)
}
} }
}; };
foreach (var pair in info.Progressions) foreach (var pair in info.Progressions)
info.Pairings.Single(p => p.ID == pair.Item1).Progression.Value = info.Pairings.Single(p => p.ID == pair.Item2); {
var src = info.Pairings.FirstOrDefault(p => p.ID == pair.Item1);
var dest = info.Pairings.FirstOrDefault(p => p.ID == pair.Item2);
if (src == null) throw new InvalidOperationException();
if (dest != null)
src.Progression.Value = dest;
}
foreach (var pairing in info.Pairings) foreach (var pairing in info.Pairings)
addPairing(pairing); addPairing(pairing);
@ -58,14 +85,23 @@ namespace osu.Game.Tournament.Screens.Ladder
private void addPairing(MatchPairing pairing) => pairingsContainer.Add(new DrawableMatchPairing(pairing)); private void addPairing(MatchPairing pairing) => pairingsContainer.Add(new DrawableMatchPairing(pairing));
public MenuItem[] ContextMenuItems => new MenuItem[] public MenuItem[] ContextMenuItems
{ {
new OsuMenuItem("Create new match", MenuItemType.Highlighted, () => get
{ {
var pos = ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position); if (!editorInfo.EditingEnabled)
addPairing(new MatchPairing { Position = new Point((int)pos.X, (int)pos.Y) }); return new MenuItem[0];
}),
}; return new MenuItem[]
{
new OsuMenuItem("Create new match", MenuItemType.Highlighted, () =>
{
var pos = ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position);
addPairing(new MatchPairing { Position = new Point((int)pos.X, (int)pos.Y) });
}),
};
}
}
protected override void Update() protected override void Update()
{ {
@ -79,7 +115,15 @@ namespace osu.Game.Tournament.Screens.Ladder
pairing.Pairing.ID = id++; pairing.Pairing.ID = id++;
if (pairing.Pairing.Progression.Value != null) if (pairing.Pairing.Progression.Value != null)
paths.Add(new ProgressionPath(pairing, pairingsContainer.Single(p => p.Pairing == pairing.Pairing.Progression.Value))); {
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));
}
} }
} }

View File

@ -63,8 +63,10 @@ namespace osu.Game.Overlays.Settings
set set
{ {
controlWithCurrent?.Current.UnbindBindings();
bindable = value; bindable = value;
controlWithCurrent?.Current.BindTo(bindable); controlWithCurrent?.Current.BindTo(bindable);
if (ShowsDefaultIndicator) if (ShowsDefaultIndicator)
{ {
restoreDefaultButton.Bindable = bindable.GetBoundCopy(); restoreDefaultButton.Bindable = bindable.GetBoundCopy();