1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 14:25:10 +08:00

Simplify orientation locking code magnificently

This commit is contained in:
Salman Alshamrani 2025-01-25 19:08:01 -05:00
parent ffc37cece0
commit bb7daae080

View File

@ -50,31 +50,23 @@ namespace osu.Game.Mobile
bool lockCurrentOrientation = localUserPlaying.Value == LocalUserPlayingState.Playing;
bool lockToPortraitOnPhone = requiresPortraitOrientation.Value;
if (lockCurrentOrientation)
if (IsTablet)
{
if (!IsTablet && lockToPortraitOnPhone && !IsCurrentOrientationPortrait)
SetAllowedOrientations(GameOrientation.Portrait);
else if (!IsTablet && !lockToPortraitOnPhone && IsCurrentOrientationPortrait)
SetAllowedOrientations(GameOrientation.Landscape);
if (lockCurrentOrientation)
SetAllowedOrientations(GameOrientation.Locked);
else
SetAllowedOrientations(null);
}
else
{
// if the orientation is already portrait/landscape according to the game's specifications,
// then use Locked instead of Portrait/Landscape to handle the case where the device is
// in landscape-left or reverse-portrait.
SetAllowedOrientations(GameOrientation.Locked);
}
return;
}
if (!IsTablet && lockToPortraitOnPhone)
{
if (lockToPortraitOnPhone)
SetAllowedOrientations(GameOrientation.Portrait);
return;
}
else if (lockCurrentOrientation)
SetAllowedOrientations(GameOrientation.Locked);
else
SetAllowedOrientations(null);
}
}
/// <summary>
/// Sets the allowed orientations the device can rotate to.