diff --git a/osu.Desktop.VisualTests/Tests/TestCaseDrawings.cs b/osu.Desktop.VisualTests/Tests/TestCaseDrawings.cs index 4fe7e805ec..69697fe714 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseDrawings.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseDrawings.cs @@ -7,6 +7,7 @@ using osu.Framework.Platform; using osu.Framework.Screens.Testing; using osu.Game.Screens.Tournament; using osu.Game.Screens.Tournament.Teams; +using osu.Game.Users; namespace osu.Desktop.VisualTests.Tests { @@ -32,57 +33,57 @@ namespace osu.Desktop.VisualTests.Tests class TestTeamList : ITeamList { - public IEnumerable Teams { get; } = new[] + public IEnumerable Teams { get; } = new[] { - new Team + new Region { FlagName = "GB", FullName = "United Kingdom", Acronym = "UK" }, - new Team + new Region { FlagName = "FR", FullName = "France", Acronym = "FRA" }, - new Team + new Region { FlagName = "CN", FullName = "China", Acronym = "CHN" }, - new Team + new Region { FlagName = "AU", FullName = "Australia", Acronym = "AUS" }, - new Team + new Region { FlagName = "JP", FullName = "Japan", Acronym = "JPN" }, - new Team + new Region { FlagName = "RO", FullName = "Romania", Acronym = "ROM" }, - new Team + new Region { FlagName = "IT", FullName = "Italy", Acronym = "PIZZA" }, - new Team + new Region { FlagName = "VE", FullName = "Venezuela", Acronym = "VNZ" }, - new Team + new Region { FlagName = "US", FullName = "United States of America", diff --git a/osu.Desktop.VisualTests/Tests/TestCaseLeaderboard.cs b/osu.Desktop.VisualTests/Tests/TestCaseLeaderboard.cs index 855bf15eba..44b26d46f7 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseLeaderboard.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseLeaderboard.cs @@ -13,6 +13,7 @@ using osu.Framework.Allocation; using osu.Framework.MathUtils; using osu.Game.Screens.Select.Leaderboards; using osu.Game.Modes; +using osu.Game.Users; namespace osu.Desktop.VisualTests { @@ -38,7 +39,12 @@ namespace osu.Desktop.VisualTests { Id = 2, Username = @"peppy", - FlagName = @"AU", + Region = new Region + { + FullName = @"Australia", + Acronym = @"AUS", + FlagName = @"AU", + }, }, }); } diff --git a/osu.Game/Graphics/UserInterface/IHasDrawableRepresentation.cs b/osu.Game/Graphics/UserInterface/IHasDrawableRepresentation.cs new file mode 100644 index 0000000000..0dfddddb3f --- /dev/null +++ b/osu.Game/Graphics/UserInterface/IHasDrawableRepresentation.cs @@ -0,0 +1,12 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; + +namespace osu.Game.Graphics.UserInterface +{ + public interface IHasDrawableRepresentation where T : Drawable + { + T CreateDrawable(); + } +} diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 19d137d0e2..6acdc17996 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -1,25 +1,18 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; using OpenTK; -using OpenTK.Graphics; +using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Colour; -using osu.Game.Graphics; using osu.Game.Modes; -using osu.Framework.Graphics.Textures; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Primitives; -using osu.Framework.Graphics.Transforms; namespace osu.Game.Screens.Select.Leaderboards { public class Leaderboard : Container { private ScrollContainer scrollContainer; - private FillFlowContainer scrollFlow; + private FillFlowContainer scrollFlow; private Score[] scores; public Score[] Scores @@ -30,10 +23,10 @@ namespace osu.Game.Screens.Select.Leaderboards if (value == scores) return; scores = value; - var scoreDisplays = new List(); + var scoreDisplays = new List(); for (int i = 0; i < value.Length; i++) { - scoreDisplays.Add(new LeaderboardScoreDisplay(value[i], i + 1)); + scoreDisplays.Add(new LeaderboardScore(value[i], i + 1)); } scrollFlow.Children = scoreDisplays; @@ -51,7 +44,7 @@ namespace osu.Game.Screens.Select.Leaderboards ScrollDraggerVisible = false, Children = new Drawable[] { - scrollFlow = new FillFlowContainer + scrollFlow = new FillFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScoreDisplay.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs similarity index 88% rename from osu.Game/Screens/Select/Leaderboards/LeaderboardScoreDisplay.cs rename to osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index c9242a9ba3..82eae852a4 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScoreDisplay.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -13,15 +13,16 @@ using osu.Game.Graphics.Sprites; using osu.Game.Modes; using osu.Framework.Graphics.Textures; using osu.Framework.Allocation; +using System.Linq; namespace osu.Game.Screens.Select.Leaderboards { - public class LeaderboardScoreDisplay : Container + public class LeaderboardScore : Container { private const float height = 70; private const float corner_radius = 5; private const float edge_margin = 10; - private const float background_opacity = 0.25f; + private const float background_alpha = 0.25f; private const float score_letter_size = 20f; private readonly EdgeEffect imageShadow = new EdgeEffect @@ -33,7 +34,7 @@ namespace osu.Game.Screens.Select.Leaderboards private Box background; private Container content; - private Sprite avatar, flag; + private Sprite avatar; private FillFlowContainer modsContainer; private readonly int index; @@ -43,18 +44,17 @@ namespace osu.Game.Screens.Select.Leaderboards private void load(TextureStore textures) { avatar.Texture = textures.Get($@"https://a.ppy.sh/{Score.User.Id}") ?? textures.Get(@"Online/avatar-guest"); - flag.Texture = textures.Get($@"Flags/{Score.User.FlagName}"); } protected override bool OnHover(Framework.Input.InputState state) { - background.FadeColour(Color4.Black.Opacity(0.5f), 300, EasingTypes.OutQuint); + background.FadeTo(0.5f, 300, EasingTypes.OutQuint); return base.OnHover(state); } protected override void OnHoverLost(Framework.Input.InputState state) { - background.FadeColour(Color4.Black.Opacity(background_opacity), 200, EasingTypes.OutQuint); + background.FadeTo(background_alpha, 200, EasingTypes.OutQuint); base.OnHoverLost(state); } @@ -73,7 +73,7 @@ namespace osu.Game.Screens.Select.Leaderboards }); } - public LeaderboardScoreDisplay(Score score, int i) + public LeaderboardScore(Score score, int i) { Score = score; index = i; @@ -81,6 +81,10 @@ namespace osu.Game.Screens.Select.Leaderboards RelativeSizeAxes = Axes.X; Height = height; + var flag = Score.User.Region.CreateDrawable(); + flag.Width = 30; + flag.RelativeSizeAxes = Axes.Y; + Children = new Drawable[] { new Container @@ -115,7 +119,8 @@ namespace osu.Game.Screens.Select.Leaderboards background = new Box { RelativeSizeAxes = Axes.Both, - Colour = Color4.Black.Opacity(background_opacity), + Colour = Color4.Black, + Alpha = background_alpha, }, }, }, @@ -167,18 +172,7 @@ namespace osu.Game.Screens.Select.Leaderboards Masking = true, Children = new Drawable[] { - flag = new Sprite - { - RelativeSizeAxes = Axes.Y, - Width = 30f, - }, - new Sprite - { - Origin = Anchor.BottomRight, - Anchor = Anchor.BottomRight, - RelativeSizeAxes = Axes.Y, - Width = 50f, - }, + flag, }, }, new FillFlowContainer diff --git a/osu.Game/Screens/Tournament/Drawings.cs b/osu.Game/Screens/Tournament/Drawings.cs index f9155bbc2a..b6a304c699 100644 --- a/osu.Game/Screens/Tournament/Drawings.cs +++ b/osu.Game/Screens/Tournament/Drawings.cs @@ -21,6 +21,7 @@ using osu.Game.Screens.Tournament.Components; using osu.Game.Screens.Tournament.Teams; using OpenTK; using OpenTK.Graphics; +using osu.Game.Users; namespace osu.Game.Screens.Tournament { @@ -36,7 +37,7 @@ namespace osu.Game.Screens.Tournament private GroupContainer groupsContainer; private OsuSpriteText fullTeamNameText; - private List allTeams = new List(); + private List allTeams = new List(); private DrawingsConfigManager drawingsConfig; @@ -238,7 +239,7 @@ namespace osu.Game.Screens.Tournament reset(true); } - private void onTeamSelected(Team team) + private void onTeamSelected(Region team) { groupsContainer.AddTeam(team); @@ -278,13 +279,13 @@ namespace osu.Game.Screens.Tournament teamsContainer.ClearTeams(); allTeams.Clear(); - foreach (Team t in TeamList.Teams) + foreach (Region r in TeamList.Teams) { - if (groupsContainer.ContainsTeam(t.FullName)) + if (groupsContainer.ContainsTeam(r.FullName)) continue; - allTeams.Add(t); - teamsContainer.AddTeam(t); + allTeams.Add(r); + teamsContainer.AddTeam(r); } } @@ -314,7 +315,7 @@ namespace osu.Game.Screens.Tournament if (line.ToUpper().StartsWith("GROUP")) continue; - Team teamToAdd = allTeams.FirstOrDefault(t => t.FullName == line); + Region teamToAdd = allTeams.FirstOrDefault(r => r.FullName == line); if (teamToAdd == null) continue; diff --git a/osu.Game/Screens/Tournament/Group.cs b/osu.Game/Screens/Tournament/Group.cs index 44af4c8182..b2b1648684 100644 --- a/osu.Game/Screens/Tournament/Group.cs +++ b/osu.Game/Screens/Tournament/Group.cs @@ -14,6 +14,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Screens.Tournament.Teams; using OpenTK; using OpenTK.Graphics; +using osu.Game.Users; namespace osu.Game.Screens.Tournament { @@ -73,7 +74,7 @@ namespace osu.Game.Screens.Tournament }; } - public void AddTeam(Team team) + public void AddTeam(Region team) { GroupTeam gt = new GroupTeam(team); @@ -91,7 +92,7 @@ namespace osu.Game.Screens.Tournament return allTeams.Any(t => t.Team.FullName == fullName); } - public bool RemoveTeam(Team team) + public bool RemoveTeam(Region team) { allTeams.RemoveAll(gt => gt.Team == team); @@ -122,12 +123,12 @@ namespace osu.Game.Screens.Tournament class GroupTeam : Container { - public Team Team; + public Region Team; private FillFlowContainer innerContainer; private Sprite flagSprite; - public GroupTeam(Team team) + public GroupTeam(Region team) { Team = team; diff --git a/osu.Game/Screens/Tournament/GroupContainer.cs b/osu.Game/Screens/Tournament/GroupContainer.cs index 936881b47c..fd27fcf520 100644 --- a/osu.Game/Screens/Tournament/GroupContainer.cs +++ b/osu.Game/Screens/Tournament/GroupContainer.cs @@ -6,6 +6,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Screens.Tournament.Teams; using OpenTK; +using osu.Game.Users; namespace osu.Game.Screens.Tournament { @@ -61,7 +62,7 @@ namespace osu.Game.Screens.Tournament } } - public void AddTeam(Team team) + public void AddTeam(Region team) { if (groups[currentGroup].TeamsCount == maxTeams) return; diff --git a/osu.Game/Screens/Tournament/ScrollingTeamContainer.cs b/osu.Game/Screens/Tournament/ScrollingTeamContainer.cs index 35369247ff..feaf8f53b6 100644 --- a/osu.Game/Screens/Tournament/ScrollingTeamContainer.cs +++ b/osu.Game/Screens/Tournament/ScrollingTeamContainer.cs @@ -12,18 +12,18 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Transforms; using osu.Framework.Threading; -using osu.Game.Screens.Tournament.Teams; using OpenTK; using OpenTK.Graphics; +using osu.Game.Users; namespace osu.Game.Screens.Tournament { public class ScrollingTeamContainer : Container { public event Action OnScrollStarted; - public event Action OnSelected; + public event Action OnSelected; - private readonly List availableTeams = new List(); + private readonly List availableTeams = new List(); private Container tracker; @@ -151,7 +151,7 @@ namespace osu.Game.Screens.Tournament } } - public void AddTeam(Team team) + public void AddTeam(Region team) { if (availableTeams.Contains(team)) return; @@ -162,12 +162,12 @@ namespace osu.Game.Screens.Tournament scrollState = ScrollState.Idle; } - public void AddTeams(IEnumerable teams) + public void AddTeams(IEnumerable teams) { if (teams == null) return; - foreach (Team t in teams) + foreach (Region t in teams) AddTeam(t); } @@ -178,7 +178,7 @@ namespace osu.Game.Screens.Tournament scrollState = ScrollState.Idle; } - public void RemoveTeam(Team team) + public void RemoveTeam(Region team) { availableTeams.Remove(team); @@ -319,7 +319,7 @@ namespace osu.Game.Screens.Tournament public const float WIDTH = 58; public const float HEIGHT = 41; - public Team Team; + public Region Team; private Sprite flagSprite; private Box outline; @@ -339,7 +339,7 @@ namespace osu.Game.Screens.Tournament } } - public ScrollingTeam(Team team) + public ScrollingTeam(Region team) { Team = team; diff --git a/osu.Game/Screens/Tournament/Teams/ITeamList.cs b/osu.Game/Screens/Tournament/Teams/ITeamList.cs index a4476b64c6..b1093968cd 100644 --- a/osu.Game/Screens/Tournament/Teams/ITeamList.cs +++ b/osu.Game/Screens/Tournament/Teams/ITeamList.cs @@ -2,11 +2,12 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using osu.Game.Users; namespace osu.Game.Screens.Tournament.Teams { public interface ITeamList { - IEnumerable Teams { get; } + IEnumerable Teams { get; } } } diff --git a/osu.Game/Screens/Tournament/Teams/StorageBackedTeamList.cs b/osu.Game/Screens/Tournament/Teams/StorageBackedTeamList.cs index 7de48dd55b..89bdb20d28 100644 --- a/osu.Game/Screens/Tournament/Teams/StorageBackedTeamList.cs +++ b/osu.Game/Screens/Tournament/Teams/StorageBackedTeamList.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using osu.Framework.Logging; using osu.Framework.Platform; +using osu.Game.Users; namespace osu.Game.Screens.Tournament.Teams { @@ -20,11 +21,11 @@ namespace osu.Game.Screens.Tournament.Teams this.storage = storage; } - public IEnumerable Teams + public IEnumerable Teams { get { - var teams = new List(); + var teams = new List(); try { @@ -52,7 +53,7 @@ namespace osu.Game.Screens.Tournament.Teams string acronym = split.Length >= 3 ? split[2].Trim() : teamName; acronym = acronym.Substring(0, Math.Min(3, acronym.Length)); - teams.Add(new Team() + teams.Add(new Region() { FlagName = flagName, FullName = teamName, diff --git a/osu.Game/Screens/Tournament/Teams/Team.cs b/osu.Game/Screens/Tournament/Teams/Team.cs deleted file mode 100644 index 226f35ec1d..0000000000 --- a/osu.Game/Screens/Tournament/Teams/Team.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -namespace osu.Game.Screens.Tournament.Teams -{ - public class Team - { - /// - /// The name of this team. - /// - public string FullName; - - /// - /// Short acronym which appears in the group boxes post-selection. - /// - public string Acronym; - - /// - /// Two-letter flag acronym (ISO 3166 standard) - /// - public string FlagName; - } -} diff --git a/osu.Game/Users/Badge.cs b/osu.Game/Users/Badge.cs new file mode 100644 index 0000000000..341d3fab1d --- /dev/null +++ b/osu.Game/Users/Badge.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Users +{ + public class Badge : IHasDrawableRepresentation + { + public string Name; + public Texture Texture; // TODO: Replace this with something better + + public Sprite CreateDrawable() + { + return new Sprite + { + Texture = Texture, + }; + } + } +} diff --git a/osu.Game/Users/Region.cs b/osu.Game/Users/Region.cs new file mode 100644 index 0000000000..99ed29ba05 --- /dev/null +++ b/osu.Game/Users/Region.cs @@ -0,0 +1,73 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Users +{ + public class Region : IHasDrawableRepresentation + { + /// + /// The name of this team. + /// + public string FullName; + + /// + /// Short acronym which appears in the group boxes post-selection. + /// + public string Acronym; + + /// + /// Two-letter flag acronym (ISO 3166 standard) + /// + public string FlagName; + + public DrawableFlag CreateDrawable() + { + return new DrawableFlag(FlagName); + } + } + + public class DrawableFlag : Container + { + private Sprite sprite; + private TextureStore textures; + + private string flagName; + public string FlagName + { + get { return flagName; } + set + { + if (value == flagName) return; + flagName = value; + sprite.Texture = textures.Get($@"Flags/{flagName}"); + } + } + + [BackgroundDependencyLoader] + private void load(TextureStore ts) + { + textures = ts; + sprite.Texture = textures.Get($@"Flags/{flagName}"); + } + + public DrawableFlag(string name) + { + flagName = name; + + Children = new Drawable[] + { + sprite = new Sprite + { + RelativeSizeAxes = Axes.Both, + }, + }; + } + } +} diff --git a/osu.Game/Users/User.cs b/osu.Game/Users/User.cs index 8301becc76..d6da17483c 100644 --- a/osu.Game/Users/User.cs +++ b/osu.Game/Users/User.cs @@ -1,16 +1,15 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; + namespace osu.Game.Users { public class User { public int Id; public string Username; - - /// - /// Two-letter flag acronym (ISO 3166 standard) - /// - public string FlagName; + public Region Region; + public IEnumerable Badges; } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index ad66e335eb..68d9e0f5d1 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -217,7 +217,6 @@ - @@ -311,7 +310,10 @@ - + + + +