1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-28 18:34:18 +00:00

Implement UI state switching and pausing

This commit is contained in:
Steffo 2023-10-01 15:31:49 +02:00
parent 4cd407dd1e
commit 39a0310a53
Signed by: steffo
GPG key ID: 2A24051445686895
4 changed files with 83 additions and 2 deletions

View file

@ -1,2 +1,21 @@
extends VBoxContainer
class_name GameUI
## Emitted when the Score button is pressed.
signal score_button_pressed
## Emitted when the Spawn button is pressed.
signal spawn_button_pressed
## Emitted when the Shop button is presesd.
signal shop_button_pressed
func _on_score_button_pressed():
score_button_pressed.emit()
func _on_spawn_button_pressed():
spawn_button_pressed.emit()
func _on_shop_button_pressed():
shop_button_pressed.emit()

View file

@ -45,3 +45,7 @@ layout_mode = 2
size_flags_horizontal = 8
text = "Shop"
alignment = 2
[connection signal="pressed" from="UpperButtons/ScoreButton" to="." method="_on_score_button_pressed"]
[connection signal="pressed" from="UpperButtons/SpawnButton" to="." method="_on_spawn_button_pressed"]
[connection signal="pressed" from="UpperButtons/ShopButton" to="." method="_on_shop_button_pressed"]

47
root.gd
View file

@ -1,2 +1,49 @@
extends Node
class_name Root
@onready var tree: SceneTree = get_tree()
@onready var game_ui: GameUI = $UI/GameUI
@onready var shop_ui: ShopUI = $UI/ShopUI
enum UIState {
GAME,
SHOP,
SCORE,
}
@export var ui_state: UIState:
get:
return ui_state
set(value):
match value:
UIState.GAME:
tree.paused = false
game_ui.show()
shop_ui.hide()
UIState.SHOP:
tree.paused = true
game_ui.hide()
shop_ui.show()
UIState.SCORE:
pass
func _on_game_ui_score_button_pressed():
ui_state = UIState.SCORE
func _on_shop_ui_back_button_pressed():
ui_state = UIState.GAME
func _on_shop_ui_delete_button_pressed():
ui_state = UIState.GAME
func _on_shop_ui_score_button_pressed():
ui_state = UIState.SCORE
func _on_game_ui_shop_button_pressed():
ui_state = UIState.SHOP
func _on_game_ui_spawn_button_pressed():
pass # Replace with function body.

View file

@ -1,11 +1,13 @@
[gd_scene load_steps=5 format=3 uid="uid://cbccs6kwwf265"]
[gd_scene load_steps=6 format=3 uid="uid://cbccs6kwwf265"]
[ext_resource type="Script" path="res://root.gd" id="1_8jrhk"]
[ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="1_h26ax"]
[ext_resource type="PackedScene" uid="uid://mfa1v4fsnupp" path="res://interface/game_container.tscn" id="1_xjgvu"]
[ext_resource type="PackedScene" uid="uid://cklkdygv61bny" path="res://interface/shop_ui.tscn" id="3_lvefk"]
[ext_resource type="PackedScene" uid="uid://bo5unrhqpoyim" path="res://interface/game_ui.tscn" id="5_2cc15"]
[node name="Root" type="Node"]
script = ExtResource("1_8jrhk")
[node name="UI" type="Control" parent="."]
texture_filter = 1
@ -19,11 +21,20 @@ size_flags_vertical = 8
theme = ExtResource("1_h26ax")
[node name="GameContainer" parent="UI" instance=ExtResource("1_xjgvu")]
process_mode = 1
layout_mode = 1
[node name="GameUI" parent="UI" instance=ExtResource("5_2cc15")]
process_mode = 3
layout_mode = 1
[node name="ShopUI" parent="UI" instance=ExtResource("3_lvefk")]
visible = false
process_mode = 3
layout_mode = 1
[connection signal="score_button_pressed" from="UI/GameUI" to="." method="_on_game_ui_score_button_pressed"]
[connection signal="shop_button_pressed" from="UI/GameUI" to="." method="_on_game_ui_shop_button_pressed"]
[connection signal="spawn_button_pressed" from="UI/GameUI" to="." method="_on_game_ui_spawn_button_pressed"]
[connection signal="back_button_pressed" from="UI/ShopUI" to="." method="_on_shop_ui_back_button_pressed"]
[connection signal="delete_button_pressed" from="UI/ShopUI" to="." method="_on_shop_ui_delete_button_pressed"]
[connection signal="score_button_pressed" from="UI/ShopUI" to="." method="_on_shop_ui_score_button_pressed"]