1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 06:07:25 +08:00
osu-lazer/osu.Game/Screens/Tournament/GroupContainer.cs

106 lines
2.9 KiB
C#
Raw Normal View History

2017-03-08 14:50:52 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-02-27 14:02:38 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
2017-03-03 19:42:22 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using OpenTK;
using osu.Game.Screens.Tournament.Teams;
2017-02-27 14:02:38 +08:00
namespace osu.Game.Screens.Tournament
{
2017-03-03 19:46:07 +08:00
public class GroupContainer : Container
2017-02-27 14:02:38 +08:00
{
private readonly List<Group> groups = new List<Group>();
2017-02-27 14:02:38 +08:00
private readonly int maxTeams;
private int currentGroup;
2017-02-27 22:09:26 +08:00
2017-05-02 13:21:22 +08:00
public GroupContainer(int numGroups, int teamsPerGroup)
2017-02-27 14:02:38 +08:00
{
2017-03-03 19:42:22 +08:00
FlowContainer<Group> bottomGroups;
FlowContainer<Group> topGroups;
2017-02-27 22:09:26 +08:00
maxTeams = teamsPerGroup;
2017-02-27 14:02:38 +08:00
char nextGroupName = 'A';
Children = new[]
{
2017-03-03 19:42:22 +08:00
topGroups = new FillFlowContainer<Group>
2017-03-03 12:17:06 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
2017-02-27 14:02:38 +08:00
2017-03-03 12:17:06 +08:00
AutoSizeAxes = Axes.Both,
2017-02-27 14:02:38 +08:00
2017-03-03 12:17:06 +08:00
Spacing = new Vector2(7f, 0)
},
2017-03-03 19:42:22 +08:00
bottomGroups = new FillFlowContainer<Group>
2017-03-03 12:17:06 +08:00
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
2017-02-27 14:02:38 +08:00
2017-03-03 12:17:06 +08:00
AutoSizeAxes = Axes.Both,
2017-02-27 14:02:38 +08:00
2017-03-03 12:17:06 +08:00
Spacing = new Vector2(7f, 0)
}
};
2017-02-27 14:02:38 +08:00
for (int i = 0; i < numGroups; i++)
{
Group g = new Group(nextGroupName.ToString());
2017-03-03 19:42:22 +08:00
groups.Add(g);
2017-02-27 14:02:38 +08:00
nextGroupName++;
if (i < (int)Math.Ceiling(numGroups / 2f))
topGroups.Add(g);
else
bottomGroups.Add(g);
}
}
2017-05-02 17:00:37 +08:00
public void AddTeam(DrawingsTeam team)
2017-02-27 14:02:38 +08:00
{
2017-03-03 19:42:22 +08:00
if (groups[currentGroup].TeamsCount == maxTeams)
return;
2017-02-27 14:02:38 +08:00
2017-05-02 13:21:22 +08:00
groups[currentGroup].AddTeam(team);
2017-03-03 19:42:22 +08:00
currentGroup = (currentGroup + 1) % groups.Count;
2017-02-27 14:02:38 +08:00
}
public bool ContainsTeam(string fullName)
{
2017-03-03 19:42:22 +08:00
return groups.Any(g => g.ContainsTeam(fullName));
}
public void ClearTeams()
2017-02-27 14:02:38 +08:00
{
2017-03-03 19:42:22 +08:00
foreach (Group g in groups)
g.ClearTeams();
2017-02-27 14:02:38 +08:00
currentGroup = 0;
2017-02-27 14:02:38 +08:00
}
2017-03-03 19:42:22 +08:00
public string GetStringRepresentation()
{
StringBuilder sb = new StringBuilder();
2017-03-03 12:17:06 +08:00
2017-03-03 19:42:22 +08:00
foreach (Group g in groups)
{
2017-03-03 19:42:22 +08:00
if (g != groups.First())
sb.AppendLine();
sb.AppendLine($"Group {g.GroupName}");
2017-03-03 19:42:22 +08:00
sb.Append(g.GetStringRepresentation());
}
return sb.ToString();
}
2017-02-27 14:02:38 +08:00
}
}