From 234b04dfc567629da9056ee6925882afd066126d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 10 Sep 2018 04:51:38 +0900 Subject: [PATCH] Add basic ladder manager and state retention --- .../TestCaseLadderManager.cs | 34 +++++++++++++ .../TestCaseMatchPairings.cs | 13 ++--- osu.Game.Tournament.Tests/teams.json | 1 + .../Components/TournamentTeam.cs | 13 ++++- .../Components/StorageBackedTeamList.cs | 1 - .../Ladder/Components/DrawableMatchPairing.cs | 33 +++++++++++- .../Ladder/Components/DrawableMatchTeam.cs | 47 ++++++++++++++--- .../Screens/Ladder/Components/LadderInfo.cs | 9 ++++ .../Ladder/Components/LadderManager.cs | 51 +++++++++++++++++++ .../Screens/Ladder/Components/MatchPairing.cs | 21 ++++++-- 10 files changed, 199 insertions(+), 24 deletions(-) create mode 100644 osu.Game.Tournament.Tests/TestCaseLadderManager.cs create mode 100644 osu.Game.Tournament.Tests/teams.json create mode 100644 osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs create mode 100644 osu.Game.Tournament/Screens/Ladder/Components/LadderManager.cs diff --git a/osu.Game.Tournament.Tests/TestCaseLadderManager.cs b/osu.Game.Tournament.Tests/TestCaseLadderManager.cs new file mode 100644 index 0000000000..dc4633aa17 --- /dev/null +++ b/osu.Game.Tournament.Tests/TestCaseLadderManager.cs @@ -0,0 +1,34 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; +using osu.Framework.Allocation; +using osu.Game.Tests.Visual; +using osu.Game.Tournament.Components; +using osu.Game.Tournament.Screens.Ladder.Components; + +namespace osu.Game.Tournament.Tests +{ + public class TestCaseLadderManager : OsuTestCase + { + [Cached] + private readonly LadderManager manager; + + public TestCaseLadderManager() + { + var teams = JsonConvert.DeserializeObject>(File.ReadAllText(@"teams.json")); + var ladder = JsonConvert.DeserializeObject(File.ReadAllText(@"bracket.json")) ?? new LadderInfo(); + + Child = manager = new LadderManager(ladder, teams); + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + File.WriteAllText(@"bracket.json", JsonConvert.SerializeObject(manager.Info)); + } + } +} diff --git a/osu.Game.Tournament.Tests/TestCaseMatchPairings.cs b/osu.Game.Tournament.Tests/TestCaseMatchPairings.cs index 553e48a822..bd6b085b0f 100644 --- a/osu.Game.Tournament.Tests/TestCaseMatchPairings.cs +++ b/osu.Game.Tournament.Tests/TestCaseMatchPairings.cs @@ -28,8 +28,8 @@ namespace osu.Game.Tournament.Tests public TestCaseMatchPairings() { - FillFlowContainer level1; - FillFlowContainer level2; + Container level1; + Container level2; var pairing1 = new MatchPairing( new TournamentTeam { FlagName = "AU", FullName = "Australia", }, @@ -47,16 +47,14 @@ namespace osu.Game.Tournament.Tests } ); - Child = new FillFlowContainer + Child = new Container { AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, Children = new Drawable[] { - level1 = new FillFlowContainer + level1 = new Container { AutoSizeAxes = Axes.Both, - Direction = FillDirection.Vertical, Children = new[] { new DrawableMatchPairing(pairing1), @@ -64,10 +62,9 @@ namespace osu.Game.Tournament.Tests new DrawableMatchPairing(new MatchPairing()), } }, - level2 = new FillFlowContainer + level2 = new Container { AutoSizeAxes = Axes.Both, - Direction = FillDirection.Vertical, Margin = new MarginPadding(20), Children = new[] { diff --git a/osu.Game.Tournament.Tests/teams.json b/osu.Game.Tournament.Tests/teams.json new file mode 100644 index 0000000000..7df0040469 --- /dev/null +++ b/osu.Game.Tournament.Tests/teams.json @@ -0,0 +1 @@ +[{"Players":[{"id":3632846,"username":"lxLucasxl"},{"id":7110363,"username":"BubShish"},{"id":5748843,"username":"Fisk-"},{"id":4585260,"username":"A b y s s"},{"id":9513273,"username":"VorticalEx"},{"id":7341471,"username":"Bossplays_02"}],"Name":"Argentina","Acronym":"ARG"},{"Players":[{"id":2956184,"username":"Lusty Platypus"},{"id":2145124,"username":"Spartan-"},{"id":4018184,"username":"Rek"},{"id":4247722,"username":"PotassiumF"},{"id":9527845,"username":"AngeLItchysick"},{"id":8832989,"username":"[Crz]Yukikaze-"}],"Name":"Australia","Acronym":"AUS"},{"Players":[{"id":9530019,"username":"Lothus"},{"id":2288363,"username":"SillyFangirl"},{"id":4917435,"username":"FelipeLink"},{"id":5691061,"username":"andreymc"},{"id":4794096,"username":"Shedin"},{"id":3224958,"username":"Lazarento"}],"Name":"Brazil","Acronym":"BRA"},{"Players":[{"id":2747704,"username":"Dawt"},{"id":7025841,"username":"CommandoBlack"},{"id":5390121,"username":"Piggy"},{"id":2198070,"username":"beary605"},{"id":2777647,"username":"Freeflow"},{"id":9675053,"username":"Kiyora"}],"Name":"Canada","Acronym":"CAN"},{"Players":[{"id":5281416,"username":"WalterToro"},{"id":2225008,"username":"Skalim"},{"id":469808,"username":"Sophti"},{"id":4686036,"username":"sebaex"},{"id":4116072,"username":"Arkener"},{"id":4531184,"username":"Raizenn"}],"Name":"Chile","Acronym":"CHL"},{"Players":[{"id":89545,"username":"ZhangFan"},{"id":7215250,"username":"[Crz]Mix0130"},{"id":7961511,"username":"[Crz]Hina"},{"id":7082178,"username":"[Crz]Satori"},{"id":6659363,"username":"Wilben_Chan"},{"id":5270332,"username":"[Crz]Lucifer"}],"Name":"China","Acronym":"CHN"},{"Players":[{"id":2883132,"username":"Jole"},{"id":5001658,"username":"FreakyHands"},{"id":4402263,"username":"mart732c"},{"id":6751666,"username":"tailsdk"},{"id":5352616,"username":"Kainura"},{"id":8969233,"username":"zyglrox"}],"Name":"Denmark","Acronym":"DNK"},{"Players":[{"id":8132964,"username":"Camopoltergeist"},{"id":4789005,"username":"princesswell"},{"id":9663200,"username":"--Vanilla--"},{"id":1982941,"username":"matti644"},{"id":8370443,"username":"Your Daughter"},{"id":8105584,"username":"Twist-X"}],"Name":"Finland","Acronym":"FIN"},{"Players":[{"id":1594604,"username":"Azubeur"},{"id":2284328,"username":"Elementaires"},{"id":3897919,"username":"AntoAa"},{"id":4056690,"username":"Todestrieb"},{"id":7190228,"username":"Cunu"},{"id":3909293,"username":"DemonWaves"}],"Name":"France","Acronym":"FRA"},{"Players":[{"id":4516252,"username":"Malox"},{"id":3357640,"username":"ElectroYan"},{"id":5587671,"username":"-Dom-"},{"id":9764403,"username":"tyro901"},{"id":7009106,"username":"Nediz"},{"id":6232245,"username":"LastExceed"}],"Name":"Germany","Acronym":"GER"},{"Players":[{"id":5417362,"username":"Mooncha"},{"id":2121137,"username":"ng051106"},{"id":4544555,"username":"Opean"},{"id":643394,"username":"Snow Note"}],"Name":"['Hong Kong']","Acronym":"HKG"},{"Players":[{"id":5767941,"username":"RemFangirl"},{"id":4557440,"username":"reyss"},{"id":5492871,"username":"LovelySerenade"},{"id":6045757,"username":"Nixeria-sama"},{"id":5114499,"username":"lombit"},{"id":3497139,"username":"LordBoker-"}],"Name":"Indonesia","Acronym":"IDN"},{"Players":[{"id":3461860,"username":"Yomiel"},{"id":5245132,"username":"BadIsTheNewGod"},{"id":3244389,"username":"Mura7797"},{"id":8889323,"username":"extramen"},{"id":8485394,"username":"Cribob"},{"id":6380163,"username":"CribobFanBoy"}],"Name":"Italy","Acronym":"ITA"},{"Players":[{"id":1824775,"username":"inteliser"},{"id":7540718,"username":"tinpura"},{"id":1847698,"username":"PiraTom"},{"id":10011429,"username":"[ misa ]"},{"id":8679066,"username":"mach_jp"},{"id":10242062,"username":"AMDuskia1996"}],"Name":"Japan","Acronym":"JPN"},{"Players":[{"id":3946113,"username":"idqoos123"},{"id":10543278,"username":"hh27v5Fangirl"},{"id":8566617,"username":"capchon"},{"id":5315736,"username":"my2tic"}],"Name":"Macau","Acronym":"MAC"},{"Players":[{"id":7727987,"username":"Neokje"},{"id":8287005,"username":"[MY]xRay"},{"id":9627666,"username":"Minisora"},{"id":6237337,"username":"watarakisah"},{"id":6363947,"username":"Kiritolow"},{"id":4477497,"username":"cheewee10"}],"Name":"Malaysia","Acronym":"MYS"},{"Players":[{"id":1098581,"username":"mrdawn2"},{"id":9369363,"username":"TheSnooperPS"},{"id":6964358,"username":"Redenor"},{"id":9630674,"username":"Freek"},{"id":2827823,"username":"Boots"},{"id":5183940,"username":"2fast4you98"}],"Name":"Netherlands","Acronym":"NLD"},{"Players":[{"id":86188,"username":"Staiain"},{"id":7676585,"username":"Bizarrely_F4st"},{"id":3494742,"username":"KarlF"},{"id":3750387,"username":"Falniir"},{"id":9000473,"username":"Jesen"},{"id":2764122,"username":"Hjeg"}],"Name":"Norway","Acronym":"NOR"},{"Players":[{"id":914472,"username":"akuma123"},{"id":6114633,"username":"DaZeRo5"},{"id":11885200,"username":"DaKub"},{"id":10218427,"username":"Ovento17"}],"Name":"Peru","Acronym":"PER"},{"Players":[{"id":2039089,"username":"arcwinolivirus"},{"id":4469895,"username":"SurfChu85"},{"id":2471512,"username":"JztCallMeRon"},{"id":9770359,"username":"Toyohime-"},{"id":2722489,"username":"Cielo Day"},{"id":3770641,"username":"Ainyan"}],"Name":"Philippines","Acronym":"PHL"},{"Players":[{"id":743282,"username":"Tidek"},{"id":1654221,"username":"Hudonom"},{"id":6382502,"username":"Kroly-"},{"id":6905790,"username":"Arkitev"},{"id":2235750,"username":"_underjoy"},{"id":3353343,"username":"[-Agonys-]"}],"Name":"Poland","Acronym":"POL"},{"Players":[{"id":9074986,"username":"AngeloLagusa"},{"id":5145890,"username":"Jormungand"},{"id":9847747,"username":"MAZAFUKER1337"},{"id":8035172,"username":"fegasaren"},{"id":7767168,"username":"claer"}],"Name":"['Russian Federation']","Acronym":"RUS"},{"Players":[{"id":7199159,"username":"ByeForNow"},{"id":876528,"username":"Tamaneko"},{"id":8612061,"username":"Polytetral"},{"id":7462804,"username":"Lindyes"},{"id":4574597,"username":"OrienST8"},{"id":9362562,"username":"LuigiClaren"}],"Name":"Singapore","Acronym":"SGP"},{"Players":[{"id":6699923,"username":"SuddenDeath"},{"id":7014697,"username":"Estonians"},{"id":8474029,"username":"wonder5193"},{"id":8283444,"username":"[ Special ]"},{"id":903155,"username":"Nausicaa"},{"id":7945868,"username":"SnowScent"}],"Name":"['South Korea']","Acronym":"KOR"},{"Players":[{"id":3154852,"username":"aitor98"},{"id":8141215,"username":"David5_"},{"id":7935867,"username":"miguel-580"},{"id":6809566,"username":"itsdarious555"},{"id":8497100,"username":"GreenSoul"}],"Name":"Spain","Acronym":"ESP"},{"Players":[{"id":1612580,"username":"Vent"},{"id":6872025,"username":"Couil"},{"id":2229274,"username":"Xytox"},{"id":4899311,"username":"Stug"},{"id":5045509,"username":"YoShiZoRi"},{"id":3918056,"username":"Craty"}],"Name":"Sweden","Acronym":"SWE"},{"Players":[{"id":4952941,"username":"Gamer97"},{"id":8642966,"username":"Adyrem"},{"id":8372292,"username":"doere_"},{"id":9593126,"username":"Monogai"},{"id":3974114,"username":"Haprapra"},{"id":2573716,"username":"Akayro"}],"Name":"Switzerland","Acronym":"CHE"},{"Players":[{"id":766374,"username":"LostCool"},{"id":2838908,"username":"4ksrub"},{"id":6535376,"username":"SharpKunG1412"},{"id":2772110,"username":"BossMadWolf"},{"id":8521723,"username":"MyZterioN-"},{"id":6456531,"username":"-[DaNieL_TH]-"}],"Name":"Thailand","Acronym":"THA"},{"Players":[{"id":2656856,"username":"Sakaki"},{"id":6193819,"username":"SaKuRaLaN"},{"id":1990582,"username":"mspstommy"},{"id":8819232,"username":"Tamamo Desu"},{"id":11531528,"username":"Red MewFew"},{"id":1967808,"username":"luckygino"}],"Name":"Taiwan","Acronym":"TWN"},{"Players":[{"id":3359035,"username":"Amascite"},{"id":4168230,"username":"PikachuNick"},{"id":3617889,"username":"itsjakey"},{"id":3799946,"username":"xSnaggles"},{"id":6814203,"username":"Civilization"},{"id":6701945,"username":"Domblade"}],"Name":"['United Kingdom']","Acronym":"GBR"},{"Players":[{"id":7616811,"username":"TheToaphster"},{"id":2141612,"username":"stupud man"},{"id":7687954,"username":"Neuro-"},{"id":3251373,"username":"-Electro-"},{"id":5610085,"username":"EtienneXC"},{"id":2594280,"username":"Chrubble"}],"Name":"['United States']","Acronym":"USA"},{"Players":[{"id":2243452,"username":"Nakatoru"},{"id":8065567,"username":"Aezlack"},{"id":8301758,"username":"Edvo"},{"id":2140739,"username":"[_Chichinya_]"},{"id":8198818,"username":"[_Gearfrik_]"},{"id":1489811,"username":"_Yisus_"}],"Name":"Venezuela","Acronym":"VEN"}] \ No newline at end of file diff --git a/osu.Game.Tournament/Components/TournamentTeam.cs b/osu.Game.Tournament/Components/TournamentTeam.cs index 03d787af76..14e874e9ef 100644 --- a/osu.Game.Tournament/Components/TournamentTeam.cs +++ b/osu.Game.Tournament/Components/TournamentTeam.cs @@ -1,6 +1,9 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; +using osu.Game.Users; + namespace osu.Game.Tournament.Components { public class TournamentTeam @@ -10,10 +13,16 @@ namespace osu.Game.Tournament.Components /// public string FullName; + private string flagName; + /// /// Name of the file containing the flag. /// - public string FlagName; + public string FlagName + { + get { return flagName ?? Acronym.Substring(0, 2); } + set { flagName = value; } + } private string acronym; @@ -25,5 +34,7 @@ namespace osu.Game.Tournament.Components get { return acronym ?? FullName.Substring(0, 3); } set { acronym = value; } } + + public List Players { get; set; } } } diff --git a/osu.Game.Tournament/Screens/Drawings/Components/StorageBackedTeamList.cs b/osu.Game.Tournament/Screens/Drawings/Components/StorageBackedTeamList.cs index 44ee9d64ca..625f05edac 100644 --- a/osu.Game.Tournament/Screens/Drawings/Components/StorageBackedTeamList.cs +++ b/osu.Game.Tournament/Screens/Drawings/Components/StorageBackedTeamList.cs @@ -50,7 +50,6 @@ namespace osu.Game.Tournament.Screens.Drawings.Components teams.Add(new TournamentTeam { - FlagName = split[0].Trim(), FullName = split[1].Trim(), Acronym = split.Length >= 3 ? split[2].Trim() : null }); diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs index 8191df6680..62d38a2ee6 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchPairing.cs @@ -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; + } } } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs index 06b400976c..1077438693 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs @@ -2,11 +2,15 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +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.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Input.EventArgs; using osu.Framework.Input.States; using osu.Game.Graphics; @@ -18,8 +22,9 @@ using OpenTK.Input; namespace osu.Game.Tournament.Screens.Ladder.Components { - public class DrawableMatchTeam : DrawableTournamentTeam + public class DrawableMatchTeam : DrawableTournamentTeam, IHasContextMenu { + private readonly Bindable team; private readonly MatchPairing pairing; private OsuSpriteText scoreText; private Box background; @@ -31,10 +36,12 @@ namespace osu.Game.Tournament.Screens.Ladder.Components private Color4 colourNormal; private readonly Func isWinner; + private LadderManager manager; - public DrawableMatchTeam(TournamentTeam team, MatchPairing pairing) + public DrawableMatchTeam(Bindable team, MatchPairing pairing) : base(team) { + this.team = team.GetBoundCopy(); this.pairing = pairing; Size = new Vector2(150, 40); @@ -53,14 +60,16 @@ namespace osu.Game.Tournament.Screens.Ladder.Components isWinner = () => pairing.Winner == Team; completed.BindTo(pairing.Completed); - if (team != null) - score.BindTo(team == pairing.Team1.Value ? pairing.Team1Score : pairing.Team2Score); + if (team.Value != null) + score.BindTo(team.Value == pairing.Team1.Value ? pairing.Team1Score : pairing.Team2Score); } } - [BackgroundDependencyLoader] - private void load(OsuColour colours) + [BackgroundDependencyLoader(true)] + private void load(OsuColour colours, LadderManager manager) { + this.manager = manager; + colourWinner = colours.BlueDarker; colourNormal = OsuColour.Gray(0.2f); @@ -117,7 +126,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) { - if (Team == null) return true; + if (Team == null) return false; if (args.Button == MouseButton.Left) { @@ -136,7 +145,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components pairing.CancelMatchStart(); } - return true; + return false; } private void updateWinStyle() @@ -147,5 +156,27 @@ namespace osu.Game.Tournament.Screens.Ladder.Components scoreText.Font = AcronymText.Font = winner ? "Exo2.0-Bold" : "Exo2.0-Regular"; } + + public MenuItem[] ContextMenuItems => new[] + { + new MenuItem("Populate team", () => team.Value = manager.Teams.Random()), + }; + } + + internal static class Extensions + { + public static T Random(this IEnumerable enumerable) + { + if (enumerable == null) + { + throw new ArgumentNullException(nameof(enumerable)); + } + + // note: creating a Random instance each call may not be correct for you, + // consider a thread-safe static instance + var r = new Random(); + var list = enumerable as IList ?? enumerable.ToList(); + return list.Count == 0 ? default(T) : list[r.Next(0, list.Count)]; + } } } diff --git a/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs b/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs new file mode 100644 index 0000000000..e65cc7a512 --- /dev/null +++ b/osu.Game.Tournament/Screens/Ladder/Components/LadderInfo.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace osu.Game.Tournament.Screens.Ladder.Components +{ + public class LadderInfo + { + public List Pairings = new List(); + } +} diff --git a/osu.Game.Tournament/Screens/Ladder/Components/LadderManager.cs b/osu.Game.Tournament/Screens/Ladder/Components/LadderManager.cs new file mode 100644 index 0000000000..b7764f946f --- /dev/null +++ b/osu.Game.Tournament/Screens/Ladder/Components/LadderManager.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Input.States; +using osu.Game.Graphics.Cursor; +using osu.Game.Tournament.Components; +using SixLabors.Primitives; + +namespace osu.Game.Tournament.Screens.Ladder.Components +{ + public class LadderManager : CompositeDrawable + { + public readonly LadderInfo Info; + public readonly List Teams; + private readonly OsuContextMenuContainer content; + + public LadderManager(LadderInfo info, List teams) + { + Info = info; + Teams = teams; + + RelativeSizeAxes = Axes.Both; + + InternalChild = content = new OsuContextMenuContainer + { + RelativeSizeAxes = Axes.Both + }; + + foreach (var pairing in info.Pairings) + addPairing(pairing); + } + + protected void AddPairing(MatchPairing pairing) + { + Info.Pairings.Add(pairing); + addPairing(pairing); + } + + private void addPairing(MatchPairing pairing) => content.Add(new DrawableMatchPairing(pairing)); + + protected override bool OnClick(InputState state) + { + AddPairing(new MatchPairing + { + Position = new Point((int)state.Mouse.Position.X, (int)state.Mouse.Position.Y) + }); + + return true; + } + } +} diff --git a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs index b615330cc2..d2a8f66cfd 100644 --- a/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs +++ b/osu.Game.Tournament/Screens/Ladder/Components/MatchPairing.cs @@ -1,8 +1,10 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using Newtonsoft.Json; using osu.Framework.Configuration; using osu.Game.Tournament.Components; +using SixLabors.Primitives; namespace osu.Game.Tournament.Screens.Ladder.Components { @@ -11,13 +13,22 @@ namespace osu.Game.Tournament.Screens.Ladder.Components /// public class MatchPairing { - public Bindable Team1 = new Bindable(); - public Bindable Team1Score = new Bindable(); + public readonly Bindable Team1 = new Bindable(); - public Bindable Team2 = new Bindable(); - public Bindable Team2Score = new Bindable(); + public readonly Bindable Team1Score = new Bindable(); - public Bindable Completed = new Bindable(); + public readonly Bindable Team2 = new Bindable(); + + public readonly Bindable Team2Score = new Bindable(); + + public readonly Bindable Completed = new Bindable(); + + [JsonProperty] + public Point Position; + + public MatchPairing() + { + } public MatchPairing(TournamentTeam team1 = null, TournamentTeam team2 = null) {