1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:07:23 +08:00

Add deletion support

This commit is contained in:
Dean Herbert 2018-09-21 19:58:47 +09:00
parent 0076ef3447
commit f2f4e964c5
5 changed files with 52 additions and 16 deletions

View File

@ -6,6 +6,8 @@ using System.IO;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Tests.Visual;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Ladder;
@ -26,7 +28,11 @@ namespace osu.Game.Tournament.Tests
var teams = JsonConvert.DeserializeObject<List<TournamentTeam>>(File.ReadAllText(@"teams.json"));
var ladder = File.Exists(@"bracket.json") ? JsonConvert.DeserializeObject<LadderInfo>(File.ReadAllText(@"bracket.json")) : new LadderInfo();
Child = manager = new LadderManager(ladder, teams);
Child = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Child = manager = new LadderManager(ladder, teams)
};
}
protected override void Dispose(bool isDisposing)

View File

@ -119,5 +119,14 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
Pairing.Position = new Point((int)pos.X, (int)pos.Y);
return true;
}
public void Remove()
{
if (Pairing.ProgressionSource.Value != null)
Pairing.ProgressionSource.Value.Progression.Value = null;
Pairing.Progression.Value = null;
Expire();
}
}
}

View File

@ -15,6 +15,7 @@ using osu.Framework.Input.EventArgs;
using osu.Framework.Input.States;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Tournament.Components;
using OpenTK;
using OpenTK.Graphics;
@ -157,10 +158,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
scoreText.Font = AcronymText.Font = winner ? "Exo2.0-Bold" : "Exo2.0-Regular";
}
public MenuItem[] ContextMenuItems => new[]
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new MenuItem("Populate team", () => team.Value = manager.Teams.Random()),
new MenuItem("Join with", () => manager.JoinRequest(pairing)),
new OsuMenuItem("Populate team", MenuItemType.Standard, () => team.Value = manager.Teams.Random()),
new OsuMenuItem("Join with", MenuItemType.Standard, () => manager.RequestJoin(pairing)),
new OsuMenuItem("Remove", MenuItemType.Destructive, () => manager.Remove(pairing)),
};
}

View File

@ -28,11 +28,26 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
[JsonIgnore]
public readonly Bindable<MatchPairing> Progression = new Bindable<MatchPairing>();
[JsonIgnore]
public readonly Bindable<MatchPairing> ProgressionSource = new Bindable<MatchPairing>();
[JsonProperty]
public Point Position;
private MatchPairing lastProgression; // todo: fix if we ever get LastValue inside Bindable<>.
public MatchPairing()
{
Progression.ValueChanged += progression =>
{
if (lastProgression != null)
lastProgression.ProgressionSource.Value = null;
if (progression != null)
progression.ProgressionSource.Value = this;
lastProgression = progression;
};
}
public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null)

View File

@ -2,16 +2,18 @@ using System.Collections.Generic;
using System.Linq;
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.States;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Ladder.Components;
using SixLabors.Primitives;
namespace osu.Game.Tournament.Screens.Ladder
{
public class LadderManager : CompositeDrawable
public class LadderManager : CompositeDrawable, IHasContextMenu
{
public readonly List<TournamentTeam> Teams;
private readonly Container<DrawableMatchPairing> pairingsContainer;
@ -23,7 +25,7 @@ namespace osu.Game.Tournament.Screens.Ladder
RelativeSizeAxes = Axes.Both;
InternalChild = new OsuContextMenuContainer
InternalChild = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
@ -56,15 +58,14 @@ namespace osu.Game.Tournament.Screens.Ladder
private void addPairing(MatchPairing pairing) => pairingsContainer.Add(new DrawableMatchPairing(pairing));
protected override bool OnClick(InputState state)
public MenuItem[] ContextMenuItems => new MenuItem[]
{
addPairing(new MatchPairing
new OsuMenuItem("Create new match", MenuItemType.Highlighted, () =>
{
Position = new Point((int)state.Mouse.Position.X, (int)state.Mouse.Position.Y)
});
return true;
}
var pos = ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position);
addPairing(new MatchPairing { Position = new Point((int)pos.X, (int)pos.Y) });
}),
};
protected override void Update()
{
@ -82,7 +83,7 @@ namespace osu.Game.Tournament.Screens.Ladder
}
}
public void JoinRequest(MatchPairing pairing) => AddInternal(new JoinRequestHandler(pairingsContainer, pairing));
public void RequestJoin(MatchPairing pairing) => AddInternal(new JoinRequestHandler(pairingsContainer, pairing));
private class JoinRequestHandler : CompositeDrawable
{
@ -126,7 +127,8 @@ namespace osu.Game.Tournament.Screens.Ladder
if (found != null)
{
Source.Progression.Value = found.Pairing;
if (found.Pairing != Source)
Source.Progression.Value = found.Pairing;
Expire();
return true;
}
@ -134,5 +136,7 @@ namespace osu.Game.Tournament.Screens.Ladder
return false;
}
}
public void Remove(MatchPairing pairing) => pairingsContainer.FirstOrDefault(p => p.Pairing == pairing)?.Remove();
}
}