Skip to content

Commit

Permalink
feat: added theme for loop gui
Browse files Browse the repository at this point in the history
  • Loading branch information
akorzunin committed Aug 14, 2024
1 parent 9cc02e6 commit a4caa6f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
Binary file modified .godot/uid_cache.bin
Binary file not shown.
9 changes: 8 additions & 1 deletion src/components/GameProgress.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class_name GameProgress
@onready var game_state_manager: GameStateManager = %GameStateManager
@onready var loop_timer: LoopTimer = %LoopTimer
@onready var debug_stats_container: DebugStatsContainer = %DebugStatsContainer
@onready var gui: LoopGui = $'../Gui'

var figures_passed := 0
var time_passed := 0.
Expand All @@ -21,18 +22,24 @@ func reset():
func _ready() -> void:
game_state_manager.game_state_changed.connect(_on_game_state)

func start():
gui.show_stats_panel(true)

func end():
time_passed = loop_timer.get_raw_elapsed_time()
gui.show_stats_panel(false)

func _on_game_state(old_state: GameStateManager.GameState, new_state: GameStateManager.GameState):
var gs := GameStateManager.GameState
if new_state == gs.GAME_END:
end()
pass
elif new_state == gs.GAME_ACTIVE:
start()

func _physics_process(delta: float) -> void:
debug_stats_container.nodes_passed.label_text = str(figures_passed)
debug_stats_container.time_passed.label_text = loop_timer.get_elapsed_time()
gui.game_state_label.set_text(str(figures_passed))

func get_score():
return "score\nnodes: %s\ntime: %s" % [
Expand Down
19 changes: 7 additions & 12 deletions src/components/gui/LoopGui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ extends Node
class_name LoopGui

@onready var game_state_manager: GameStateManager = %GameStateManager
@onready var game_state_label: Label = $LoopUi/GameStatePanel/VBoxContainer/HFlowContainer/GameStateLabel
@onready var loop_timer: LoopTimer = %LoopTimer
@onready var game_state_label: Label = $LoopUi/GameStatePanel/VBoxContainer/HFlowContainer/GameStateLabel
@onready var timer_rich_text_label: Label = $LoopUi/TimerPanel/CenterContainer/TimerRichTextLabel
@onready var debug_stats_container: DebugStatsContainer = %DebugStatsContainer
@onready var common_controls: CommonControls = %CommonControls
@onready var loop_ui: Control = $LoopUi

# Called when the node enters the scene tree for the first time.
func _ready():
game_state_manager.game_state_changed.connect(_on_game_state_changed)
common_controls.toggle_debug_stats.connect(_on_debug_stats_toggle)
if G.settings.SHOW_DEBUG_STATS:
debug_stats_container.show()
Expand All @@ -22,15 +21,11 @@ func _physics_process(delta: float) -> void:
timer_rich_text_label.set_text(loop_timer.get_elapsed_time())
pass


func _on_game_state_changed(old_state: GameStateManager.GameState, new_state: GameStateManager.GameState):
game_state_label.set_text(GameStateManager.GameStateNames[new_state])
var gs := GameStateManager.GameState
if new_state == gs.GAME_END:
loop_ui.hide()
else:
loop_ui.show()


func _on_debug_stats_toggle(v: bool):
DebugStatsContainer.toggle(v, debug_stats_container)

func show_stats_panel(state: bool):
if state:
loop_ui.show()
return
loop_ui.hide()
20 changes: 13 additions & 7 deletions src/scenes/LoopScene.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=32 format=3 uid="uid://dhbnayqnukkof"]
[gd_scene load_steps=34 format=3 uid="uid://dhbnayqnukkof"]

