Add basic escape menu

main
copygirl 1 year ago
parent cca3cdbb82
commit c8cfd73005
  1. 51
      EscapeMenu.cs
  2. 92
      escape_menu.tscn
  3. 12
      player/CameraController.cs
  4. 2
      player/MovementController.cs
  5. 51
      player/player.tscn
  6. 15
      scenes/game.tscn

@ -0,0 +1,51 @@
public partial class EscapeMenu : CenterContainer
{
[Export] public Container SideButtons { get; set; }
[Export] public TabContainer Tabs { get; set; }
public override void _Ready()
{
foreach (var child in SideButtons.GetChildren())
if ((child is BaseButton button) && button.ToggleMode)
button.Pressed += () => {
for (var i = 0; i < Tabs.GetTabCount(); i++)
if (Tabs.GetTabControl(i).Name == button.Name)
Tabs.CurrentTab = i;
};
}
public override void _Input(InputEvent @event)
{
if (!Visible) {
var isMouseCaptured = Input.MouseMode == Input.MouseModeEnum.Captured;
if (!isMouseCaptured && @event.IsActionPressed("ui_cancel")) {
Visible = true;
GetViewport().SetInputAsHandled();
}
return;
}
if (@event.IsActionPressed("ui_cancel")) {
OnReturnPressed();
GetViewport().SetInputAsHandled();
}
}
public void OnTabChanged(int tabIndex)
{
var tabName = Tabs.GetTabControl(tabIndex).Name;
foreach (var child in SideButtons.GetChildren())
if ((child is BaseButton button) && button.ToggleMode)
button.ButtonPressed = button.Name == tabName;
}
public void OnReturnPressed()
{
Visible = false;
}
public void OnQuitPressed()
{
GetTree().Quit();
}
}

