Finish mobile support

This commit is contained in:
Lncvrt committed 2026-02-24 15:13:48 -07:00
1 parent 39ee3d4982
commit 8094c3f7c2
6 files changed
+40 -26

No files matched your search

+2
View File
@@ -8,5 +8,7 @@ public partial class PauseMenuContinueButton : Button {
Globals.IsPaused = false;
GetNode<Control>("../..").QueueFree();
if (Utils.IsMobile()) GetNode<Node2D>("/root/Game/CanvasLayer/MobileButtons").Visible = true;
}
}
+8 -4
View File
@@ -13,6 +13,8 @@ public partial class Player : Node2D {
var WindowScale = WindowSize / ScreenSize;
Position = new Vector2(x: DisplayServer.WindowGetSize().X / 2, y: (WindowSize.Y / WindowScale.Y) - 100);
if (Utils.IsMobile()) GetNode<Node2D>("/root/Game/CanvasLayer/MobileButtons").Visible = true;
}
public override void _Process(double delta) {
@@ -23,18 +25,18 @@ public partial class Player : Node2D {
Vector2 Pos = Position;
if (!Globals.IsPaused) {
if ((Input.IsKeyPressed(Key.Left) || Input.IsKeyPressed(Key.A) || doLeft) && Pos.X > ScreenBorders) {
if ((Utils.IsMobile() ? doLeft : Input.IsKeyPressed(Key.Left) || Input.IsKeyPressed(Key.A)) && Pos.X > ScreenBorders) {
GetNode<Sprite2D>("Texture").FlipH = false;
Pos.X -= Globals.MovementSpeed * (float)delta;
}
float ScreenWidth = (WindowSize.X / WindowScale.X) - ScreenBorders;
if ((Input.IsKeyPressed(Key.Right) || Input.IsKeyPressed(Key.D) || doRight) && Pos.X < ScreenWidth) {
if ((Utils.IsMobile() ? doRight : Input.IsKeyPressed(Key.Right) || Input.IsKeyPressed(Key.D)) && Pos.X < ScreenWidth) {
GetNode<Sprite2D>("Texture").FlipH = true;
Pos.X += Globals.MovementSpeed * (float)delta;
}
if ((Input.IsKeyPressed(Key.Space) || doJump) && Pos.Y >= 976) {
if ((Utils.IsMobile() ? doJump : Input.IsKeyPressed(Key.Space)) && Pos.Y >= 976) {
VelocityY = Globals.JumpHeight;
GetNode<AudioStreamPlayer>("JumpSoundPlayer").Play();
}
@@ -79,7 +81,7 @@ public partial class Player : Node2D {
Globals.BerrySpeed = Globals.DefaultBerrySpeed * 2f;
}
if (Input.IsActionJustPressed("EscapeKey")) {
if (!Utils.IsMobile() && Input.IsActionJustPressed("EscapeKey")) {
if (!Globals.IsPaused) {
PackedScene PauseMenu = GD.Load<PackedScene>("res://Prefabs/PauseMenu.tscn");
@@ -112,6 +114,8 @@ public partial class Player : Node2D {
private void MobileJumpMoveDown() => doJump = true;
private void MobileJumpMoveUp() => doJump = false;
private void MobilePausePressed() {
if (Utils.IsMobile()) GetNode<Node2D>("/root/Game/CanvasLayer/MobileButtons").Visible = false;
PackedScene PauseMenu = GD.Load<PackedScene>("res://Prefabs/PauseMenu.tscn");
Control PauseMenuInstance = PauseMenu.Instantiate<Control>();
+12 -8
View File
@@ -9,26 +9,30 @@ public partial class SettingsContainer : VBoxContainer
public override void _Ready() {
List<string> settings = Utils.LoadSettings();
string fullscreen = settings.ElementAtOrDefault(0) ?? "1";
string vsync = settings.ElementAtOrDefault(1) ?? "1";
string showfps = settings.ElementAtOrDefault(2) ?? "0";
GetNode<CheckBox>("Fullscreen/CheckBox").ButtonPressed = fullscreen == "1";
GetNode<CheckBox>("VSync/CheckBox").ButtonPressed = vsync == "1";
if (Utils.IsMobile()) {
GetNode<Control>("Fullscreen").Visible = false;
GetNode<Control>("VSync").Visible = false;
} else {
string fullscreen = settings.ElementAtOrDefault(0) ?? "1";
string vsync = settings.ElementAtOrDefault(1) ?? "1";
GetNode<CheckBox>("Fullscreen/CheckBox").ButtonPressed = fullscreen == "1";
GetNode<CheckBox>("VSync/CheckBox").ButtonPressed = vsync == "1";
}
GetNode<CheckBox>("ShowFPS/CheckBox").ButtonPressed = showfps == "1";
ignoreToggle = false;
}
public static void Fullscreen_Toggled(bool on)
{
if (ignoreToggle) return;
if (ignoreToggle || Utils.IsMobile()) return;
Toggle(0, on);
Utils.ToggleFullscreen(on);
}
public static void VSync_Toggled(bool on)
{
if (ignoreToggle) return;
if (ignoreToggle || Utils.IsMobile()) return;
Toggle(1, on);
Utils.ToggleVSync(on);
}
@@ -38,7 +42,7 @@ public partial class SettingsContainer : VBoxContainer
if (ignoreToggle) return;
Toggle(2, on);
}
private static void Toggle(int id, bool on) {
List<string> values = Utils.LoadSettings();
while (values.Count <= id) values.Add("0");
+4 -1
View File
@@ -5,6 +5,7 @@ using Godot;
public class Utils {
public static void ToggleFullscreen(bool on, List<string> settings)
{
if (IsMobile()) return;
DisplayServer.WindowSetMode(on ? DisplayServer.WindowMode.Fullscreen : DisplayServer.WindowMode.Maximized);
string vsync = settings.ElementAtOrDefault(1) ?? "1";
@@ -19,7 +20,7 @@ public class Utils {
public static void ToggleVSync(bool on)
{
DisplayServer.WindowSetVsyncMode(on ? DisplayServer.VSyncMode.Enabled : DisplayServer.VSyncMode.Disabled);
if (!IsMobile()) DisplayServer.WindowSetVsyncMode(on ? DisplayServer.VSyncMode.Enabled : DisplayServer.VSyncMode.Disabled);
}
public static List<string> LoadSettings() {
@@ -27,4 +28,6 @@ public class Utils {
List<string> values = [.. value.Split(':')];
return values;
}
public static bool IsMobile() => OS.GetName() == "iOS" || OS.GetName() == "Android";
}