1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00
osu-lazer/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs

51 lines
1.5 KiB
C#
Raw Normal View History

using System;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Tournament.Screens.Setup
{
internal class ResolutionSelector : ActionableInfo
{
private const int minimum_window_height = 480;
private const int maximum_window_height = 2160;
public new Action<int> Action;
private OsuNumberBox numberBox;
protected override Drawable CreateComponent()
{
var drawable = base.CreateComponent();
FlowContainer.Insert(-1, numberBox = new OsuNumberBox
{
Text = "1080",
Width = 100
});
base.Action = () =>
{
if (string.IsNullOrEmpty(numberBox.Text))
return;
// box contains text
if (!int.TryParse(numberBox.Text, out var 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);
};
return drawable;
}
}
}