2017-02-27 14:02:38 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Tournament
|
|
|
|
|
{
|
|
|
|
|
public class GroupsContainer : Container
|
|
|
|
|
{
|
|
|
|
|
private FlowContainer<Group> topGroups;
|
|
|
|
|
private FlowContainer<Group> bottomGroups;
|
|
|
|
|
|
|
|
|
|
private List<Group> allGroups = new List<Group>();
|
|
|
|
|
|
2017-02-27 22:09:26 +08:00
|
|
|
|
private int maxTeams;
|
2017-03-03 11:06:35 +08:00
|
|
|
|
private int currentGroup;
|
2017-02-27 22:09:26 +08:00
|
|
|
|
|
|
|
|
|
public GroupsContainer(int numGroups, int teamsPerGroup)
|
2017-02-27 14:02:38 +08:00
|
|
|
|
{
|
2017-02-27 22:09:26 +08:00
|
|
|
|
maxTeams = teamsPerGroup;
|
|
|
|
|
|
2017-02-27 14:02:38 +08:00
|
|
|
|
char nextGroupName = 'A';
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
topGroups = new FlowContainer<Group>()
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
|
|
|
|
|
Spacing = new Vector2(7f, 0)
|
|
|
|
|
},
|
|
|
|
|
bottomGroups = new FlowContainer<Group>()
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
|
|
|
|
|
Spacing = new Vector2(7f, 0)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numGroups; i++)
|
|
|
|
|
{
|
|
|
|
|
Group g = new Group(nextGroupName.ToString());
|
|
|
|
|
|
|
|
|
|
allGroups.Add(g);
|
|
|
|
|
nextGroupName++;
|
|
|
|
|
|
|
|
|
|
if (i < (int)Math.Ceiling(numGroups / 2f))
|
|
|
|
|
topGroups.Add(g);
|
|
|
|
|
else
|
|
|
|
|
bottomGroups.Add(g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddTeam(Team team)
|
|
|
|
|
{
|
2017-03-03 11:06:35 +08:00
|
|
|
|
if (allGroups[currentGroup].TeamsCount == maxTeams)
|
|
|
|
|
return;
|
2017-02-27 14:02:38 +08:00
|
|
|
|
|
2017-03-03 11:06:35 +08:00
|
|
|
|
allGroups[currentGroup].AddTeam(team);
|
|
|
|
|
|
|
|
|
|
currentGroup = (currentGroup + 1) % allGroups.Count;
|
2017-02-27 14:02:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 21:50:34 +08:00
|
|
|
|
public bool ContainsTeam(string fullName)
|
|
|
|
|
{
|
|
|
|
|
return allGroups.Any(g => g.ContainsTeam(fullName));
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-03 11:06:35 +08:00
|
|
|
|
public void ClearTeams()
|
2017-02-27 14:02:38 +08:00
|
|
|
|
{
|
2017-03-02 11:02:50 +08:00
|
|
|
|
foreach (Group g in allGroups)
|
2017-03-03 11:06:35 +08:00
|
|
|
|
g.ClearTeams();
|
2017-02-27 14:02:38 +08:00
|
|
|
|
|
2017-03-03 11:06:35 +08:00
|
|
|
|
currentGroup = 0;
|
2017-02-27 14:02:38 +08:00
|
|
|
|
}
|
2017-03-02 11:02:50 +08:00
|
|
|
|
|
|
|
|
|
public string ToStringRepresentation()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
foreach (Group g in allGroups)
|
|
|
|
|
{
|
|
|
|
|
if (g != allGroups.First())
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
sb.AppendLine($"Group {g.GroupName}");
|
|
|
|
|
sb.Append(g.ToStringRepresentation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
2017-02-27 14:02:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|