public TestCaseBadgeContainer()
        {
            BadgeContainer badgeContainer;

            Child = badgeContainer = new BadgeContainer
            {
                RelativeSizeAxes = Axes.Both
            };

            AddStep("Show 1 badge", () => badgeContainer.ShowBadges(new[]
            {
                new Badge
                {
                    AwardedAt   = DateTimeOffset.Now,
                    Description = "Appreciates compasses",
                    ImageUrl    = "https://assets.ppy.sh/profile-badges/mg2018-1star.png",
                }
            }));

            AddStep("Show 2 badges", () => badgeContainer.ShowBadges(new[]
            {
                new Badge
                {
                    AwardedAt   = DateTimeOffset.Now,
                    Description = "Contributed to osu!lazer testing",
                    ImageUrl    = "https://assets.ppy.sh/profile-badges/contributor.png",
                },
                new Badge
                {
                    AwardedAt   = DateTimeOffset.Now,
                    Description = "Appreciates compasses",
                    ImageUrl    = "https://assets.ppy.sh/profile-badges/mg2018-1star.png",
                }
            }));

            AddStep("Show many badges", () => badgeContainer.ShowBadges(Enumerable.Range(1, 20).Select(i => new Badge
            {
                AwardedAt   = DateTimeOffset.Now,
                Description = $"Contributed to osu!lazer testing {i} times",
                ImageUrl    = "https://assets.ppy.sh/profile-badges/contributor.jpg",
            }).ToArray()));
        }
Exemplo n.º 2
0
        private void loadUser()
        {
            LoadComponentAsync(new UserCoverBackground(user)
            {
                RelativeSizeAxes = Axes.Both,
                Anchor           = Anchor.Centre,
                Origin           = Anchor.Centre,
                FillMode         = FillMode.Fill,
                OnLoadComplete   = d => d.FadeInFromZero(200),
                Depth            = float.MaxValue,
            }, coverContainer.Add);

            if (user.IsSupporter)
            {
                SupporterTag.Show();
            }

            if (!string.IsNullOrEmpty(user.Colour))
            {
                colourBar.Colour = OsuColour.FromHex(user.Colour);
                colourBar.Show();
            }

            void boldItalic(SpriteText t) => t.Font = @"Exo2.0-BoldItalic";
            void lightText(SpriteText t) => t.Alpha = 0.8f;

            OsuSpriteText createScoreText(string text) => new OsuSpriteText
            {
                TextSize = 14,
                Text     = text
            };

            OsuSpriteText createScoreNumberText(string text) => new OsuSpriteText
            {
                TextSize = 14,
                Font     = @"Exo2.0-Bold",
                Anchor   = Anchor.TopRight,
                Origin   = Anchor.TopRight,
                Text     = text
            };

            if (user.Country != null)
            {
                infoTextLeft.AddText("From ", lightText);
                infoTextLeft.AddText(user.Country.FullName, boldItalic);
                countryFlag.Country = user.Country;
            }

            infoTextLeft.NewParagraph();

            if (user.JoinDate.ToUniversalTime().Year < 2008)
            {
                infoTextLeft.AddText(new DrawableJoinDate(user.JoinDate), lightText);
            }
            else
            {
                infoTextLeft.AddText("Joined ", lightText);
                infoTextLeft.AddText(new DrawableJoinDate(user.JoinDate), boldItalic);
            }

            infoTextLeft.NewLine();
            infoTextLeft.AddText("Last seen ", lightText);
            infoTextLeft.AddText(new DrawableDate(user.LastVisit), boldItalic);
            infoTextLeft.NewParagraph();

            if (user.PlayStyle?.Length > 0)
            {
                infoTextLeft.AddText("Plays with ", lightText);
                infoTextLeft.AddText(string.Join(", ", user.PlayStyle), boldItalic);
            }

            infoTextLeft.NewLine();
            infoTextLeft.AddText("Contributed ", lightText);
            infoTextLeft.AddLink($@"{user.PostCount} forum posts", url: $"https://osu.ppy.sh/users/{user.Id}/posts", creationParameters: boldItalic);

            string websiteWithoutProtcol = user.Website;

            if (!string.IsNullOrEmpty(websiteWithoutProtcol))
            {
                int protocolIndex = websiteWithoutProtcol.IndexOf("//", StringComparison.Ordinal);
                if (protocolIndex >= 0)
                {
                    websiteWithoutProtcol = websiteWithoutProtcol.Substring(protocolIndex + 2);
                }
            }

            tryAddInfoRightLine(FontAwesome.fa_map_marker, user.Location);
            tryAddInfoRightLine(FontAwesome.fa_heart_o, user.Interests);
            tryAddInfoRightLine(FontAwesome.fa_suitcase, user.Occupation);
            infoTextRight.NewParagraph();
            if (!string.IsNullOrEmpty(user.Twitter))
            {
                tryAddInfoRightLine(FontAwesome.fa_twitter, "@" + user.Twitter, $@"https://twitter.com/{user.Twitter}");
            }
            tryAddInfoRightLine(FontAwesome.fa_gamepad, user.Discord);
            tryAddInfoRightLine(FontAwesome.fa_skype, user.Skype, @"skype:" + user.Skype + @"?chat");
            tryAddInfoRightLine(FontAwesome.fa_lastfm, user.Lastfm, $@"https://last.fm/users/{user.Lastfm}");
            tryAddInfoRightLine(FontAwesome.fa_globe, websiteWithoutProtcol, user.Website);

            if (user.Statistics != null)
            {
                levelBadge.Show();
                levelText.Text = user.Statistics.Level.Current.ToString();

                scoreText.Add(createScoreText("Ranked Score"));
                scoreNumberText.Add(createScoreNumberText(user.Statistics.RankedScore.ToString(@"#,0")));
                scoreText.Add(createScoreText("Accuracy"));
                scoreNumberText.Add(createScoreNumberText($"{user.Statistics.Accuracy:0.##}%"));
                scoreText.Add(createScoreText("Play Count"));
                scoreNumberText.Add(createScoreNumberText(user.Statistics.PlayCount.ToString(@"#,0")));
                scoreText.Add(createScoreText("Total Score"));
                scoreNumberText.Add(createScoreNumberText(user.Statistics.TotalScore.ToString(@"#,0")));
                scoreText.Add(createScoreText("Total Hits"));
                scoreNumberText.Add(createScoreNumberText(user.Statistics.TotalHits.ToString(@"#,0")));
                scoreText.Add(createScoreText("Max Combo"));
                scoreNumberText.Add(createScoreNumberText(user.Statistics.MaxCombo.ToString(@"#,0")));
                scoreText.Add(createScoreText("Replays Watched by Others"));
                scoreNumberText.Add(createScoreNumberText(user.Statistics.ReplaysWatched.ToString(@"#,0")));

                gradeSSPlus.DisplayCount = user.Statistics.GradesCount.SSPlus;
                gradeSSPlus.Show();
                gradeSS.DisplayCount = user.Statistics.GradesCount.SS;
                gradeSS.Show();
                gradeSPlus.DisplayCount = user.Statistics.GradesCount.SPlus;
                gradeSPlus.Show();
                gradeS.DisplayCount = user.Statistics.GradesCount.S;
                gradeS.Show();
                gradeA.DisplayCount = user.Statistics.GradesCount.A;
                gradeA.Show();

                rankGraph.User.Value = user;
            }

            badgeContainer.ShowBadges(user.Badges);
        }