2019-01-24 16:43:03 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-09-21 14:08:43 +08:00
|
|
|
|
2019-11-20 20:19:49 +08:00
|
|
|
using System;
|
2022-03-13 13:21:52 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-03-26 12:31:49 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2024-01-20 04:49:14 +08:00
|
|
|
using osuTK;
|
2018-09-21 14:08:43 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.UI
|
|
|
|
{
|
2019-03-26 12:31:49 +08:00
|
|
|
public partial class TaikoPlayfieldAdjustmentContainer : PlayfieldAdjustmentContainer
|
2018-09-21 14:08:43 +08:00
|
|
|
{
|
2023-04-27 00:05:47 +08:00
|
|
|
public const float MAXIMUM_ASPECT = 16f / 9f;
|
|
|
|
public const float MINIMUM_ASPECT = 5f / 4f;
|
|
|
|
|
|
|
|
public readonly IBindable<bool> LockPlayfieldAspectRange = new BindableBool(true);
|
2022-03-13 13:21:52 +08:00
|
|
|
|
2024-01-20 04:49:14 +08:00
|
|
|
public TaikoPlayfieldAdjustmentContainer()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
RelativePositionAxes = Axes.Y;
|
|
|
|
Height = TaikoPlayfield.BASE_HEIGHT;
|
|
|
|
}
|
|
|
|
|
2018-09-21 14:08:43 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2024-01-20 04:49:14 +08:00
|
|
|
const float base_relative_height = TaikoPlayfield.BASE_HEIGHT / 768;
|
|
|
|
|
|
|
|
float relativeHeight = base_relative_height;
|
2022-03-13 13:21:52 +08:00
|
|
|
|
2023-01-09 15:28:08 +08:00
|
|
|
// Players coming from stable expect to be able to change the aspect ratio regardless of the window size.
|
|
|
|
// We originally wanted to limit this more, but there was considerable pushback from the community.
|
|
|
|
//
|
|
|
|
// As a middle-ground, the aspect ratio can still be adjusted in the downwards direction but has a maximum limit.
|
|
|
|
// This is still a bit weird, because readability changes with window size, but it is what it is.
|
2023-04-27 00:05:47 +08:00
|
|
|
if (LockPlayfieldAspectRange.Value)
|
|
|
|
{
|
2023-10-17 16:40:44 +08:00
|
|
|
float currentAspect = Parent!.ChildSize.X / Parent!.ChildSize.Y;
|
2023-04-27 00:05:47 +08:00
|
|
|
|
|
|
|
if (currentAspect > MAXIMUM_ASPECT)
|
2024-01-20 04:49:14 +08:00
|
|
|
relativeHeight *= currentAspect / MAXIMUM_ASPECT;
|
2023-04-27 00:05:47 +08:00
|
|
|
else if (currentAspect < MINIMUM_ASPECT)
|
2024-01-20 04:49:14 +08:00
|
|
|
relativeHeight *= currentAspect / MINIMUM_ASPECT;
|
2023-04-27 00:05:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Limit the maximum relative height of the playfield to one-third of available area to avoid it masking out on extreme resolutions.
|
2024-01-20 04:49:14 +08:00
|
|
|
relativeHeight = Math.Min(relativeHeight, 1f / 3f);
|
2020-05-12 14:51:59 +08:00
|
|
|
|
2023-04-27 00:05:47 +08:00
|
|
|
// Position the taiko playfield exactly one playfield from the top of the screen, if there is enough space for it.
|
|
|
|
// Note that the relative height cannot exceed one-third - if that limit is hit, the playfield will be exactly centered.
|
2024-01-20 04:49:14 +08:00
|
|
|
Y = relativeHeight;
|
|
|
|
|
|
|
|
Scale = new Vector2(Math.Max(relativeHeight / base_relative_height, 1f));
|
|
|
|
Width = 1 / Scale.X;
|
2018-09-21 14:08:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|