mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 05:42:56 +08:00
Ensure exiting is disallowed if we're not at the main menu
This commit is contained in:
parent
7ef710de22
commit
11a11802ed
@ -5,7 +5,11 @@ using System;
|
||||
using Android.App;
|
||||
using Android.OS;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Updater;
|
||||
using osu.Game.Utils;
|
||||
using Xamarin.Essentials;
|
||||
@ -17,6 +21,8 @@ namespace osu.Android
|
||||
[Cached]
|
||||
private readonly OsuGameActivity gameActivity;
|
||||
|
||||
private readonly BindableBool allowExiting = new BindableBool();
|
||||
|
||||
public OsuGameAndroid(OsuGameActivity activity)
|
||||
: base(null)
|
||||
{
|
||||
@ -67,16 +73,45 @@ namespace osu.Android
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetHost(GameHost host)
|
||||
{
|
||||
base.SetHost(host);
|
||||
host.AllowExitingAndroid.AddSource(allowExiting);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
LoadComponentAsync(new GameplayScreenRotationLocker(), Add);
|
||||
}
|
||||
|
||||
protected override void ScreenChanged(IScreen current, IScreen newScreen)
|
||||
{
|
||||
base.ScreenChanged(current, newScreen);
|
||||
|
||||
switch (newScreen)
|
||||
{
|
||||
case MainMenu _:
|
||||
// allow the MainMenu to (dis)allow exiting based on its ButtonSystemState.
|
||||
allowExiting.Value = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
allowExiting.Value = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
||||
|
||||
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
Host.AllowExitingAndroid.RemoveSource(allowExiting);
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
|
||||
private class AndroidBatteryInfo : BatteryInfo
|
||||
{
|
||||
public override double ChargeLevel => Battery.ChargeLevel;
|
||||
|
Loading…
Reference in New Issue
Block a user