Finish making settings
This commit is contained in:
18 files changed
+118
-33
No files matched your search
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class BackToMenuLogic : Control {
|
||||
public void _on_menu_button_up() {
|
||||
|
||||
@@ -2,6 +2,7 @@ using Godot;
|
||||
|
||||
public partial class BazookaManager : Node {
|
||||
public static string HighScore = "0";
|
||||
public static string Settings = "1";
|
||||
|
||||
public static string Read(string saveKey, string defaultValue) {
|
||||
string path = "user://" + saveKey + ".txt";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class BerryLogic : Node2D {
|
||||
string BerryType = "";
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class VersionChecker : Control {
|
||||
public partial class FirstLoad : Control {
|
||||
public override void _Ready() {
|
||||
Label VersionLabel = GetNode<Label>("Version");
|
||||
Label VersionLabel = GetNode<Label>("VersionText/Version");
|
||||
string GameVersion = ProjectSettings.GetSetting("application/config/version").AsString();
|
||||
|
||||
VersionLabel.Text = "Version: " + GameVersion;
|
||||
|
||||
if (Globals.VersionChecked) {
|
||||
Label LatestVersionLabel = GetNode<Label>("LatestVersion");
|
||||
if (Globals.FirstLoadDone) {
|
||||
Label LatestVersionLabel = GetNode<Label>("VersionText/LatestVersion");
|
||||
|
||||
LatestVersionLabel.Text = "Latest Version: " + Globals.LatestVersion;
|
||||
} else {
|
||||
HttpRequest GetLatestVersionNode = GetNode<HttpRequest>("LatestVersion/HTTPRequest");
|
||||
//Load settings
|
||||
List<string> settings = Utils.LoadSettings();
|
||||
string fullscreen = settings.ElementAtOrDefault(0) ?? "1";
|
||||
Utils.ToggleFullscreen(fullscreen == "1", settings); //This will also load VSync
|
||||
|
||||
//Version checking
|
||||
HttpRequest GetLatestVersionNode = GetNode<HttpRequest>("VersionText/LatestVersion/HTTPRequest");
|
||||
|
||||
GetLatestVersionNode.RequestCompleted += OnRequestCompleted;
|
||||
|
||||
@@ -36,11 +42,11 @@ public partial class VersionChecker : Control {
|
||||
Globals.AccessLevel = ResponseValues[0];
|
||||
Globals.LatestVersion = ResponseValues[1];
|
||||
|
||||
Label LatestVersionLabel = GetNode<Label>("LatestVersion");
|
||||
Label LatestVersionLabel = GetNode<Label>("VersionText/LatestVersion");
|
||||
|
||||
LatestVersionLabel.Text = "Latest Version: " + Globals.LatestVersion;
|
||||
|
||||
Globals.VersionChecked = true;
|
||||
Globals.FirstLoadDone = true;
|
||||
|
||||
string GameVersion = ProjectSettings.GetSetting("application/config/version").AsString();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://cyo278cd6hfm
|
||||
+1
-2
@@ -1,10 +1,9 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Globals : Node {
|
||||
public static string LatestVersion = "";
|
||||
public static string AccessLevel = "";
|
||||
public static bool VersionChecked = false;
|
||||
public static bool FirstLoadDone = false;
|
||||
|
||||
public static float MovementSpeed = 800f;
|
||||
public static float DefaultMovementSpeed = MovementSpeed;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class LoadSaveFIle : Control {
|
||||
public override void _Ready() {
|
||||
Globals.HighScore = int.Parse(BazookaManager.Read(BazookaManager.HighScore, "0"));
|
||||
}
|
||||
public override void _Ready() {
|
||||
Globals.HighScore = int.Parse(BazookaManager.Read(BazookaManager.HighScore, "0"));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class OutdatedVersionLogic : Control {
|
||||
public override void _Ready() {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class PauseMenuContinueButton : Button {
|
||||
public void _on_button_up() {
|
||||
|
||||
+3
-4
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Player : Node2D {
|
||||
private float ScreenBorders = 120f;
|
||||
@@ -21,18 +20,18 @@ public partial class Player : Node2D {
|
||||
Vector2 Pos = Position;
|
||||
|
||||
if (!Globals.IsPaused) {
|
||||
if ((Input.IsKeyPressed((Key)Key.Left) || Input.IsKeyPressed((Key)Key.A)) && Pos.X > ScreenBorders) {
|
||||
if ((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)Key.Right) || Input.IsKeyPressed((Key)Key.D)) && Pos.X < ScreenWidth) {
|
||||
if ((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)Key.Space) && Pos.Y >= 976) {
|
||||
if (Input.IsKeyPressed(Key.Space) && Pos.Y >= 976) {
|
||||
VelocityY = Globals.JumpHeight;
|
||||
GetNode<AudioStreamPlayer>("JumpSoundPlayer").Play();
|
||||
}
|
||||
|
||||
@@ -20,4 +20,4 @@ public partial class SceneSwitcher : Button {
|
||||
GD.PrintErr("Failed to change scene: " + error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class SettingsContainer : VBoxContainer
|
||||
{
|
||||
private static bool ignoreToggle = true;
|
||||
|
||||
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";
|
||||
GetNode<CheckBox>("ShowFPS/CheckBox").ButtonPressed = showfps == "1";
|
||||
|
||||
ignoreToggle = false;
|
||||
}
|
||||
|
||||
public static void Fullscreen_Toggled(bool on)
|
||||
{
|
||||
if (ignoreToggle) return;
|
||||
Toggle(0, on);
|
||||
Utils.ToggleFullscreen(on);
|
||||
}
|
||||
|
||||
public static void VSync_Toggled(bool on)
|
||||
{
|
||||
if (ignoreToggle) return;
|
||||
Toggle(1, on);
|
||||
Utils.ToggleVSync(on);
|
||||
}
|
||||
|
||||
public static void ShowFPS_Toggled(bool on)
|
||||
{
|
||||
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");
|
||||
values[id] = on ? "1" : "0";
|
||||
string newValue = string.Join(":", values);
|
||||
BazookaManager.Write(BazookaManager.Settings, newValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://jpjswk46hc64
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
public class Utils {
|
||||
public static void ToggleFullscreen(bool on, List<string> settings)
|
||||
{
|
||||
DisplayServer.WindowSetMode(on ? DisplayServer.WindowMode.Fullscreen : DisplayServer.WindowMode.Maximized);
|
||||
|
||||
string vsync = settings.ElementAtOrDefault(1) ?? "1";
|
||||
ToggleVSync(vsync == "1");
|
||||
}
|
||||
|
||||
public static void ToggleFullscreen(bool on)
|
||||
{
|
||||
List<string> settings = LoadSettings();
|
||||
ToggleFullscreen(on, settings);
|
||||
}
|
||||
|
||||
public static void ToggleVSync(bool on)
|
||||
{
|
||||
DisplayServer.WindowSetVsyncMode(on ? DisplayServer.VSyncMode.Enabled : DisplayServer.VSyncMode.Disabled);
|
||||
}
|
||||
|
||||
public static List<string> LoadSettings() {
|
||||
string value = BazookaManager.Read(BazookaManager.Settings, "");
|
||||
List<string> values = [.. value.Split(':')];
|
||||
return values;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bnh8syp13bsom
|
||||
@@ -1 +0,0 @@
|
||||
uid://c61hc1raouekv
|
||||
Reference in new issue
Block a user