From 8cf9e496d1c4c8e987e189eaa3572f87a3ec7472 Mon Sep 17 00:00:00 2001 From: CloneWith Date: Mon, 24 Feb 2025 13:58:51 +0800 Subject: [PATCH 1/4] Update client resolution on number box commit --- .../Screens/Setup/ResolutionSelector.cs | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs index c700e3bfdd59..8a3febd000a1 100644 --- a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs +++ b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs @@ -22,32 +22,37 @@ protected override Drawable CreateComponent() FlowContainer.Insert(-1, numberBox = new OsuNumberBox { Text = "1080", - Width = 100 + Width = 100, + CommitOnFocusLost = false, }); - base.Action = () => - { - if (string.IsNullOrEmpty(numberBox.Text)) - return; - - // box contains text - if (!int.TryParse(numberBox.Text, out int number)) - { - // at this point, the only reason we can arrive here is if the input number was too big to parse into an int - // so clamp to max allowed value - number = maximum_window_height; - } - else - { - number = Math.Clamp(number, minimum_window_height, maximum_window_height); - } - - // in case number got clamped, reset number in numberBox - numberBox.Text = number.ToString(); - - Action?.Invoke(number); - }; + numberBox.OnCommit += (_, _) => checkAndApply(); + base.Action = checkAndApply; + return drawable; } + + private void checkAndApply() + { + if (string.IsNullOrEmpty(numberBox?.Text)) + return; + + // box contains text + if (!int.TryParse(numberBox.Text, out int number)) + { + // at this point, the only reason we can arrive here is if the input number was too big to parse into an int + // so clamp to max allowed value + number = maximum_window_height; + } + else + { + number = Math.Clamp(number, minimum_window_height, maximum_window_height); + } + + // in case number got clamped, reset number in numberBox + numberBox.Text = number.ToString(); + + Action?.Invoke(number); + } } } From 00122e972c3a6bb766de4504cbcc76f7550aa48a Mon Sep 17 00:00:00 2001 From: CloneWith Date: Mon, 24 Feb 2025 14:12:20 +0800 Subject: [PATCH 2/4] Keep focus on number box after resolution changes --- osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs index 8a3febd000a1..100767f963c0 100644 --- a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs +++ b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs @@ -24,6 +24,7 @@ protected override Drawable CreateComponent() Text = "1080", Width = 100, CommitOnFocusLost = false, + ReleaseFocusOnCommit = false, }); numberBox.OnCommit += (_, _) => checkAndApply(); From dcec0696577cc223a8dee025638ecba26cafb814 Mon Sep 17 00:00:00 2001 From: CloneWith Date: Tue, 25 Feb 2025 22:43:50 +0800 Subject: [PATCH 3/4] Add conformation popup upon new resolution applied by setup --- .../Setup/ResolutionConfirmationPopup.cs | 160 ++++++++++++++++++ .../Screens/Setup/SetupScreen.cs | 7 +- 2 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Tournament/Screens/Setup/ResolutionConfirmationPopup.cs diff --git a/osu.Game.Tournament/Screens/Setup/ResolutionConfirmationPopup.cs b/osu.Game.Tournament/Screens/Setup/ResolutionConfirmationPopup.cs new file mode 100644 index 000000000000..d23afe1dfc26 --- /dev/null +++ b/osu.Game.Tournament/Screens/Setup/ResolutionConfirmationPopup.cs @@ -0,0 +1,160 @@ +// 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.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Input.Events; +using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; +using osu.Game.Graphics.UserInterfaceV2; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Tournament.Screens.Setup +{ + public partial class ResolutionConfirmationPopup : CompositeDrawable + { + private readonly Action? keepChangesAction; + private readonly Action? revertAction; + + private ProgressBar countdownBar = null!; + + private readonly BindableDouble countdownProgress = new BindableDouble(); + + public ResolutionConfirmationPopup(Action? keepChangesAction = null, Action? revertAction = null) + { + this.keepChangesAction = keepChangesAction; + this.revertAction = revertAction; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + RelativeSizeAxes = Axes.Both; + + InternalChildren = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black.Opacity(0.2f), + }, + new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, + AutoSizeEasing = Easing.OutQuint, + AutoSizeDuration = 500, + Masking = true, + CornerRadius = 10, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colours.GreySeaFoamDark, + }, + new FillFlowContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Spacing = new Vector2(15), + Padding = new MarginPadding(10), + Children = new Drawable[] + { + new TournamentSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = "Keep changes?", + Font = OsuFont.Torus.With(size: 40, weight: FontWeight.SemiBold), + }, + new TournamentSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = "Reverting to previous resolution in 15 seconds.", + Font = OsuFont.Torus.With(size: 20), + }, + countdownBar = new ProgressBar(false) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + EndTime = 15, + Height = 6, + Masking = true, + CornerRadius = 3, + FillColour = colours.Sky, + }, + new FillFlowContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(10), + Children = new Drawable[] + { + new DangerousRoundedButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = "Keep changes", + Width = 200, + Action = () => invokeAndExpire(keepChangesAction), + }, + new RoundedButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Text = "Revert", + Width = 200, + Action = () => invokeAndExpire(revertAction), + }, + }, + }, + }, + }, + }, + }, + }; + } + + private void invokeAndExpire(Action? action) + { + action?.Invoke(); + this.FadeOut(500, Easing.OutQuint).Then().Expire(); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + countdownProgress.BindValueChanged(p => + { + countdownBar.CurrentTime = p.NewValue; + + if (p.NewValue == 15d) + { + invokeAndExpire(revertAction); + } + }); + + this.TransformBindableTo(countdownProgress, 15d, 15000); + } + + protected override bool OnHover(HoverEvent e) => true; + + protected override bool OnClick(ClickEvent e) => true; + + protected override bool OnScroll(ScrollEvent e) => true; + } +} diff --git a/osu.Game.Tournament/Screens/Setup/SetupScreen.cs b/osu.Game.Tournament/Screens/Setup/SetupScreen.cs index fed9d625ee45..cca0c6e84306 100644 --- a/osu.Game.Tournament/Screens/Setup/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/Setup/SetupScreen.cs @@ -131,7 +131,12 @@ private void reload() ButtonText = "Set height", Action = height => { - windowSize.Value = new Size((int)(height * aspect_ratio / TournamentSceneManager.STREAM_AREA_WIDTH * TournamentSceneManager.REQUIRED_WIDTH), height); + Size previousSize = windowSize.Value; + Size newSize = new Size((int)(height * aspect_ratio / TournamentSceneManager.STREAM_AREA_WIDTH * TournamentSceneManager.REQUIRED_WIDTH), height); + if (previousSize == newSize) return; + + windowSize.Value = newSize; + AddInternal(new ResolutionConfirmationPopup(revertAction: () => windowSize.Value = previousSize)); } }, new LabelledSwitchButton From 1d9767380edd275a66858c5ffa30b23257157a6f Mon Sep 17 00:00:00 2001 From: CloneWith Date: Tue, 25 Feb 2025 22:46:47 +0800 Subject: [PATCH 4/4] Release focus on commit of resolution number box --- osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs index 100767f963c0..8a3febd000a1 100644 --- a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs +++ b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs @@ -24,7 +24,6 @@ protected override Drawable CreateComponent() Text = "1080", Width = 100, CommitOnFocusLost = false, - ReleaseFocusOnCommit = false, }); numberBox.OnCommit += (_, _) => checkAndApply();