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;
|
|
|
|
|
|
|
|
|
|
namespace osu.Android
|
|
|
|
|
{
|
|
|
|
|
public class GameplayScreenRotationLocker : Component
|
|
|
|
|
{
|
|
|
|
|
private Bindable<bool> localUserPlaying;
|
|
|
|
|
|
2020-10-19 02:07:42 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuGameActivity gameActivity { get; set; }
|
|
|
|
|
|
2020-10-14 19:43:56 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuGame game)
|
|
|
|
|
{
|
|
|
|
|
localUserPlaying = game.LocalUserPlaying.GetBoundCopy();
|
2020-10-19 01:42:05 +08:00
|
|
|
|
localUserPlaying.ValueChanged += updateLock;
|
2020-10-14 19:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-17 01:21:51 +08:00
|
|
|
|
private void updateLock(ValueChangedEvent<bool> 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
|
|
|
|
{
|
2020-10-19 02:07:42 +08:00
|
|
|
|
gameActivity.RequestedOrientation = userPlaying.NewValue ? ScreenOrientation.Locked : ScreenOrientation.FullUser;
|
2020-10-14 19:43:56 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|