From 25a1c7a8ad53618d68f5a0cefac5302ec69cd160 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 27 Feb 2017 14:19:07 +0900 Subject: [PATCH] Initial groups implementation. --- osu-resources | 2 +- .../Tests/TestCaseDrawings.cs | 23 +++ .../osu.Desktop.VisualTests.csproj | 1 + osu.Game/Screens/Tournament/Drawings.cs | 123 +++++++++++++ osu.Game/Screens/Tournament/Group.cs | 162 ++++++++++++++++++ osu.Game/Screens/Tournament/Team.cs | 16 ++ osu.Game/Screens/Tournament/Tournament.cs | 14 ++ osu.Game/osu.Game.csproj | 4 + 8 files changed, 344 insertions(+), 1 deletion(-) create mode 100644 osu.Desktop.VisualTests/Tests/TestCaseDrawings.cs create mode 100644 osu.Game/Screens/Tournament/Drawings.cs create mode 100644 osu.Game/Screens/Tournament/Group.cs create mode 100644 osu.Game/Screens/Tournament/Team.cs create mode 100644 osu.Game/Screens/Tournament/Tournament.cs diff --git a/osu-resources b/osu-resources index 51f2b9b37f..29dda31250 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 51f2b9b37f38cd349a3dd728a78f8fffcb3a54f5 +Subproject commit 29dda31250aedb71f76d1c6b98f0bf0eebc798b2 diff --git a/osu.Desktop.VisualTests/Tests/TestCaseDrawings.cs b/osu.Desktop.VisualTests/Tests/TestCaseDrawings.cs new file mode 100644 index 0000000000..039d522084 --- /dev/null +++ b/osu.Desktop.VisualTests/Tests/TestCaseDrawings.cs @@ -0,0 +1,23 @@ +using osu.Framework.Screens.Testing; +using osu.Game.Screens.Tournament; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Desktop.VisualTests.Tests +{ + class TestCaseDrawings : TestCase + { + public override string Name => @"Drawings"; + public override string Description => "Tournament drawings"; + + public override void Reset() + { + base.Reset(); + + Add(new Drawings()); + } + } +} diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index cd899d4dd2..822ba4e0cb 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -176,6 +176,7 @@ + diff --git a/osu.Game/Screens/Tournament/Drawings.cs b/osu.Game/Screens/Tournament/Drawings.cs new file mode 100644 index 0000000000..09bbaf5732 --- /dev/null +++ b/osu.Game/Screens/Tournament/Drawings.cs @@ -0,0 +1,123 @@ +using OpenTK; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Primitives; +using osu.Game.Screens.Backgrounds; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Screens.Tournament +{ + public class Drawings : OsuScreen + { + protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault(); + + public Drawings() + { + GroupContainer gc; + + Children = new[] + { + gc = new GroupContainer(8) + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + + Padding = new MarginPadding() + { + Top = 35f, + Bottom = 35f + } + } + }; + + Team t = new Team() + { + FullName = "Australia", + Acronym = "AUS", + FlagName = "AU" + }; + + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + gc.AddTeam(t); + } + + class GroupContainer : Container + { + private FlowContainer topGroups; + private FlowContainer bottomGroups; + + private List allGroups = new List(); + + public GroupContainer(int numGroups) + { + char nextGroupName = 'A'; + + Children = new[] + { + topGroups = new FlowContainer() + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + + AutoSizeAxes = Axes.Both, + + Spacing = new Vector2(7f, 0) + }, + bottomGroups = new FlowContainer() + { + 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) + { + for (int i = 0; i < allGroups.Count; i++) + { + if (allGroups[i].TeamsCount == 8) + continue; + + allGroups[i].AddTeam(team); + break; + } + } + } + } +} diff --git a/osu.Game/Screens/Tournament/Group.cs b/osu.Game/Screens/Tournament/Group.cs new file mode 100644 index 0000000000..2c0df7b8f2 --- /dev/null +++ b/osu.Game/Screens/Tournament/Group.cs @@ -0,0 +1,162 @@ +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Screens.Tournament +{ + public class Group : Container + { + public string GroupName; + + public int TeamsCount => topTeamsCount + bottomTeamsCount; + + private FlowContainer topTeams; + private FlowContainer bottomTeams; + + private int topTeamsCount; + private int bottomTeamsCount; + + public Group(string name) + { + GroupName = name; + + Size = new Vector2(176, 128); + + Masking = true; + CornerRadius = 4; + + Children = new Drawable[] + { + new Box() + { + RelativeSizeAxes = Axes.Both, + Colour = new Color4(54, 54, 54, 255) + }, + // Group name + new SpriteText() + { + 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), + }, + topTeams = new FlowContainer() + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + + Position = new Vector2(0, 21f), + Spacing = new Vector2(6f, 0), + + Padding = new MarginPadding() + { + Left = 7f, + Right = 7f + }, + + Direction = FlowDirections.Horizontal + }, + bottomTeams = new FlowContainer() + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + + Position = new Vector2(0, -7f), + Spacing = new Vector2(6f, 0), + + Padding = new MarginPadding() + { + Left = 7f, + Right = 7f + }, + + Direction = FlowDirections.Horizontal + } + }; + } + + public void AddTeam(Team team) + { + if (topTeamsCount < 4) + { + topTeams.Add(new GroupTeam(team)); + topTeamsCount++; + } + else if (bottomTeamsCount < 4) + { + bottomTeams.Add(new GroupTeam(team)); + bottomTeamsCount++; + } + } + + public void RemoveTeam(Team team) + { + if (topTeams.RemoveAll(gt => gt.Team == team) > 0) + topTeamsCount--; + else if (bottomTeams.RemoveAll(gt => gt.Team == team) > 0) + bottomTeamsCount--; + } + + class GroupTeam : FlowContainer + { + public Team Team; + + private Sprite flagSprite; + + public GroupTeam(Team team) + { + Team = team; + + Size = new Vector2(36, 0); + AutoSizeAxes = Axes.Y; + Direction = FlowDirections.Vertical; + + Spacing = new Vector2(0, 5f); + + Children = new Drawable[] + { + flagSprite = new Sprite() + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + + FillMode = FillMode.Fit + }, + new SpriteText() + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + + Text = team.Acronym.ToUpper(), + TextSize = 10f, + Font = @"Exo2.0-Bold" + } + }; + } + + [BackgroundDependencyLoader] + private void load(TextureStore textures) + { + flagSprite.Texture = textures.Get($@"Flags/{Team.FlagName}"); + } + } + } +} diff --git a/osu.Game/Screens/Tournament/Team.cs b/osu.Game/Screens/Tournament/Team.cs new file mode 100644 index 0000000000..196af107a9 --- /dev/null +++ b/osu.Game/Screens/Tournament/Team.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Screens.Tournament +{ + public class Team + { + public string FullName; + public string Acronym; + + public string FlagName; + } +} diff --git a/osu.Game/Screens/Tournament/Tournament.cs b/osu.Game/Screens/Tournament/Tournament.cs new file mode 100644 index 0000000000..5fb041873d --- /dev/null +++ b/osu.Game/Screens/Tournament/Tournament.cs @@ -0,0 +1,14 @@ +using osu.Game.Screens.Backgrounds; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Screens.Tournament +{ + public class Tournament : OsuScreen + { + protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault(); + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 8a8afd2fe0..2f6143cf53 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -209,6 +209,10 @@ + + + +