@ -0,0 +1,92 @@
[gd_scene load_steps=3 format=3 uid="uid://c5ooi36ibspfo"]
[ext_resource type="Script" path="res://EscapeMenu.cs" id="1_5qxrt"]
[sub_resource type="LabelSettings" id="LabelSettings_u8eqm"]
font_size = 22
[node name="EscapeMenu" type="CenterContainer" node_paths=PackedStringArray("SideButtons", "Tabs")]
offset_right = 562.0
offset_bottom = 404.0
mouse_filter = 0
script = ExtResource("1_5qxrt")
SideButtons = NodePath("PanelContainer/MarginContainer/VBoxContainer/GridContainer/SideButtons")
Tabs = NodePath("PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer")
[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 4
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Escape Menu"
label_settings = SubResource("LabelSettings_u8eqm")
horizontal_alignment = 1
[node name="GridContainer" type="GridContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/h_separation = 6
theme_override_constants/v_separation = 6
columns = 2
[node name="SideButtons" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer"]
custom_minimum_size = Vector2(160, 0)
layout_mode = 2
[node name="Gameplay" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/SideButtons"]
layout_mode = 2
toggle_mode = true
button_pressed = true
text = "Gameplay"
[node name="Multiplayer" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/SideButtons"]
layout_mode = 2
toggle_mode = true
text = "Multiplayer"
[node name="TabContainer" type="TabContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer"]
custom_minimum_size = Vector2(400, 300)
layout_mode = 2
size_flags_vertical = 3
tabs_visible = false
[node name="Gameplay" type="CenterContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Gameplay"]
layout_mode = 2
text = "Gameplay
(nothing here yet)"
horizontal_alignment = 1
[node name="Multiplayer" type="CenterContainer" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer"]
visible = false
layout_mode = 2
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer/Multiplayer"]
layout_mode = 2
text = "Multiplayer
(nothing here yet)"
horizontal_alignment = 1
[node name="Quit" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer"]
layout_mode = 2
text = "Quit to Desktop"
[node name="Return" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/GridContainer"]
layout_mode = 2
text = "Return to Game
"
[connection signal="tab_changed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/TabContainer" to="." method="OnTabChanged"]
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/Quit" to="." method="OnQuitPressed"]
[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/GridContainer/Return" to="." method="OnReturnPressed"]

@ -26,14 +26,20 @@ public partial class CameraController : Node
}
}
public override void _UnhandledInput(InputEvent @event)
public override void _Input(InputEvent @event)
{
if (!_player.IsLocal) return;
if (@event.IsActionPressed("ui_cancel") && IsMouseCaptured) {
if (IsMouseCaptured && @event.IsActionPressed("ui_cancel")) {
// When escape is pressed, release the mouse.
Input.MouseMode = Input.MouseModeEnum.Visible;
GetViewport().SetInputAsHandled();
} else switch (@event) {
}
}
public override void _UnhandledInput(InputEvent @event)
{
if (!_player.IsLocal) return;
switch (@event) {
case InputEventMouseButton { ButtonIndex: MouseButton.Left, Pressed: true } when !IsMouseCaptured:
// When left mouse button is pressed, capture the mouse.
Input.MouseMode = Input.MouseModeEnum.Captured;

@ -35,7 +35,7 @@ public partial class MovementController : Node
public override void _UnhandledInput(InputEvent @event)
{
if(!_player.IsLocal) return;
if (!_player.IsLocal) return;
// TODO: Sprinting.

@ -823,35 +823,35 @@ shape = SubResource("CapsuleShape3D_l8s0f")
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.75, 0)
[node name="Root" type="BoneAttachment3D" parent="Model/Skeleton" index="0"]
transform = Transform3D(-1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0.198674, 0)
transform = Transform3D(-1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0.198819, 0)
bone_name = "Root"
bone_idx = 2
use_external_skeleton = true
external_skeleton = NodePath("../Skeleton3D")
[node name="LowerBody" type="BoneAttachment3D" parent="Model/Skeleton/Root"]
transform = Transform3D(-1, -1.80478e-09, 8.74042e-08, 8.71645e-08, 0.0562133, 0.998419, -6.71521e-09, 0.998419, -0.0562134, 0, 0, -0.199593)
transform = Transform3D(-1, -1.37451e-09, 8.7412e-08, 8.71645e-08, 0.0611276, 0.99813, -6.71522e-09, 0.99813, -0.0611275, 0, 0, -0.199593)
bone_name = "LowerBody"
bone_idx = 3
use_external_skeleton = true
external_skeleton = NodePath("../../Skeleton3D")
[node name="UpperBody" type="BoneAttachment3D" parent="Model/Skeleton/Root/LowerBody"]
transform = Transform3D(1, -7.15076e-09, 8.71298e-08, 0, 0.996649, 0.0817951, -8.74228e-08, -0.0817951, 0.996649, 0, 0.154362, 0)
transform = Transform3D(1, -8.24329e-09, 8.70333e-08, -4.44089e-16, 0.995544, 0.0942922, -8.74228e-08, -0.0942922, 0.995544, 8.88178e-16, 0.154362, 0)
bone_name = "UpperBody"
bone_idx = 4
use_external_skeleton = true
external_skeleton = NodePath("../../../Skeleton3D")
[node name="Neck" type="BoneAttachment3D" parent="Model/Skeleton/Root/LowerBody/UpperBody"]
transform = Transform3D(1, 2.22045e-16, 0, 8.88178e-16, 0.998891, -0.0470728, -7.10543e-15, 0.0470728, 0.998892, 6.66134e-16, 0.251888, 0)
transform = Transform3D(1, -8.88178e-16, -7.10543e-15, 0, 0.998891, -0.0470728, 0, 0.0470728, 0.998892, -1.11022e-16, 0.251888, 5.58794e-09)
bone_name = "Neck"
bone_idx = 5
use_external_skeleton = true
external_skeleton = NodePath("../../../../Skeleton3D")
[node name="Head" type="BoneAttachment3D" parent="Model/Skeleton/Root/LowerBody/UpperBody/Neck"]
transform = Transform3D(-1, 4.67566e-10, 8.74215e-08, 8.74228e-08, 0.0053482, 0.999986, 0, 0.999986, -0.00534832, 1.11022e-16, 0.101598, 3.72529e-09)
transform = Transform3D(-1, 4.50711e-10, 8.74216e-08, 8.74228e-08, 0.00515562, 0.999987, -7.10543e-15, 0.999987, -0.00515556, -4.44089e-16, 0.101598, 7.45058e-09)
bone_name = "Head"
bone_idx = 6
use_external_skeleton = true
@ -860,40 +860,41 @@ external_skeleton = NodePath("../../../../../Skeleton3D")
[node name="Camera" type="Camera3D" parent="Model/Skeleton/Root/LowerBody/UpperBody/Neck/Head"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.08, 0.04)
cull_mask = 1
current = true
[node name="UpperArm_L" type="BoneAttachment3D" parent="Model/Skeleton/Root/LowerBody/UpperBody"]
transform = Transform3D(-0.949823, 0.312787, -0.000684065, -0.31241, -0.948781, -0.0470616, -0.0153693, -0.0444865, 0.998892, 0.0873834, 0.213866, -0.00179177)
transform = Transform3D(-0.94861, 0.316447, -0.000603795, -0.316069, -0.947568, -0.0470641, -0.0154654, -0.0444547, 0.998892, 0.0873834, 0.213866, -0.00179176)
bone_name = "UpperArm_L"
bone_idx = 7
use_external_skeleton = true
external_skeleton = NodePath("../../../../Skeleton3D")
[node name="UpperArm_R" type="BoneAttachment3D" parent="Model/Skeleton/Root/LowerBody/UpperBody"]
transform = Transform3D(-0.949823, -0.312787, 0.000684064, 0.31241, -0.948781, -0.0470616, 0.0153693, -0.0444865, 0.998892, -0.0873834, 0.213866, -0.00179177)
transform = Transform3D(-0.94861, -0.316447, 0.000603795, 0.316069, -0.947568, -0.0470641, 0.0154654, -0.0444547, 0.998892, -0.0873834, 0.213866, -0.00179176)
bone_name = "UpperArm_R"
bone_idx = 14
use_external_skeleton = true
external_skeleton = NodePath("../../../../Skeleton3D")
[node name="Skeleton3D" parent="Model/Skeleton" index="1"]
bones/1/rotation = Quaternion(-0.725527, 1.06167e-18, -1.00434e-18, 0.688194)
bones/2/position = Vector3(0, 0.198675, 0)
bones/3/rotation = Quaternion(2.93651e-08, 0.72671, 0.686945, 3.23786e-08)
bones/4/rotation = Quaternion(-0.0409319, 4.36748e-08, 1.78919e-09, 0.999162)
bones/6/rotation = Quaternion(3.09912e-08, 0.708995, 0.705213, 3.08259e-08)
bones/7/rotation = Quaternion(-0.00406577, -0.0231861, 0.987104, -0.158341)
bones/8/rotation = Quaternion(9.74191e-05, 0.000328126, -0.0786104, 0.996905)
bones/9/rotation = Quaternion(-7.20592e-05, -0.0003409, -0.00150931, 0.999999)
bones/14/rotation = Quaternion(0.00406577, -0.0231861, 0.987104, 0.158341)
bones/15/rotation = Quaternion(9.74189e-05, -0.000328126, 0.0786104, 0.996905)
bones/16/rotation = Quaternion(-7.20589e-05, 0.0003409, 0.00150931, 0.999999)
bones/21/rotation = Quaternion(0.0107169, -0.719663, 0.694155, 0.0108845)
bones/22/rotation = Quaternion(0.0628015, 0.00254414, 0.0038346, 0.998015)
bones/23/rotation = Quaternion(-0.00149249, -0.672831, 0.739548, -0.0191091)
bones/24/rotation = Quaternion(-0.0107169, -0.719663, 0.694155, -0.0108845)
bones/25/rotation = Quaternion(0.0628015, -0.00254414, -0.0038346, 0.998015)
bones/26/rotation = Quaternion(0.00149248, -0.672831, 0.739548, 0.0191091)
bones/28/rotation = Quaternion(-0.725527, 1.06167e-18, -1.00434e-18, 0.688194)
bones/1/rotation = Quaternion(-0.723196, 4.5135e-18, -4.26977e-18, 0.690643)
bones/2/position = Vector3(0, 0.198819, 0)
bones/3/rotation = Quaternion(2.94447e-08, 0.728398, 0.685154, 3.23062e-08)
bones/4/rotation = Quaternion(-0.0471987, 4.36627e-08, 2.06312e-09, 0.998886)
bones/6/rotation = Quaternion(3.09882e-08, 0.708927, 0.705282, 3.08288e-08)
bones/7/rotation = Quaternion(-0.00407106, -0.0231858, 0.986797, -0.160245)
bones/8/rotation = Quaternion(8.60099e-05, 0.000289714, -0.076692, 0.997055)
bones/9/rotation = Quaternion(-6.24049e-05, -0.000295211, -0.00375171, 0.999993)
bones/14/rotation = Quaternion(0.00407106, -0.0231858, 0.986797, 0.160245)
bones/15/rotation = Quaternion(8.60101e-05, -0.000289714, 0.0766921, 0.997055)
bones/16/rotation = Quaternion(-6.24048e-05, 0.000295211, 0.0037517, 0.999993)
bones/21/rotation = Quaternion(0.010666, -0.718595, 0.695263, 0.0108048)
bones/22/rotation = Quaternion(0.0583992, 0.00254482, 0.00356579, 0.998284)
bones/23/rotation = Quaternion(-0.00141986, -0.675636, 0.736986, -0.0191147)
bones/24/rotation = Quaternion(-0.010666, -0.718595, 0.695263, -0.0108048)
bones/25/rotation = Quaternion(0.0583992, -0.00254482, -0.00356579, 0.998284)
bones/26/rotation = Quaternion(0.00141986, -0.675636, 0.736986, 0.0191147)
bones/28/rotation = Quaternion(-0.723196, 4.5135e-18, -4.26977e-18, 0.690643)
[node name="MovementController" type="Node" parent="."]
script = ExtResource("2_1pst4")

@ -1,9 +1,10 @@
[gd_scene load_steps=7 format=3 uid="uid://puuk72ficqhu"]
[gd_scene load_steps=8 format=3 uid="uid://puuk72ficqhu"]
[ext_resource type="PackedScene" uid="uid://bwfuet1irfi17" path="res://scenes/workshop.tscn" id="1_m8m3w"]
[ext_resource type="Shader" path="res://assets/shaders/outline.gdshader" id="2_yvnqw"]
[ext_resource type="Script" path="res://scripts/OutlineCamera.cs" id="3_wd8hf"]
[ext_resource type="Texture2D" uid="uid://lxxfestfg2dt" path="res://assets/crosshair.png" id="4_06ang"]
[ext_resource type="PackedScene" uid="uid://c5ooi36ibspfo" path="res://escape_menu.tscn" id="4_77nbu"]
[ext_resource type="Script" path="res://scripts/Crosshair.cs" id="5_i8gkf"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ke1l3"]
@ -32,6 +33,7 @@ render_target_update_mode = 4
[node name="OutlineCamera" type="Camera3D" parent="OutlineViewportContainer/OutlineViewport"]
cull_mask = 2
current = true
script = ExtResource("3_wd8hf")
[node name="HUD" type="Control" parent="."]
@ -43,6 +45,17 @@ grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
[node name="EscapeMenu" parent="HUD" instance=ExtResource("4_77nbu")]
visible = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = 0.0
offset_bottom = 0.0
grow_horizontal = 2
grow_vertical = 2
[node name="Crosshair" type="TextureRect" parent="HUD"]
layout_mode = 1
anchors_preset = 8

Loading…
Cancel
Save