Add pause & resume feature

This commit is contained in:
Moe Poi ~ 2023-10-08 17:45:25 +07:00
parent ececd2a489
commit 91cc081a36
12 changed files with 241 additions and 1 deletions

BIN
assets/icons/layout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bmecglpsq1jrd"
path="res://.godot/imported/layout.png-887f121dd114e1b5e2f5287261adc761.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/icons/layout.png"
dest_files=["res://.godot/imported/layout.png-887f121dd114e1b5e2f5287261adc761.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
assets/icons/main-menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cgl1iul3vlrds"
path="res://.godot/imported/main-menu.png-be1f92ae566ee7e3f4b625b68ab5d6e1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/icons/main-menu.png"
dest_files=["res://.godot/imported/main-menu.png-be1f92ae566ee7e3f4b625b68ab5d6e1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
assets/icons/resume.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c7j841b5u4tu3"
path="res://.godot/imported/resume.png-07f5ac308baa50202dc9ab9a3941f0bd.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/icons/resume.png"
dest_files=["res://.godot/imported/resume.png-07f5ac308baa50202dc9ab9a3941f0bd.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=13 format=3 uid="uid://btdewn34d67m"]
[gd_scene load_steps=14 format=3 uid="uid://btdewn34d67m"]
[ext_resource type="Script" path="res://scripts/stages/1/game_manager.gd" id="1_aosti"]
[ext_resource type="Texture2D" uid="uid://cnxj0mf3luxo" path="res://assets/tileset/ashlands/tf_A5_ashlands_3.png" id="2_1njjc"]
[ext_resource type="Texture2D" uid="uid://danbfdqmqu23q" path="res://assets/tileset/ashlands/tf_B_ashlands_3.png" id="3_l5wod"]
[ext_resource type="Script" path="res://scripts/stages/1/summon.gd" id="4_gt08o"]
[ext_resource type="PackedScene" uid="uid://bhnv1dsggssil" path="res://scenes/ui/pause_menu.tscn" id="5_0gif7"]
[ext_resource type="PackedScene" uid="uid://cd5r1v6f8hahx" path="res://scenes/ui/tower_menu.tscn" id="5_3w5lp"]
[ext_resource type="PackedScene" uid="uid://cy88k4uxt1v37" path="res://scenes/ui/game_stats.tscn" id="6_hbxxi"]
[ext_resource type="PackedScene" uid="uid://bvoenhbaqiqj2" path="res://scenes/towers/placement/placement.tscn" id="6_mao4r"]
@ -525,6 +526,7 @@ _data = {
point_count = 4
[node name="GameManager" type="Node2D"]
process_mode = 1
script = ExtResource("1_aosti")
[node name="TileMap" type="TileMap" parent="."]
@ -549,6 +551,9 @@ one_shot = true
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="PauseMenu" parent="CanvasLayer" instance=ExtResource("5_0gif7")]
visible = false
[node name="TowerMenu" parent="CanvasLayer" instance=ExtResource("5_3w5lp")]
visible = false

View file

@ -103,3 +103,5 @@ texture = ExtResource("3_r1i66")
[node name="6" type="TextureRect" parent="Health/GridContainer"]
layout_mode = 2
texture = ExtResource("3_r1i66")
[connection signal="pressed" from="Pause/PauseButton" to="." method="_on_pause_button_pressed"]

94
scenes/ui/pause_menu.tscn Normal file
View file

@ -0,0 +1,94 @@
[gd_scene load_steps=5 format=3 uid="uid://bhnv1dsggssil"]
[ext_resource type="Script" path="res://scripts/ui/pause_menu.gd" id="1_4u0k0"]
[ext_resource type="Texture2D" uid="uid://c7j841b5u4tu3" path="res://assets/icons/resume.png" id="1_kdmgn"]
[ext_resource type="Texture2D" uid="uid://cgl1iul3vlrds" path="res://assets/icons/main-menu.png" id="2_febfx"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hrh7j"]
bg_color = Color(0.145098, 0.145098, 0.145098, 1)
[node name="PauseMenu" type="Control"]
process_mode = 2
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_4u0k0")
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -200.0
offset_top = -206.0
offset_right = 203.0
offset_bottom = 222.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_hrh7j")
[node name="MarginContainer" type="MarginContainer" parent="Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_bottom = 2.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/MarginContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="Panel/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "PAUSED"
horizontal_alignment = 1
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="TextureButton" type="TextureButton" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 6
texture_normal = ExtResource("1_kdmgn")
[node name="Label" type="Label" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 6
text = "Resume"
horizontal_alignment = 1
justification_flags = 162
[node name="VBoxContainer2" type="VBoxContainer" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="TextureButton" type="TextureButton" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 6
texture_normal = ExtResource("2_febfx")
[node name="Label" type="Label" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 6
text = "Main Menu"
horizontal_alignment = 1
[connection signal="pressed" from="Panel/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/TextureButton" to="." method="_on_resume_button_pressed"]

View file

@ -6,12 +6,15 @@ var config_path = "res://scripts/stages/1/config.gd"
var config = load(config_path).new()
var data = {
"paused": false,
"tower": {},
"health": config.game['health'],
"resource": config.game['resource']
}
func _ready():
$CanvasLayer/GameStats.connect("on_paused", on_game_paused)
$CanvasLayer/PauseMenu.connect("on_resume", on_game_resume)
$CanvasLayer/GameStats.set_resource(data['resource'])
$base.connect("enemy_entered_base", on_enemy_entered_base)
var placements = $Placements.get_children()
@ -19,6 +22,16 @@ func _ready():
placement.connect("on_placement", on_game_placement)
$CanvasLayer/TowerMenu.connect("build_tower", on_build_tower)
func on_game_paused():
data['paused'] = !data['paused']
get_tree().paused = data['paused']
$CanvasLayer/PauseMenu.show_menu()
func on_game_resume():
data['paused'] = !data['paused']
get_tree().paused = data['paused']
$CanvasLayer/PauseMenu.hide_menu()
func on_game_placement(pos, tower_placement_id):
var tower_id = null
var disabled = false

View file

@ -1,5 +1,6 @@
extends Control
signal on_paused()
func set_resource(value):
$Resources/Label.text = str(value)
@ -11,3 +12,6 @@ func set_damage(value):
if !health.is_empty():
health[len(health) - 1].queue_free()
health.pop_back()
func _on_pause_button_pressed():
on_paused.emit()

20
scripts/ui/pause_menu.gd Normal file
View file

@ -0,0 +1,20 @@
extends Control
signal on_resume()
# Called when the node enters the scene tree for the first time.
func _ready():
hide()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func show_menu():
show()
func hide_menu():
hide()
func _on_resume_button_pressed():
on_resume.emit()