2020-10-14 11:43:56 +00: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.
|
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-10-14 11:43:56 +00:00
|
|
|
|
using Android.Content.PM;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game;
|
|
|
|
|
|
|
|
|
|
namespace osu.Android
|
|
|
|
|
{
|
|
|
|
|
public partial class GameplayScreenRotationLocker : Component
|
|
|
|
|
{
|
|
|
|
|
private Bindable<bool> localUserPlaying;
|
|
|
|
|
|
2020-10-18 18:07:42 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuGameActivity gameActivity { get; set; }
|
|
|
|
|
|
2020-10-14 11:43:56 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuGame game)
|
|
|
|
|
{
|
|
|
|
|
localUserPlaying = game.LocalUserPlaying.GetBoundCopy();
|
2020-10-19 08:01:24 +00:00
|
|
|
|
localUserPlaying.BindValueChanged(updateLock, true);
|
2020-10-14 11:43:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 17:21:51 +00:00
|
|
|
|
private void updateLock(ValueChangedEvent<bool> userPlaying)
|
2020-10-14 11:43:56 +00:00
|
|
|
|
{
|
2020-10-18 18:07:42 +00:00
|
|
|
|
gameActivity.RunOnUiThread(() =>
|
2020-10-14 11:43:56 +00:00
|
|
|
|
{
|
2022-02-03 12:55:04 +00:00
|
|
|
|
gameActivity.RequestedOrientation = userPlaying.NewValue ? ScreenOrientation.Locked : gameActivity.DefaultOrientation;
|
2020-10-14 11:43:56 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|