Add real pause menu
This commit is contained in:
parent
c2103b2810
commit
19335709e3
@ -15,6 +15,10 @@ run/main_scene="res://scenes/demo/demo.tscn"
|
|||||||
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
|
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
|
||||||
config/icon="res://misc/icon.svg"
|
config/icon="res://misc/icon.svg"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
UserSettings="*res://scripts/UserSettings.cs"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/viewport_width=1920
|
window/size/viewport_width=1920
|
||||||
@ -42,6 +46,14 @@ texture={
|
|||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
ui_accept={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194309,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
move_forward={
|
move_forward={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
||||||
@ -103,6 +115,12 @@ sprint={
|
|||||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null)
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
toggle_pause_menu={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[internationalization]
|
[internationalization]
|
||||||
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
[gd_scene load_steps=2 format=3 uid="uid://c670g1qg5gaug"]
|
[gd_scene load_steps=3 format=3 uid="uid://c670g1qg5gaug"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/PauseMenu.cs" id="1_p5jo3"]
|
[ext_resource type="Script" path="res://scripts/PauseMenu.cs" id="1_p5jo3"]
|
||||||
|
|
||||||
[node name="PauseMenu" type="Control"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_he4q6"]
|
||||||
|
bg_color = Color(0.109074, 0.275986, 0.806965, 1)
|
||||||
|
|
||||||
|
[node name="PauseMenu" type="Control" node_paths=PackedStringArray("InitialFocusTarget", "VolumeSlider", "CameraSensitivityX", "CameraSensitivityY", "CameraInvertX", "CameraInvertY")]
|
||||||
|
process_mode = 3
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@ -10,8 +14,15 @@ anchor_bottom = 1.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
script = ExtResource("1_p5jo3")
|
script = ExtResource("1_p5jo3")
|
||||||
|
InitialFocusTarget = NodePath("CenterContainer/PanelContainer/MarginContainer/Option List/ContinueButton")
|
||||||
|
VolumeSlider = NodePath("CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer/VolumeSlider")
|
||||||
|
CameraSensitivityX = NodePath("CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer/CameraXSlider")
|
||||||
|
CameraSensitivityY = NodePath("CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer/CameraYSlider")
|
||||||
|
CameraInvertX = NodePath("CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer/CameraXInvCheck")
|
||||||
|
CameraInvertY = NodePath("CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer/CameraYInvCheck")
|
||||||
|
|
||||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||||
|
process_mode = 2
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@ -19,9 +30,84 @@ anchor_bottom = 1.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="Button" type="Button" parent="CenterContainer"]
|
[node name="PanelContainer" type="PanelContainer" parent="CenterContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_font_sizes/font_size = 50
|
theme_override_styles/panel = SubResource("StyleBoxFlat_he4q6")
|
||||||
|
|
||||||
|
[node name="MarginContainer" type="MarginContainer" parent="CenterContainer/PanelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/margin_left = 20
|
||||||
|
theme_override_constants/margin_top = 20
|
||||||
|
theme_override_constants/margin_right = 20
|
||||||
|
theme_override_constants/margin_bottom = 20
|
||||||
|
|
||||||
|
[node name="Option List" type="VBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 16
|
||||||
|
|
||||||
|
[node name="ContinueButton" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/Option List"]
|
||||||
|
layout_mode = 2
|
||||||
|
focus_neighbor_top = NodePath("../QuitButton")
|
||||||
text = "Continue"
|
text = "Continue"
|
||||||
|
|
||||||
[connection signal="pressed" from="CenterContainer/Button" to="." method="Close"]
|
[node name="GridContainer" type="GridContainer" parent="CenterContainer/PanelContainer/MarginContainer/Option List"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/h_separation = 14
|
||||||
|
theme_override_constants/v_separation = 9
|
||||||
|
columns = 2
|
||||||
|
|
||||||
|
[node name="VolumeLabel" type="Label" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Volume"
|
||||||
|
|
||||||
|
[node name="VolumeSlider" type="HSlider" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
custom_minimum_size = Vector2(100, 0)
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 1
|
||||||
|
max_value = 1.0
|
||||||
|
step = 0.1
|
||||||
|
|
||||||
|
[node name="CameraXLabel" type="Label" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Camera yaw speed"
|
||||||
|
|
||||||
|
[node name="CameraXSlider" type="HSlider" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 1
|
||||||
|
max_value = 10.0
|
||||||
|
step = 0.25
|
||||||
|
|
||||||
|
[node name="CameraXInvLabel" type="Label" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Camera invert yaw"
|
||||||
|
|
||||||
|
[node name="CameraXInvCheck" type="CheckButton" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
action_mode = 0
|
||||||
|
|
||||||
|
[node name="CameraYLabel" type="Label" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Camera pitch speed"
|
||||||
|
|
||||||
|
[node name="CameraYSlider" type="HSlider" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 1
|
||||||
|
max_value = 10.0
|
||||||
|
step = 0.25
|
||||||
|
|
||||||
|
[node name="CameraYInvLabel" type="Label" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Camera invert pitch"
|
||||||
|
|
||||||
|
[node name="CameraYInvCheck" type="CheckButton" parent="CenterContainer/PanelContainer/MarginContainer/Option List/GridContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
action_mode = 0
|
||||||
|
|
||||||
|
[node name="QuitButton" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/Option List"]
|
||||||
|
layout_mode = 2
|
||||||
|
focus_neighbor_bottom = NodePath("../ContinueButton")
|
||||||
|
text = "Quit"
|
||||||
|
|
||||||
|
[connection signal="pressed" from="CenterContainer/PanelContainer/MarginContainer/Option List/ContinueButton" to="." method="Close"]
|
||||||
|
[connection signal="pressed" from="CenterContainer/PanelContainer/MarginContainer/Option List/QuitButton" to="." method="Quit"]
|
||||||
|
@ -2,20 +2,43 @@ using Godot;
|
|||||||
|
|
||||||
namespace Gmtk24 {
|
namespace Gmtk24 {
|
||||||
public partial class PauseMenu : Control {
|
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;
|
private bool Opened = false;
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
|
VolumeSlider.Value = UserSettings.Singleton.Volume;
|
||||||
|
VolumeSlider.ValueChanged += (value) => UserSettings.Singleton.Volume = (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();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Input(InputEvent @event) {
|
public override void _Input(InputEvent @event) {
|
||||||
if (@event is InputEventKey keyEvent) {
|
if (@event.IsActionPressed("toggle_pause_menu")) {
|
||||||
if (keyEvent.Pressed && keyEvent.Keycode == Key.Escape) {
|
if (Opened) {
|
||||||
if (Opened) {
|
Close();
|
||||||
Close();
|
} else {
|
||||||
} else {
|
Open();
|
||||||
Open();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,13 +46,22 @@ namespace Gmtk24 {
|
|||||||
public void Open() {
|
public void Open() {
|
||||||
Visible = true;
|
Visible = true;
|
||||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||||
|
GetTree().Paused = true;
|
||||||
|
if (IsInstanceValid(InitialFocusTarget)) {
|
||||||
|
InitialFocusTarget.GrabFocus();
|
||||||
|
}
|
||||||
Opened = true;
|
Opened = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close() {
|
public void Close() {
|
||||||
|
GetTree().Paused = false;
|
||||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||||
Visible = false;
|
Visible = false;
|
||||||
Opened = false;
|
Opened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Quit() {
|
||||||
|
GetTree().Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,10 @@ namespace Gmtk24 {
|
|||||||
|
|
||||||
public override void _UnhandledInput(InputEvent @event) {
|
public override void _UnhandledInput(InputEvent @event) {
|
||||||
if (@event is InputEventMouseMotion mouseMotion && Input.MouseMode == Input.MouseModeEnum.Captured) {
|
if (@event is InputEventMouseMotion mouseMotion && Input.MouseMode == Input.MouseModeEnum.Captured) {
|
||||||
var cameraSensitivityX = 2f; // FIXME: use camera sensitivity and invert settings
|
var cameraSensitivity = UserSettings.Singleton.GetCameraSpeedMultipliers();
|
||||||
var cameraSensitivityY = 2f; // FIXME: use camera sensitivity and invert settings
|
|
||||||
var mouseMultiplier = 0.0003f;
|
var mouseMultiplier = 0.0003f;
|
||||||
CurrentYaw -= mouseMotion.ScreenRelative.X * mouseMultiplier * cameraSensitivityX;
|
CurrentYaw -= mouseMotion.ScreenRelative.X * mouseMultiplier * cameraSensitivity.X;
|
||||||
CurrentPitch -= mouseMotion.ScreenRelative.Y * mouseMultiplier * cameraSensitivityY;
|
CurrentPitch -= mouseMotion.ScreenRelative.Y * mouseMultiplier * cameraSensitivity.Y;
|
||||||
GetViewport().SetInputAsHandled();
|
GetViewport().SetInputAsHandled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,11 +37,10 @@ namespace Gmtk24 {
|
|||||||
public override void _Process(double delta) {
|
public override void _Process(double delta) {
|
||||||
var yawInput = Input.GetActionStrength("look_left") - Input.GetActionStrength("look_right");
|
var yawInput = Input.GetActionStrength("look_left") - Input.GetActionStrength("look_right");
|
||||||
var pitchInput = Input.GetActionStrength("look_up") - Input.GetActionStrength("look_down");
|
var pitchInput = Input.GetActionStrength("look_up") - Input.GetActionStrength("look_down");
|
||||||
var cameraSensitivityX = 2f; // FIXME: use camera sensitivity and invert settings
|
var cameraSensitivity = UserSettings.Singleton.GetCameraSpeedMultipliers();
|
||||||
var cameraSensitivityY = 2f; // FIXME: use camera sensitivity and invert settings
|
CurrentYaw += yawInput * cameraSensitivity.X * (float)delta;
|
||||||
CurrentYaw += yawInput * cameraSensitivityX * (float)delta;
|
|
||||||
if (Eye != null) {
|
if (Eye != null) {
|
||||||
CurrentPitch += pitchInput * cameraSensitivityY * (float)delta;
|
CurrentPitch += pitchInput * cameraSensitivity.Y * (float)delta;
|
||||||
CurrentPitch = Mathf.Clamp(CurrentPitch, -Mathf.Pi * 0.49f, Mathf.Pi * 0.49f);
|
CurrentPitch = Mathf.Clamp(CurrentPitch, -Mathf.Pi * 0.49f, Mathf.Pi * 0.49f);
|
||||||
}
|
}
|
||||||
Eye.Quaternion = new Quaternion(Vector3.Up, CurrentYaw) * new Quaternion(Vector3.Right, CurrentPitch);
|
Eye.Quaternion = new Quaternion(Vector3.Up, CurrentYaw) * new Quaternion(Vector3.Right, CurrentPitch);
|
||||||
|
25
scripts/UserSettings.cs
Normal file
25
scripts/UserSettings.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Gmtk24 {
|
||||||
|
public partial class UserSettings : Node {
|
||||||
|
/// <summary>The singleton instance of this class, set when Godot
|
||||||
|
/// instantiates the Autoload scripts.</summary>
|
||||||
|
public static UserSettings Singleton { get; private set; }
|
||||||
|
|
||||||
|
public float Volume = 0.2f;
|
||||||
|
public float CameraSensitivityX = 2f;
|
||||||
|
public float CameraSensitivityY = 2f;
|
||||||
|
public bool CameraInvertX = false;
|
||||||
|
public bool CameraInvertY = false;
|
||||||
|
|
||||||
|
public override void _Ready() {
|
||||||
|
Singleton = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector2 GetCameraSpeedMultipliers() {
|
||||||
|
var x = CameraSensitivityX * (CameraInvertX ? -1 : 1);
|
||||||
|
var y = CameraSensitivityY * (CameraInvertY ? -1 : 1);
|
||||||
|
return new Vector2(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user