Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust the behaviour of resolution number box in tournament client #32074

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions osu.Game.Tournament/Screens/Setup/ResolutionConfirmationPopup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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;
}
}
51 changes: 28 additions & 23 deletions osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
7 changes: 6 additions & 1 deletion osu.Game.Tournament/Screens/Setup/SetupScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading