mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Ensure exiting is disallowed if we're not at the main menu
This commit is contained in:
@ -5,7 +5,11 @@ using System;
|
|||||||
using Android.App;
|
using Android.App;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Screens;
|
||||||
using osu.Game;
|
using osu.Game;
|
||||||
|
using osu.Game.Screens.Menu;
|
||||||
using osu.Game.Updater;
|
using osu.Game.Updater;
|
||||||
using osu.Game.Utils;
|
using osu.Game.Utils;
|
||||||
using Xamarin.Essentials;
|
using Xamarin.Essentials;
|
||||||
@ -17,6 +21,8 @@ namespace osu.Android
|
|||||||
[Cached]
|
[Cached]
|
||||||
private readonly OsuGameActivity gameActivity;
|
private readonly OsuGameActivity gameActivity;
|
||||||
|
|
||||||
|
private readonly BindableBool allowExiting = new BindableBool();
|
||||||
|
|
||||||
public OsuGameAndroid(OsuGameActivity activity)
|
public OsuGameAndroid(OsuGameActivity activity)
|
||||||
: base(null)
|
: 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()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
LoadComponentAsync(new GameplayScreenRotationLocker(), Add);
|
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 UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
||||||
|
|
||||||
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
|
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
Host.AllowExitingAndroid.RemoveSource(allowExiting);
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
}
|
||||||
|
|
||||||
private class AndroidBatteryInfo : BatteryInfo
|
private class AndroidBatteryInfo : BatteryInfo
|
||||||
{
|
{
|
||||||
public override double ChargeLevel => Battery.ChargeLevel;
|
public override double ChargeLevel => Battery.ChargeLevel;
|
||||||
|
Reference in New Issue
Block a user