Refactored Main.gd a bit, moved HUD out of Level

This commit is contained in:
unfa 2021-06-03 22:34:36 +02:00
parent 53c8ee86fd
commit 9927ab2d6f
4 changed files with 160 additions and 152 deletions

142
Game/Assets/HUD/HUD.tscn Normal file
View file

@ -0,0 +1,142 @@
[gd_scene load_steps=9 format=2]
[ext_resource path="res://Assets/HUD/Vignette.png" type="Texture2D" id=1]
[ext_resource path="res://Assets/HUD/Crosshair.png" type="Texture2D" id=2]
[ext_resource path="res://Assets/SFX/UI_Confirm_Kill.wav" type="AudioStream" id=3]
[ext_resource path="res://Assets/SFX/UI_Confirm_Hit.wav" type="AudioStream" id=4]
[ext_resource path="res://Assets/HUD/Crosshair.gd" type="Script" id=5]
[sub_resource type="Animation" id=1]
resource_name = "Default"
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("Crosshair:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PackedFloat32Array( 0 ),
"transitions": PackedFloat32Array( 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ) ]
}
[sub_resource type="Animation" id=2]
length = 0.2
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("Crosshair:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PackedFloat32Array( 0, 0.1, 0.2 ),
"transitions": PackedFloat32Array( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 0.716667, 0, 1 ), Color( 1, 0.716667, 0, 1 ), Color( 1, 1, 1, 1 ) ]
}
tracks/1/type = "audio"
tracks/1/path = NodePath("Hit_Confirmation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"clips": [ {
"end_offset": 0.0,
"start_offset": 0.0,
"stream": ExtResource( 4 )
} ],
"times": PackedFloat32Array( 0 )
}
[sub_resource type="Animation" id=3]
length = 0.5
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("Crosshair:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PackedFloat32Array( 0, 0.25, 0.5 ),
"transitions": PackedFloat32Array( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 0.0532926, 0, 1 ), Color( 1, 0.0532926, 0, 1 ), Color( 1, 1, 1, 1 ) ]
}
tracks/1/type = "audio"
tracks/1/path = NodePath("Hit_Confirmation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"clips": [ {
"end_offset": 0.0,
"start_offset": 0.0,
"stream": ExtResource( 3 )
} ],
"times": PackedFloat32Array( 0 )
}
[node name="HUD" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = null
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Crosshair" type="Control" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
script = ExtResource( 5 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Crosshair" type="TextureRect" parent="Crosshair"]
texture_filter = 2
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -32.0
offset_top = -32.0
offset_right = 96.0
offset_bottom = 96.0
rect_scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 2 )
expand = true
script = null
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AnimationPlayer" type="AnimationPlayer" parent="Crosshair"]
autoplay = "Default"
anims/Default = SubResource( 1 )
anims/Hit = SubResource( 2 )
anims/Kill = SubResource( 3 )
blend_times = [ ]
script = null
[node name="Hit_Confirmation" type="AudioStreamPlayer" parent="Crosshair"]
stream = ExtResource( 3 )
script = null
[node name="Vignette" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 1 )
expand = true
stretch_mode = 7
script = null
__meta__ = {
"_edit_use_anchors_": false
}

File diff suppressed because one or more lines are too long

View file

@ -1,18 +1,21 @@
extends Node
enum GameFocus {IN_MENU, PLAYING, TYPING, AFK}
enum GameFocus {MENU, GAME, CHAT, AWAY}
var mode = GameFocus.IN_MENU
@onready var gui = $GUI
@onready var player = $Level/Player
var focus = GameFocus.MENU
func _input(event) -> void:
if Input.is_action_just_pressed("ui_cancel"):
if mode == GameFocus.PLAYING:
if focus == GameFocus.GAME:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
$CanvasLayer/GUI.show()
$Level/Player.input_active = false
mode = GameFocus.IN_MENU
elif mode == GameFocus.IN_MENU:
gui.show()
player.input_active = false
focus = GameFocus.MENU
elif focus == GameFocus.MENU:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$CanvasLayer/GUI.hide()
$Level/Player.input_active = true
mode = GameFocus.PLAYING
gui.hide()
player.input_active = true
focus = GameFocus.GAME

View file

@ -1,16 +1,15 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Level.tscn" type="PackedScene" id=1]
[ext_resource path="res://GUI.tscn" type="PackedScene" id=2]
[ext_resource path="res://Main.gd" type="Script" id=3]
[ext_resource path="res://Assets/HUD/HUD.tscn" type="PackedScene" id=4]
[node name="Main" type="Node"]
script = ExtResource( 3 )
[node name="CanvasLayer" type="CanvasLayer" parent="."]
layer = 5
script = null
[node name="HUD" parent="." instance=ExtResource( 4 )]
[node name="GUI" parent="CanvasLayer" instance=ExtResource( 2 )]
[node name="GUI" parent="." instance=ExtResource( 2 )]
[node name="Level" parent="." instance=ExtResource( 1 )]