Add grouping configuration

This commit is contained in:
Dean Herbert 2018-09-24 23:30:37 +09:00
parent ad63ff2d06
commit 1644775f7b
4 changed files with 34 additions and 3 deletions

View File

@ -1,12 +1,15 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; 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.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
using osu.Game.Screens.Play.PlayerSettings; using osu.Game.Screens.Play.PlayerSettings;
namespace osu.Game.Tournament.Screens.Ladder.Components namespace osu.Game.Tournament.Screens.Ladder.Components
@ -19,6 +22,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
private OsuTextBox textboxTeam1; private OsuTextBox textboxTeam1;
private OsuTextBox textboxTeam2; private OsuTextBox textboxTeam2;
private SettingsDropdown<TournamentGrouping> groupingDropdown;
[Resolved] [Resolved]
private LadderEditorInfo editorInfo { get; set; } = null; private LadderEditorInfo editorInfo { get; set; } = null;
@ -28,6 +32,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
{ {
var teamEntries = editorInfo.Teams; var teamEntries = editorInfo.Teams;
var groupingOptions = editorInfo.Groupings.Select(g => new KeyValuePair<string, TournamentGrouping>(g.Name, g)).Prepend(new KeyValuePair<string, TournamentGrouping>("None", new TournamentGrouping()));
Children = new Drawable[] Children = new Drawable[]
{ {
new PlayerCheckbox new PlayerCheckbox
@ -67,6 +73,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
}, },
}, },
textboxTeam2 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 }, textboxTeam2 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
groupingDropdown = new SettingsDropdown<TournamentGrouping>
{
Bindable = new Bindable<TournamentGrouping>(),
Items = groupingOptions
},
// new Container // new Container
// { // {
// RelativeSizeAxes = Axes.X, // RelativeSizeAxes = Axes.X,
@ -99,6 +110,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
{ {
textboxTeam1.Text = selection?.Team1.Value?.Acronym; textboxTeam1.Text = selection?.Team1.Value?.Acronym;
textboxTeam2.Text = selection?.Team2.Value?.Acronym; textboxTeam2.Text = selection?.Team2.Value?.Acronym;
groupingDropdown.Bindable.Value = selection?.Grouping.Value ?? groupingOptions.First().Value;
}; };
textboxTeam1.OnCommit = (val, newText) => textboxTeam1.OnCommit = (val, newText) =>
@ -113,6 +125,12 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
editorInfo.Selected.Value.Team2.Value = teamEntries.FirstOrDefault(t => t.Acronym == val.Text); editorInfo.Selected.Value.Team2.Value = teamEntries.FirstOrDefault(t => t.Acronym == val.Text);
}; };
groupingDropdown.Bindable.ValueChanged += grouping =>
{
if (editorInfo.Selected.Value != null)
editorInfo.Selected.Value.Grouping.Value = grouping;
};
// sliderBestOf.Bindable.ValueChanged += val => // sliderBestOf.Bindable.ValueChanged += val =>
// { // {
// if (editorInfo.Selected.Value != null) editorInfo.Selected.Value.BestOf.Value = (int)val; // if (editorInfo.Selected.Value != null) editorInfo.Selected.Value.BestOf.Value = (int)val;

View File

@ -25,6 +25,7 @@ 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 Bindable<TournamentGrouping> Grouping = new Bindable<TournamentGrouping>(); public readonly Bindable<TournamentGrouping> Grouping = new Bindable<TournamentGrouping>();
[JsonIgnore] [JsonIgnore]

View File

@ -1,15 +1,17 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
namespace osu.Game.Tournament.Screens.Ladder.Components namespace osu.Game.Tournament.Screens.Ladder.Components
{ {
public class TournamentGrouping public class TournamentGrouping
{ {
public int ID;
public string Name; public string Name;
public string Description; public string Description;
public int BestOf; public int BestOf;
public List<int> Pairings = new List<int>();
} }
} }

View File

@ -21,6 +21,7 @@ namespace osu.Game.Tournament.Screens.Ladder
{ {
public readonly BindableBool EditingEnabled = new BindableBool(); public readonly BindableBool EditingEnabled = new BindableBool();
public List<TournamentTeam> Teams = new List<TournamentTeam>(); public List<TournamentTeam> Teams = new List<TournamentTeam>();
public List<TournamentGrouping> Groupings = new List<TournamentGrouping>();
public readonly Bindable<MatchPairing> Selected = new Bindable<MatchPairing>(); public readonly Bindable<MatchPairing> Selected = new Bindable<MatchPairing>();
} }
@ -36,6 +37,7 @@ namespace osu.Game.Tournament.Screens.Ladder
public LadderManager(LadderInfo info, List<TournamentTeam> teams) public LadderManager(LadderInfo info, List<TournamentTeam> teams)
{ {
editorInfo.Teams = Teams = teams; editorInfo.Teams = Teams = teams;
editorInfo.Groupings = info.Groupings;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -75,19 +77,27 @@ namespace osu.Game.Tournament.Screens.Ladder
foreach (var pairing in info.Pairings) foreach (var pairing in info.Pairings)
addPairing(pairing); addPairing(pairing);
foreach (var group in info.Groupings)
foreach (var id in group.Pairings)
info.Pairings.Single(p => p.ID == id).Grouping.Value = group;
} }
public LadderInfo CreateInfo() public LadderInfo CreateInfo()
{ {
var pairings = pairingsContainer.Select(p => p.Pairing).ToList(); var pairings = pairingsContainer.Select(p => p.Pairing).ToList();
foreach (var g in editorInfo.Groupings)
g.Pairings = pairings.Where(p => p.Grouping.Value == g).Select(p => p.ID).ToList();
return new LadderInfo return new LadderInfo
{ {
Pairings = pairings, Pairings = pairings,
Progressions = pairings Progressions = pairings
.Where(p => p.Progression.Value != null) .Where(p => p.Progression.Value != null)
.Select(p => (p.ID, p.Progression.Value.ID)) .Select(p => (p.ID, p.Progression.Value.ID))
.ToList() .ToList(),
Groupings = editorInfo.Groupings
}; };
} }