1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 09:37:42 +08:00
osu-lazer/osu.Game/Screens/Tournament/Group.cs

187 lines
5.4 KiB
C#
Raw Normal View History

2017-03-03 12:17:24 +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
2017-03-03 19:27:53 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
2017-02-27 13:19:07 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2017-03-03 19:27:53 +08:00
using osu.Game.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Screens.Tournament.Teams;
2017-02-27 13:19:07 +08:00
namespace osu.Game.Screens.Tournament
{
public class Group : Container
{
2017-03-03 14:59:33 +08:00
public readonly string GroupName;
2017-02-27 13:19:07 +08:00
public int TeamsCount { get; private set; }
2017-02-27 13:19:07 +08:00
private readonly FlowContainer<GroupTeam> teams;
2017-02-27 13:19:07 +08:00
private readonly List<GroupTeam> allTeams = new List<GroupTeam>();
2017-02-27 13:19:07 +08:00
public Group(string name)
{
GroupName = name;
Size = new Vector2(176, 128);
Masking = true;
CornerRadius = 4;
Children = new Drawable[]
{
2017-03-03 19:27:53 +08:00
new Box
2017-02-27 13:19:07 +08:00
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(54, 54, 54, 255)
},
// Group name
2017-03-03 19:27:53 +08:00
new OsuSpriteText
2017-02-27 13:19:07 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Position = new Vector2(0, 7f),
Text = $"GROUP {name.ToUpper()}",
TextSize = 8f,
Font = @"Exo2.0-Bold",
Colour = new Color4(255, 204, 34, 255),
},
2017-03-03 19:27:53 +08:00
teams = new FillFlowContainer<GroupTeam>
2017-02-27 13:19:07 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-03-03 19:42:22 +08:00
Spacing = new Vector2(6f, 22),
2017-02-27 13:19:07 +08:00
2017-03-03 19:27:53 +08:00
Margin = new MarginPadding
2017-02-27 13:19:07 +08:00
{
Top = 21f,
Bottom = 7f,
2017-02-27 13:19:07 +08:00
Left = 7f,
Right = 7f
}
2017-02-27 13:19:07 +08:00
}
};
}
2017-05-02 17:00:37 +08:00
public void AddTeam(DrawingsTeam team)
2017-02-27 13:19:07 +08:00
{
2017-05-02 13:21:22 +08:00
GroupTeam gt = new GroupTeam(team);
if (TeamsCount < 8)
2017-02-27 13:19:07 +08:00
{
teams.Add(gt);
allTeams.Add(gt);
TeamsCount++;
2017-02-27 13:19:07 +08:00
}
}
public bool ContainsTeam(string fullName)
{
return allTeams.Any(t => t.Team.FullName == fullName);
}
2017-05-02 17:00:37 +08:00
public bool RemoveTeam(DrawingsTeam team)
2017-02-27 13:19:07 +08:00
{
allTeams.RemoveAll(gt => gt.Team == team);
if (teams.RemoveAll(gt => gt.Team == team) > 0)
2017-02-27 14:02:38 +08:00
{
TeamsCount--;
2017-02-27 14:02:38 +08:00
return true;
}
return false;
}
public void ClearTeams()
{
allTeams.Clear();
teams.Clear();
2017-02-27 14:02:38 +08:00
TeamsCount = 0;
2017-02-27 13:19:07 +08:00
}
2017-03-03 19:42:22 +08:00
public string GetStringRepresentation()
{
StringBuilder sb = new StringBuilder();
foreach (GroupTeam gt in allTeams)
sb.AppendLine(gt.Team.FullName);
return sb.ToString();
}
2017-03-07 09:59:19 +08:00
private class GroupTeam : Container
2017-02-27 13:19:07 +08:00
{
2017-05-02 17:00:37 +08:00
public readonly DrawingsTeam Team;
2017-02-27 13:19:07 +08:00
private readonly FillFlowContainer innerContainer;
private readonly Sprite flagSprite;
2017-02-27 13:19:07 +08:00
2017-05-02 17:00:37 +08:00
public GroupTeam(DrawingsTeam team)
2017-02-27 13:19:07 +08:00
{
Team = team;
2017-03-03 19:42:22 +08:00
Width = 36;
2017-02-27 13:19:07 +08:00
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
2017-03-03 19:27:53 +08:00
innerContainer = new FillFlowContainer
2017-02-27 13:19:07 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5f),
Children = new Drawable[]
{
2017-03-03 19:27:53 +08:00
flagSprite = new Sprite
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
FillMode = FillMode.Fit
},
2017-03-03 19:27:53 +08:00
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = team.Acronym.ToUpper(),
TextSize = 10f,
Font = @"Exo2.0-Bold"
}
}
2017-02-27 13:19:07 +08:00
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
2017-03-03 19:42:22 +08:00
innerContainer.ScaleTo(1.5f);
innerContainer.ScaleTo(1f, 200);
}
2017-02-27 13:19:07 +08:00
[BackgroundDependencyLoader]
2017-05-02 13:21:22 +08:00
private void load(TextureStore textures)
2017-02-27 13:19:07 +08:00
{
2017-05-02 13:21:22 +08:00
flagSprite.Texture = textures.Get($@"Flags/{Team.FlagName}");
2017-02-27 13:19:07 +08:00
}
}
}
}