2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-08 06:50:52 +00:00
|
|
|
|
using System;
|
2017-02-27 06:02:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2017-03-03 11:42:22 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-06-18 05:51:48 +00:00
|
|
|
|
using osu.Game.Tournament.Models;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-08-25 12:40:40 +00:00
|
|
|
|
namespace osu.Game.Tournament.Screens.Drawings.Components
|
2017-02-27 06:02:38 +00:00
|
|
|
|
{
|
2017-03-03 11:46:07 +00:00
|
|
|
|
public partial class GroupContainer : Container
|
2017-02-27 06:02:38 +00:00
|
|
|
|
{
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly List<Group> groups = new List<Group>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly int maxTeams;
|
2017-03-03 03:06:35 +00:00
|
|
|
|
private int currentGroup;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-02 05:21:22 +00:00
|
|
|
|
public GroupContainer(int numGroups, int teamsPerGroup)
|
2017-02-27 06:02:38 +00:00
|
|
|
|
{
|
2017-03-03 11:42:22 +00:00
|
|
|
|
FlowContainer<Group> bottomGroups;
|
|
|
|
|
FlowContainer<Group> topGroups;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-27 14:09:26 +00:00
|
|
|
|
maxTeams = teamsPerGroup;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-27 06:02:38 +00:00
|
|
|
|
char nextGroupName = 'A';
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-27 06:02:38 +00:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-03-03 11:42:22 +00:00
|
|
|
|
topGroups = new FillFlowContainer<Group>
|
2017-03-03 04:17:06 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 04:17:06 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 04:17:06 +00:00
|
|
|
|
Spacing = new Vector2(7f, 0)
|
|
|
|
|
},
|
2017-03-03 11:42:22 +00:00
|
|
|
|
bottomGroups = new FillFlowContainer<Group>
|
2017-03-03 04:17:06 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 04:17:06 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 04:17:06 +00:00
|
|
|
|
Spacing = new Vector2(7f, 0)
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-27 06:02:38 +00:00
|
|
|
|
for (int i = 0; i < numGroups; i++)
|
|
|
|
|
{
|
|
|
|
|
Group g = new Group(nextGroupName.ToString());
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 11:42:22 +00:00
|
|
|
|
groups.Add(g);
|
2017-02-27 06:02:38 +00:00
|
|
|
|
nextGroupName++;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-11-24 23:45:42 +00:00
|
|
|
|
if (i < (int)MathF.Ceiling(numGroups / 2f))
|
2017-02-27 06:02:38 +00:00
|
|
|
|
topGroups.Add(g);
|
|
|
|
|
else
|
|
|
|
|
bottomGroups.Add(g);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-08-25 12:40:40 +00:00
|
|
|
|
public void AddTeam(TournamentTeam team)
|
2017-02-27 06:02:38 +00:00
|
|
|
|
{
|
2017-03-03 11:42:22 +00:00
|
|
|
|
if (groups[currentGroup].TeamsCount == maxTeams)
|
2017-03-03 03:06:35 +00:00
|
|
|
|
return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-02 05:21:22 +00:00
|
|
|
|
groups[currentGroup].AddTeam(team);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 11:42:22 +00:00
|
|
|
|
currentGroup = (currentGroup + 1) % groups.Count;
|
2017-02-27 06:02:38 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-27 13:50:34 +00:00
|
|
|
|
public bool ContainsTeam(string fullName)
|
|
|
|
|
{
|
2017-03-03 11:42:22 +00:00
|
|
|
|
return groups.Any(g => g.ContainsTeam(fullName));
|
2017-02-27 13:50:34 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 03:06:35 +00:00
|
|
|
|
public void ClearTeams()
|
2017-02-27 06:02:38 +00:00
|
|
|
|
{
|
2017-03-03 11:42:22 +00:00
|
|
|
|
foreach (Group g in groups)
|
2017-03-03 03:06:35 +00:00
|
|
|
|
g.ClearTeams();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 03:06:35 +00:00
|
|
|
|
currentGroup = 0;
|
2017-02-27 06:02:38 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 11:42:22 +00:00
|
|
|
|
public string GetStringRepresentation()
|
2017-03-02 03:02:50 +00:00
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-03 11:42:22 +00:00
|
|
|
|
foreach (Group g in groups)
|
2017-03-02 03:02:50 +00:00
|
|
|
|
{
|
2017-03-03 11:42:22 +00:00
|
|
|
|
if (g != groups.First())
|
2017-03-02 03:02:50 +00:00
|
|
|
|
sb.AppendLine();
|
|
|
|
|
sb.AppendLine($"Group {g.GroupName}");
|
2017-03-03 11:42:22 +00:00
|
|
|
|
sb.Append(g.GetStringRepresentation());
|
2017-03-02 03:02:50 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-02 03:02:50 +00:00
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
2017-02-27 06:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|