2020-10-14 19:43:56 +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.
|
|
|
|
|
|
|
|
|
|
using Android.Content.PM;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game;
|
2024-10-01 17:25:45 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2020-10-14 19:43:56 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Android
|
|
|
|
|
{
|
2022-11-27 00:59:38 +08:00
|
|
|
|
public partial class GameplayScreenRotationLocker : Component
|
2020-10-14 19:43:56 +08:00
|
|
|
|
{
|
2024-10-07 15:43:50 +08:00
|
|
|
|
private IBindable<LocalUserPlayingState> localUserPlaying = null!;
|
2020-10-14 19:43:56 +08:00
|
|
|
|
|
2020-10-19 02:07:42 +08:00
|
|
|
|
[Resolved]
|
2023-06-23 00:37:25 +08:00
|
|
|
|
private OsuGameActivity gameActivity { get; set; } = null!;
|
2020-10-19 02:07:42 +08:00
|
|
|
|
|
2020-10-14 19:43:56 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2024-10-01 17:25:45 +08:00
|
|
|
|
private void load(ILocalUserPlayInfo localUserPlayInfo)
|
2020-10-14 19:43:56 +08:00
|
|
|
|
{
|
2024-10-01 17:25:45 +08:00
|
|
|
|
localUserPlaying = localUserPlayInfo.PlayingState.GetBoundCopy();
|
2020-10-19 16:01:24 +08:00
|
|
|
|
localUserPlaying.BindValueChanged(updateLock, true);
|
2020-10-14 19:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-07 15:43:50 +08:00
|
|
|
|
private void updateLock(ValueChangedEvent<LocalUserPlayingState> userPlaying)
|
2020-10-14 19:43:56 +08:00
|
|
|
|
{
|
2020-10-19 02:07:42 +08:00
|
|
|
|
gameActivity.RunOnUiThread(() =>
|
2020-10-14 19:43:56 +08:00
|
|
|
|
{
|
2024-10-07 15:43:50 +08:00
|
|
|
|
gameActivity.RequestedOrientation = userPlaying.NewValue != LocalUserPlayingState.NotPlaying ? ScreenOrientation.Locked : gameActivity.DefaultOrientation;
|
2020-10-14 19:43:56 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|