1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 05:32:56 +08:00
osu-lazer/osu.iOS/OsuGameIOS.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
2.9 KiB
C#
Raw Normal View History

// 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 System;
using Foundation;
using Microsoft.Maui.Devices;
using osu.Framework.Graphics;
using osu.Framework.iOS;
using osu.Framework.Platform;
using osu.Game;
using osu.Game.Screens;
using osu.Game.Updater;
using osu.Game.Utils;
using UIKit;
namespace osu.iOS
{
public partial class OsuGameIOS : OsuGame
{
private readonly AppDelegate appDelegate;
2019-03-01 22:20:34 +08:00
public override Version AssemblyVersion => new Version(NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString());
public override bool HideUnlicensedContent => true;
public OsuGameIOS(AppDelegate appDelegate)
{
this.appDelegate = appDelegate;
}
protected override void LoadComplete()
{
base.LoadComplete();
UserPlayingState.BindValueChanged(_ => updateOrientation());
}
protected override void ScreenChanged(IOsuScreen? current, IOsuScreen? newScreen)
{
base.ScreenChanged(current, newScreen);
if (newScreen != null)
updateOrientation();
}
private void updateOrientation()
{
bool iPad = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad;
var orientation = MobileUtils.GetOrientation(this, (IOsuScreen)ScreenStack.CurrentScreen, iPad);
switch (orientation)
{
case MobileUtils.Orientation.Locked:
appDelegate.Orientations = (UIInterfaceOrientationMask)(1 << (int)appDelegate.CurrentOrientation);
break;
case MobileUtils.Orientation.Portrait:
appDelegate.Orientations = UIInterfaceOrientationMask.Portrait;
break;
case MobileUtils.Orientation.Default:
appDelegate.Orientations = null;
break;
}
}
protected override UpdateManager CreateUpdateManager() => new MobileUpdateNotifier();
protected override BatteryInfo CreateBatteryInfo() => new IOSBatteryInfo();
protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorageIOS((IOSGameHost)host, defaultStorage);
protected override Edges SafeAreaOverrideEdges =>
// iOS shows a home indicator at the bottom, and adds a safe area to account for this.
// Because we have the home indicator (mostly) hidden we don't really care about drawing in this region.
Edges.Bottom;
private class IOSBatteryInfo : BatteryInfo
{
2022-07-30 20:26:19 +08:00
public override double? ChargeLevel => Battery.ChargeLevel;
2022-07-30 20:26:19 +08:00
public override bool OnBattery => Battery.PowerSource == BatteryPowerSource.Battery;
}
}
}