2019-03-01 19:59:39 +09: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 System;
|
|
|
|
|
using Foundation;
|
2022-12-12 01:26:13 +03:00
|
|
|
|
using Microsoft.Maui.Devices;
|
2022-02-04 18:58:29 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
2024-12-09 08:16:37 -05:00
|
|
|
|
using osu.Framework.iOS;
|
|
|
|
|
using osu.Framework.Platform;
|
2019-03-01 19:59:39 +09:00
|
|
|
|
using osu.Game;
|
2025-01-25 20:01:12 -05:00
|
|
|
|
using osu.Game.Screens;
|
2019-12-20 13:50:57 +09:00
|
|
|
|
using osu.Game.Updater;
|
2021-04-08 19:34:35 -04:00
|
|
|
|
using osu.Game.Utils;
|
2025-02-14 18:35:27 +09:00
|
|
|
|
using osuTK;
|
2025-01-01 01:43:43 -05:00
|
|
|
|
using UIKit;
|
2019-03-01 19:59:39 +09:00
|
|
|
|
|
|
|
|
|
namespace osu.iOS
|
|
|
|
|
{
|
2022-11-26 17:59:38 +01:00
|
|
|
|
public partial class OsuGameIOS : OsuGame
|
2019-03-01 19:59:39 +09:00
|
|
|
|
{
|
2024-12-24 09:23:52 -05:00
|
|
|
|
private readonly AppDelegate appDelegate;
|
2019-03-01 23:20:34 +09:00
|
|
|
|
public override Version AssemblyVersion => new Version(NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString());
|
2020-10-06 13:09:42 +09:00
|
|
|
|
|
2024-12-23 14:39:07 +09:00
|
|
|
|
public override bool HideUnlicensedContent => true;
|
|
|
|
|
|
2025-02-20 09:29:18 -05:00
|
|
|
|
public override Vector2 ScalingContainerTargetDrawSize => new Vector2(1024, 1024 * DrawHeight / DrawWidth);
|
2025-01-01 01:43:43 -05:00
|
|
|
|
|
2024-12-24 09:23:52 -05:00
|
|
|
|
public OsuGameIOS(AppDelegate appDelegate)
|
|
|
|
|
{
|
|
|
|
|
this.appDelegate = appDelegate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2025-01-25 20:01:12 -05:00
|
|
|
|
UserPlayingState.BindValueChanged(_ => updateOrientation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ScreenChanged(IOsuScreen? current, IOsuScreen? newScreen)
|
|
|
|
|
{
|
|
|
|
|
base.ScreenChanged(current, newScreen);
|
|
|
|
|
|
|
|
|
|
if (newScreen != null)
|
|
|
|
|
updateOrientation();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 05:55:21 -05:00
|
|
|
|
private void updateOrientation() => UIApplication.SharedApplication.InvokeOnMainThread(() =>
|
2025-01-25 20:01:12 -05:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
2025-02-10 05:55:21 -05:00
|
|
|
|
});
|
2024-12-24 09:23:52 -05:00
|
|
|
|
|
2024-07-05 03:29:09 -04:00
|
|
|
|
protected override UpdateManager CreateUpdateManager() => new MobileUpdateNotifier();
|
2021-04-08 19:34:35 -04:00
|
|
|
|
|
2021-04-12 10:52:12 -04:00
|
|
|
|
protected override BatteryInfo CreateBatteryInfo() => new IOSBatteryInfo();
|
2021-04-09 17:55:41 -04:00
|
|
|
|
|
2024-12-09 08:16:37 -05:00
|
|
|
|
protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorageIOS((IOSGameHost)host, defaultStorage);
|
|
|
|
|
|
2022-02-04 16:10:49 +03:00
|
|
|
|
protected override Edges SafeAreaOverrideEdges =>
|
2022-02-04 18:58:29 +09:00
|
|
|
|
// 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;
|
|
|
|
|
|
2021-04-12 10:52:12 -04:00
|
|
|
|
private class IOSBatteryInfo : BatteryInfo
|
2021-04-08 19:34:35 -04:00
|
|
|
|
{
|
2022-07-30 14:26:19 +02:00
|
|
|
|
public override double? ChargeLevel => Battery.ChargeLevel;
|
2021-04-08 19:34:35 -04:00
|
|
|
|
|
2022-07-30 14:26:19 +02:00
|
|
|
|
public override bool OnBattery => Battery.PowerSource == BatteryPowerSource.Battery;
|
2021-04-08 19:34:35 -04:00
|
|
|
|
}
|
2019-03-01 19:59:39 +09:00
|
|
|
|
}
|
|
|
|
|
}
|