Finish mobile support
This commit is contained in:
6 files changed
+39
-25
No files matched your search
@@ -138,6 +138,7 @@ text = "FPS: {}"
|
|||||||
script = ExtResource("7_acvyw")
|
script = ExtResource("7_acvyw")
|
||||||
|
|
||||||
[node name="MobileButtons" type="Node2D" parent="CanvasLayer" unique_id=2096815990]
|
[node name="MobileButtons" type="Node2D" parent="CanvasLayer" unique_id=2096815990]
|
||||||
|
visible = false
|
||||||
|
|
||||||
[node name="PauseButton" type="Button" parent="CanvasLayer/MobileButtons" unique_id=1375970461]
|
[node name="PauseButton" type="Button" parent="CanvasLayer/MobileButtons" unique_id=1375970461]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
|
|||||||
+13
-13
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=9 format=3 uid="uid://ctb5p8ymhcshq"]
|
[gd_scene format=3 uid="uid://ctb5p8ymhcshq"]
|
||||||
|
|
||||||
[ext_resource type="FontFile" uid="uid://dq7nkk7n7wrq4" path="res://Fonts/Lexend.ttf" id="1_flfri"]
|
[ext_resource type="FontFile" uid="uid://dq7nkk7n7wrq4" path="res://Fonts/Lexend.ttf" id="1_flfri"]
|
||||||
[ext_resource type="Script" uid="uid://bc4miccifwrk0" path="res://Scripts/SceneSwitcher.cs" id="2_yrknh"]
|
[ext_resource type="Script" uid="uid://bc4miccifwrk0" path="res://Scripts/SceneSwitcher.cs" id="2_yrknh"]
|
||||||
@@ -19,7 +19,7 @@ bg_color = Color(0.830335, 0.830335, 0.830335, 1)
|
|||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ppjuv"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ppjuv"]
|
||||||
bg_color = Color(0.95158, 0.95158, 0.95158, 1)
|
bg_color = Color(0.95158, 0.95158, 0.95158, 1)
|
||||||
|
|
||||||
[node name="Settings" type="Control"]
|
[node name="Settings" type="Control" unique_id=1371896601]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@@ -27,7 +27,7 @@ anchor_bottom = 1.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="Back" type="Button" parent="."]
|
[node name="Back" type="Button" parent="." unique_id=1537294544]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
offset_left = 40.0
|
offset_left = 40.0
|
||||||
offset_top = 40.0
|
offset_top = 40.0
|
||||||
@@ -48,7 +48,7 @@ text = "Back"
|
|||||||
script = ExtResource("2_yrknh")
|
script = ExtResource("2_yrknh")
|
||||||
ScenePath = "res://Scenes/MainMenu.tscn"
|
ScenePath = "res://Scenes/MainMenu.tscn"
|
||||||
|
|
||||||
[node name="SettingsContainer" type="VBoxContainer" parent="."]
|
[node name="SettingsContainer" type="VBoxContainer" parent="." unique_id=1809676807]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = 8
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
@@ -65,10 +65,10 @@ theme_override_constants/separation = 179
|
|||||||
alignment = 1
|
alignment = 1
|
||||||
script = ExtResource("3_mjqtt")
|
script = ExtResource("3_mjqtt")
|
||||||
|
|
||||||
[node name="Fullscreen" type="Control" parent="SettingsContainer"]
|
[node name="Fullscreen" type="Control" parent="SettingsContainer" unique_id=499515635]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="CheckBox" type="CheckBox" parent="SettingsContainer/Fullscreen"]
|
[node name="CheckBox" type="CheckBox" parent="SettingsContainer/Fullscreen" unique_id=2060186930]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 6
|
anchors_preset = 6
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
@@ -86,7 +86,7 @@ theme_override_icons/checked = ExtResource("3_w1nw0")
|
|||||||
theme_override_icons/unchecked = ExtResource("4_mjqtt")
|
theme_override_icons/unchecked = ExtResource("4_mjqtt")
|
||||||
icon_alignment = 1
|
icon_alignment = 1
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="SettingsContainer/Fullscreen"]
|
[node name="Label" type="Label" parent="SettingsContainer/Fullscreen" unique_id=110687269]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = 8
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
@@ -104,10 +104,10 @@ theme_override_font_sizes/font_size = 76
|
|||||||
text = "Fullscreen"
|
text = "Fullscreen"
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
[node name="VSync" type="Control" parent="SettingsContainer"]
|
[node name="VSync" type="Control" parent="SettingsContainer" unique_id=193073500]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="CheckBox" type="CheckBox" parent="SettingsContainer/VSync"]
|
[node name="CheckBox" type="CheckBox" parent="SettingsContainer/VSync" unique_id=1778104483]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 6
|
anchors_preset = 6
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
@@ -125,7 +125,7 @@ theme_override_icons/checked = ExtResource("3_w1nw0")
|
|||||||
theme_override_icons/unchecked = ExtResource("4_mjqtt")
|
theme_override_icons/unchecked = ExtResource("4_mjqtt")
|
||||||
icon_alignment = 1
|
icon_alignment = 1
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="SettingsContainer/VSync"]
|
[node name="Label" type="Label" parent="SettingsContainer/VSync" unique_id=497093617]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = 8
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
@@ -143,10 +143,10 @@ theme_override_font_sizes/font_size = 76
|
|||||||
text = "Vsync"
|
text = "Vsync"
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
[node name="ShowFPS" type="Control" parent="SettingsContainer"]
|
[node name="ShowFPS" type="Control" parent="SettingsContainer" unique_id=446297884]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="CheckBox" type="CheckBox" parent="SettingsContainer/ShowFPS"]
|
[node name="CheckBox" type="CheckBox" parent="SettingsContainer/ShowFPS" unique_id=1193185044]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 6
|
anchors_preset = 6
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
@@ -164,7 +164,7 @@ theme_override_icons/checked = ExtResource("3_w1nw0")
|
|||||||
theme_override_icons/unchecked = ExtResource("4_mjqtt")
|
theme_override_icons/unchecked = ExtResource("4_mjqtt")
|
||||||
icon_alignment = 1
|
icon_alignment = 1
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="SettingsContainer/ShowFPS"]
|
[node name="Label" type="Label" parent="SettingsContainer/ShowFPS" unique_id=948287068]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = 8
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
|
|||||||
@@ -8,5 +8,7 @@ public partial class PauseMenuContinueButton : Button {
|
|||||||
|
|
||||||
Globals.IsPaused = false;
|
Globals.IsPaused = false;
|
||||||
GetNode<Control>("../..").QueueFree();
|
GetNode<Control>("../..").QueueFree();
|
||||||
|
|
||||||
|
if (Utils.IsMobile()) GetNode<Node2D>("/root/Game/CanvasLayer/MobileButtons").Visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-4
@@ -13,6 +13,8 @@ public partial class Player : Node2D {
|
|||||||
var WindowScale = WindowSize / ScreenSize;
|
var WindowScale = WindowSize / ScreenSize;
|
||||||
|
|
||||||
Position = new Vector2(x: DisplayServer.WindowGetSize().X / 2, y: (WindowSize.Y / WindowScale.Y) - 100);
|
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) {
|
public override void _Process(double delta) {
|
||||||
@@ -23,18 +25,18 @@ public partial class Player : Node2D {
|
|||||||
Vector2 Pos = Position;
|
Vector2 Pos = Position;
|
||||||
|
|
||||||
if (!Globals.IsPaused) {
|
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;
|
GetNode<Sprite2D>("Texture").FlipH = false;
|
||||||
Pos.X -= Globals.MovementSpeed * (float)delta;
|
Pos.X -= Globals.MovementSpeed * (float)delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScreenWidth = (WindowSize.X / WindowScale.X) - ScreenBorders;
|
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;
|
GetNode<Sprite2D>("Texture").FlipH = true;
|
||||||
Pos.X += Globals.MovementSpeed * (float)delta;
|
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;
|
VelocityY = Globals.JumpHeight;
|
||||||
GetNode<AudioStreamPlayer>("JumpSoundPlayer").Play();
|
GetNode<AudioStreamPlayer>("JumpSoundPlayer").Play();
|
||||||
}
|
}
|
||||||
@@ -79,7 +81,7 @@ public partial class Player : Node2D {
|
|||||||
Globals.BerrySpeed = Globals.DefaultBerrySpeed * 2f;
|
Globals.BerrySpeed = Globals.DefaultBerrySpeed * 2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.IsActionJustPressed("EscapeKey")) {
|
if (!Utils.IsMobile() && Input.IsActionJustPressed("EscapeKey")) {
|
||||||
if (!Globals.IsPaused) {
|
if (!Globals.IsPaused) {
|
||||||
PackedScene PauseMenu = GD.Load<PackedScene>("res://Prefabs/PauseMenu.tscn");
|
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 MobileJumpMoveDown() => doJump = true;
|
||||||
private void MobileJumpMoveUp() => doJump = false;
|
private void MobileJumpMoveUp() => doJump = false;
|
||||||
private void MobilePausePressed() {
|
private void MobilePausePressed() {
|
||||||
|
if (Utils.IsMobile()) GetNode<Node2D>("/root/Game/CanvasLayer/MobileButtons").Visible = false;
|
||||||
|
|
||||||
PackedScene PauseMenu = GD.Load<PackedScene>("res://Prefabs/PauseMenu.tscn");
|
PackedScene PauseMenu = GD.Load<PackedScene>("res://Prefabs/PauseMenu.tscn");
|
||||||
|
|
||||||
Control PauseMenuInstance = PauseMenu.Instantiate<Control>();
|
Control PauseMenuInstance = PauseMenu.Instantiate<Control>();
|
||||||
|
|||||||
@@ -9,26 +9,30 @@ public partial class SettingsContainer : VBoxContainer
|
|||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
List<string> settings = Utils.LoadSettings();
|
List<string> settings = Utils.LoadSettings();
|
||||||
|
|
||||||
string fullscreen = settings.ElementAtOrDefault(0) ?? "1";
|
|
||||||
string vsync = settings.ElementAtOrDefault(1) ?? "1";
|
|
||||||
string showfps = settings.ElementAtOrDefault(2) ?? "0";
|
string showfps = settings.ElementAtOrDefault(2) ?? "0";
|
||||||
GetNode<CheckBox>("Fullscreen/CheckBox").ButtonPressed = fullscreen == "1";
|
if (Utils.IsMobile()) {
|
||||||
GetNode<CheckBox>("VSync/CheckBox").ButtonPressed = vsync == "1";
|
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";
|
GetNode<CheckBox>("ShowFPS/CheckBox").ButtonPressed = showfps == "1";
|
||||||
|
|
||||||
ignoreToggle = false;
|
ignoreToggle = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Fullscreen_Toggled(bool on)
|
public static void Fullscreen_Toggled(bool on)
|
||||||
{
|
{
|
||||||
if (ignoreToggle) return;
|
if (ignoreToggle || Utils.IsMobile()) return;
|
||||||
Toggle(0, on);
|
Toggle(0, on);
|
||||||
Utils.ToggleFullscreen(on);
|
Utils.ToggleFullscreen(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void VSync_Toggled(bool on)
|
public static void VSync_Toggled(bool on)
|
||||||
{
|
{
|
||||||
if (ignoreToggle) return;
|
if (ignoreToggle || Utils.IsMobile()) return;
|
||||||
Toggle(1, on);
|
Toggle(1, on);
|
||||||
Utils.ToggleVSync(on);
|
Utils.ToggleVSync(on);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -5,6 +5,7 @@ using Godot;
|
|||||||
public class Utils {
|
public class Utils {
|
||||||
public static void ToggleFullscreen(bool on, List<string> settings)
|
public static void ToggleFullscreen(bool on, List<string> settings)
|
||||||
{
|
{
|
||||||
|
if (IsMobile()) return;
|
||||||
DisplayServer.WindowSetMode(on ? DisplayServer.WindowMode.Fullscreen : DisplayServer.WindowMode.Maximized);
|
DisplayServer.WindowSetMode(on ? DisplayServer.WindowMode.Fullscreen : DisplayServer.WindowMode.Maximized);
|
||||||
|
|
||||||
string vsync = settings.ElementAtOrDefault(1) ?? "1";
|
string vsync = settings.ElementAtOrDefault(1) ?? "1";
|
||||||
@@ -19,7 +20,7 @@ public class Utils {
|
|||||||
|
|
||||||
public static void ToggleVSync(bool on)
|
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() {
|
public static List<string> LoadSettings() {
|
||||||
@@ -27,4 +28,6 @@ public class Utils {
|
|||||||
List<string> values = [.. value.Split(':')];
|
List<string> values = [.. value.Split(':')];
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsMobile() => OS.GetName() == "iOS" || OS.GetName() == "Android";
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user