From f5c652325a55402d71dfb3182dea9769906f5d1b Mon Sep 17 00:00:00 2001 From: _ltn <46729135+rltn@users.noreply.github.com> Date: Thu, 27 Apr 2023 23:44:18 +0300 Subject: [PATCH 1/8] Create UpdateableCountryText.cs --- .../Users/Drawables/UpdateableCountryText.cs | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 osu.Game/Users/Drawables/UpdateableCountryText.cs diff --git a/osu.Game/Users/Drawables/UpdateableCountryText.cs b/osu.Game/Users/Drawables/UpdateableCountryText.cs new file mode 100644 index 0000000000..60174505a5 --- /dev/null +++ b/osu.Game/Users/Drawables/UpdateableCountryText.cs @@ -0,0 +1,67 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Allocation; +using osu.Framework.Input.Events; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; +using osu.Framework.Extensions; + +namespace osu.Game.Users.Drawables +{ + public partial class UpdateableCountryText : ModelBackedDrawable + { + public CountryCode CountryCode + { + get => Model; + set => Model = value; + } + + public bool ShowPlaceholderOnUnknown = true; + + public Action? Action; + + protected override Drawable? CreateDrawable(CountryCode countryCode) + { + if (countryCode == CountryCode.Unknown && !ShowPlaceholderOnUnknown) + return null; + + return new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + new OsuSpriteText + { + Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), + Margin = new MarginPadding { Left = 5 }, + Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreLeft, + Text = countryCode.GetDescription(), + }, + new HoverClickSounds() + } + }; + } + + [Resolved] + private RankingsOverlay? rankingsOverlay { get; set; } + + public UpdateableCountryText(CountryCode countryCode = CountryCode.Unknown) + { + CountryCode = countryCode; + } + protected override bool OnClick(ClickEvent e) + { + Action?.Invoke(); + rankingsOverlay?.ShowCountry(CountryCode); + return true; + } + } + +} \ No newline at end of file From b13201fb792801e87b5a9148abd2a9ec6a011976 Mon Sep 17 00:00:00 2001 From: _ltn <46729135+rltn@users.noreply.github.com> Date: Fri, 28 Apr 2023 01:14:42 +0300 Subject: [PATCH 2/8] UpdateableCountryText rewrite --- .../Users/Drawables/UpdateableCountryText.cs | 55 ++++++------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/osu.Game/Users/Drawables/UpdateableCountryText.cs b/osu.Game/Users/Drawables/UpdateableCountryText.cs index 60174505a5..fd749da707 100644 --- a/osu.Game/Users/Drawables/UpdateableCountryText.cs +++ b/osu.Game/Users/Drawables/UpdateableCountryText.cs @@ -7,6 +7,7 @@ using osu.Framework.Input.Events; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics; +using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; @@ -14,53 +15,31 @@ using osu.Framework.Extensions; namespace osu.Game.Users.Drawables { - public partial class UpdateableCountryText : ModelBackedDrawable + public partial class UpdateableCountryText : OsuHoverContainer { - public CountryCode CountryCode - { - get => Model; - set => Model = value; - } public bool ShowPlaceholderOnUnknown = true; - public Action? Action; - - protected override Drawable? CreateDrawable(CountryCode countryCode) - { - if (countryCode == CountryCode.Unknown && !ShowPlaceholderOnUnknown) - return null; - - return new Container - { - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] - { - new OsuSpriteText - { - Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), - Margin = new MarginPadding { Left = 5 }, - Origin = Anchor.CentreLeft, - Anchor = Anchor.CentreLeft, - Text = countryCode.GetDescription(), - }, - new HoverClickSounds() - } - }; - } - [Resolved] private RankingsOverlay? rankingsOverlay { get; set; } - - public UpdateableCountryText(CountryCode countryCode = CountryCode.Unknown) + public UpdateableCountryText() { - CountryCode = countryCode; + AutoSizeAxes = Axes.Both; } - protected override bool OnClick(ClickEvent e) + + // [BackgroundDependencyLoader] + public void load(CountryCode countryCode) { - Action?.Invoke(); - rankingsOverlay?.ShowCountry(CountryCode); - return true; + Action = () => + { + rankingsOverlay?.ShowCountry(countryCode); + }; + + Child = new OsuSpriteText + { + Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), + Text = countryCode.GetDescription(), + }; } } From e9843f20665a00da524cc240a1ea307d00d548d2 Mon Sep 17 00:00:00 2001 From: _ltn <46729135+rltn@users.noreply.github.com> Date: Fri, 28 Apr 2023 01:16:50 +0300 Subject: [PATCH 3/8] replace country text object --- osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs index d04329430b..811628c3c1 100644 --- a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs @@ -38,7 +38,7 @@ namespace osu.Game.Overlays.Profile.Header private ExternalLinkButton openUserExternally = null!; private OsuSpriteText titleText = null!; private UpdateableFlag userFlag = null!; - private OsuSpriteText userCountryText = null!; + private UpdateableCountryText userCountryText = null!; private GroupBadgeFlow groupBadgeFlow = null!; private ToggleCoverButton coverToggle = null!; @@ -156,9 +156,8 @@ namespace osu.Game.Overlays.Profile.Header Size = new Vector2(28, 20), ShowPlaceholderOnUnknown = false, }, - userCountryText = new OsuSpriteText + userCountryText = new UpdateableCountryText { - Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), Margin = new MarginPadding { Left = 5 }, Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, @@ -201,7 +200,7 @@ namespace osu.Game.Overlays.Profile.Header usernameText.Text = user?.Username ?? string.Empty; openUserExternally.Link = $@"{api.WebsiteRootUrl}/users/{user?.Id ?? 0}"; userFlag.CountryCode = user?.CountryCode ?? default; - userCountryText.Text = (user?.CountryCode ?? default).GetDescription(); + userCountryText.load(user?.CountryCode ?? default); supporterTag.SupportLevel = user?.SupportLevel ?? 0; titleText.Text = user?.Title ?? string.Empty; titleText.Colour = Color4Extensions.FromHex(user?.Colour ?? "fff"); From 092377fdaa234738a79eeb409cea0e5722c154a4 Mon Sep 17 00:00:00 2001 From: _ltn <46729135+rltn@users.noreply.github.com> Date: Fri, 28 Apr 2023 01:47:14 +0300 Subject: [PATCH 4/8] moving UpdateableCountryText --- .../Profile/Header/TopHeaderContainer.cs | 41 +++++++++++++++++ .../Users/Drawables/UpdateableCountryText.cs | 46 ------------------- 2 files changed, 41 insertions(+), 46 deletions(-) delete mode 100644 osu.Game/Users/Drawables/UpdateableCountryText.cs diff --git a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs index 811628c3c1..54c84e08b8 100644 --- a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs @@ -19,6 +19,20 @@ using osu.Game.Users; using osu.Game.Users.Drawables; using osuTK; + +using System; +// using osu.Framework.Allocation; +using osu.Framework.Input.Events; +// using osu.Framework.Graphics; +// using osu.Framework.Graphics.Containers; +// using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +// using osu.Game.Graphics.Sprites; +// using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; +using osu.Framework.Graphics.Sprites; +// using osu.Framework.Extensions; + namespace osu.Game.Overlays.Profile.Header { public partial class TopHeaderContainer : CompositeDrawable @@ -158,6 +172,7 @@ namespace osu.Game.Overlays.Profile.Header }, userCountryText = new UpdateableCountryText { + Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), Margin = new MarginPadding { Left = 5 }, Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, @@ -228,5 +243,31 @@ namespace osu.Game.Overlays.Profile.Header Masking = true; } } + + private partial class UpdateableCountryText : OsuHoverContainer + { + public bool ShowPlaceholderOnUnknown = true; + public FontUsage Font = default; + [Resolved] + private RankingsOverlay? rankingsOverlay { get; set; } + public UpdateableCountryText() + { + AutoSizeAxes = Axes.Both; + } + + public void load(CountryCode countryCode) + { + Action = () => + { + rankingsOverlay?.ShowCountry(countryCode); + }; + + Child = new OsuSpriteText + { + Font = Font, + Text = countryCode.GetDescription(), + }; + } + } } } diff --git a/osu.Game/Users/Drawables/UpdateableCountryText.cs b/osu.Game/Users/Drawables/UpdateableCountryText.cs deleted file mode 100644 index fd749da707..0000000000 --- a/osu.Game/Users/Drawables/UpdateableCountryText.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using osu.Framework.Allocation; -using osu.Framework.Input.Events; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Game.Graphics; -using osu.Game.Graphics.Containers; -using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; -using osu.Game.Overlays; -using osu.Framework.Extensions; - -namespace osu.Game.Users.Drawables -{ - public partial class UpdateableCountryText : OsuHoverContainer - { - - public bool ShowPlaceholderOnUnknown = true; - - [Resolved] - private RankingsOverlay? rankingsOverlay { get; set; } - public UpdateableCountryText() - { - AutoSizeAxes = Axes.Both; - } - - // [BackgroundDependencyLoader] - public void load(CountryCode countryCode) - { - Action = () => - { - rankingsOverlay?.ShowCountry(countryCode); - }; - - Child = new OsuSpriteText - { - Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), - Text = countryCode.GetDescription(), - }; - } - } - -} \ No newline at end of file From 4d144cd5b5fb3e787fd51b75cef459bfab56fbf4 Mon Sep 17 00:00:00 2001 From: _ltn <46729135+rltn@users.noreply.github.com> Date: Fri, 28 Apr 2023 02:06:13 +0300 Subject: [PATCH 5/8] clearing the code --- .../Profile/Header/TopHeaderContainer.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs index 54c84e08b8..3485037925 100644 --- a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs @@ -9,8 +9,10 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; using osu.Game.Configuration; using osu.Game.Graphics; +using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; @@ -20,19 +22,6 @@ using osu.Game.Users.Drawables; using osuTK; -using System; -// using osu.Framework.Allocation; -using osu.Framework.Input.Events; -// using osu.Framework.Graphics; -// using osu.Framework.Graphics.Containers; -// using osu.Game.Graphics; -using osu.Game.Graphics.Containers; -// using osu.Game.Graphics.Sprites; -// using osu.Game.Graphics.UserInterface; -using osu.Game.Overlays; -using osu.Framework.Graphics.Sprites; -// using osu.Framework.Extensions; - namespace osu.Game.Overlays.Profile.Header { public partial class TopHeaderContainer : CompositeDrawable @@ -246,10 +235,12 @@ namespace osu.Game.Overlays.Profile.Header private partial class UpdateableCountryText : OsuHoverContainer { - public bool ShowPlaceholderOnUnknown = true; + public FontUsage Font = default; + [Resolved] private RankingsOverlay? rankingsOverlay { get; set; } + public UpdateableCountryText() { AutoSizeAxes = Axes.Both; From 17730f05bcf42c6af0c8876c46ae218adf71bb32 Mon Sep 17 00:00:00 2001 From: _ltn <46729135+rltn@users.noreply.github.com> Date: Fri, 28 Apr 2023 05:47:05 +0300 Subject: [PATCH 6/8] remove UpdateableCountryText --- .../Profile/Header/TopHeaderContainer.cs | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs index 3485037925..01fbf137d8 100644 --- a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs @@ -21,7 +21,6 @@ using osu.Game.Users; using osu.Game.Users.Drawables; using osuTK; - namespace osu.Game.Overlays.Profile.Header { public partial class TopHeaderContainer : CompositeDrawable @@ -41,7 +40,6 @@ namespace osu.Game.Overlays.Profile.Header private ExternalLinkButton openUserExternally = null!; private OsuSpriteText titleText = null!; private UpdateableFlag userFlag = null!; - private UpdateableCountryText userCountryText = null!; private GroupBadgeFlow groupBadgeFlow = null!; private ToggleCoverButton coverToggle = null!; @@ -204,7 +202,6 @@ namespace osu.Game.Overlays.Profile.Header usernameText.Text = user?.Username ?? string.Empty; openUserExternally.Link = $@"{api.WebsiteRootUrl}/users/{user?.Id ?? 0}"; userFlag.CountryCode = user?.CountryCode ?? default; - userCountryText.load(user?.CountryCode ?? default); supporterTag.SupportLevel = user?.SupportLevel ?? 0; titleText.Text = user?.Title ?? string.Empty; titleText.Colour = Color4Extensions.FromHex(user?.Colour ?? "fff"); @@ -232,33 +229,5 @@ namespace osu.Game.Overlays.Profile.Header Masking = true; } } - - private partial class UpdateableCountryText : OsuHoverContainer - { - - public FontUsage Font = default; - - [Resolved] - private RankingsOverlay? rankingsOverlay { get; set; } - - public UpdateableCountryText() - { - AutoSizeAxes = Axes.Both; - } - - public void load(CountryCode countryCode) - { - Action = () => - { - rankingsOverlay?.ShowCountry(countryCode); - }; - - Child = new OsuSpriteText - { - Font = Font, - Text = countryCode.GetDescription(), - }; - } - } } } From 4b0ee392f6d5bb6ec29a0c014fdc199543475e40 Mon Sep 17 00:00:00 2001 From: _ltn <46729135+rltn@users.noreply.github.com> Date: Fri, 28 Apr 2023 05:48:54 +0300 Subject: [PATCH 7/8] add OsuHoverContainer --- .../Profile/Header/TopHeaderContainer.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs index 01fbf137d8..618e487dc3 100644 --- a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs @@ -33,6 +33,9 @@ namespace osu.Game.Overlays.Profile.Header [Resolved] private IAPIProvider api { get; set; } = null!; + [Resolved] + private RankingsOverlay? rankingsOverlay { get; set; } + private UserCoverBackground cover = null!; private SupporterIcon supporterTag = null!; private UpdateableAvatar avatar = null!; @@ -40,6 +43,8 @@ namespace osu.Game.Overlays.Profile.Header private ExternalLinkButton openUserExternally = null!; private OsuSpriteText titleText = null!; private UpdateableFlag userFlag = null!; + private OsuHoverContainer userCountryContainer = null!; + private OsuSpriteText userCountryText = null!; private GroupBadgeFlow groupBadgeFlow = null!; private ToggleCoverButton coverToggle = null!; @@ -157,13 +162,20 @@ namespace osu.Game.Overlays.Profile.Header Size = new Vector2(28, 20), ShowPlaceholderOnUnknown = false, }, - userCountryText = new UpdateableCountryText + userCountryContainer = new OsuHoverContainer { - Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), Margin = new MarginPadding { Left = 5 }, Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, - } + AutoSizeAxes = Axes.Both, + Children = new Drawable[] + { + userCountryText = new OsuSpriteText + { + Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), + }, + }, + }, } }, } @@ -202,6 +214,8 @@ namespace osu.Game.Overlays.Profile.Header usernameText.Text = user?.Username ?? string.Empty; openUserExternally.Link = $@"{api.WebsiteRootUrl}/users/{user?.Id ?? 0}"; userFlag.CountryCode = user?.CountryCode ?? default; + userCountryText.Text = (user?.CountryCode ?? default).GetDescription(); + userCountryContainer.Action = () => rankingsOverlay?.ShowCountry(user?.CountryCode ?? default); supporterTag.SupportLevel = user?.SupportLevel ?? 0; titleText.Text = user?.Title ?? string.Empty; titleText.Colour = Color4Extensions.FromHex(user?.Colour ?? "fff"); From 2d6c0d2900be5779bc1ceea643458372c403daeb Mon Sep 17 00:00:00 2001 From: _ltn <46729135+rltn@users.noreply.github.com> Date: Fri, 28 Apr 2023 19:24:07 +0300 Subject: [PATCH 8/8] use of Child instead of Children --- .../Overlays/Profile/Header/TopHeaderContainer.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs index 618e487dc3..de678cb5d1 100644 --- a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs @@ -9,7 +9,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Containers; @@ -164,16 +163,13 @@ namespace osu.Game.Overlays.Profile.Header }, userCountryContainer = new OsuHoverContainer { - Margin = new MarginPadding { Left = 5 }, - Origin = Anchor.CentreLeft, - Anchor = Anchor.CentreLeft, AutoSizeAxes = Axes.Both, - Children = new Drawable[] + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Margin = new MarginPadding { Left = 5 }, + Child = userCountryText = new OsuSpriteText { - userCountryText = new OsuSpriteText - { - Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), - }, + Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular), }, }, }