From 5c640d15a0e15edd1749a57da7d6d537797bd4ff Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 21 Nov 2022 15:17:54 +0900 Subject: [PATCH 01/49] Stop requesting messages as part of initial chat presence --- osu.Game/Online/API/Requests/GetUpdatesRequest.cs | 1 + osu.Game/Online/Notifications/NotificationsClient.cs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/API/Requests/GetUpdatesRequest.cs b/osu.Game/Online/API/Requests/GetUpdatesRequest.cs index ce2689d262..529c579996 100644 --- a/osu.Game/Online/API/Requests/GetUpdatesRequest.cs +++ b/osu.Game/Online/API/Requests/GetUpdatesRequest.cs @@ -25,6 +25,7 @@ namespace osu.Game.Online.API.Requests var req = base.CreateWebRequest(); if (channel != null) req.AddParameter(@"channel", channel.Id.ToString()); req.AddParameter(@"since", since.ToString()); + req.AddParameter(@"includes[]", "presence"); return req; } diff --git a/osu.Game/Online/Notifications/NotificationsClient.cs b/osu.Game/Online/Notifications/NotificationsClient.cs index 6198707111..5654fa6396 100644 --- a/osu.Game/Online/Notifications/NotificationsClient.cs +++ b/osu.Game/Online/Notifications/NotificationsClient.cs @@ -67,8 +67,11 @@ namespace osu.Game.Online.Notifications protected void HandleChannelParted(Channel channel) => ChannelParted?.Invoke(channel); - protected void HandleMessages(List messages) + protected void HandleMessages(List? messages) { + if (messages == null) + return; + NewMessages?.Invoke(messages); lastMessageId = Math.Max(lastMessageId, messages.LastOrDefault()?.Id ?? 0); } From efd73ea9dac00cc875cd91560df520c0c2797fdb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 21 Nov 2022 15:22:57 +0900 Subject: [PATCH 02/49] Rename method to suit better --- osu.Game/Online/Notifications/NotificationsClient.cs | 4 ++-- osu.Game/Tests/PollingNotificationsClient.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/Notifications/NotificationsClient.cs b/osu.Game/Online/Notifications/NotificationsClient.cs index 5654fa6396..5762e0e588 100644 --- a/osu.Game/Online/Notifications/NotificationsClient.cs +++ b/osu.Game/Online/Notifications/NotificationsClient.cs @@ -33,11 +33,11 @@ namespace osu.Game.Online.Notifications public override Task ConnectAsync(CancellationToken cancellationToken) { - API.Queue(CreateFetchMessagesRequest(0)); + API.Queue(CreateInitialFetchRequest(0)); return Task.CompletedTask; } - protected APIRequest CreateFetchMessagesRequest(long? lastMessageId = null) + protected APIRequest CreateInitialFetchRequest(long? lastMessageId = null) { var fetchReq = new GetUpdatesRequest(lastMessageId ?? this.lastMessageId); diff --git a/osu.Game/Tests/PollingNotificationsClient.cs b/osu.Game/Tests/PollingNotificationsClient.cs index c1f032a647..571a7a1ed1 100644 --- a/osu.Game/Tests/PollingNotificationsClient.cs +++ b/osu.Game/Tests/PollingNotificationsClient.cs @@ -24,7 +24,7 @@ namespace osu.Game.Tests { while (!cancellationToken.IsCancellationRequested) { - await API.PerformAsync(CreateFetchMessagesRequest()); + await API.PerformAsync(CreateInitialFetchRequest()); await Task.Delay(1000, cancellationToken); } }, cancellationToken); From 462a213ffc616a3c92569776d66d28d7f569a311 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 21 Nov 2022 15:23:04 +0900 Subject: [PATCH 03/49] Add TODO note about handling initial silences --- osu.Game/Online/API/Requests/GetUpdatesResponse.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Online/API/Requests/GetUpdatesResponse.cs b/osu.Game/Online/API/Requests/GetUpdatesResponse.cs index 61f6a8664d..7e030ce922 100644 --- a/osu.Game/Online/API/Requests/GetUpdatesResponse.cs +++ b/osu.Game/Online/API/Requests/GetUpdatesResponse.cs @@ -16,5 +16,7 @@ namespace osu.Game.Online.API.Requests [JsonProperty] public List Messages; + + // TODO: Handle Silences here (will need to add to includes[] in the request). } } From 4084a2b0669509433826e2676711c000a3be2b9a Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Mon, 21 Nov 2022 18:57:59 -0800 Subject: [PATCH 04/49] Highlight `ChatLine` username on hover --- osu.Game/Overlays/Chat/ChatLine.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index a991103fac..af5fa89ca1 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -23,6 +23,7 @@ using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; using osuTK; using osuTK.Graphics; +using osu.Framework.Input.Events; namespace osu.Game.Overlays.Chat { @@ -291,6 +292,20 @@ namespace osu.Game.Overlays.Chat return items.ToArray(); } } + + protected override bool OnHover(HoverEvent e) + { + this.FadeColour(new Color4(1.4f, 1.4f, 1.4f, 1), 150, Easing.OutQuint); + + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + base.OnHoverLost(e); + + this.FadeColour(Color4.White, 250, Easing.OutQuint); + } } private static readonly Color4[] username_colours = From a2b505f4c09f94854a5ef3f6dedc831ad6452a3c Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Tue, 22 Nov 2022 00:31:22 -0800 Subject: [PATCH 05/49] Use a direct `Lighten` instead of >1f Color4 values --- osu.Game/Overlays/Chat/ChatLine.cs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index af5fa89ca1..bfbffabd2b 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -61,6 +61,8 @@ namespace osu.Game.Overlays.Chat private OsuSpriteText username = null!; + private Drawable usernameColouredDrawable = null!; + private Container? highlight; private readonly Bindable prefer24HourTime = new Bindable(); @@ -89,6 +91,10 @@ namespace osu.Game.Overlays.Chat ? Color4Extensions.FromHex(message.Sender.Colour) : username_colours[message.Sender.Id % username_colours.Length]; + // this can be either the username sprite text or a container + // around it depending on which branch is taken in createUsername() + var usernameDrawable = createUsername(); + InternalChild = new GridContainer { RelativeSizeAxes = Axes.X, @@ -113,13 +119,13 @@ namespace osu.Game.Overlays.Chat Colour = colourProvider?.Background1 ?? Colour4.White, AlwaysPresent = true, }, - new MessageSender(message.Sender) + new MessageSender(message.Sender, usernameColouredDrawable) { Width = UsernameWidth, AutoSizeAxes = Axes.Y, Origin = Anchor.TopRight, Anchor = Anchor.TopRight, - Child = createUsername(), + Child = usernameDrawable, Margin = new MarginPadding { Horizontal = Spacing }, }, ContentFlow = new LinkFlowContainer(t => @@ -198,7 +204,6 @@ namespace osu.Game.Overlays.Chat username = new OsuSpriteText { Shadow = false, - Colour = senderHasColour ? colours.ChatBlue : usernameColour, Truncate = true, EllipsisString = "…", Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Bold, italics: true), @@ -208,7 +213,13 @@ namespace osu.Game.Overlays.Chat }; if (!senderHasColour) + { + usernameColouredDrawable = username; + usernameColouredDrawable.Colour = usernameColour; return username; + } + + username.Colour = colours.ChatBlue; // Background effect return new Container @@ -233,7 +244,7 @@ namespace osu.Game.Overlays.Chat CornerRadius = 4, Children = new Drawable[] { - new Box + usernameColouredDrawable = new Box { RelativeSizeAxes = Axes.Both, Colour = usernameColour, @@ -252,15 +263,19 @@ namespace osu.Game.Overlays.Chat private class MessageSender : OsuClickableContainer, IHasContextMenu { private readonly APIUser sender; + private readonly Drawable colouredDrawable; + private readonly Color4 defaultColour; private Action startChatAction = null!; [Resolved] private IAPIProvider api { get; set; } = null!; - public MessageSender(APIUser sender) + public MessageSender(APIUser sender, Drawable colouredDrawable) { this.sender = sender; + this.colouredDrawable = colouredDrawable; + defaultColour = colouredDrawable.Colour; } [BackgroundDependencyLoader] @@ -295,7 +310,7 @@ namespace osu.Game.Overlays.Chat protected override bool OnHover(HoverEvent e) { - this.FadeColour(new Color4(1.4f, 1.4f, 1.4f, 1), 150, Easing.OutQuint); + colouredDrawable.FadeColour(defaultColour.Lighten(0.4f), 150, Easing.OutQuint); return base.OnHover(e); } @@ -304,7 +319,7 @@ namespace osu.Game.Overlays.Chat { base.OnHoverLost(e); - this.FadeColour(Color4.White, 250, Easing.OutQuint); + colouredDrawable.FadeColour(defaultColour, 250, Easing.OutQuint); } } From a2ea7a3f58f6177ed116bf297b9af92e017a0858 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Thu, 8 Sep 2022 02:20:48 +0800 Subject: [PATCH 06/49] show selected mod and use ILocalisedBindableString in np --- .../Online/TestSceneNowPlayingCommand.cs | 11 +++++ osu.Game/Online/Chat/NowPlayingCommand.cs | 48 +++++++++++++++---- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs b/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs index 2df9089a8a..6dbe9a71d9 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs @@ -11,6 +11,7 @@ using osu.Game.Beatmaps; using osu.Game.Online.API; using osu.Game.Online.Chat; using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; using osu.Game.Users; namespace osu.Game.Tests.Visual.Online @@ -77,6 +78,16 @@ namespace osu.Game.Tests.Visual.Online AddAssert("Check link not present", () => !postTarget.LastMessage.Contains("https://")); } + [Test] + public void TestModPresence() + { + AddStep("Add Hidden mod", () => SelectedMods.Value = new[] { Ruleset.Value.CreateInstance().CreateMod() }); + + AddStep("Run command", () => Add(new NowPlayingCommand())); + + AddAssert("Check mod is present", () => postTarget.LastMessage.Contains("+Hidden")); + } + public class PostTarget : Component, IChannelPostTarget { public void PostMessage(string text, bool isAction = false, Channel target = null) diff --git a/osu.Game/Online/Chat/NowPlayingCommand.cs b/osu.Game/Online/Chat/NowPlayingCommand.cs index 6a25ceb919..ea44bd93d8 100644 --- a/osu.Game/Online/Chat/NowPlayingCommand.cs +++ b/osu.Game/Online/Chat/NowPlayingCommand.cs @@ -1,13 +1,15 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System.Collections.Generic; +using System.Text; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Online.API; +using osu.Game.Rulesets.Mods; using osu.Game.Users; namespace osu.Game.Online.Chat @@ -15,21 +17,27 @@ namespace osu.Game.Online.Chat public class NowPlayingCommand : Component { [Resolved] - private IChannelPostTarget channelManager { get; set; } + private IChannelPostTarget channelManager { get; set; } = null!; [Resolved] - private IAPIProvider api { get; set; } + private IAPIProvider api { get; set; } = null!; [Resolved] - private Bindable currentBeatmap { get; set; } + private Bindable currentBeatmap { get; set; } = null!; - private readonly Channel target; + [Resolved] + private Bindable> selectedMods { get; set; } = null!; + + [Resolved] + private LocalisationManager localisation { get; set; } = null!; + + private readonly Channel? target; /// /// Creates a new to post the currently-playing beatmap to a parenting . /// /// The target channel to post to. If null, the currently-selected channel will be posted to. - public NowPlayingCommand(Channel target = null) + public NowPlayingCommand(Channel? target = null) { this.target = target; } @@ -59,9 +67,31 @@ namespace osu.Game.Online.Chat break; } - string beatmapString = beatmapInfo.OnlineID > 0 ? $"[{api.WebsiteRootUrl}/b/{beatmapInfo.OnlineID} {beatmapInfo}]" : beatmapInfo.ToString(); + string beatmapString() + { + string beatmapInfoString = localisation.GetLocalisedBindableString(beatmapInfo.GetDisplayTitleRomanisable()).Value; - channelManager.PostMessage($"is {verb} {beatmapString}", true, target); + return beatmapInfo.OnlineID > 0 ? $"[{api.WebsiteRootUrl}/b/{beatmapInfo.OnlineID} {beatmapInfoString}]" : beatmapInfoString; + } + + string modString() + { + if (selectedMods.Value.Count == 0) + { + return string.Empty; + } + + StringBuilder modS = new StringBuilder(); + + foreach (var mod in selectedMods.Value) + { + modS.Append($"+{mod.Name} "); + } + + return modS.ToString(); + } + + channelManager.PostMessage($"is {verb} {beatmapString()} {modString()}", true, target); Expire(); } } From 92ed2ed4eff4516b292da3ebc58969589d64103a Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sat, 26 Nov 2022 12:19:08 +0100 Subject: [PATCH 07/49] Refactor star "DifficultyRangeFilterControl" into generic range slider class --- .../TestSceneDifficultyRangeFilterControl.cs | 28 --- .../UserInterface/TestSceneRangeSlider.cs | 60 +++++ .../Graphics/UserInterface/RangeSlider.cs | 210 ++++++++++++++++++ .../Select/DifficultyRangeFilterControl.cs | 152 ------------- osu.Game/Screens/Select/FilterControl.cs | 10 +- 5 files changed, 279 insertions(+), 181 deletions(-) delete mode 100644 osu.Game.Tests/Visual/SongSelect/TestSceneDifficultyRangeFilterControl.cs create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs create mode 100644 osu.Game/Graphics/UserInterface/RangeSlider.cs delete mode 100644 osu.Game/Screens/Select/DifficultyRangeFilterControl.cs diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneDifficultyRangeFilterControl.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneDifficultyRangeFilterControl.cs deleted file mode 100644 index 7ae2c6e5e2..0000000000 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneDifficultyRangeFilterControl.cs +++ /dev/null @@ -1,28 +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 NUnit.Framework; -using osu.Framework.Graphics; -using osu.Game.Screens.Select; -using osuTK; - -namespace osu.Game.Tests.Visual.SongSelect -{ - public class TestSceneDifficultyRangeFilterControl : OsuTestScene - { - [Test] - public void TestBasic() - { - AddStep("create control", () => - { - Child = new DifficultyRangeFilterControl - { - Width = 200, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(3), - }; - }); - } - } -} diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs new file mode 100644 index 0000000000..6a8a6304c8 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs @@ -0,0 +1,60 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; +using osuTK; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneRangeSlider : OsuTestScene + { + [Cached] + private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); + + private readonly BindableNumber customStart = new BindableNumber + { + MinValue = 0, + MaxValue = 100, + Precision = 0.001f + }; + + private readonly BindableNumber customEnd = new BindableNumber(100) + { + MinValue = 0, + MaxValue = 100, + Precision = 0.1f + }; + + [Test] + public void TestBasic() + { + AddStep("create Control", () => Child = new RangeSlider + { + Width = 200, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(3), + LowerBound = customStart, + UpperBound = customEnd, + TooltipSuffix = "suffix", + NubWidth = Nub.HEIGHT * 2, + DefaultStringLowerBound = "Start", + DefaultStringUpperBound = "End" + }); + AddStep("Test Range", () => + { + customStart.Value = 50; + customEnd.Value = 75; + }); + AddStep("Test nub pushing", () => + { + customStart.Value = 90; + }); + } + } +} diff --git a/osu.Game/Graphics/UserInterface/RangeSlider.cs b/osu.Game/Graphics/UserInterface/RangeSlider.cs new file mode 100644 index 0000000000..d654adf626 --- /dev/null +++ b/osu.Game/Graphics/UserInterface/RangeSlider.cs @@ -0,0 +1,210 @@ +// 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.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Input.Events; +using osu.Framework.Localisation; +using osu.Game.Graphics.Sprites; +using osu.Game.Overlays; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Graphics.UserInterface +{ + public class RangeSlider : CompositeDrawable + { + /// + /// The lower limiting value + /// + public Bindable LowerBound + { + set => lowerBound.Current = value; + } + + /// + /// The upper limiting value + /// + public Bindable UpperBound + { + set => upperBound.Current = value; + } + + /// + /// Text that describes this RangeSlider's functionality + /// + public string Label + { + set => label.Text = value; + } + + public float NubWidth + { + set => lowerBound.NubWidth = upperBound.NubWidth = value; + } + + /// + /// Minimum difference between the lower bound and higher bound + /// + public float MinRange + { + set => minRange = value; + } + + /// + /// lower bound display for when it is set to its default value + /// + public string DefaultStringLowerBound + { + set => lowerBound.DefaultString = value; + } + + /// + /// upper bound display for when it is set to its default value + /// + public string DefaultStringUpperBound + { + set => upperBound.DefaultString = value; + } + + public LocalisableString DefaultTooltipLowerBound + { + set => lowerBound.DefaultTooltip = value; + } + + public LocalisableString DefaultTooltipUpperBound + { + set => upperBound.DefaultTooltip = value; + } + + public string TooltipSuffix + { + set => upperBound.TooltipSuffix = lowerBound.TooltipSuffix = value; + } + + private float minRange = 0.1f; + + private readonly OsuSpriteText label; + + private readonly LowerBoundSlider lowerBound; + private readonly UpperBoundSlider upperBound; + + public RangeSlider() + { + const float vertical_offset = 13; + + InternalChildren = new Drawable[] + { + label = new OsuSpriteText + { + Font = OsuFont.GetFont(size: 14), + }, + upperBound = new UpperBoundSlider + { + KeyboardStep = 0.1f, + RelativeSizeAxes = Axes.X, + Y = vertical_offset, + }, + lowerBound = new LowerBoundSlider + { + KeyboardStep = 0.1f, + RelativeSizeAxes = Axes.X, + Y = vertical_offset, + } + }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + lowerBound.Current.ValueChanged += min => upperBound.Current.Value = Math.Max(min.NewValue + minRange, upperBound.Current.Value); + upperBound.Current.ValueChanged += max => lowerBound.Current.Value = Math.Min(max.NewValue - minRange, lowerBound.Current.Value); + } + + private class LowerBoundSlider : BoundSlider + { + protected override void LoadComplete() + { + base.LoadComplete(); + + LeftBox.Height = 6; // hide any colour bleeding from overlap + + AccentColour = BackgroundColour; + BackgroundColour = Color4.Transparent; + } + + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => + base.ReceivePositionalInputAt(screenSpacePos) + && screenSpacePos.X <= Nub.ScreenSpaceDrawQuad.TopRight.X; + } + + private class UpperBoundSlider : BoundSlider + { + protected override void LoadComplete() + { + base.LoadComplete(); + + RightBox.Height = 6; // just to match the left bar height really + } + + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => + base.ReceivePositionalInputAt(screenSpacePos) + && screenSpacePos.X >= Nub.ScreenSpaceDrawQuad.TopLeft.X; + } + + protected class BoundSlider : OsuSliderBar + { + public string? DefaultString; + public LocalisableString? DefaultTooltip; + public string? TooltipSuffix; + public float NubWidth { get; set; } = Nub.HEIGHT; + + public override LocalisableString TooltipText => + (Current.IsDefault ? DefaultTooltip : Current.Value.ToString($@"0.## {TooltipSuffix}")) ?? Current.Value.ToString($@"0.## {TooltipSuffix}"); + + protected override bool OnHover(HoverEvent e) + { + base.OnHover(e); + return true; // Make sure only one nub shows hover effect at once. + } + + protected override void LoadComplete() + { + base.LoadComplete(); + Nub.Width = NubWidth; + RangePadding = Nub.Width / 2; + + OsuSpriteText currentDisplay; + + Nub.Add(currentDisplay = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Y = -0.5f, + Colour = Color4.White, + Font = OsuFont.Torus.With(size: 10), + }); + + Current.BindValueChanged(current => + { + currentDisplay.Text = (current.NewValue != Current.Default ? current.NewValue.ToString("N1") : DefaultString) ?? current.NewValue.ToString("N1"); + }, true); + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider? colourProvider) + { + if (colourProvider == null) return; + + AccentColour = colourProvider.Background2; + Nub.AccentColour = colourProvider.Background2; + Nub.GlowingAccentColour = colourProvider.Background1; + Nub.GlowColour = colourProvider.Background2; + } + } + } +} diff --git a/osu.Game/Screens/Select/DifficultyRangeFilterControl.cs b/osu.Game/Screens/Select/DifficultyRangeFilterControl.cs deleted file mode 100644 index 45e7ff4caa..0000000000 --- a/osu.Game/Screens/Select/DifficultyRangeFilterControl.cs +++ /dev/null @@ -1,152 +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.Bindables; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Input.Events; -using osu.Framework.Localisation; -using osu.Game.Configuration; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; -using osu.Game.Localisation; -using osuTK; -using osuTK.Graphics; - -namespace osu.Game.Screens.Select -{ - internal class DifficultyRangeFilterControl : CompositeDrawable - { - private Bindable lowerStars = null!; - private Bindable upperStars = null!; - - [BackgroundDependencyLoader] - private void load(OsuConfigManager config) - { - const float vertical_offset = 13; - - InternalChildren = new Drawable[] - { - new OsuSpriteText - { - Text = "Difficulty range", - Font = OsuFont.GetFont(size: 14), - }, - new MaximumStarsSlider - { - Current = config.GetBindable(OsuSetting.DisplayStarsMaximum), - KeyboardStep = 0.1f, - RelativeSizeAxes = Axes.X, - Y = vertical_offset, - }, - new MinimumStarsSlider - { - Current = config.GetBindable(OsuSetting.DisplayStarsMinimum), - KeyboardStep = 0.1f, - RelativeSizeAxes = Axes.X, - Y = vertical_offset, - } - }; - - lowerStars = config.GetBindable(OsuSetting.DisplayStarsMinimum); - upperStars = config.GetBindable(OsuSetting.DisplayStarsMaximum); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - lowerStars.ValueChanged += min => upperStars.Value = Math.Max(min.NewValue + 0.1, upperStars.Value); - upperStars.ValueChanged += max => lowerStars.Value = Math.Min(max.NewValue - 0.1, lowerStars.Value); - } - - private class MinimumStarsSlider : StarsSlider - { - public MinimumStarsSlider() - : base("0") - { - } - - public override LocalisableString TooltipText => Current.Value.ToString(@"0.## stars"); - - protected override void LoadComplete() - { - base.LoadComplete(); - - LeftBox.Height = 6; // hide any colour bleeding from overlap - - AccentColour = BackgroundColour; - BackgroundColour = Color4.Transparent; - } - - public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => - base.ReceivePositionalInputAt(screenSpacePos) - && screenSpacePos.X <= Nub.ScreenSpaceDrawQuad.TopRight.X; - } - - private class MaximumStarsSlider : StarsSlider - { - public MaximumStarsSlider() - : base("∞") - { - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - RightBox.Height = 6; // just to match the left bar height really - } - - public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => - base.ReceivePositionalInputAt(screenSpacePos) - && screenSpacePos.X >= Nub.ScreenSpaceDrawQuad.TopLeft.X; - } - - private class StarsSlider : OsuSliderBar - { - private readonly string defaultString; - - public override LocalisableString TooltipText => Current.IsDefault - ? UserInterfaceStrings.NoLimit - : Current.Value.ToString(@"0.## stars"); - - protected StarsSlider(string defaultString) - { - this.defaultString = defaultString; - } - - protected override bool OnHover(HoverEvent e) - { - base.OnHover(e); - return true; // Make sure only one nub shows hover effect at once. - } - - protected override void LoadComplete() - { - base.LoadComplete(); - Nub.Width = Nub.HEIGHT; - RangePadding = Nub.Width / 2; - - OsuSpriteText currentDisplay; - - Nub.Add(currentDisplay = new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Y = -0.5f, - Colour = Color4.White, - Font = OsuFont.Torus.With(size: 10), - }); - - Current.BindValueChanged(current => - { - currentDisplay.Text = current.NewValue != Current.Default ? current.NewValue.ToString("N1") : defaultString; - }, true); - } - } - } -} diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index ae82285fba..91ba394416 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -16,6 +16,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osu.Game.Localisation; using osu.Game.Resources.Localisation.Web; using osu.Game.Rulesets; using osu.Game.Screens.Select.Filter; @@ -172,12 +173,19 @@ namespace osu.Game.Screens.Select Height = 40, Children = new Drawable[] { - new DifficultyRangeFilterControl + new RangeSlider { Anchor = Anchor.TopLeft, Origin = Anchor.TopLeft, + Label = "Difficulty range", + LowerBound = config.GetBindable(OsuSetting.DisplayStarsMinimum), + UpperBound = config.GetBindable(OsuSetting.DisplayStarsMaximum), RelativeSizeAxes = Axes.Both, Width = 0.48f, + DefaultStringLowerBound = "0", + DefaultStringUpperBound = "∞", + DefaultTooltipUpperBound = UserInterfaceStrings.NoLimit, + TooltipSuffix = "stars" }, collectionDropdown = new CollectionDropdown { From 1ebaf4963d2cc71c8de39f473cba4d0414f6b432 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sat, 26 Nov 2022 13:59:05 +0100 Subject: [PATCH 08/49] Improve tests slightly --- .../Visual/UserInterface/TestSceneRangeSlider.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs index 6a8a6304c8..189a6b61f5 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs @@ -14,13 +14,13 @@ namespace osu.Game.Tests.Visual.UserInterface public class TestSceneRangeSlider : OsuTestScene { [Cached] - private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); + private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Red); private readonly BindableNumber customStart = new BindableNumber { MinValue = 0, MaxValue = 100, - Precision = 0.001f + Precision = 0.1f }; private readonly BindableNumber customEnd = new BindableNumber(100) @@ -44,7 +44,8 @@ namespace osu.Game.Tests.Visual.UserInterface TooltipSuffix = "suffix", NubWidth = Nub.HEIGHT * 2, DefaultStringLowerBound = "Start", - DefaultStringUpperBound = "End" + DefaultStringUpperBound = "End", + MinRange = 10 }); AddStep("Test Range", () => { From 8ecb4aa30b35256edbae8b532c7ab9f20216a955 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Sun, 27 Nov 2022 09:41:08 +0900 Subject: [PATCH 09/49] better method name --- osu.Game/Online/Chat/NowPlayingCommand.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/Chat/NowPlayingCommand.cs b/osu.Game/Online/Chat/NowPlayingCommand.cs index ea44bd93d8..63df052644 100644 --- a/osu.Game/Online/Chat/NowPlayingCommand.cs +++ b/osu.Game/Online/Chat/NowPlayingCommand.cs @@ -67,14 +67,14 @@ namespace osu.Game.Online.Chat break; } - string beatmapString() + string getBeatmapPart() { string beatmapInfoString = localisation.GetLocalisedBindableString(beatmapInfo.GetDisplayTitleRomanisable()).Value; return beatmapInfo.OnlineID > 0 ? $"[{api.WebsiteRootUrl}/b/{beatmapInfo.OnlineID} {beatmapInfoString}]" : beatmapInfoString; } - string modString() + string getModPart() { if (selectedMods.Value.Count == 0) { @@ -91,7 +91,7 @@ namespace osu.Game.Online.Chat return modS.ToString(); } - channelManager.PostMessage($"is {verb} {beatmapString()} {modString()}", true, target); + channelManager.PostMessage($"is {verb} {getBeatmapPart()} {getModPart()}", true, target); Expire(); } } From 653875bbb452e8ac9297fcc345ec7af027518c99 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Sun, 27 Nov 2022 09:41:41 +0900 Subject: [PATCH 10/49] only post mod when ingame --- osu.Game/Online/Chat/NowPlayingCommand.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Online/Chat/NowPlayingCommand.cs b/osu.Game/Online/Chat/NowPlayingCommand.cs index 63df052644..93ea597afa 100644 --- a/osu.Game/Online/Chat/NowPlayingCommand.cs +++ b/osu.Game/Online/Chat/NowPlayingCommand.cs @@ -76,6 +76,8 @@ namespace osu.Game.Online.Chat string getModPart() { + if (api.Activity.Value is UserActivity.InGame) return string.Empty; + if (selectedMods.Value.Count == 0) { return string.Empty; From 02e3ebe1a01a39fb692ac13d2c37f6c7bdbc138a Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Sun, 27 Nov 2022 09:42:55 +0900 Subject: [PATCH 11/49] DifficultyIncrease use `+` and other all `-` mod.Name to mod.Acronym --- osu.Game/Online/Chat/NowPlayingCommand.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/Chat/NowPlayingCommand.cs b/osu.Game/Online/Chat/NowPlayingCommand.cs index 93ea597afa..6d3e1ad50c 100644 --- a/osu.Game/Online/Chat/NowPlayingCommand.cs +++ b/osu.Game/Online/Chat/NowPlayingCommand.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using System.Linq; using System.Text; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -76,7 +77,7 @@ namespace osu.Game.Online.Chat string getModPart() { - if (api.Activity.Value is UserActivity.InGame) return string.Empty; + if (api.Activity.Value is not UserActivity.InGame) return string.Empty; if (selectedMods.Value.Count == 0) { @@ -85,9 +86,14 @@ namespace osu.Game.Online.Chat StringBuilder modS = new StringBuilder(); - foreach (var mod in selectedMods.Value) + foreach (var mod in selectedMods.Value.Where(mod => mod.Type == ModType.DifficultyIncrease)) { - modS.Append($"+{mod.Name} "); + modS.Append($"+{mod.Acronym} "); + } + + foreach (var mod in selectedMods.Value.Where(mod => mod.Type != ModType.DifficultyIncrease)) + { + modS.Append($"-{mod.Acronym} "); } return modS.ToString(); From 54681217be3cf85387d2673ce172e2155b01e41b Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Sun, 27 Nov 2022 10:44:06 +0900 Subject: [PATCH 12/49] fix test --- osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs b/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs index 1bd2118d5a..362ebd1e74 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs @@ -81,11 +81,13 @@ namespace osu.Game.Tests.Visual.Online [Test] public void TestModPresence() { + AddStep("Set activity", () => api.Activity.Value = new UserActivity.InSoloGame(new BeatmapInfo(), new RulesetInfo())); + AddStep("Add Hidden mod", () => SelectedMods.Value = new[] { Ruleset.Value.CreateInstance().CreateMod() }); AddStep("Run command", () => Add(new NowPlayingCommand())); - AddAssert("Check mod is present", () => postTarget.LastMessage.Contains("+Hidden")); + AddAssert("Check mod is present", () => postTarget.LastMessage.Contains("+HD")); } public partial class PostTarget : Component, IChannelPostTarget From 1a914d0df7b4e413be152327756b683f117a3d88 Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Sun, 27 Nov 2022 02:43:22 +0000 Subject: [PATCH 13/49] Remove `#nullable disable` from `TimingScreen` --- osu.Game/Screens/Edit/Timing/TimingScreen.cs | 26 +++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/osu.Game/Screens/Edit/Timing/TimingScreen.cs b/osu.Game/Screens/Edit/Timing/TimingScreen.cs index 43fca40526..4a38d64583 100644 --- a/osu.Game/Screens/Edit/Timing/TimingScreen.cs +++ b/osu.Game/Screens/Edit/Timing/TimingScreen.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Framework.Allocation; @@ -50,24 +48,24 @@ namespace osu.Game.Screens.Edit.Timing public partial class ControlPointList : CompositeDrawable { - private OsuButton deleteButton; - private ControlPointTable table; + private OsuButton deleteButton = null!; + private ControlPointTable table = null!; + private OsuScrollContainer scroll = null!; + private RoundedButton addButton = null!; private readonly IBindableList controlPointGroups = new BindableList(); - private RoundedButton addButton; + [Resolved] + private EditorClock clock { get; set; } = null!; [Resolved] - private EditorClock clock { get; set; } + protected EditorBeatmap Beatmap { get; private set; } = null!; [Resolved] - protected EditorBeatmap Beatmap { get; private set; } + private Bindable selectedGroup { get; set; } = null!; [Resolved] - private Bindable selectedGroup { get; set; } - - [Resolved(canBeNull: true)] - private IEditorChangeHandler changeHandler { get; set; } + private IEditorChangeHandler? changeHandler { get; set; } [BackgroundDependencyLoader] private void load(OverlayColourProvider colours) @@ -132,8 +130,8 @@ namespace osu.Game.Screens.Edit.Timing deleteButton.Enabled.Value = selected.NewValue != null; addButton.Text = selected.NewValue != null - ? "+ Clone to current time" - : "+ Add at current time"; + ? @"+ Clone to current time" + : @"+ Add at current time"; }, true); controlPointGroups.BindTo(Beatmap.ControlPointInfo.Groups); @@ -159,7 +157,7 @@ namespace osu.Game.Screens.Edit.Timing addButton.Enabled.Value = clock.CurrentTimeAccurate != selectedGroup.Value?.Time; } - private Type trackedType; + private Type? trackedType; /// /// Given the user has selected a control point group, we want to track any group which is From b6d7bec2405299d5d7428a40473462671e30b6be Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Sun, 27 Nov 2022 02:45:56 +0000 Subject: [PATCH 14/49] Remove `#nullable disabled` from `EditorTable` and it's derived classes --- osu.Game/Screens/Edit/EditorTable.cs | 8 +------ .../Screens/Edit/Timing/ControlPointTable.cs | 18 +++++++------- osu.Game/Screens/Edit/Verify/IssueTable.cs | 24 +++++++++---------- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/osu.Game/Screens/Edit/EditorTable.cs b/osu.Game/Screens/Edit/EditorTable.cs index f97a8c5572..f62106745b 100644 --- a/osu.Game/Screens/Edit/EditorTable.cs +++ b/osu.Game/Screens/Edit/EditorTable.cs @@ -1,8 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System; using osu.Framework.Allocation; using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; @@ -84,11 +83,6 @@ namespace osu.Game.Screens.Edit Alpha = 0, }, }; - - // todo delete - Action = () => - { - }; } private Color4 colourHover; diff --git a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs index 5c131c0b6d..7bc59c77f8 100644 --- a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs +++ b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; @@ -23,10 +21,10 @@ namespace osu.Game.Screens.Edit.Timing public partial class ControlPointTable : EditorTable { [Resolved] - private Bindable selectedGroup { get; set; } + private Bindable selectedGroup { get; set; } = null!; [Resolved] - private EditorClock clock { get; set; } + private EditorClock clock { get; set; } = null!; public const float TIMING_COLUMN_WIDTH = 230; @@ -81,8 +79,8 @@ namespace osu.Game.Screens.Edit.Timing { var columns = new List { - new TableColumn("Time", Anchor.CentreLeft, new Dimension(GridSizeMode.Absolute, TIMING_COLUMN_WIDTH)), - new TableColumn("Attributes", Anchor.CentreLeft), + new TableColumn(@"Time", Anchor.CentreLeft, new Dimension(GridSizeMode.Absolute, TIMING_COLUMN_WIDTH)), + new TableColumn(@"Attributes", Anchor.CentreLeft), }; return columns.ToArray(); @@ -162,12 +160,13 @@ namespace osu.Game.Screens.Edit.Timing .Where(matchFunction) .Select(createAttribute) .Where(c => c != null) + .Select(c => c!) // arbitrary ordering to make timing points first. // probably want to explicitly define order in the future. .OrderByDescending(c => c.GetType().Name); } - private Drawable createAttribute(ControlPoint controlPoint) + private Drawable? createAttribute(ControlPoint controlPoint) { switch (controlPoint) { @@ -182,9 +181,10 @@ namespace osu.Game.Screens.Edit.Timing case SampleControlPoint sample: return new SampleRowAttribute(sample); - } - return null; + default: + return null; + } } } } diff --git a/osu.Game/Screens/Edit/Verify/IssueTable.cs b/osu.Game/Screens/Edit/Verify/IssueTable.cs index 6fdf9c76e2..3c72815d1f 100644 --- a/osu.Game/Screens/Edit/Verify/IssueTable.cs +++ b/osu.Game/Screens/Edit/Verify/IssueTable.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; @@ -20,19 +18,19 @@ namespace osu.Game.Screens.Edit.Verify { public partial class IssueTable : EditorTable { - [Resolved] - private VerifyScreen verify { get; set; } - - private Bindable selectedIssue; + private Bindable selectedIssue = null!; [Resolved] - private EditorClock clock { get; set; } + private VerifyScreen verify { get; set; } = null!; [Resolved] - private EditorBeatmap editorBeatmap { get; set; } + private EditorClock clock { get; set; } = null!; [Resolved] - private Editor editor { get; set; } + private EditorBeatmap editorBeatmap { get; set; } = null!; + + [Resolved] + private Editor editor { get; set; } = null!; public IEnumerable Issues { @@ -88,10 +86,10 @@ namespace osu.Game.Screens.Edit.Verify var columns = new List { new TableColumn(string.Empty, Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize)), - new TableColumn("Type", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 60)), - new TableColumn("Time", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 60)), - new TableColumn("Message", Anchor.CentreLeft), - new TableColumn("Category", Anchor.CentreRight, new Dimension(GridSizeMode.AutoSize)), + new TableColumn(@"Type", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 60)), + new TableColumn(@"Time", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 60)), + new TableColumn(@"Message", Anchor.CentreLeft), + new TableColumn(@"Category", Anchor.CentreRight, new Dimension(GridSizeMode.AutoSize)), }; return columns.ToArray(); From 792334a1902e8ea80a18b0d1a232c1ade5c4638d Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Sun, 27 Nov 2022 02:47:02 +0000 Subject: [PATCH 15/49] Move Control Group timing data into it's own component --- .../Screens/Edit/Timing/ControlPointTable.cs | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs index 7bc59c77f8..e8fd71afa3 100644 --- a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs +++ b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs @@ -90,32 +90,38 @@ namespace osu.Game.Screens.Edit.Timing { return new Drawable[] { - new FillFlowContainer - { - RelativeSizeAxes = Axes.Y, - Width = TIMING_COLUMN_WIDTH, - Spacing = new Vector2(5), - Children = new Drawable[] - { - new OsuSpriteText - { - Text = group.Time.ToEditorFormattedString(), - Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold), - Width = 70, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - }, - new ControlGroupAttributes(group, c => c is TimingControlPoint) - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - } - } - }, - new ControlGroupAttributes(group, c => !(c is TimingControlPoint)) + new ControlGroupTiming(group), + new ControlGroupAttributes(group, c => c is not TimingControlPoint) }; } + private partial class ControlGroupTiming : FillFlowContainer + { + public ControlGroupTiming(ControlPointGroup group) + { + Name = @"ControlGroupTiming"; + RelativeSizeAxes = Axes.Y; + Width = TIMING_COLUMN_WIDTH; + Spacing = new Vector2(5); + Children = new Drawable[] + { + new OsuSpriteText + { + Text = group.Time.ToEditorFormattedString(), + Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold), + Width = 70, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }, + new ControlGroupAttributes(group, c => c is TimingControlPoint) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + } + }; + } + } + private partial class ControlGroupAttributes : CompositeDrawable { private readonly Func matchFunction; @@ -130,6 +136,7 @@ namespace osu.Game.Screens.Edit.Timing AutoSizeAxes = Axes.X; RelativeSizeAxes = Axes.Y; + Name = @"ControlGroupAttributes"; InternalChild = fill = new FillFlowContainer { From 3c56b9c93a24638907466361adf45919713bcbfb Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Sun, 27 Nov 2022 02:47:54 +0000 Subject: [PATCH 16/49] Add `OnRowSelected` event to `EditorTable` --- osu.Game/Screens/Edit/EditorTable.cs | 13 +++++++++++++ osu.Game/Screens/Edit/Timing/ControlPointTable.cs | 8 +------- osu.Game/Screens/Edit/Timing/TimingScreen.cs | 4 +++- osu.Game/Screens/Edit/Verify/IssueTable.cs | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Edit/EditorTable.cs b/osu.Game/Screens/Edit/EditorTable.cs index f62106745b..7b607e9afc 100644 --- a/osu.Game/Screens/Edit/EditorTable.cs +++ b/osu.Game/Screens/Edit/EditorTable.cs @@ -19,6 +19,8 @@ namespace osu.Game.Screens.Edit { public abstract partial class EditorTable : TableContainer { + public event Action? OnRowSelected; + private const float horizontal_inset = 20; protected const float ROW_HEIGHT = 25; @@ -44,6 +46,17 @@ namespace osu.Game.Screens.Edit }); } + protected void SetRowSelected(object? item) + { + foreach (var b in BackgroundFlow) + { + b.Selected = ReferenceEquals(b.Item, item); + + if (b.Selected) + OnRowSelected?.Invoke(b); + } + } + protected override Drawable CreateHeader(int index, TableColumn column) => new HeaderText(column?.Header ?? default); private partial class HeaderText : OsuSpriteText diff --git a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs index e8fd71afa3..464a8e92ad 100644 --- a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs +++ b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs @@ -63,17 +63,11 @@ namespace osu.Game.Screens.Edit.Timing selectedGroup.BindValueChanged(_ => { - // TODO: This should scroll the selected row into view. updateSelectedGroup(); }, true); } - private void updateSelectedGroup() - { - // TODO: This should scroll the selected row into view. - foreach (var b in BackgroundFlow) - b.Selected = ReferenceEquals(b.Item, selectedGroup?.Value); - } + private void updateSelectedGroup() => SetRowSelected(selectedGroup?.Value); private TableColumn[] createHeaders() { diff --git a/osu.Game/Screens/Edit/Timing/TimingScreen.cs b/osu.Game/Screens/Edit/Timing/TimingScreen.cs index 4a38d64583..2c40add77c 100644 --- a/osu.Game/Screens/Edit/Timing/TimingScreen.cs +++ b/osu.Game/Screens/Edit/Timing/TimingScreen.cs @@ -86,7 +86,7 @@ namespace osu.Game.Screens.Edit.Timing RelativeSizeAxes = Axes.Y, Width = ControlPointTable.TIMING_COLUMN_WIDTH + margins, }, - new OsuScrollContainer + scroll = new OsuScrollContainer { RelativeSizeAxes = Axes.Both, Child = table = new ControlPointTable(), @@ -140,6 +140,8 @@ namespace osu.Game.Screens.Edit.Timing table.ControlGroups = controlPointGroups; changeHandler?.SaveState(); }, true); + + table.OnRowSelected += (drawable) => scroll.ScrollIntoView(drawable); } protected override bool OnClick(ClickEvent e) diff --git a/osu.Game/Screens/Edit/Verify/IssueTable.cs b/osu.Game/Screens/Edit/Verify/IssueTable.cs index 3c72815d1f..75e7c2e43d 100644 --- a/osu.Game/Screens/Edit/Verify/IssueTable.cs +++ b/osu.Game/Screens/Edit/Verify/IssueTable.cs @@ -77,7 +77,7 @@ namespace osu.Game.Screens.Edit.Verify selectedIssue = verify.SelectedIssue.GetBoundCopy(); selectedIssue.BindValueChanged(issue => { - foreach (var b in BackgroundFlow) b.Selected = b.Item == issue.NewValue; + SetRowSelected(issue); }, true); } From 8dcd1a206713f375adde35d6adb80efc9685a29a Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Sun, 27 Nov 2022 02:48:15 +0000 Subject: [PATCH 17/49] Add test to verify selected timing point will be scrolled into view --- .../Visual/Editing/TestSceneTimingScreen.cs | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTimingScreen.cs b/osu.Game.Tests/Visual/Editing/TestSceneTimingScreen.cs index 86a977fd3f..216c35de65 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneTimingScreen.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneTimingScreen.cs @@ -10,6 +10,8 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Testing; +using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Graphics.Containers; using osu.Game.Overlays; using osu.Game.Rulesets.Edit; using osu.Game.Screens.Edit; @@ -26,6 +28,7 @@ namespace osu.Game.Tests.Visual.Editing private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); private TimingScreen timingScreen; + private EditorBeatmap editorBeatmap; protected override bool ScrollUsingMouseWheel => false; @@ -35,8 +38,11 @@ namespace osu.Game.Tests.Visual.Editing Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value); Beatmap.Disabled = true; + } - var editorBeatmap = new EditorBeatmap(Beatmap.Value.GetPlayableBeatmap(Ruleset.Value)); + private void reloadEditorBeatmap() + { + editorBeatmap = new EditorBeatmap(Beatmap.Value.GetPlayableBeatmap(Ruleset.Value)); Child = new DependencyProvidingContainer { @@ -58,7 +64,9 @@ namespace osu.Game.Tests.Visual.Editing { AddStep("Stop clock", () => EditorClock.Stop()); - AddUntilStep("wait for rows to load", () => Child.ChildrenOfType().Any()); + AddStep("Reload Editor Beatmap", reloadEditorBeatmap); + + AddUntilStep("Wait for rows to load", () => Child.ChildrenOfType().Any()); } [Test] @@ -95,6 +103,37 @@ namespace osu.Game.Tests.Visual.Editing AddUntilStep("Selection changed", () => timingScreen.SelectedGroup.Value.Time == 69670); } + [Test] + public void TestScrollControlGroupIntoView() + { + AddStep("Add many control points", () => + { + editorBeatmap.ControlPointInfo.Clear(); + + editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint()); + + for (int i = 0; i < 100; i++) + { + editorBeatmap.ControlPointInfo.Add((i + 1) * 1000, new EffectControlPoint + { + KiaiMode = Convert.ToBoolean(i % 2), + }); + } + }); + + AddStep("Select first effect point", () => + { + InputManager.MoveMouseTo(Child.ChildrenOfType().First()); + InputManager.Click(MouseButton.Left); + }); + + AddStep("Seek to beginning", () => EditorClock.Seek(0)); + + AddStep("Seek to last point", () => EditorClock.Seek(101 * 1000)); + + AddUntilStep("Scrolled to end", () => timingScreen.ChildrenOfType().First().IsScrolledToEnd()); + } + protected override void Dispose(bool isDisposing) { Beatmap.Disabled = false; From 6000e146681d2feb5423addf7dbbd8edeffa99e6 Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Sun, 27 Nov 2022 03:08:54 +0000 Subject: [PATCH 18/49] Correctly select issue row --- osu.Game/Screens/Edit/Verify/IssueTable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Verify/IssueTable.cs b/osu.Game/Screens/Edit/Verify/IssueTable.cs index 75e7c2e43d..d78108b026 100644 --- a/osu.Game/Screens/Edit/Verify/IssueTable.cs +++ b/osu.Game/Screens/Edit/Verify/IssueTable.cs @@ -77,7 +77,7 @@ namespace osu.Game.Screens.Edit.Verify selectedIssue = verify.SelectedIssue.GetBoundCopy(); selectedIssue.BindValueChanged(issue => { - SetRowSelected(issue); + SetRowSelected(issue.NewValue); }, true); } From 218c04c1749ea4a591bee3ad7b3c1b3fc8ecf57d Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Sun, 27 Nov 2022 03:23:08 +0000 Subject: [PATCH 19/49] Code quality --- osu.Game/Screens/Edit/EditorTable.cs | 2 +- osu.Game/Screens/Edit/Timing/ControlPointTable.cs | 4 ++-- osu.Game/Screens/Edit/Timing/TimingScreen.cs | 2 +- osu.Game/Screens/Edit/Verify/IssueTable.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Edit/EditorTable.cs b/osu.Game/Screens/Edit/EditorTable.cs index 7b607e9afc..2443cfcbf0 100644 --- a/osu.Game/Screens/Edit/EditorTable.cs +++ b/osu.Game/Screens/Edit/EditorTable.cs @@ -57,7 +57,7 @@ namespace osu.Game.Screens.Edit } } - protected override Drawable CreateHeader(int index, TableColumn column) => new HeaderText(column?.Header ?? default); + protected override Drawable CreateHeader(int index, TableColumn? column) => new HeaderText(column?.Header ?? default); private partial class HeaderText : OsuSpriteText { diff --git a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs index 464a8e92ad..b3cc41af72 100644 --- a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs +++ b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs @@ -35,7 +35,7 @@ namespace osu.Game.Screens.Edit.Timing Content = null; BackgroundFlow.Clear(); - if (value?.Any() != true) + if (!value.Any()) return; foreach (var group in value) @@ -67,7 +67,7 @@ namespace osu.Game.Screens.Edit.Timing }, true); } - private void updateSelectedGroup() => SetRowSelected(selectedGroup?.Value); + private void updateSelectedGroup() => SetRowSelected(selectedGroup.Value); private TableColumn[] createHeaders() { diff --git a/osu.Game/Screens/Edit/Timing/TimingScreen.cs b/osu.Game/Screens/Edit/Timing/TimingScreen.cs index 2c40add77c..69eff776e6 100644 --- a/osu.Game/Screens/Edit/Timing/TimingScreen.cs +++ b/osu.Game/Screens/Edit/Timing/TimingScreen.cs @@ -141,7 +141,7 @@ namespace osu.Game.Screens.Edit.Timing changeHandler?.SaveState(); }, true); - table.OnRowSelected += (drawable) => scroll.ScrollIntoView(drawable); + table.OnRowSelected += drawable => scroll.ScrollIntoView(drawable); } protected override bool OnClick(ClickEvent e) diff --git a/osu.Game/Screens/Edit/Verify/IssueTable.cs b/osu.Game/Screens/Edit/Verify/IssueTable.cs index d78108b026..b37fb2b72d 100644 --- a/osu.Game/Screens/Edit/Verify/IssueTable.cs +++ b/osu.Game/Screens/Edit/Verify/IssueTable.cs @@ -39,7 +39,7 @@ namespace osu.Game.Screens.Edit.Verify Content = null; BackgroundFlow.Clear(); - if (value == null) + if (!value.Any()) return; foreach (var issue in value) From db7f429e39b892226a30c62cd2635104e14e21af Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sun, 27 Nov 2022 10:44:05 +0100 Subject: [PATCH 20/49] Fix partial class issues and adjust test slightly --- .../Visual/UserInterface/TestSceneRangeSlider.cs | 2 +- osu.Game/Graphics/UserInterface/RangeSlider.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs index 189a6b61f5..d0e3ff737c 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs @@ -11,7 +11,7 @@ using osuTK; namespace osu.Game.Tests.Visual.UserInterface { - public class TestSceneRangeSlider : OsuTestScene + public partial class TestSceneRangeSlider : OsuTestScene { [Cached] private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Red); diff --git a/osu.Game/Graphics/UserInterface/RangeSlider.cs b/osu.Game/Graphics/UserInterface/RangeSlider.cs index d654adf626..c8306b70fb 100644 --- a/osu.Game/Graphics/UserInterface/RangeSlider.cs +++ b/osu.Game/Graphics/UserInterface/RangeSlider.cs @@ -15,7 +15,7 @@ using osuTK.Graphics; namespace osu.Game.Graphics.UserInterface { - public class RangeSlider : CompositeDrawable + public partial class RangeSlider : CompositeDrawable { /// /// The lower limiting value @@ -125,7 +125,7 @@ namespace osu.Game.Graphics.UserInterface upperBound.Current.ValueChanged += max => lowerBound.Current.Value = Math.Min(max.NewValue - minRange, lowerBound.Current.Value); } - private class LowerBoundSlider : BoundSlider + private partial class LowerBoundSlider : BoundSlider { protected override void LoadComplete() { @@ -142,7 +142,7 @@ namespace osu.Game.Graphics.UserInterface && screenSpacePos.X <= Nub.ScreenSpaceDrawQuad.TopRight.X; } - private class UpperBoundSlider : BoundSlider + private partial class UpperBoundSlider : BoundSlider { protected override void LoadComplete() { @@ -156,7 +156,7 @@ namespace osu.Game.Graphics.UserInterface && screenSpacePos.X >= Nub.ScreenSpaceDrawQuad.TopLeft.X; } - protected class BoundSlider : OsuSliderBar + protected partial class BoundSlider : OsuSliderBar { public string? DefaultString; public LocalisableString? DefaultTooltip; From ba1717c2ca9710dbaaf4ab146d7c51fd018f3abb Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 29 Nov 2022 02:36:27 +0300 Subject: [PATCH 21/49] Don't draw 0 thickness triangles --- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 6e9e7591a8..ed9b6019f1 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -256,7 +256,7 @@ namespace osu.Game.Graphics.Backgrounds { base.Draw(renderer); - if (Source.AimCount == 0) + if (Source.AimCount == 0 || thickness == 0) return; if (vertexBatch == null || vertexBatch.Size != Source.AimCount) From 3e277a92e963bb709e22a3625edae25dc9f2f4b5 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 29 Nov 2022 03:21:59 +0300 Subject: [PATCH 22/49] Fix incorrect texel size calculation --- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 30 ++++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index ed9b6019f1..6e6514690d 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -227,6 +227,9 @@ namespace osu.Game.Graphics.Backgrounds private Texture texture = null!; private readonly List parts = new List(); + + private readonly Vector2 triangleSize = new Vector2(1f, equilateral_triangle_ratio) * triangle_size; + private Vector2 size; private float thickness; private float texelSize; @@ -246,7 +249,15 @@ namespace osu.Game.Graphics.Backgrounds texture = Source.texture; size = Source.DrawSize; thickness = Source.Thickness; - texelSize = Math.Max(1.5f / Source.ScreenSpaceDrawQuad.Size.X, 1.5f / Source.ScreenSpaceDrawQuad.Size.Y); + + Quad triangleQuad = new Quad( + Vector2Extensions.Transform(Vector2.Zero, DrawInfo.Matrix), + Vector2Extensions.Transform(new Vector2(triangle_size, 0f), DrawInfo.Matrix), + Vector2Extensions.Transform(new Vector2(0f, triangleSize.Y), DrawInfo.Matrix), + Vector2Extensions.Transform(triangleSize, DrawInfo.Matrix) + ); + + texelSize = 1.5f / triangleQuad.Height; parts.Clear(); parts.AddRange(Source.parts); @@ -269,14 +280,15 @@ namespace osu.Game.Graphics.Backgrounds shader.GetUniform("thickness").UpdateValue(ref thickness); shader.GetUniform("texelSize").UpdateValue(ref texelSize); + float texturePartWidth = triangleSize.X / size.X; + float texturePartHeight = triangleSize.Y / size.Y * texture_height; + foreach (TriangleParticle particle in parts) { - var offset = triangle_size * new Vector2(0.5f, equilateral_triangle_ratio); - - Vector2 topLeft = particle.Position * size + new Vector2(-offset.X, 0f); - Vector2 topRight = particle.Position * size + new Vector2(offset.X, 0); - Vector2 bottomLeft = particle.Position * size + new Vector2(-offset.X, offset.Y); - Vector2 bottomRight = particle.Position * size + new Vector2(offset.X, offset.Y); + Vector2 topLeft = particle.Position * size - new Vector2(triangleSize.X * 0.5f, 0f); + Vector2 topRight = topLeft + new Vector2(triangleSize.X, 0f); + Vector2 bottomLeft = topLeft + new Vector2(0f, triangleSize.Y); + Vector2 bottomRight = topLeft + triangleSize; var drawQuad = new Quad( Vector2Extensions.Transform(topLeft, DrawInfo.Matrix), @@ -288,8 +300,8 @@ namespace osu.Game.Graphics.Backgrounds var tRect = new Quad( topLeft.X / size.X, topLeft.Y / size.Y * texture_height, - (topRight.X - topLeft.X) / size.X, - (bottomRight.Y - topRight.Y) / size.Y * texture_height + texturePartWidth, + texturePartHeight ).AABBFloat; renderer.DrawQuad(texture, drawQuad, DrawColourInfo.Colour, tRect, vertexBatch.AddAction, textureCoords: tRect); From c2d8ffc225f8a9e8a4cde803f0d03d3927771465 Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Mon, 28 Nov 2022 17:50:12 -0800 Subject: [PATCH 23/49] Refactor `ChatLine` username drawable creation --- .../Visual/Online/TestSceneChatLink.cs | 4 +- osu.Game/Online/Chat/StandAloneChatDisplay.cs | 2 +- osu.Game/Overlays/Chat/ChatLine.cs | 367 ++++++++++-------- 3 files changed, 199 insertions(+), 174 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs b/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs index de44986001..3bb8b948d0 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs @@ -130,11 +130,11 @@ namespace osu.Game.Tests.Visual.Online Color4 textColour = isAction && hasBackground ? Color4Extensions.FromHex(newLine.Message.Sender.Colour) : Color4.White; - var linkCompilers = newLine.ContentFlow.Where(d => d is DrawableLinkCompiler).ToList(); + var linkCompilers = newLine.DrawableContentFlow.Where(d => d is DrawableLinkCompiler).ToList(); var linkSprites = linkCompilers.SelectMany(comp => ((DrawableLinkCompiler)comp).Parts); return linkSprites.All(d => d.Colour == linkColour) - && newLine.ContentFlow.Except(linkSprites.Concat(linkCompilers)).All(d => d.Colour == textColour); + && newLine.DrawableContentFlow.Except(linkSprites.Concat(linkCompilers)).All(d => d.Colour == textColour); } } } diff --git a/osu.Game/Online/Chat/StandAloneChatDisplay.cs b/osu.Game/Online/Chat/StandAloneChatDisplay.cs index 81db3f0d53..667ba8c742 100644 --- a/osu.Game/Online/Chat/StandAloneChatDisplay.cs +++ b/osu.Game/Online/Chat/StandAloneChatDisplay.cs @@ -189,7 +189,7 @@ namespace osu.Game.Online.Chat protected class StandAloneMessage : ChatLine { - protected override float TextSize => 15; + protected override float FontSize => 15; protected override float Spacing => 5; protected override float UsernameWidth => 75; diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index bfbffabd2b..422dcf63df 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -24,11 +24,15 @@ using osu.Game.Online.Chat; using osuTK; using osuTK.Graphics; using osu.Framework.Input.Events; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Localisation; namespace osu.Game.Overlays.Chat { public class ChatLine : CompositeDrawable { + private Message message = null!; + public Message Message { get => message; @@ -45,55 +49,35 @@ namespace osu.Game.Overlays.Chat } } - public LinkFlowContainer ContentFlow { get; private set; } = null!; + public IReadOnlyCollection DrawableContentFlow => drawableContentFlow; - protected virtual float TextSize => 20; + protected virtual float FontSize => 20; protected virtual float Spacing => 15; protected virtual float UsernameWidth => 130; - private Color4 usernameColour; - - private OsuSpriteText timestamp = null!; - - private Message message = null!; - - private OsuSpriteText username = null!; - - private Drawable usernameColouredDrawable = null!; - - private Container? highlight; - - private readonly Bindable prefer24HourTime = new Bindable(); - - private bool senderHasColour => !string.IsNullOrEmpty(message.Sender.Colour); - - private bool messageHasColour => Message.IsAction && senderHasColour; - [Resolved] private ChannelManager? chatManager { get; set; } [Resolved] - private OsuColour colours { get; set; } = null!; + private OverlayColourProvider? colourProvider { get; set; } + + private readonly OsuSpriteText drawableTimestamp; + + private readonly DrawableUsername drawableUsername; + + private readonly LinkFlowContainer drawableContentFlow; + + private readonly Bindable prefer24HourTime = new Bindable(); + + private Container? highlight; public ChatLine(Message message) { Message = message; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - } - - [BackgroundDependencyLoader] - private void load(OverlayColourProvider? colourProvider, OsuConfigManager configManager) - { - usernameColour = senderHasColour - ? Color4Extensions.FromHex(message.Sender.Colour) - : username_colours[message.Sender.Id % username_colours.Length]; - - // this can be either the username sprite text or a container - // around it depending on which branch is taken in createUsername() - var usernameDrawable = createUsername(); InternalChild = new GridContainer { @@ -110,30 +94,24 @@ namespace osu.Game.Overlays.Chat { new Drawable[] { - timestamp = new OsuSpriteText + drawableTimestamp = new OsuSpriteText { Shadow = false, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Font = OsuFont.GetFont(size: TextSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true), - Colour = colourProvider?.Background1 ?? Colour4.White, + Font = OsuFont.GetFont(size: FontSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true), AlwaysPresent = true, }, - new MessageSender(message.Sender, usernameColouredDrawable) + drawableUsername = new DrawableUsername(message.Sender) { Width = UsernameWidth, + FontSize = FontSize, AutoSizeAxes = Axes.Y, Origin = Anchor.TopRight, Anchor = Anchor.TopRight, - Child = usernameDrawable, Margin = new MarginPadding { Horizontal = Spacing }, }, - ContentFlow = new LinkFlowContainer(t => - { - t.Shadow = false; - t.Font = t.Font.With(size: TextSize, italics: Message.IsAction); - t.Colour = messageHasColour ? Color4Extensions.FromHex(message.Sender.Colour) : colourProvider?.Content1 ?? Colour4.White; - }) + drawableContentFlow = new LinkFlowContainer(styleMessageContent) { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, @@ -141,18 +119,23 @@ namespace osu.Game.Overlays.Chat }, } }; + } + [BackgroundDependencyLoader] + private void load(OsuConfigManager configManager) + { configManager.BindWith(OsuSetting.Prefer24HourTime, prefer24HourTime); + prefer24HourTime.BindValueChanged(_ => updateTimestamp()); } protected override void LoadComplete() { base.LoadComplete(); + drawableTimestamp.Colour = colourProvider?.Background1 ?? Colour4.White; + updateMessageContent(); FinishTransforms(true); - - prefer24HourTime.BindValueChanged(_ => updateTimestamp()); } /// @@ -167,7 +150,7 @@ namespace osu.Game.Overlays.Chat CornerRadius = 2f, Masking = true, RelativeSizeAxes = Axes.Both, - Colour = usernameColour.Darken(1f), + Colour = drawableUsername.Colour.Darken(1f), Depth = float.MaxValue, Child = new Box { RelativeSizeAxes = Axes.Both } }); @@ -177,140 +160,182 @@ namespace osu.Game.Overlays.Chat highlight.Expire(); } + private void styleMessageContent(SpriteText text) + { + text.Shadow = false; + text.Font = text.Font.With(size: FontSize, italics: Message.IsAction); + + bool messageHasColour = Message.IsAction && !string.IsNullOrEmpty(message.Sender.Colour); + text.Colour = messageHasColour ? Color4Extensions.FromHex(message.Sender.Colour) : colourProvider?.Content1 ?? Colour4.White; + } + private void updateMessageContent() { this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint); - timestamp.FadeTo(message is LocalEchoMessage ? 0 : 1, 500, Easing.OutQuint); + drawableTimestamp.FadeTo(message is LocalEchoMessage ? 0 : 1, 500, Easing.OutQuint); updateTimestamp(); - username.Text = $@"{message.Sender.Username}"; + drawableUsername.Text = $@"{message.Sender.Username}"; // remove non-existent channels from the link list message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument.ToString()) != true); - ContentFlow.Clear(); - ContentFlow.AddLinks(message.DisplayContent, message.Links); + drawableContentFlow.Clear(); + drawableContentFlow.AddLinks(message.DisplayContent, message.Links); } private void updateTimestamp() { - timestamp.Text = prefer24HourTime.Value + drawableTimestamp.Text = prefer24HourTime.Value ? $@"{message.Timestamp.LocalDateTime:HH:mm:ss}" : $@"{message.Timestamp.LocalDateTime:hh:mm:ss tt}"; } - private Drawable createUsername() + private class DrawableUsername : OsuClickableContainer, IHasContextMenu { - username = new OsuSpriteText - { - Shadow = false, - Truncate = true, - EllipsisString = "…", - Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Bold, italics: true), - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - MaxWidth = UsernameWidth, - }; + public new Color4 Colour { get; private set; } - if (!senderHasColour) + public float FontSize { - usernameColouredDrawable = username; - usernameColouredDrawable.Colour = usernameColour; - return username; + set => drawableText.Font = OsuFont.GetFont(size: value, weight: FontWeight.Bold, italics: true); } - username.Colour = colours.ChatBlue; - - // Background effect - return new Container + public LocalisableString Text { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - AutoSizeAxes = Axes.Both, - Masking = true, - CornerRadius = 4, - EdgeEffect = new EdgeEffectParameters - { - Roundness = 1, - Radius = 1, - Colour = Color4.Black.Opacity(0.3f), - Offset = new Vector2(0, 1), - Type = EdgeEffectType.Shadow, - }, - Child = new Container - { - AutoSizeAxes = Axes.Both, - Masking = true, - CornerRadius = 4, - Children = new Drawable[] - { - usernameColouredDrawable = new Box - { - RelativeSizeAxes = Axes.Both, - Colour = usernameColour, - }, - new Container - { - AutoSizeAxes = Axes.Both, - Padding = new MarginPadding { Left = 4, Right = 4, Bottom = 1, Top = -2 }, - Child = username - } - } - } - }; - } + set => drawableText.Text = value; + } - private class MessageSender : OsuClickableContainer, IHasContextMenu - { - private readonly APIUser sender; - private readonly Drawable colouredDrawable; - private readonly Color4 defaultColour; + public override float Width + { + get => base.Width; + set => base.Width = drawableText.MaxWidth = value; + } - private Action startChatAction = null!; - - [Resolved] + [Resolved(canBeNull: false)] private IAPIProvider api { get; set; } = null!; - public MessageSender(APIUser sender, Drawable colouredDrawable) + [Resolved(canBeNull: false)] + private OsuColour osuColours { get; set; } = null!; + + [Resolved] + private ChannelManager? chatManager { get; set; } + + [Resolved] + private ChatOverlay? chatOverlay { get; set; } + + [Resolved] + private UserProfileOverlay? profileOverlay { get; set; } + + private readonly APIUser user; + private readonly OsuSpriteText drawableText; + + private readonly Drawable colouredDrawable; + + public DrawableUsername(APIUser user) { - this.sender = sender; - this.colouredDrawable = colouredDrawable; - defaultColour = colouredDrawable.Colour; + this.user = user; + + Action = openUserProfile; + + drawableText = new OsuSpriteText + { + Shadow = false, + Truncate = true, + EllipsisString = "…", + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + }; + + if (string.IsNullOrWhiteSpace(user.Colour)) + { + Colour = default_colours[user.Id % default_colours.Length]; + + Child = colouredDrawable = drawableText; + } + else + { + + Colour = Color4Extensions.FromHex(user.Colour); + + Child = new Container + { + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + AutoSizeAxes = Axes.Both, + Masking = true, + CornerRadius = 4, + EdgeEffect = new EdgeEffectParameters + { + Roundness = 1, + Radius = 1, + Colour = Color4.Black.Opacity(0.3f), + Offset = new Vector2(0, 1), + Type = EdgeEffectType.Shadow, + }, + Child = new Container + { + AutoSizeAxes = Axes.Both, + Masking = true, + CornerRadius = 4, + Children = new[] + { + colouredDrawable = new Box + { + RelativeSizeAxes = Axes.Both, + }, + new Container + { + AutoSizeAxes = Axes.Both, + Padding = new MarginPadding { Left = 4, Right = 4, Bottom = 1, Top = -2 }, + Child = drawableText, + } + } + } + }; + } } - [BackgroundDependencyLoader] - private void load(UserProfileOverlay? profile, ChannelManager? chatManager, ChatOverlay? chatOverlay) + protected override void LoadComplete() { - Action = () => profile?.ShowUser(sender); - startChatAction = () => - { - chatManager?.OpenPrivateChannel(sender); - chatOverlay?.Show(); - }; + base.LoadComplete(); + + drawableText.Colour = osuColours.ChatBlue; + colouredDrawable.Colour = Colour; } public MenuItem[] ContextMenuItems { get { - if (sender.Equals(APIUser.SYSTEM_USER)) + if (user.Equals(APIUser.SYSTEM_USER)) return Array.Empty(); List items = new List { - new OsuMenuItem("View Profile", MenuItemType.Highlighted, Action) + new OsuMenuItem("View Profile", MenuItemType.Highlighted, openUserProfile) }; - if (!sender.Equals(api.LocalUser.Value)) - items.Add(new OsuMenuItem("Start Chat", MenuItemType.Standard, startChatAction)); + if (!user.Equals(api.LocalUser.Value)) + items.Add(new OsuMenuItem("Start Chat", MenuItemType.Standard, openUserChannel)); return items.ToArray(); } } + private void openUserChannel() + { + chatManager?.OpenPrivateChannel(user); + chatOverlay?.Show(); + } + + private void openUserProfile() + { + profileOverlay?.ShowUser(user); + } + protected override bool OnHover(HoverEvent e) { - colouredDrawable.FadeColour(defaultColour.Lighten(0.4f), 150, Easing.OutQuint); + colouredDrawable.FadeColour(Colour.Lighten(0.4f), 150, Easing.OutQuint); return base.OnHover(e); } @@ -319,47 +344,47 @@ namespace osu.Game.Overlays.Chat { base.OnHoverLost(e); - colouredDrawable.FadeColour(defaultColour, 250, Easing.OutQuint); + colouredDrawable.FadeColour(Colour, 250, Easing.OutQuint); } + + private static readonly Color4[] default_colours = + { + Color4Extensions.FromHex("588c7e"), + Color4Extensions.FromHex("b2a367"), + Color4Extensions.FromHex("c98f65"), + Color4Extensions.FromHex("bc5151"), + Color4Extensions.FromHex("5c8bd6"), + Color4Extensions.FromHex("7f6ab7"), + Color4Extensions.FromHex("a368ad"), + Color4Extensions.FromHex("aa6880"), + + Color4Extensions.FromHex("6fad9b"), + Color4Extensions.FromHex("f2e394"), + Color4Extensions.FromHex("f2ae72"), + Color4Extensions.FromHex("f98f8a"), + Color4Extensions.FromHex("7daef4"), + Color4Extensions.FromHex("a691f2"), + Color4Extensions.FromHex("c894d3"), + Color4Extensions.FromHex("d895b0"), + + Color4Extensions.FromHex("53c4a1"), + Color4Extensions.FromHex("eace5c"), + Color4Extensions.FromHex("ea8c47"), + Color4Extensions.FromHex("fc4f4f"), + Color4Extensions.FromHex("3d94ea"), + Color4Extensions.FromHex("7760ea"), + Color4Extensions.FromHex("af52c6"), + Color4Extensions.FromHex("e25696"), + + Color4Extensions.FromHex("677c66"), + Color4Extensions.FromHex("9b8732"), + Color4Extensions.FromHex("8c5129"), + Color4Extensions.FromHex("8c3030"), + Color4Extensions.FromHex("1f5d91"), + Color4Extensions.FromHex("4335a5"), + Color4Extensions.FromHex("812a96"), + Color4Extensions.FromHex("992861"), + }; } - - private static readonly Color4[] username_colours = - { - Color4Extensions.FromHex("588c7e"), - Color4Extensions.FromHex("b2a367"), - Color4Extensions.FromHex("c98f65"), - Color4Extensions.FromHex("bc5151"), - Color4Extensions.FromHex("5c8bd6"), - Color4Extensions.FromHex("7f6ab7"), - Color4Extensions.FromHex("a368ad"), - Color4Extensions.FromHex("aa6880"), - - Color4Extensions.FromHex("6fad9b"), - Color4Extensions.FromHex("f2e394"), - Color4Extensions.FromHex("f2ae72"), - Color4Extensions.FromHex("f98f8a"), - Color4Extensions.FromHex("7daef4"), - Color4Extensions.FromHex("a691f2"), - Color4Extensions.FromHex("c894d3"), - Color4Extensions.FromHex("d895b0"), - - Color4Extensions.FromHex("53c4a1"), - Color4Extensions.FromHex("eace5c"), - Color4Extensions.FromHex("ea8c47"), - Color4Extensions.FromHex("fc4f4f"), - Color4Extensions.FromHex("3d94ea"), - Color4Extensions.FromHex("7760ea"), - Color4Extensions.FromHex("af52c6"), - Color4Extensions.FromHex("e25696"), - - Color4Extensions.FromHex("677c66"), - Color4Extensions.FromHex("9b8732"), - Color4Extensions.FromHex("8c5129"), - Color4Extensions.FromHex("8c3030"), - Color4Extensions.FromHex("1f5d91"), - Color4Extensions.FromHex("4335a5"), - Color4Extensions.FromHex("812a96"), - Color4Extensions.FromHex("992861"), - }; } } From 8ec4dd046ee7a18ab59df4c4881815e208a0ff0b Mon Sep 17 00:00:00 2001 From: Alden Wu Date: Mon, 28 Nov 2022 18:06:44 -0800 Subject: [PATCH 24/49] Fix InspectCode errors --- osu.Game/Overlays/Chat/ChatLine.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index ad33f54848..e974db9fba 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -254,7 +254,6 @@ namespace osu.Game.Overlays.Chat } else { - Colour = Color4Extensions.FromHex(user.Colour); Child = new Container From a4819e5c9c0b37cadaf50bfdabfb4e763fae70b8 Mon Sep 17 00:00:00 2001 From: ansel <79257300125@ya.ru> Date: Tue, 29 Nov 2022 07:01:52 +0300 Subject: [PATCH 25/49] Localize actions --- osu.Game/Overlays/Comments/DrawableComment.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs index 6cb5a0fbac..8c01633fe8 100644 --- a/osu.Game/Overlays/Comments/DrawableComment.cs +++ b/osu.Game/Overlays/Comments/DrawableComment.cs @@ -331,11 +331,11 @@ namespace osu.Game.Overlays.Comments if (WasDeleted) makeDeleted(); - actionsContainer.AddLink("Copy link", copyUrl); + actionsContainer.AddLink(CommonStrings.ButtonsPermalink, copyUrl); actionsContainer.AddArbitraryDrawable(Empty().With(d => d.Width = 10)); if (Comment.UserId.HasValue && Comment.UserId.Value == api.LocalUser.Value.Id) - actionsContainer.AddLink("Delete", deleteComment); + actionsContainer.AddLink(CommonStrings.ButtonsDelete, deleteComment); else actionsContainer.AddArbitraryDrawable(new CommentReportButton(Comment)); From 16962d9a57699d7c610f21d079987b2f8e338887 Mon Sep 17 00:00:00 2001 From: ansel <79257300125@ya.ru> Date: Tue, 29 Nov 2022 07:02:02 +0300 Subject: [PATCH 26/49] Localize deleted string --- osu.Game/Overlays/Comments/DrawableComment.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs index 8c01633fe8..7bada5ef2a 100644 --- a/osu.Game/Overlays/Comments/DrawableComment.cs +++ b/osu.Game/Overlays/Comments/DrawableComment.cs @@ -553,12 +553,12 @@ namespace osu.Game.Overlays.Comments }; } - private string getParentMessage() + private LocalisableString getParentMessage() { if (parentComment == null) return string.Empty; - return parentComment.HasMessage ? parentComment.Message : parentComment.IsDeleted ? "deleted" : string.Empty; + return parentComment.HasMessage ? parentComment.Message : parentComment.IsDeleted ? CommentsStrings.Deleted : string.Empty; } } } From 96e19d4d84c97ff952d0271da2ef792be0e8b71e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 29 Nov 2022 14:36:23 +0900 Subject: [PATCH 27/49] Update framework --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 8f4750e831..17237c5ca7 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -52,7 +52,7 @@ - + diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index afc80d073f..9301670825 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -35,7 +35,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/osu.iOS.props b/osu.iOS.props index 4d8c1af28b..57e58dc16a 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -62,7 +62,7 @@ - + @@ -82,7 +82,7 @@ - + From 24deb5f5f45f3e3e2c260ed3a08baeff659e3c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 16 Nov 2022 15:54:52 +0900 Subject: [PATCH 28/49] Remove all unnecessary usage of `IHasFilterableChildren` --- osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs | 1 - osu.Game/Overlays/Settings/SettingsSection.cs | 4 +--- osu.Game/Overlays/Settings/SettingsSubsection.cs | 5 +---- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs b/osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs index 4e295ba665..24c2eee783 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneSettingsPanel.cs @@ -62,7 +62,6 @@ namespace osu.Game.Tests.Visual.Settings section.Children.Where(f => f.IsPresent) .OfType() .OfType() - .Where(f => !(f is IHasFilterableChildren)) .All(f => f.FilterTerms.Any(t => t.ToString().Contains("scaling"))) )); diff --git a/osu.Game/Overlays/Settings/SettingsSection.cs b/osu.Game/Overlays/Settings/SettingsSection.cs index dced187035..9602e4373f 100644 --- a/osu.Game/Overlays/Settings/SettingsSection.cs +++ b/osu.Game/Overlays/Settings/SettingsSection.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -19,7 +18,7 @@ using osuTK; namespace osu.Game.Overlays.Settings { - public abstract partial class SettingsSection : Container, IHasFilterableChildren + public abstract partial class SettingsSection : Container, IFilterable { protected FillFlowContainer FlowContent; protected override Container Content => FlowContent; @@ -33,7 +32,6 @@ namespace osu.Game.Overlays.Settings public abstract Drawable CreateIcon(); public abstract LocalisableString Header { get; } - public IEnumerable FilterableChildren => Children.OfType(); public virtual IEnumerable FilterTerms => new[] { Header }; public const int ITEM_SPACING = 14; diff --git a/osu.Game/Overlays/Settings/SettingsSubsection.cs b/osu.Game/Overlays/Settings/SettingsSubsection.cs index 78fb53230e..784f20a6e8 100644 --- a/osu.Game/Overlays/Settings/SettingsSubsection.cs +++ b/osu.Game/Overlays/Settings/SettingsSubsection.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Sprites; using System.Collections.Generic; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Localisation; using osu.Framework.Testing; @@ -17,7 +16,7 @@ using osu.Game.Graphics; namespace osu.Game.Overlays.Settings { [ExcludeFromDynamicCompile] - public abstract partial class SettingsSubsection : FillFlowContainer, IHasFilterableChildren + public abstract partial class SettingsSubsection : FillFlowContainer, IFilterable { protected override Container Content => FlowContent; @@ -25,8 +24,6 @@ namespace osu.Game.Overlays.Settings protected abstract LocalisableString Header { get; } - public IEnumerable FilterableChildren => Children.OfType(); - public virtual IEnumerable FilterTerms => new[] { Header }; public bool MatchingFilter From 8f78d6179bf907efe9f442c5a42a2439031a31ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 16 Nov 2022 22:58:32 +0900 Subject: [PATCH 29/49] Fix multiple issues with settings items unhiding on search --- .../Sections/Graphics/LayoutSettings.cs | 32 ++++++------------- .../Settings/Sections/Input/TabletSettings.cs | 25 ++++++++++----- osu.Game/Overlays/Settings/SettingsButton.cs | 7 +++- osu.Game/Overlays/Settings/SettingsItem.cs | 5 ++- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs index 63689961e6..bad06732d0 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs @@ -177,13 +177,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics updateScreenModeWarning(); }, true); - windowModes.BindCollectionChanged((_, _) => - { - if (windowModes.Count > 1) - windowModeDropdown.Show(); - else - windowModeDropdown.Hide(); - }, true); + windowModes.BindCollectionChanged((_, _) => updateDisplaySettingsVisibility()); currentDisplay.BindValueChanged(display => Schedule(() => { @@ -219,7 +213,11 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics scalingSettings.ResizeHeightTo(0, transition_duration, Easing.OutQuint); scalingSettings.AutoSizeAxes = scalingMode.Value != ScalingMode.Off ? Axes.Y : Axes.None; - scalingSettings.ForEach(s => s.TransferValueOnCommit = scalingMode.Value == ScalingMode.Everything); + scalingSettings.ForEach(s => + { + s.TransferValueOnCommit = scalingMode.Value == ScalingMode.Everything; + s.CanBeShown.Value = scalingMode.Value != ScalingMode.Off; + }); } } @@ -234,20 +232,10 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics private void updateDisplaySettingsVisibility() { - if (resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen) - resolutionDropdown.Show(); - else - resolutionDropdown.Hide(); - - if (displayDropdown.Items.Count() > 1) - displayDropdown.Show(); - else - displayDropdown.Hide(); - - if (host.Window?.SafeAreaPadding.Value.Total != Vector2.Zero) - safeAreaConsiderationsCheckbox.Show(); - else - safeAreaConsiderationsCheckbox.Hide(); + windowModeDropdown.CanBeShown.Value = windowModes.Count > 1; + resolutionDropdown.CanBeShown.Value = resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen; + displayDropdown.CanBeShown.Value = displayDropdown.Items.Count() > 1; + safeAreaConsiderationsCheckbox.CanBeShown.Value = host.Window?.SafeAreaPadding.Value.Total != Vector2.Zero; } private void updateScreenModeWarning() diff --git a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs index 27612738df..951cf3802f 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs @@ -143,6 +143,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input areaOffset.SetDefault(); areaSize.SetDefault(); }, + CanBeShown = { BindTarget = enabled } }, new SettingsButton { @@ -150,25 +151,29 @@ namespace osu.Game.Overlays.Settings.Sections.Input Action = () => { forceAspectRatio((float)host.Window.ClientSize.Width / host.Window.ClientSize.Height); - } + }, + CanBeShown = { BindTarget = enabled } }, new SettingsSlider { TransferValueOnCommit = true, LabelText = TabletSettingsStrings.XOffset, - Current = offsetX + Current = offsetX, + CanBeShown = { BindTarget = enabled } }, new SettingsSlider { TransferValueOnCommit = true, LabelText = TabletSettingsStrings.YOffset, - Current = offsetY + Current = offsetY, + CanBeShown = { BindTarget = enabled } }, new SettingsSlider { TransferValueOnCommit = true, LabelText = TabletSettingsStrings.Rotation, - Current = rotation + Current = rotation, + CanBeShown = { BindTarget = enabled } }, new RotationPresetButtons(tabletHandler) { @@ -181,24 +186,28 @@ namespace osu.Game.Overlays.Settings.Sections.Input { TransferValueOnCommit = true, LabelText = TabletSettingsStrings.AspectRatio, - Current = aspectRatio + Current = aspectRatio, + CanBeShown = { BindTarget = enabled } }, new SettingsCheckbox { LabelText = TabletSettingsStrings.LockAspectRatio, - Current = aspectLock + Current = aspectLock, + CanBeShown = { BindTarget = enabled } }, new SettingsSlider { TransferValueOnCommit = true, LabelText = CommonStrings.Width, - Current = sizeX + Current = sizeX, + CanBeShown = { BindTarget = enabled } }, new SettingsSlider { TransferValueOnCommit = true, LabelText = CommonStrings.Height, - Current = sizeY + Current = sizeY, + CanBeShown = { BindTarget = enabled } }, } }, diff --git a/osu.Game/Overlays/Settings/SettingsButton.cs b/osu.Game/Overlays/Settings/SettingsButton.cs index dc1be1ce9f..5091ddc2d0 100644 --- a/osu.Game/Overlays/Settings/SettingsButton.cs +++ b/osu.Game/Overlays/Settings/SettingsButton.cs @@ -3,14 +3,16 @@ using System.Collections.Generic; using System.Linq; +using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Localisation; using osu.Game.Graphics.UserInterfaceV2; namespace osu.Game.Overlays.Settings { - public partial class SettingsButton : RoundedButton, IHasTooltip + public partial class SettingsButton : RoundedButton, IHasTooltip, IConditionalFilterable { public SettingsButton() { @@ -20,6 +22,9 @@ namespace osu.Game.Overlays.Settings public LocalisableString TooltipText { get; set; } + public BindableBool CanBeShown { get; } = new BindableBool(true); + IBindable IConditionalFilterable.CanBeShown => CanBeShown; + public override IEnumerable FilterTerms { get diff --git a/osu.Game/Overlays/Settings/SettingsItem.cs b/osu.Game/Overlays/Settings/SettingsItem.cs index 577f1738ba..5f4bb9d57f 100644 --- a/osu.Game/Overlays/Settings/SettingsItem.cs +++ b/osu.Game/Overlays/Settings/SettingsItem.cs @@ -22,7 +22,7 @@ using osuTK; namespace osu.Game.Overlays.Settings { - public abstract partial class SettingsItem : Container, IFilterable, ISettingsItem, IHasCurrentValue, IHasTooltip + public abstract partial class SettingsItem : Container, IConditionalFilterable, ISettingsItem, IHasCurrentValue, IHasTooltip { protected abstract Drawable CreateControl(); @@ -144,6 +144,9 @@ namespace osu.Game.Overlays.Settings public bool FilteringActive { get; set; } + public BindableBool CanBeShown { get; } = new BindableBool(true); + IBindable IConditionalFilterable.CanBeShown => CanBeShown; + public event Action SettingChanged; private T classicDefault; From b5b79e09e4c9d46fd5bea0da7f7ed664bd7b7afa Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 29 Nov 2022 14:45:08 +0900 Subject: [PATCH 30/49] Remove unnecessary CQ disable --- osu.Game/Online/Rooms/APICreatedRoom.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Online/Rooms/APICreatedRoom.cs b/osu.Game/Online/Rooms/APICreatedRoom.cs index 7f2bd13aec..254a338a60 100644 --- a/osu.Game/Online/Rooms/APICreatedRoom.cs +++ b/osu.Game/Online/Rooms/APICreatedRoom.cs @@ -7,8 +7,6 @@ using Newtonsoft.Json; namespace osu.Game.Online.Rooms { - // TODO: Remove disable below after merging https://github.com/ppy/osu-framework/pull/5548 and applying follow-up changes game-side. - // ReSharper disable once PartialTypeWithSinglePart public partial class APICreatedRoom : Room { [JsonProperty("error")] From 61c702c02ec94f39aafafb3267665cf207a3a9ee Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 29 Nov 2022 14:45:26 +0900 Subject: [PATCH 31/49] Add new `IDependencyInjectionCandidate` interface to non-drawable cached classes --- osu.Game/Online/Rooms/Room.cs | 2 +- osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs | 2 +- osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs | 2 +- osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs | 2 +- .../Tests/Visual/OnlinePlay/OnlinePlayTestSceneDependencies.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Online/Rooms/Room.cs b/osu.Game/Online/Rooms/Room.cs index bdd7d6ce1c..8f346c4057 100644 --- a/osu.Game/Online/Rooms/Room.cs +++ b/osu.Game/Online/Rooms/Room.cs @@ -16,7 +16,7 @@ using osu.Game.Online.Rooms.RoomStatuses; namespace osu.Game.Online.Rooms { [JsonObject(MemberSerialization.OptIn)] - public partial class Room + public partial class Room : IDependencyInjectionCandidate { [Cached] [JsonProperty("id")] diff --git a/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs b/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs index b28b04f228..63688841d0 100644 --- a/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs +++ b/osu.Game/Overlays/FirstRunSetup/ScreenUIScale.cs @@ -233,7 +233,7 @@ namespace osu.Game.Overlays.FirstRunSetup return parentDependencies.Get(type, info); } - public void Inject(T instance) where T : class + public void Inject(T instance) where T : class, IDependencyInjectionCandidate { parentDependencies.Inject(instance); } diff --git a/osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs b/osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs index fbc920f7de..bb4e06654a 100644 --- a/osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs +++ b/osu.Game/Tests/Beatmaps/HitObjectSampleTest.cs @@ -164,7 +164,7 @@ namespace osu.Game.Tests.Beatmaps return fallback.Get(type, info); } - public void Inject(T instance) where T : class + public void Inject(T instance) where T : class, IDependencyInjectionCandidate { // Never used directly } diff --git a/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs b/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs index 5350030276..87488710a7 100644 --- a/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs +++ b/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestScene.cs @@ -128,7 +128,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay => OnlinePlayDependencies?.Get(type, info) ?? parent.Get(type, info); public void Inject(T instance) - where T : class + where T : class, IDependencyInjectionCandidate => injectableDependencies.Inject(instance); } } diff --git a/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestSceneDependencies.cs b/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestSceneDependencies.cs index 35bdba0038..a9acbdcd7e 100644 --- a/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestSceneDependencies.cs +++ b/osu.Game/Tests/Visual/OnlinePlay/OnlinePlayTestSceneDependencies.cs @@ -65,7 +65,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay => dependencies.Get(type, info); public void Inject(T instance) - where T : class + where T : class, IDependencyInjectionCandidate => dependencies.Inject(instance); protected void Cache(object instance) From 56a694fb04bf200be1183cae1038c41a7ad59cac Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 29 Nov 2022 15:10:21 +0900 Subject: [PATCH 32/49] Add automated test coverage of simple scenarios for `RangeSlider` --- .../UserInterface/TestSceneRangeSlider.cs | 26 ++++++++++++++++--- .../Graphics/UserInterface/RangeSlider.cs | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs index d0e3ff737c..b780764e7f 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneRangeSlider.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Testing; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osuTK; @@ -30,10 +31,12 @@ namespace osu.Game.Tests.Visual.UserInterface Precision = 0.1f }; - [Test] - public void TestBasic() + private RangeSlider rangeSlider = null!; + + [SetUpSteps] + public void SetUpSteps() { - AddStep("create Control", () => Child = new RangeSlider + AddStep("create control", () => Child = rangeSlider = new RangeSlider { Width = 200, Anchor = Anchor.Centre, @@ -47,15 +50,30 @@ namespace osu.Game.Tests.Visual.UserInterface DefaultStringUpperBound = "End", MinRange = 10 }); - AddStep("Test Range", () => + } + + [Test] + public void TestAdjustRange() + { + AddAssert("Initial lower bound is correct", () => rangeSlider.LowerBound.Value, () => Is.EqualTo(0).Within(0.1f)); + AddAssert("Initial upper bound is correct", () => rangeSlider.UpperBound.Value, () => Is.EqualTo(100).Within(0.1f)); + + AddStep("Adjust range", () => { customStart.Value = 50; customEnd.Value = 75; }); + + AddAssert("Adjusted lower bound is correct", () => rangeSlider.LowerBound.Value, () => Is.EqualTo(50).Within(0.1f)); + AddAssert("Adjusted upper bound is correct", () => rangeSlider.UpperBound.Value, () => Is.EqualTo(75).Within(0.1f)); + AddStep("Test nub pushing", () => { customStart.Value = 90; }); + + AddAssert("Pushed lower bound is correct", () => rangeSlider.LowerBound.Value, () => Is.EqualTo(90).Within(0.1f)); + AddAssert("Pushed upper bound is correct", () => rangeSlider.UpperBound.Value, () => Is.EqualTo(100).Within(0.1f)); } } } diff --git a/osu.Game/Graphics/UserInterface/RangeSlider.cs b/osu.Game/Graphics/UserInterface/RangeSlider.cs index c8306b70fb..483119cd58 100644 --- a/osu.Game/Graphics/UserInterface/RangeSlider.cs +++ b/osu.Game/Graphics/UserInterface/RangeSlider.cs @@ -22,6 +22,7 @@ namespace osu.Game.Graphics.UserInterface /// public Bindable LowerBound { + get => lowerBound.Current; set => lowerBound.Current = value; } @@ -30,6 +31,7 @@ namespace osu.Game.Graphics.UserInterface /// public Bindable UpperBound { + get => upperBound.Current; set => upperBound.Current = value; } From 7dbf3793515ba9dde17ec8b79de95d26006f360e Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Tue, 29 Nov 2022 18:22:07 +0000 Subject: [PATCH 33/49] Don't use verbatim string literals --- osu.Game/Screens/Edit/Timing/ControlPointTable.cs | 4 ++-- osu.Game/Screens/Edit/Timing/TimingScreen.cs | 4 ++-- osu.Game/Screens/Edit/Verify/IssueTable.cs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs index b3cc41af72..eeae1bcb9a 100644 --- a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs +++ b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs @@ -73,8 +73,8 @@ namespace osu.Game.Screens.Edit.Timing { var columns = new List { - new TableColumn(@"Time", Anchor.CentreLeft, new Dimension(GridSizeMode.Absolute, TIMING_COLUMN_WIDTH)), - new TableColumn(@"Attributes", Anchor.CentreLeft), + new TableColumn("Time", Anchor.CentreLeft, new Dimension(GridSizeMode.Absolute, TIMING_COLUMN_WIDTH)), + new TableColumn("Attributes", Anchor.CentreLeft), }; return columns.ToArray(); diff --git a/osu.Game/Screens/Edit/Timing/TimingScreen.cs b/osu.Game/Screens/Edit/Timing/TimingScreen.cs index 69eff776e6..2450909929 100644 --- a/osu.Game/Screens/Edit/Timing/TimingScreen.cs +++ b/osu.Game/Screens/Edit/Timing/TimingScreen.cs @@ -130,8 +130,8 @@ namespace osu.Game.Screens.Edit.Timing deleteButton.Enabled.Value = selected.NewValue != null; addButton.Text = selected.NewValue != null - ? @"+ Clone to current time" - : @"+ Add at current time"; + ? "+ Clone to current time" + : "+ Add at current time"; }, true); controlPointGroups.BindTo(Beatmap.ControlPointInfo.Groups); diff --git a/osu.Game/Screens/Edit/Verify/IssueTable.cs b/osu.Game/Screens/Edit/Verify/IssueTable.cs index b37fb2b72d..dbd007e423 100644 --- a/osu.Game/Screens/Edit/Verify/IssueTable.cs +++ b/osu.Game/Screens/Edit/Verify/IssueTable.cs @@ -86,10 +86,10 @@ namespace osu.Game.Screens.Edit.Verify var columns = new List { new TableColumn(string.Empty, Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize)), - new TableColumn(@"Type", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 60)), - new TableColumn(@"Time", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 60)), - new TableColumn(@"Message", Anchor.CentreLeft), - new TableColumn(@"Category", Anchor.CentreRight, new Dimension(GridSizeMode.AutoSize)), + new TableColumn("Type", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 60)), + new TableColumn("Time", Anchor.CentreLeft, new Dimension(GridSizeMode.AutoSize, minSize: 60)), + new TableColumn("Message", Anchor.CentreLeft), + new TableColumn("Category", Anchor.CentreRight, new Dimension(GridSizeMode.AutoSize)), }; return columns.ToArray(); From c3b5b19c327cae91684e02d6825533459743cf23 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 30 Nov 2022 04:02:35 +0300 Subject: [PATCH 34/49] Make TrianglesV2 test scene consistent --- .../Visual/Background/TestSceneTrianglesV2Background.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs index 8d6aef99ad..e8e3c80d48 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -54,7 +54,11 @@ namespace osu.Game.Tests.Visual.Background { base.LoadComplete(); - AddSliderStep("Spawn ratio", 0f, 2f, 1f, s => triangles.SpawnRatio = s); + AddSliderStep("Spawn ratio", 0f, 5f, 1f, s => + { + triangles.SpawnRatio = s; + triangles.Reset(1234); + }); AddSliderStep("Thickness", 0f, 1f, 0.02f, t => triangles.Thickness = t); } } From 3b13ca116719271c197aa5ab1f8dbbf063056ceb Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 30 Nov 2022 04:09:46 +0300 Subject: [PATCH 35/49] Remove texture from TrianglesV2 --- .../TestSceneTrianglesV2Background.cs | 4 +- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 87 ++++++------------- .../Graphics/UserInterfaceV2/RoundedButton.cs | 4 +- 3 files changed, 30 insertions(+), 65 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs index e8e3c80d48..4f37d5e988 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics.Shapes; using osuTK; using osuTK.Graphics; using osu.Game.Graphics.Backgrounds; +using osu.Framework.Graphics.Colour; namespace osu.Game.Tests.Visual.Background { @@ -42,8 +43,7 @@ namespace osu.Game.Tests.Visual.Background Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.Both, - ColourTop = Color4.White, - ColourBottom = Color4.Red + Colour = ColourInfo.GradientVertical(Color4.White, Color4.Red) } } } diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 6e6514690d..4838c1ec04 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -11,9 +11,7 @@ using osu.Framework.Allocation; using System.Collections.Generic; using osu.Framework.Graphics.Rendering; using osu.Framework.Graphics.Rendering.Vertices; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp; -using osuTK.Graphics; +using osu.Framework.Graphics.Colour; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -23,28 +21,12 @@ namespace osu.Game.Graphics.Backgrounds { private const float triangle_size = 100; private const float base_velocity = 50; - private const int texture_height = 128; /// /// sqrt(3) / 2 /// private const float equilateral_triangle_ratio = 0.866f; - private readonly Bindable colourTop = new Bindable(Color4.White); - private readonly Bindable colourBottom = new Bindable(Color4.Black); - - public Color4 ColourTop - { - get => colourTop.Value; - set => colourTop.Value = value; - } - - public Color4 ColourBottom - { - get => colourBottom.Value; - set => colourBottom.Value = value; - } - public float Thickness { get; set; } = 0.02f; // No need for invalidation since it's happening in Update() /// @@ -89,42 +71,19 @@ namespace osu.Game.Graphics.Backgrounds } [BackgroundDependencyLoader] - private void load(ShaderManager shaders) + private void load(ShaderManager shaders, IRenderer renderer) { shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "TriangleBorder"); + texture = renderer.WhitePixel; } protected override void LoadComplete() { base.LoadComplete(); - colourTop.BindValueChanged(_ => updateTexture()); - colourBottom.BindValueChanged(_ => updateTexture(), true); - spawnRatio.BindValueChanged(_ => Reset(), true); } - private void updateTexture() - { - var image = new Image(texture_height, 1); - - texture = renderer.CreateTexture(1, texture_height, true); - - for (int i = 0; i < texture_height; i++) - { - float ratio = (float)i / texture_height; - - image[i, 0] = new Rgba32( - colourBottom.Value.R * ratio + colourTop.Value.R * (1f - ratio), - colourBottom.Value.G * ratio + colourTop.Value.G * (1f - ratio), - colourBottom.Value.B * ratio + colourTop.Value.B * (1f - ratio) - ); - } - - texture.SetData(new TextureUpload(image)); - Invalidate(Invalidation.DrawNode); - } - protected override void Update() { base.Update(); @@ -280,36 +239,42 @@ namespace osu.Game.Graphics.Backgrounds shader.GetUniform("thickness").UpdateValue(ref thickness); shader.GetUniform("texelSize").UpdateValue(ref texelSize); - float texturePartWidth = triangleSize.X / size.X; - float texturePartHeight = triangleSize.Y / size.Y * texture_height; + float relativeHeight = triangleSize.Y / size.Y; + float relativeWidth = triangleSize.X / size.X; foreach (TriangleParticle particle in parts) { - Vector2 topLeft = particle.Position * size - new Vector2(triangleSize.X * 0.5f, 0f); - Vector2 topRight = topLeft + new Vector2(triangleSize.X, 0f); - Vector2 bottomLeft = topLeft + new Vector2(0f, triangleSize.Y); - Vector2 bottomRight = topLeft + triangleSize; + Vector2 topLeft = particle.Position - new Vector2(relativeWidth * 0.5f, 0f); + Vector2 topRight = topLeft + new Vector2(relativeWidth, 0f); + Vector2 bottomLeft = topLeft + new Vector2(0f, relativeHeight); + Vector2 bottomRight = bottomLeft + new Vector2(relativeWidth, 0f); var drawQuad = new Quad( - Vector2Extensions.Transform(topLeft, DrawInfo.Matrix), - Vector2Extensions.Transform(topRight, DrawInfo.Matrix), - Vector2Extensions.Transform(bottomLeft, DrawInfo.Matrix), - Vector2Extensions.Transform(bottomRight, DrawInfo.Matrix) + Vector2Extensions.Transform(topLeft * size, DrawInfo.Matrix), + Vector2Extensions.Transform(topRight * size, DrawInfo.Matrix), + Vector2Extensions.Transform(bottomLeft * size, DrawInfo.Matrix), + Vector2Extensions.Transform(bottomRight * size, DrawInfo.Matrix) ); - var tRect = new Quad( - topLeft.X / size.X, - topLeft.Y / size.Y * texture_height, - texturePartWidth, - texturePartHeight - ).AABBFloat; + ColourInfo colourInfo = triangleColourInfo(DrawColourInfo.Colour, new Quad(topLeft, topRight, bottomLeft, bottomRight)); - renderer.DrawQuad(texture, drawQuad, DrawColourInfo.Colour, tRect, vertexBatch.AddAction, textureCoords: tRect); + renderer.DrawQuad(texture, drawQuad, colourInfo, vertexAction: vertexBatch.AddAction); } shader.Unbind(); } + private static ColourInfo triangleColourInfo(ColourInfo source, Quad quad) + { + return new ColourInfo + { + TopLeft = source.Interpolate(quad.TopLeft), + TopRight = source.Interpolate(quad.TopRight), + BottomLeft = source.Interpolate(quad.BottomLeft), + BottomRight = source.Interpolate(quad.BottomRight) + }; + } + protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); diff --git a/osu.Game/Graphics/UserInterfaceV2/RoundedButton.cs b/osu.Game/Graphics/UserInterfaceV2/RoundedButton.cs index 6dc99f5269..6aded3fe32 100644 --- a/osu.Game/Graphics/UserInterfaceV2/RoundedButton.cs +++ b/osu.Game/Graphics/UserInterfaceV2/RoundedButton.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; using osu.Framework.Localisation; @@ -79,8 +80,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 Debug.Assert(triangleGradientSecondColour != null); - Triangles.ColourTop = triangleGradientSecondColour.Value; - Triangles.ColourBottom = BackgroundColour; + Triangles.Colour = ColourInfo.GradientVertical(triangleGradientSecondColour.Value, BackgroundColour); } protected override bool OnHover(HoverEvent e) From 745cb0b13aea51f224b646bfa7beace70ee836ec Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 30 Nov 2022 04:17:37 +0300 Subject: [PATCH 36/49] Improve test scene --- .../Visual/Background/TestSceneTrianglesV2Background.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs index 4f37d5e988..2a4e9a7356 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -42,8 +42,7 @@ namespace osu.Game.Tests.Visual.Background { Anchor = Anchor.Centre, Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Colour = ColourInfo.GradientVertical(Color4.White, Color4.Red) + RelativeSizeAxes = Axes.Both } } } @@ -60,6 +59,10 @@ namespace osu.Game.Tests.Visual.Background triangles.Reset(1234); }); AddSliderStep("Thickness", 0f, 1f, 0.02f, t => triangles.Thickness = t); + + AddStep("White colour", () => triangles.Colour = Color4.White); + AddStep("Vertical gradient", () => triangles.Colour = ColourInfo.GradientVertical(Color4.White, Color4.Red)); + AddStep("Horizontal gradient", () => triangles.Colour = ColourInfo.GradientHorizontal(Color4.White, Color4.Red)); } } } From 2eaefcad304c8da2780f5ab5f503f898c9e717f7 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 30 Nov 2022 04:56:07 +0300 Subject: [PATCH 37/49] Remove unused renderer --- osu.Game/Graphics/Backgrounds/TrianglesV2.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs index 4838c1ec04..d543f082b4 100644 --- a/osu.Game/Graphics/Backgrounds/TrianglesV2.cs +++ b/osu.Game/Graphics/Backgrounds/TrianglesV2.cs @@ -52,9 +52,6 @@ namespace osu.Game.Graphics.Backgrounds private readonly List parts = new List(); - [Resolved] - private IRenderer renderer { get; set; } = null!; - private Random? stableRandom; private IShader shader = null!; From fa1000777dec3af022757550bf2b9578906c8f03 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 30 Nov 2022 05:12:26 +0300 Subject: [PATCH 38/49] Add box for gradient comparison --- .../TestSceneTrianglesV2Background.cs | 50 +++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs index 2a4e9a7356..ae1f3de6bf 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneTrianglesV2Background.cs @@ -14,6 +14,7 @@ namespace osu.Game.Tests.Visual.Background public partial class TestSceneTrianglesV2Background : OsuTestScene { private readonly TrianglesV2 triangles; + private readonly Box box; public TestSceneTrianglesV2Background() { @@ -24,25 +25,44 @@ namespace osu.Game.Tests.Visual.Background RelativeSizeAxes = Axes.Both, Colour = Color4.Gray }, - new Container + new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Size = new Vector2(500, 100), - Masking = true, - CornerRadius = 40, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), Children = new Drawable[] { - new Box + new Container { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Red + Size = new Vector2(500, 100), + Masking = true, + CornerRadius = 40, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Red + }, + triangles = new TrianglesV2 + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both + } + } }, - triangles = new TrianglesV2 + new Container { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both + Size = new Vector2(500, 100), + Masking = true, + CornerRadius = 40, + Child = box = new Box + { + RelativeSizeAxes = Axes.Both + } } } } @@ -53,16 +73,16 @@ namespace osu.Game.Tests.Visual.Background { base.LoadComplete(); - AddSliderStep("Spawn ratio", 0f, 5f, 1f, s => + AddSliderStep("Spawn ratio", 0f, 10f, 1f, s => { triangles.SpawnRatio = s; triangles.Reset(1234); }); AddSliderStep("Thickness", 0f, 1f, 0.02f, t => triangles.Thickness = t); - AddStep("White colour", () => triangles.Colour = Color4.White); - AddStep("Vertical gradient", () => triangles.Colour = ColourInfo.GradientVertical(Color4.White, Color4.Red)); - AddStep("Horizontal gradient", () => triangles.Colour = ColourInfo.GradientHorizontal(Color4.White, Color4.Red)); + AddStep("White colour", () => box.Colour = triangles.Colour = Color4.White); + AddStep("Vertical gradient", () => box.Colour = triangles.Colour = ColourInfo.GradientVertical(Color4.White, Color4.Red)); + AddStep("Horizontal gradient", () => box.Colour = triangles.Colour = ColourInfo.GradientHorizontal(Color4.White, Color4.Red)); } } } From 3f4d8b39caa4acf0a86b0af332c69f2a80308804 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Wed, 30 Nov 2022 12:55:45 +0900 Subject: [PATCH 39/49] Update package again --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 17237c5ca7..75828147a5 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -52,7 +52,7 @@ - + diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 9301670825..6e75450594 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -35,7 +35,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/osu.iOS.props b/osu.iOS.props index 57e58dc16a..bb20b0474d 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -62,7 +62,7 @@ - + @@ -82,7 +82,7 @@ - + From 0659c8434156e3f2da41b6abb82317a5cafc8c46 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 14:17:49 +0900 Subject: [PATCH 40/49] Rename method to be more in line with project naming --- osu.Game/Screens/Edit/EditorTable.cs | 2 +- osu.Game/Screens/Edit/Timing/ControlPointTable.cs | 7 ++----- osu.Game/Screens/Edit/Verify/IssueTable.cs | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Edit/EditorTable.cs b/osu.Game/Screens/Edit/EditorTable.cs index 2443cfcbf0..b79d71b42b 100644 --- a/osu.Game/Screens/Edit/EditorTable.cs +++ b/osu.Game/Screens/Edit/EditorTable.cs @@ -46,7 +46,7 @@ namespace osu.Game.Screens.Edit }); } - protected void SetRowSelected(object? item) + protected void SetSelectedRow(object? item) { foreach (var b in BackgroundFlow) { diff --git a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs index eeae1bcb9a..b10959d224 100644 --- a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs +++ b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs @@ -61,13 +61,10 @@ namespace osu.Game.Screens.Edit.Timing { base.LoadComplete(); - selectedGroup.BindValueChanged(_ => - { - updateSelectedGroup(); - }, true); + selectedGroup.BindValueChanged(_ => updateSelectedGroup(), true); } - private void updateSelectedGroup() => SetRowSelected(selectedGroup.Value); + private void updateSelectedGroup() => SetSelectedRow(selectedGroup.Value); private TableColumn[] createHeaders() { diff --git a/osu.Game/Screens/Edit/Verify/IssueTable.cs b/osu.Game/Screens/Edit/Verify/IssueTable.cs index dbd007e423..ba5f98a772 100644 --- a/osu.Game/Screens/Edit/Verify/IssueTable.cs +++ b/osu.Game/Screens/Edit/Verify/IssueTable.cs @@ -77,7 +77,7 @@ namespace osu.Game.Screens.Edit.Verify selectedIssue = verify.SelectedIssue.GetBoundCopy(); selectedIssue.BindValueChanged(issue => { - SetRowSelected(issue.NewValue); + SetSelectedRow(issue.NewValue); }, true); } From 2a3b24d058eb1be089c503367bb60bfdf008319d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 14:20:54 +0900 Subject: [PATCH 41/49] Avoid need for implicit null casting --- osu.Game/Screens/Edit/Timing/ControlPointTable.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs index b10959d224..08b2ce8562 100644 --- a/osu.Game/Screens/Edit/Timing/ControlPointTable.cs +++ b/osu.Game/Screens/Edit/Timing/ControlPointTable.cs @@ -157,14 +157,12 @@ namespace osu.Game.Screens.Edit.Timing fill.ChildrenEnumerable = controlPoints .Where(matchFunction) .Select(createAttribute) - .Where(c => c != null) - .Select(c => c!) // arbitrary ordering to make timing points first. // probably want to explicitly define order in the future. .OrderByDescending(c => c.GetType().Name); } - private Drawable? createAttribute(ControlPoint controlPoint) + private Drawable createAttribute(ControlPoint controlPoint) { switch (controlPoint) { @@ -179,10 +177,9 @@ namespace osu.Game.Screens.Edit.Timing case SampleControlPoint sample: return new SampleRowAttribute(sample); - - default: - return null; } + + throw new ArgumentOutOfRangeException(nameof(controlPoint), $"Control point type {controlPoint.GetType()} is not supported"); } } } From b5c514a8f0eeb6da346e007d4d0a7a6e932579b2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 14:30:20 +0900 Subject: [PATCH 42/49] Make incoming `Channel` target non-nullable --- .../Visual/Online/TestSceneNowPlayingCommand.cs | 10 +++++----- osu.Game/Online/Chat/NowPlayingCommand.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs b/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs index 362ebd1e74..4675410164 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneNowPlayingCommand.cs @@ -34,7 +34,7 @@ namespace osu.Game.Tests.Visual.Online { AddStep("Set activity", () => api.Activity.Value = new UserActivity.InLobby(null)); - AddStep("Run command", () => Add(new NowPlayingCommand())); + AddStep("Run command", () => Add(new NowPlayingCommand(new Channel()))); AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is listening")); } @@ -44,7 +44,7 @@ namespace osu.Game.Tests.Visual.Online { AddStep("Set activity", () => api.Activity.Value = new UserActivity.Editing(new BeatmapInfo())); - AddStep("Run command", () => Add(new NowPlayingCommand())); + AddStep("Run command", () => Add(new NowPlayingCommand(new Channel()))); AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is editing")); } @@ -54,7 +54,7 @@ namespace osu.Game.Tests.Visual.Online { AddStep("Set activity", () => api.Activity.Value = new UserActivity.InSoloGame(new BeatmapInfo(), new RulesetInfo())); - AddStep("Run command", () => Add(new NowPlayingCommand())); + AddStep("Run command", () => Add(new NowPlayingCommand(new Channel()))); AddAssert("Check correct response", () => postTarget.LastMessage.Contains("is playing")); } @@ -70,7 +70,7 @@ namespace osu.Game.Tests.Visual.Online BeatmapInfo = { OnlineID = hasOnlineId ? 1234 : -1 } }); - AddStep("Run command", () => Add(new NowPlayingCommand())); + AddStep("Run command", () => Add(new NowPlayingCommand(new Channel()))); if (hasOnlineId) AddAssert("Check link presence", () => postTarget.LastMessage.Contains("/b/1234")); @@ -85,7 +85,7 @@ namespace osu.Game.Tests.Visual.Online AddStep("Add Hidden mod", () => SelectedMods.Value = new[] { Ruleset.Value.CreateInstance().CreateMod() }); - AddStep("Run command", () => Add(new NowPlayingCommand())); + AddStep("Run command", () => Add(new NowPlayingCommand(new Channel()))); AddAssert("Check mod is present", () => postTarget.LastMessage.Contains("+HD")); } diff --git a/osu.Game/Online/Chat/NowPlayingCommand.cs b/osu.Game/Online/Chat/NowPlayingCommand.cs index 540e0b0dc1..0e39f5ac91 100644 --- a/osu.Game/Online/Chat/NowPlayingCommand.cs +++ b/osu.Game/Online/Chat/NowPlayingCommand.cs @@ -38,7 +38,7 @@ namespace osu.Game.Online.Chat /// Creates a new to post the currently-playing beatmap to a parenting . /// /// The target channel to post to. If null, the currently-selected channel will be posted to. - public NowPlayingCommand(Channel? target = null) + public NowPlayingCommand(Channel target) { this.target = target; } From 2df6ccf33e2c9b5fa80ebcde33b8c46d126622e4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 14:31:54 +0900 Subject: [PATCH 43/49] Tidy up code --- osu.Game/Online/Chat/NowPlayingCommand.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/Chat/NowPlayingCommand.cs b/osu.Game/Online/Chat/NowPlayingCommand.cs index 0e39f5ac91..c65b06c6d8 100644 --- a/osu.Game/Online/Chat/NowPlayingCommand.cs +++ b/osu.Game/Online/Chat/NowPlayingCommand.cs @@ -68,6 +68,9 @@ namespace osu.Game.Online.Chat break; } + channelManager.PostMessage($"is {verb} {getBeatmapPart()} {getModPart()}", true, target); + Expire(); + string getBeatmapPart() { string beatmapInfoString = localisation.GetLocalisedBindableString(beatmapInfo.GetDisplayTitleRomanisable()).Value; @@ -84,23 +87,20 @@ namespace osu.Game.Online.Chat return string.Empty; } - StringBuilder modS = new StringBuilder(); + StringBuilder modsString = new StringBuilder(); foreach (var mod in selectedMods.Value.Where(mod => mod.Type == ModType.DifficultyIncrease)) { - modS.Append($"+{mod.Acronym} "); + modsString.Append($"+{mod.Acronym} "); } foreach (var mod in selectedMods.Value.Where(mod => mod.Type != ModType.DifficultyIncrease)) { - modS.Append($"-{mod.Acronym} "); + modsString.Append($"-{mod.Acronym} "); } - return modS.ToString(); + return modsString.ToString().Trim(); } - - channelManager.PostMessage($"is {verb} {getBeatmapPart()} {getModPart()}", true, target); - Expire(); } } } From b453eecebe494acdf95de02feb38536b8f78228e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 14:43:21 +0900 Subject: [PATCH 44/49] Ensure empty pieces do not result in whitespace between elements --- osu.Game/Online/Chat/NowPlayingCommand.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/Chat/NowPlayingCommand.cs b/osu.Game/Online/Chat/NowPlayingCommand.cs index c65b06c6d8..2734b4e6dd 100644 --- a/osu.Game/Online/Chat/NowPlayingCommand.cs +++ b/osu.Game/Online/Chat/NowPlayingCommand.cs @@ -68,7 +68,15 @@ namespace osu.Game.Online.Chat break; } - channelManager.PostMessage($"is {verb} {getBeatmapPart()} {getModPart()}", true, target); + string[] pieces = + { + "is", + verb, + getBeatmapPart(), + getModPart(), + }; + + channelManager.PostMessage(string.Join(' ', pieces.Where(p => !string.IsNullOrEmpty(p))), true, target); Expire(); string getBeatmapPart() From 8bf5d6884d33ea13c06e72ed716b0fa0a15b089a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 14:47:16 +0900 Subject: [PATCH 45/49] Add ruleset to now playing string --- osu.Game/Online/Chat/NowPlayingCommand.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/osu.Game/Online/Chat/NowPlayingCommand.cs b/osu.Game/Online/Chat/NowPlayingCommand.cs index 2734b4e6dd..9902704883 100644 --- a/osu.Game/Online/Chat/NowPlayingCommand.cs +++ b/osu.Game/Online/Chat/NowPlayingCommand.cs @@ -10,6 +10,7 @@ using osu.Framework.Graphics; using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Online.API; +using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Users; @@ -29,6 +30,9 @@ namespace osu.Game.Online.Chat [Resolved] private Bindable> selectedMods { get; set; } = null!; + [Resolved] + private IBindable currentRuleset { get; set; } = null!; + [Resolved] private LocalisationManager localisation { get; set; } = null!; @@ -73,6 +77,7 @@ namespace osu.Game.Online.Chat "is", verb, getBeatmapPart(), + getRulesetPart(), getModPart(), }; @@ -86,6 +91,13 @@ namespace osu.Game.Online.Chat return beatmapInfo.OnlineID > 0 ? $"[{api.WebsiteRootUrl}/b/{beatmapInfo.OnlineID} {beatmapInfoString}]" : beatmapInfoString; } + string getRulesetPart() + { + if (api.Activity.Value is not UserActivity.InGame) return string.Empty; + + return $"<{currentRuleset.Value.Name}>"; + } + string getModPart() { if (api.Activity.Value is not UserActivity.InGame) return string.Empty; From 7fca5ee28dceb89f189232b51937bc541d16979a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 16:04:00 +0900 Subject: [PATCH 46/49] Move `DrawableUsername` into own file It's too large at this point to be a nested class. --- osu.Game/Overlays/Chat/ChatLine.cs | 206 ------------------- osu.Game/Overlays/Chat/DrawableUsername.cs | 222 +++++++++++++++++++++ 2 files changed, 222 insertions(+), 206 deletions(-) create mode 100644 osu.Game/Overlays/Chat/DrawableUsername.cs diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index e974db9fba..4d5fbaac42 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -1,7 +1,6 @@ // 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 System.Linq; using System.Collections.Generic; using osu.Framework.Allocation; @@ -9,23 +8,13 @@ using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Cursor; -using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.UserInterface; 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; -using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; -using osuTK; -using osuTK.Graphics; -using osu.Framework.Input.Events; using osu.Framework.Graphics.Sprites; -using osu.Framework.Localisation; namespace osu.Game.Overlays.Chat { @@ -190,200 +179,5 @@ namespace osu.Game.Overlays.Chat ? $@"{message.Timestamp.LocalDateTime:HH:mm:ss}" : $@"{message.Timestamp.LocalDateTime:hh:mm:ss tt}"; } - - private partial class DrawableUsername : OsuClickableContainer, IHasContextMenu - { - public new Color4 Colour { get; private set; } - - public float FontSize - { - set => drawableText.Font = OsuFont.GetFont(size: value, weight: FontWeight.Bold, italics: true); - } - - public LocalisableString Text - { - set => drawableText.Text = value; - } - - public override float Width - { - get => base.Width; - set => base.Width = drawableText.MaxWidth = value; - } - - [Resolved(canBeNull: false)] - private IAPIProvider api { get; set; } = null!; - - [Resolved(canBeNull: false)] - private OsuColour osuColours { get; set; } = null!; - - [Resolved] - private ChannelManager? chatManager { get; set; } - - [Resolved] - private ChatOverlay? chatOverlay { get; set; } - - [Resolved] - private UserProfileOverlay? profileOverlay { get; set; } - - private readonly APIUser user; - private readonly OsuSpriteText drawableText; - - private readonly Drawable colouredDrawable; - - public DrawableUsername(APIUser user) - { - this.user = user; - - Action = openUserProfile; - - drawableText = new OsuSpriteText - { - Shadow = false, - Truncate = true, - EllipsisString = "…", - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - }; - - if (string.IsNullOrWhiteSpace(user.Colour)) - { - Colour = default_colours[user.Id % default_colours.Length]; - - Child = colouredDrawable = drawableText; - } - else - { - Colour = Color4Extensions.FromHex(user.Colour); - - Child = new Container - { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - AutoSizeAxes = Axes.Both, - Masking = true, - CornerRadius = 4, - EdgeEffect = new EdgeEffectParameters - { - Roundness = 1, - Radius = 1, - Colour = Color4.Black.Opacity(0.3f), - Offset = new Vector2(0, 1), - Type = EdgeEffectType.Shadow, - }, - Child = new Container - { - AutoSizeAxes = Axes.Both, - Masking = true, - CornerRadius = 4, - Children = new[] - { - colouredDrawable = new Box - { - RelativeSizeAxes = Axes.Both, - }, - new Container - { - AutoSizeAxes = Axes.Both, - Padding = new MarginPadding { Left = 4, Right = 4, Bottom = 1, Top = -2 }, - Child = drawableText, - } - } - } - }; - } - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - drawableText.Colour = osuColours.ChatBlue; - colouredDrawable.Colour = Colour; - } - - public MenuItem[] ContextMenuItems - { - get - { - if (user.Equals(APIUser.SYSTEM_USER)) - return Array.Empty(); - - List items = new List - { - new OsuMenuItem("View Profile", MenuItemType.Highlighted, openUserProfile) - }; - - if (!user.Equals(api.LocalUser.Value)) - items.Add(new OsuMenuItem("Start Chat", MenuItemType.Standard, openUserChannel)); - - return items.ToArray(); - } - } - - private void openUserChannel() - { - chatManager?.OpenPrivateChannel(user); - chatOverlay?.Show(); - } - - private void openUserProfile() - { - profileOverlay?.ShowUser(user); - } - - protected override bool OnHover(HoverEvent e) - { - colouredDrawable.FadeColour(Colour.Lighten(0.4f), 150, Easing.OutQuint); - - return base.OnHover(e); - } - - protected override void OnHoverLost(HoverLostEvent e) - { - base.OnHoverLost(e); - - colouredDrawable.FadeColour(Colour, 250, Easing.OutQuint); - } - - private static readonly Color4[] default_colours = - { - Color4Extensions.FromHex("588c7e"), - Color4Extensions.FromHex("b2a367"), - Color4Extensions.FromHex("c98f65"), - Color4Extensions.FromHex("bc5151"), - Color4Extensions.FromHex("5c8bd6"), - Color4Extensions.FromHex("7f6ab7"), - Color4Extensions.FromHex("a368ad"), - Color4Extensions.FromHex("aa6880"), - - Color4Extensions.FromHex("6fad9b"), - Color4Extensions.FromHex("f2e394"), - Color4Extensions.FromHex("f2ae72"), - Color4Extensions.FromHex("f98f8a"), - Color4Extensions.FromHex("7daef4"), - Color4Extensions.FromHex("a691f2"), - Color4Extensions.FromHex("c894d3"), - Color4Extensions.FromHex("d895b0"), - - Color4Extensions.FromHex("53c4a1"), - Color4Extensions.FromHex("eace5c"), - Color4Extensions.FromHex("ea8c47"), - Color4Extensions.FromHex("fc4f4f"), - Color4Extensions.FromHex("3d94ea"), - Color4Extensions.FromHex("7760ea"), - Color4Extensions.FromHex("af52c6"), - Color4Extensions.FromHex("e25696"), - - Color4Extensions.FromHex("677c66"), - Color4Extensions.FromHex("9b8732"), - Color4Extensions.FromHex("8c5129"), - Color4Extensions.FromHex("8c3030"), - Color4Extensions.FromHex("1f5d91"), - Color4Extensions.FromHex("4335a5"), - Color4Extensions.FromHex("812a96"), - Color4Extensions.FromHex("992861"), - }; - } } } diff --git a/osu.Game/Overlays/Chat/DrawableUsername.cs b/osu.Game/Overlays/Chat/DrawableUsername.cs new file mode 100644 index 0000000000..c8c7d38ce6 --- /dev/null +++ b/osu.Game/Overlays/Chat/DrawableUsername.cs @@ -0,0 +1,222 @@ +// 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 System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Effects; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input.Events; +using osu.Framework.Localisation; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.Chat; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Overlays.Chat +{ + public partial class DrawableUsername : OsuClickableContainer, IHasContextMenu + { + public new Color4 Colour { get; private set; } + + public float FontSize + { + set => drawableText.Font = OsuFont.GetFont(size: value, weight: FontWeight.Bold, italics: true); + } + + public LocalisableString Text + { + set => drawableText.Text = value; + } + + public override float Width + { + get => base.Width; + set => base.Width = drawableText.MaxWidth = value; + } + + [Resolved(canBeNull: false)] + private IAPIProvider api { get; set; } = null!; + + [Resolved(canBeNull: false)] + private OsuColour osuColours { get; set; } = null!; + + [Resolved] + private ChannelManager? chatManager { get; set; } + + [Resolved] + private ChatOverlay? chatOverlay { get; set; } + + [Resolved] + private UserProfileOverlay? profileOverlay { get; set; } + + private readonly APIUser user; + private readonly OsuSpriteText drawableText; + + private readonly Drawable colouredDrawable; + + public DrawableUsername(APIUser user) + { + this.user = user; + + Action = openUserProfile; + + drawableText = new OsuSpriteText + { + Shadow = false, + Truncate = true, + EllipsisString = "…", + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + }; + + if (string.IsNullOrWhiteSpace(user.Colour)) + { + Colour = default_colours[user.Id % default_colours.Length]; + + Child = colouredDrawable = drawableText; + } + else + { + Colour = Color4Extensions.FromHex(user.Colour); + + Child = new Container + { + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + AutoSizeAxes = Axes.Both, + Masking = true, + CornerRadius = 4, + EdgeEffect = new EdgeEffectParameters + { + Roundness = 1, + Radius = 1, + Colour = Color4.Black.Opacity(0.3f), + Offset = new Vector2(0, 1), + Type = EdgeEffectType.Shadow, + }, + Child = new Container + { + AutoSizeAxes = Axes.Both, + Masking = true, + CornerRadius = 4, + Children = new[] + { + colouredDrawable = new Box + { + RelativeSizeAxes = Axes.Both, + }, + new Container + { + AutoSizeAxes = Axes.Both, + Padding = new MarginPadding { Left = 4, Right = 4, Bottom = 1, Top = -2 }, + Child = drawableText, + } + } + } + }; + } + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + drawableText.Colour = osuColours.ChatBlue; + colouredDrawable.Colour = Colour; + } + + public MenuItem[] ContextMenuItems + { + get + { + if (user.Equals(APIUser.SYSTEM_USER)) + return Array.Empty(); + + List items = new List + { + new OsuMenuItem("View Profile", MenuItemType.Highlighted, openUserProfile) + }; + + if (!user.Equals(api.LocalUser.Value)) + items.Add(new OsuMenuItem("Start Chat", MenuItemType.Standard, openUserChannel)); + + return items.ToArray(); + } + } + + private void openUserChannel() + { + chatManager?.OpenPrivateChannel(user); + chatOverlay?.Show(); + } + + private void openUserProfile() + { + profileOverlay?.ShowUser(user); + } + + protected override bool OnHover(HoverEvent e) + { + colouredDrawable.FadeColour(Colour.Lighten(0.4f), 150, Easing.OutQuint); + + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + base.OnHoverLost(e); + + colouredDrawable.FadeColour(Colour, 250, Easing.OutQuint); + } + + private static readonly Color4[] default_colours = + { + Color4Extensions.FromHex("588c7e"), + Color4Extensions.FromHex("b2a367"), + Color4Extensions.FromHex("c98f65"), + Color4Extensions.FromHex("bc5151"), + Color4Extensions.FromHex("5c8bd6"), + Color4Extensions.FromHex("7f6ab7"), + Color4Extensions.FromHex("a368ad"), + Color4Extensions.FromHex("aa6880"), + + Color4Extensions.FromHex("6fad9b"), + Color4Extensions.FromHex("f2e394"), + Color4Extensions.FromHex("f2ae72"), + Color4Extensions.FromHex("f98f8a"), + Color4Extensions.FromHex("7daef4"), + Color4Extensions.FromHex("a691f2"), + Color4Extensions.FromHex("c894d3"), + Color4Extensions.FromHex("d895b0"), + + Color4Extensions.FromHex("53c4a1"), + Color4Extensions.FromHex("eace5c"), + Color4Extensions.FromHex("ea8c47"), + Color4Extensions.FromHex("fc4f4f"), + Color4Extensions.FromHex("3d94ea"), + Color4Extensions.FromHex("7760ea"), + Color4Extensions.FromHex("af52c6"), + Color4Extensions.FromHex("e25696"), + + Color4Extensions.FromHex("677c66"), + Color4Extensions.FromHex("9b8732"), + Color4Extensions.FromHex("8c5129"), + Color4Extensions.FromHex("8c3030"), + Color4Extensions.FromHex("1f5d91"), + Color4Extensions.FromHex("4335a5"), + Color4Extensions.FromHex("812a96"), + Color4Extensions.FromHex("992861"), + }; + } +} From 80b0e4a99da48122dd4cfbc2224ab3681bda8a45 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 16:07:21 +0900 Subject: [PATCH 47/49] Rename `Colour` to avoid conflict with `Drawable.Colour` --- osu.Game/Overlays/Chat/ChatLine.cs | 2 +- osu.Game/Overlays/Chat/DrawableUsername.cs | 26 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index 4d5fbaac42..2b8718939e 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -139,7 +139,7 @@ namespace osu.Game.Overlays.Chat CornerRadius = 2f, Masking = true, RelativeSizeAxes = Axes.Both, - Colour = drawableUsername.Colour.Darken(1f), + Colour = drawableUsername.AccentColour.Darken(1f), Depth = float.MaxValue, Child = new Box { RelativeSizeAxes = Axes.Both } }); diff --git a/osu.Game/Overlays/Chat/DrawableUsername.cs b/osu.Game/Overlays/Chat/DrawableUsername.cs index c8c7d38ce6..d6dbb76f37 100644 --- a/osu.Game/Overlays/Chat/DrawableUsername.cs +++ b/osu.Game/Overlays/Chat/DrawableUsername.cs @@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Chat { public partial class DrawableUsername : OsuClickableContainer, IHasContextMenu { - public new Color4 Colour { get; private set; } + public Color4 AccentColour { get; } public float FontSize { @@ -45,19 +45,19 @@ namespace osu.Game.Overlays.Chat set => base.Width = drawableText.MaxWidth = value; } - [Resolved(canBeNull: false)] + [Resolved] private IAPIProvider api { get; set; } = null!; - [Resolved(canBeNull: false)] - private OsuColour osuColours { get; set; } = null!; - [Resolved] + private OsuColour colours { get; set; } = null!; + + [Resolved(canBeNull: true)] private ChannelManager? chatManager { get; set; } - [Resolved] + [Resolved(canBeNull: true)] private ChatOverlay? chatOverlay { get; set; } - [Resolved] + [Resolved(canBeNull: true)] private UserProfileOverlay? profileOverlay { get; set; } private readonly APIUser user; @@ -82,13 +82,13 @@ namespace osu.Game.Overlays.Chat if (string.IsNullOrWhiteSpace(user.Colour)) { - Colour = default_colours[user.Id % default_colours.Length]; + AccentColour = default_colours[user.Id % default_colours.Length]; Child = colouredDrawable = drawableText; } else { - Colour = Color4Extensions.FromHex(user.Colour); + AccentColour = Color4Extensions.FromHex(user.Colour); Child = new Container { @@ -132,8 +132,8 @@ namespace osu.Game.Overlays.Chat { base.LoadComplete(); - drawableText.Colour = osuColours.ChatBlue; - colouredDrawable.Colour = Colour; + drawableText.Colour = colours.ChatBlue; + colouredDrawable.Colour = AccentColour; } public MenuItem[] ContextMenuItems @@ -168,7 +168,7 @@ namespace osu.Game.Overlays.Chat protected override bool OnHover(HoverEvent e) { - colouredDrawable.FadeColour(Colour.Lighten(0.4f), 150, Easing.OutQuint); + colouredDrawable.FadeColour(AccentColour.Lighten(0.4f), 150, Easing.OutQuint); return base.OnHover(e); } @@ -177,7 +177,7 @@ namespace osu.Game.Overlays.Chat { base.OnHoverLost(e); - colouredDrawable.FadeColour(Colour, 250, Easing.OutQuint); + colouredDrawable.FadeColour(AccentColour, 250, Easing.OutQuint); } private static readonly Color4[] default_colours = From 24ee363563d23cf558011b1bad1e0cacdfa17295 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 16:12:17 +0900 Subject: [PATCH 48/49] Only hover when hovering actual text --- osu.Game/Overlays/Chat/DrawableUsername.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Overlays/Chat/DrawableUsername.cs b/osu.Game/Overlays/Chat/DrawableUsername.cs index d6dbb76f37..4a3aa6e53f 100644 --- a/osu.Game/Overlays/Chat/DrawableUsername.cs +++ b/osu.Game/Overlays/Chat/DrawableUsername.cs @@ -29,6 +29,9 @@ namespace osu.Game.Overlays.Chat { public Color4 AccentColour { get; } + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => + Child.ReceivePositionalInputAt(screenSpacePos); + public float FontSize { set => drawableText.Font = OsuFont.GetFont(size: value, weight: FontWeight.Bold, italics: true); From f7b7b58718fbff59fdb39a382f5a1c06374245ba Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 30 Nov 2022 16:20:01 +0900 Subject: [PATCH 49/49] Adjust colour and tween to feel better --- osu.Game/Overlays/Chat/DrawableUsername.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Chat/DrawableUsername.cs b/osu.Game/Overlays/Chat/DrawableUsername.cs index 4a3aa6e53f..7026d519a5 100644 --- a/osu.Game/Overlays/Chat/DrawableUsername.cs +++ b/osu.Game/Overlays/Chat/DrawableUsername.cs @@ -171,7 +171,7 @@ namespace osu.Game.Overlays.Chat protected override bool OnHover(HoverEvent e) { - colouredDrawable.FadeColour(AccentColour.Lighten(0.4f), 150, Easing.OutQuint); + colouredDrawable.FadeColour(AccentColour.Lighten(0.6f), 30, Easing.OutQuint); return base.OnHover(e); } @@ -180,7 +180,7 @@ namespace osu.Game.Overlays.Chat { base.OnHoverLost(e); - colouredDrawable.FadeColour(AccentColour, 250, Easing.OutQuint); + colouredDrawable.FadeColour(AccentColour, 800, Easing.OutQuint); } private static readonly Color4[] default_colours =