using Godot; namespace Gmtk24 { public partial class PauseMenu : Control { [Export] public Control InitialFocusTarget; [ExportCategory("Setting controls")] [Export] public Range VolumeSlider; [Export] public Range CameraSensitivityX; [Export] public Range CameraSensitivityY; [Export] public BaseButton CameraInvertX; [Export] public BaseButton CameraInvertY; private bool Opened = false; public override void _Ready() { VolumeSlider.Value = UserSettings.Singleton.Volume; VolumeSlider.ValueChanged += (value) => UserSettings.Singleton.SetVolume((float)value); CameraSensitivityX.Value = UserSettings.Singleton.CameraSensitivityX; CameraSensitivityX.ValueChanged += (value) => UserSettings.Singleton.CameraSensitivityX = (float)value; CameraSensitivityY.Value = UserSettings.Singleton.CameraSensitivityY; CameraSensitivityY.ValueChanged += (value) => UserSettings.Singleton.CameraSensitivityY = (float)value; CameraInvertX.ButtonPressed = UserSettings.Singleton.CameraInvertX; CameraInvertX.Toggled += (on) => UserSettings.Singleton.CameraInvertX = on; CameraInvertY.ButtonPressed = UserSettings.Singleton.CameraInvertY; CameraInvertY.Toggled += (on) => UserSettings.Singleton.CameraInvertY = on; Close(); } public override void _Input(InputEvent @event) { if (@event.IsActionPressed("toggle_pause_menu")) { if (Opened) { Close(); } else { Open(); } } } public void Open() { Visible = true; Input.MouseMode = Input.MouseModeEnum.Visible; GetTree().Paused = true; if (IsInstanceValid(InitialFocusTarget)) { InitialFocusTarget.GrabFocus(); } Opened = true; } public void Close() { GetTree().Paused = false; Input.MouseMode = Input.MouseModeEnum.Captured; Visible = false; Opened = false; } public void Quit() { GetTree().Quit(); } } }