added a toggle for displaying under the notch

This commit is contained in:
Ell 2023-03-04 12:28:05 +01:00
parent def208809c
commit c9e0ff8ec2
6 changed files with 33 additions and 11 deletions

View file

@ -46,10 +46,6 @@ public class Activity1 : AndroidGameActivity {
this.game.GraphicsDeviceManager.ApplyChanges();
};
// don't render under notches
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.Never;
this.view = this.game.Services.GetService(typeof(View)) as View;
this.SetContentView(this.view);

View file

@ -1,10 +1,11 @@
using Android.App;
using Android.Content;
using Android.OS;
using Android.Views;
using TouchyTickets;
using Uri = Android.Net.Uri;
namespace Android;
namespace Android;
public class AndroidPlatform : Platform {
@ -22,6 +23,12 @@ public class AndroidPlatform : Platform {
}
}
public override void SetRenderUnderNotch(bool value) {
// don't render under notches by default
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
this.activity.Window.Attributes.LayoutInDisplayCutoutMode = value ? LayoutInDisplayCutoutMode.ShortEdges : LayoutInDisplayCutoutMode.Never;
}
public override void OpenRateLink() {
this.activity.StartActivity(new Intent(Intent.ActionView, Uri.Parse("https://play.google.com/store/apps/details?id=de.ellpeck.touchytickets")));
}

View file

@ -9,7 +9,7 @@ using MLEM.Startup;
using TouchyTickets.Upgrades;
using Vector2 = Microsoft.Xna.Framework.Vector2;
namespace TouchyTickets;
namespace TouchyTickets;
public class GameImpl : MlemGame {
@ -30,6 +30,7 @@ public class GameImpl : MlemGame {
public GameImpl(Platform platform) {
this.Platform = platform;
this.Platform.SetRenderUnderNotch(false);
GameImpl.Instance = this;
}
@ -106,7 +107,7 @@ public class GameImpl : MlemGame {
#if DEBUG
return 3;
#else
return (int) BigInteger.Min(3, this.Tickets / this.GetStarPrice());
return (int) BigInteger.Min(3, this.Tickets / this.GetStarPrice());
#endif
}

View file

@ -24,6 +24,14 @@ public class Options {
[DataMember]
public bool WhileYouWereAwayMessage = true;
[DataMember]
public bool RenderUnderNotch {
get => this.renderUnderNotch;
set {
this.renderUnderNotch = value;
GameImpl.Instance.Platform.SetRenderUnderNotch(value);
}
}
[DataMember]
public bool KeepScreenOn {
get => this.keepScreenOn;
set {
@ -31,12 +39,14 @@ public class Options {
GameImpl.Instance.Platform.SetKeepScreenOn(value);
}
}
private bool keepScreenOn;
[DataMember]
public bool AutoBuyEnabled = true;
[DataMember]
public int MinTicketsForAutoBuy = 50000;
private bool renderUnderNotch;
private bool keepScreenOn;
public static void Save() {
var file = Options.GetOptionsFile(true);
using var stream = new JsonTextWriter(file.CreateText());

View file

@ -1,10 +1,11 @@
namespace TouchyTickets;
namespace TouchyTickets;
public abstract class Platform {
public abstract void SetKeepScreenOn(bool keep);
public abstract void SetRenderUnderNotch(bool value);
public abstract void OpenRateLink();
}

View file

@ -415,6 +415,13 @@ public class Ui {
Options.Save();
}
});
optionList.AddChild(new Checkbox(Anchor.AutoLeft, new Vector2(1, 24), Localization.Get("RenderUnderNotch"), Options.Instance.RenderUnderNotch) {
PositionOffset = new Vector2(0, 2),
OnCheckStateChange = (_, value) => {
Options.Instance.RenderUnderNotch = value;
Options.Save();
}
});
optionList.AddChild(new Checkbox(Anchor.AutoLeft, new Vector2(1, 24), Localization.Get("KeepScreenOn"), Options.Instance.KeepScreenOn) {
PositionOffset = new Vector2(0, 2),
OnCheckStateChange = (_, value) => {