Add universal HUD
This commit is contained in:
parent
1d8d47a248
commit
6d50a76cff
25
hud.gd
Normal file
25
hud.gd
Normal file
@ -0,0 +1,25 @@
|
||||
extends VBoxContainer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
toggle_hud() # This should hide the HUD by default
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
toggle_hud()
|
||||
|
||||
func toggle_hud() -> void:
|
||||
|
||||
var should_show = Input.mouse_mode == Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
if should_show:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
show()
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
hide()
|
||||
|
||||
func _on_menu_button_pressed() -> void:
|
||||
var err = get_tree().change_scene_to_file("res://menu.tscn")
|
||||
if err != OK:
|
||||
print("Failed to switch scenes: ", error_string(err))
|
1
hud.gd.uid
Normal file
1
hud.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dys441ih752an
|
13
hud.tscn
Normal file
13
hud.tscn
Normal file
@ -0,0 +1,13 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b5x7fmpwck335"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dys441ih752an" path="res://hud.gd" id="1_37p78"]
|
||||
|
||||
[node name="HUD" type="VBoxContainer"]
|
||||
script = ExtResource("1_37p78")
|
||||
|
||||
[node name="MenuButton" type="Button" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Back to Menu"
|
||||
|
||||
[connection signal="pressed" from="MenuButton" to="." method="_on_menu_button_pressed"]
|
@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://27pb62xwsqd8"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://27pb62xwsqd8"]
|
||||
|
||||
[ext_resource type="MeshLibrary" uid="uid://bedqgubx1g1uf" path="res://prototypes.tres" id="1_mqqdr"]
|
||||
[ext_resource type="Script" uid="uid://d2bvvjsibau8c" path="res://addons/simple-portal-system/scripts/portal.gd" id="2_b14t7"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://bqilnvlfws6xh" path="res://portal-mesh.tres" id="2_cgnft"]
|
||||
[ext_resource type="PackedScene" uid="uid://cgdlowfuuorvi" path="res://player.tscn" id="3_b0o0q"]
|
||||
[ext_resource type="Script" uid="uid://bkv7t4hw21byg" path="res://addons/simple-portal-system/scripts/simple_portal_teleport.gd" id="4_snwvi"]
|
||||
[ext_resource type="PackedScene" uid="uid://b5x7fmpwck335" path="res://hud.tscn" id="6_phjvl"]
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_b0o0q"]
|
||||
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
|
||||
@ -23,6 +24,10 @@ size = Vector3(2, 2, 0.5)
|
||||
|
||||
[node name="level_3rooms" type="Node3D"]
|
||||
|
||||
[node name="HUD" parent="." instance=ExtResource("6_phjvl")]
|
||||
offset_right = 137.0
|
||||
offset_bottom = 23.0
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_snwvi")
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://dpatwnepecl8r"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://dpatwnepecl8r"]
|
||||
|
||||
[ext_resource type="MeshLibrary" uid="uid://bedqgubx1g1uf" path="res://prototypes.tres" id="1_7nma7"]
|
||||
[ext_resource type="PackedScene" uid="uid://cgdlowfuuorvi" path="res://player.tscn" id="2_7nma7"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://bqilnvlfws6xh" path="res://portal-mesh.tres" id="3_ok2r5"]
|
||||
[ext_resource type="Script" uid="uid://d2bvvjsibau8c" path="res://addons/simple-portal-system/scripts/portal.gd" id="4_n2ayn"]
|
||||
[ext_resource type="Script" uid="uid://bkv7t4hw21byg" path="res://addons/simple-portal-system/scripts/simple_portal_teleport.gd" id="5_dfyqt"]
|
||||
[ext_resource type="PackedScene" uid="uid://b5x7fmpwck335" path="res://hud.tscn" id="6_00lyl"]
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_lquwl"]
|
||||
|
||||
@ -19,7 +20,11 @@ sky = SubResource("Sky_7mycd")
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1bvp3"]
|
||||
size = Vector3(2, 2.5, 0.2)
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
[node name="Level_5_rooms" type="Node3D"]
|
||||
|
||||
[node name="HUD" parent="." instance=ExtResource("6_00lyl")]
|
||||
offset_right = 114.0
|
||||
offset_bottom = 39.0
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_272bh")
|
||||
|
@ -8,6 +8,7 @@
|
||||
[ext_resource type="Script" uid="uid://d2bvvjsibau8c" path="res://addons/simple-portal-system/scripts/portal.gd" id="5_wg85y"]
|
||||
[ext_resource type="Script" uid="uid://bkv7t4hw21byg" path="res://addons/simple-portal-system/scripts/simple_portal_teleport.gd" id="6_3fidx"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://bqilnvlfws6xh" path="res://portal-mesh.tres" id="7_hwdx8"]
|
||||
[ext_resource type="PackedScene" uid="uid://b5x7fmpwck335" path="res://hud.tscn" id="9_2wcgd"]
|
||||
|
||||
[sub_resource type="Environment" id="Environment_7knre"]
|
||||
background_mode = 1
|
||||
@ -20,9 +21,6 @@ size = Vector3(2, 1, 2)
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_2wcgd"]
|
||||
size = Vector3(2, 2.5, 8.79824)
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_hwdx8"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
@ -302,17 +300,4 @@ fade_out_color = Color(0.590126, 0.615058, 0.699408, 1)
|
||||
exit_cull_mask = 1048573
|
||||
exit_portal = NodePath("../P_bottom")
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="."]
|
||||
size = Vector2i(512, 288)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="SubViewport"]
|
||||
transform = Transform3D(-0.00436047, 0.491726, -0.870739, 0, 0.870747, 0.491731, 0.999991, 0.00214418, -0.00379687, -34.9621, 17.276, -0.665714)
|
||||
fov = 52.5
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="CanvasLayer"]
|
||||
visible = false
|
||||
offset_right = 512.0
|
||||
offset_bottom = 288.0
|
||||
texture = SubResource("ViewportTexture_hwdx8")
|
||||
[node name="HUD" parent="." instance=ExtResource("9_2wcgd")]
|
||||
|
@ -7,15 +7,9 @@ const JUMP_VELOCITY = 4.5
|
||||
const MOUSE_SENSITIVITY = 0.005
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
rotate_y(-event.screen_relative.x * MOUSE_SENSITIVITY)
|
||||
camera.rotate_x(-event.screen_relative.y * MOUSE_SENSITIVITY)
|
||||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-80), deg_to_rad(80))
|
||||
|
Loading…
Reference in New Issue
Block a user