[ext_resource type="Script" path="res://src/scenes/init/LoopScene.gd" id="1_rcesrc"]
[ext_resource type="Shader" path="res://src/shaders/LoopSceneSky.gdshader" id="1_xr744"]
Expand All @@ -21,8 +21,9 @@
[ext_resource type="Script" path="res://src/components/spawners/Despawner.gd" id="11_wkoqb"]
[ext_resource type="Script" path="res://src/components/EndRay.gd" id="12_486y3"]
[ext_resource type="Script" path="res://src/components/controls/CommonControls.gd" id="12_fcd1m"]
[ext_resource type="FontFile" uid="uid://bbybk2vrrp4il" path="res://src/fonts/plastic-bag/Plastic Bag.otf" id="13_kcvb1"]
[ext_resource type="Theme" uid="uid://bqb5wheue6nip" path="res://src/themes/LoopGuiTheme.tres" id="13_ryoi1"]
[ext_resource type="Script" path="res://src/components/timers/ScaleTimer.gd" id="14_3258y"]
[ext_resource type="Texture2D" uid="uid://dho54u5o0pgkt" path="res://assets/build/textures/1x/LoopGuiTileInv.png" id="14_xcs0c"]
[ext_resource type="Script" path="res://src/components/settings/Config.gd" id="18_tjx6c"]
[ext_resource type="Script" path="res://src/components/GameProgress.gd" id="19_mtejl"]

Expand All @@ -47,6 +48,11 @@ render_priority = 0
shader = ExtResource("5_ban2q")
shader_parameter/color = Color(0.937, 0.267, 0.267, 1)

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_6yuip"]
texture = ExtResource("14_xcs0c")
expand_margin_right = 25.0
expand_margin_bottom = 15.0

[sub_resource type="BoxShape3D" id="BoxShape3D_cw5a6"]

[node name="LoopScene" type="Node3D"]
Expand Down Expand Up @@ -99,12 +105,13 @@ layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
theme = ExtResource("13_ryoi1")

[node name="GameStatePanel" type="PanelContainer" parent="Gui/LoopUi"]
visible = false
layout_mode = 0
offset_right = 264.0
offset_bottom = 80.0
theme_override_styles/panel = SubResource("StyleBoxTexture_6yuip")

[node name="CenterContainer" type="VFlowContainer" parent="Gui/LoopUi/GameStatePanel"]
layout_mode = 2
Expand All @@ -119,12 +126,12 @@ alignment = 1

[node name="Label" type="Label" parent="Gui/LoopUi/GameStatePanel/VBoxContainer/HFlowContainer"]
layout_mode = 2
text = "GAME_STATE: "
text = "Nodes: "
horizontal_alignment = 1

[node name="GameStateLabel" type="Label" parent="Gui/LoopUi/GameStatePanel/VBoxContainer/HFlowContainer"]
layout_mode = 2
text = "NULL"
text = "0"

[node name="TimerPanel" type="PanelContainer" parent="Gui/LoopUi"]
layout_mode = 1
Expand All @@ -145,13 +152,12 @@ layout_mode = 2
custom_minimum_size = Vector2(86.765, 23.805)
layout_mode = 2
size_flags_horizontal = 4
theme_override_fonts/font = ExtResource("13_kcvb1")
theme_override_font_sizes/font_size = 21
text = "00:00:000
"

[node name="DebugStatsContainer" parent="Gui" instance=ExtResource("8_jh3v8")]
unique_name_in_owner = true
visible = false

[node name="ControlsContainer" type="PanelContainer" parent="Gui"]
anchors_preset = 15
Expand Down
Binary file modified src/themes/Base.theme
Binary file not shown.
17 changes: 17 additions & 0 deletions src/themes/LoopGuiTheme.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[gd_resource type="Theme" load_steps=4 format=3 uid="uid://bqb5wheue6nip"]

[ext_resource type="FontFile" uid="uid://bbybk2vrrp4il" path="res://src/fonts/plastic-bag/Plastic Bag.otf" id="1_0kl3p"]
[ext_resource type="Texture2D" uid="uid://b8e111n2q73go" path="res://assets/build/textures/1x/LoopGuiTile.png" id="1_cweir"]

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_7pdq7"]
texture = ExtResource("1_cweir")
expand_margin_left = 5.0
expand_margin_bottom = 10.0

[resource]
default_font = ExtResource("1_0kl3p")
default_font_size = 24
PanelContainer/colors/base_col = Color(0, 0, 0, 1)
PanelContainer/font_sizes/DefaultFontSize = 24
PanelContainer/fonts/DefaultFont = ExtResource("1_0kl3p")
PanelContainer/styles/panel = SubResource("StyleBoxTexture_7pdq7")

0 comments on commit a4caa6f

Please sign in to comment.