summaryrefslogtreecommitdiff
path: root/Scenes/UI
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-10 11:48:05 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-10 11:48:05 +0200
commit46556d864b9685c3b09a0038f5de83966fe7ff94 (patch)
treec68082eacd35559e14565d1598dd694972fb8e0e /Scenes/UI
Initial commit
Diffstat (limited to 'Scenes/UI')
-rw-r--r--Scenes/UI/Health.gd41
-rw-r--r--Scenes/UI/Health.tscn42
-rw-r--r--Scenes/UI/HealthBar.gd44
-rw-r--r--Scenes/UI/HealthBar.tscn15
-rw-r--r--Scenes/UI/Menu.gd65
-rw-r--r--Scenes/UI/Menu.tscn130
6 files changed, 337 insertions, 0 deletions
diff --git a/Scenes/UI/Health.gd b/Scenes/UI/Health.gd
new file mode 100644
index 0000000..eb88522
--- /dev/null
+++ b/Scenes/UI/Health.gd
@@ -0,0 +1,41 @@
+extends Control
+
+
+@export var color_full: Color = Color(1, 0, 0, 1)
+@export var color_empty: Color = Color(0, 0, 0, 1)
+@export var color_extra_full: Color = Color(1, 1, 0, 1)
+@export var color_extra_empty: Color = Color(0, 0, 0, 0)
+
+
+func set_full():
+ self.set_color_all(self.color_full)
+
+
+func set_empty():
+ self.set_color_all(self.color_empty)
+
+
+func set_full_parts(parts: int):
+ self.set_empty()
+ for i in range(1, parts+1):
+ self.set_color(i, self.color_full)
+
+
+func set_extra_full():
+ self.set_color_all(self.color_extra_full)
+
+
+func set_extra_full_parts(parts: int):
+ self.set_color_all(self.color_extra_empty)
+ for i in range(1, parts+1):
+ self.set_color(i, self.color_extra_full)
+
+
+func set_color(index: int, color: Color):
+ var color_rect: ColorRect = get_node("ColorRect" + str(index))
+ color_rect.set_color(color)
+
+
+func set_color_all(color: Color):
+ for i in range(1, 4+1):
+ self.set_color(i, color)
diff --git a/Scenes/UI/Health.tscn b/Scenes/UI/Health.tscn
new file mode 100644
index 0000000..c0c6b76
--- /dev/null
+++ b/Scenes/UI/Health.tscn
@@ -0,0 +1,42 @@
+[gd_scene load_steps=2 format=3 uid="uid://cd3dyvl10j0wa"]
+
+[ext_resource type="Script" path="res://Scenes/UI/Health.gd" id="1_6m5ll"]
+
+[node name="GridContainer" type="Control"]
+custom_minimum_size = Vector2(8, 8)
+layout_mode = 3
+anchors_preset = 0
+offset_right = 8.0
+offset_bottom = 8.0
+size_flags_horizontal = 12
+size_flags_vertical = 12
+script = ExtResource("1_6m5ll")
+color_full = Color(0.862745, 0, 0, 1)
+
+[node name="ColorRect1" type="ColorRect" parent="."]
+custom_minimum_size = Vector2(4, 4)
+layout_mode = 2
+offset_right = 2.0
+offset_bottom = 2.0
+
+[node name="ColorRect2" type="ColorRect" parent="."]
+custom_minimum_size = Vector2(4, 4)
+layout_mode = 2
+offset_top = 4.0
+offset_right = 4.0
+offset_bottom = 8.0
+
+[node name="ColorRect3" type="ColorRect" parent="."]
+custom_minimum_size = Vector2(4, 4)
+layout_mode = 2
+offset_left = 4.0
+offset_top = 4.0
+offset_right = 8.0
+offset_bottom = 8.0
+
+[node name="ColorRect4" type="ColorRect" parent="."]
+custom_minimum_size = Vector2(4, 4)
+layout_mode = 2
+offset_left = 4.0
+offset_right = 8.0
+offset_bottom = 4.0
diff --git a/Scenes/UI/HealthBar.gd b/Scenes/UI/HealthBar.gd
new file mode 100644
index 0000000..8c4c90d
--- /dev/null
+++ b/Scenes/UI/HealthBar.gd
@@ -0,0 +1,44 @@
+extends Control
+
+
+var Health = preload("res://Scenes/UI/Health.tscn")
+var player: Player
+
+
+func connect_to_player(player_to_connect: Player):
+ self.player = player_to_connect
+ self.draw_health()
+
+ self.player.connect("damaged", func (_health): self.draw_health())
+
+
+func draw_health():
+ for child in $HBoxContainer.get_children():
+ child.queue_free()
+
+ for i in int(player.health / 4.0):
+ var healthNode = Health.instantiate()
+ healthNode.set_full()
+ $HBoxContainer.add_child(healthNode)
+
+ if player.health % 4 > 0:
+ var healthNode = Health.instantiate()
+ healthNode.set_full_parts(player.health % 4)
+ $HBoxContainer.add_child(healthNode)
+
+ var health_diff = player.maxHealth - player.health
+ for i in int(health_diff / 4.0):
+ var healthNode = Health.instantiate()
+ healthNode.set_empty()
+ $HBoxContainer.add_child(healthNode)
+
+ if player.extraHealth > 0:
+ for i in int(player.extraHealth / 4.0):
+ var healthNode = Health.instantiate()
+ healthNode.set_extra_full()
+ $HBoxContainer.add_child(healthNode)
+
+ if player.extraHealth % 4 > 0:
+ var healthNode = Health.instantiate()
+ healthNode.set_extra_full_parts(player.extraHealth % 4)
+ $HBoxContainer.add_child(healthNode)
diff --git a/Scenes/UI/HealthBar.tscn b/Scenes/UI/HealthBar.tscn
new file mode 100644
index 0000000..6335714
--- /dev/null
+++ b/Scenes/UI/HealthBar.tscn
@@ -0,0 +1,15 @@
+[gd_scene load_steps=2 format=3 uid="uid://buju4hh2nrrvs"]
+
+[ext_resource type="Script" path="res://Scenes/UI/HealthBar.gd" id="1_t85yh"]
+
+[node name="HealthBar" type="Control"]
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+script = ExtResource("1_t85yh")
+
+[node name="HBoxContainer" type="HBoxContainer" parent="."]
+layout_mode = 1
diff --git a/Scenes/UI/Menu.gd b/Scenes/UI/Menu.gd
new file mode 100644
index 0000000..b482342
--- /dev/null
+++ b/Scenes/UI/Menu.gd
@@ -0,0 +1,65 @@
+extends TabContainer
+
+
+func _ready():
+ hide()
+
+
+func _input(_event: InputEvent):
+ if Input.is_action_just_pressed("ui_menu"):
+ if get_tree().paused: # game is paused
+ self.close_menu()
+ else: # game is running
+ self.open_menu()
+
+ if Input.is_action_pressed("ui_menu_left"):
+ if get_current_tab() > 0:
+ set_current_tab(get_current_tab() - 1)
+ if Input.is_action_pressed("ui_menu_right"):
+ if get_current_tab() < get_tab_count() - 1:
+ set_current_tab(get_current_tab() + 1)
+
+
+func open_menu():
+ get_tree().paused = true
+ show()
+
+
+func close_menu():
+ hide()
+ get_tree().paused = false
+
+
+func get_player():
+ return get_tree().get_current_scene().get_node("Player")
+
+
+### Bombs ###
+
+
+func _on_button_bomb_normal_pressed():
+ self.get_player().Bomb = preload("res://Scenes/Entities/Bombs/Bomb__Normal.tscn")
+
+
+func _on_button_bomb_breakables_pressed():
+ self.get_player().Bomb = preload("res://Scenes/Entities/Bombs/Bomb__Breakables.tscn")
+
+
+func _on_bomb_power_item_selected(index):
+ var power = int($Bombs/Panel/HBoxContainer/VBoxContainer2/BombPower.get_item_text(index))
+ self.get_player().bomb_power = power
+
+
+### System ###
+
+
+func quit_game():
+ get_tree().quit()
+
+
+func _on_button_resume_pressed():
+ self.close_menu()
+
+
+func _on_button_quit_pressed():
+ self.quit_game()
diff --git a/Scenes/UI/Menu.tscn b/Scenes/UI/Menu.tscn
new file mode 100644
index 0000000..4a8f26e
--- /dev/null
+++ b/Scenes/UI/Menu.tscn
@@ -0,0 +1,130 @@
+[gd_scene load_steps=8 format=3 uid="uid://d3xrwsv32hs6k"]
+
+[ext_resource type="Script" path="res://Scenes/UI/Menu.gd" id="1_vwah3"]
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_flq5r"]
+bg_color = Color(0, 0, 0, 0.784314)
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_u0ugs"]
+bg_color = Color(0, 0, 0, 0.784314)
+
+[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_p483f"]
+
+[sub_resource type="LabelSettings" id="LabelSettings_3ht7i"]
+font_size = 10
+
+[sub_resource type="LabelSettings" id="LabelSettings_s4847"]
+font_size = 10
+
+[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_7at3v"]
+
+[node name="TabContainer" type="TabContainer"]
+process_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+theme_override_font_sizes/font_size = 10
+theme_override_styles/panel = SubResource("StyleBoxFlat_flq5r")
+theme_override_styles/tabbar_background = SubResource("StyleBoxFlat_u0ugs")
+clip_tabs = false
+script = ExtResource("1_vwah3")
+
+[node name="Bombs" type="MarginContainer" parent="."]
+layout_mode = 2
+theme_override_constants/margin_left = 8
+theme_override_constants/margin_top = 8
+theme_override_constants/margin_right = 8
+theme_override_constants/margin_bottom = 8
+
+[node name="Panel" type="Panel" parent="Bombs"]
+layout_mode = 2
+theme_override_styles/panel = SubResource("StyleBoxEmpty_p483f")
+
+[node name="HBoxContainer" type="HBoxContainer" parent="Bombs/Panel"]
+layout_mode = 1
+offset_right = 177.0
+offset_bottom = 101.0
+
+[node name="VBoxContainer" type="VBoxContainer" parent="Bombs/Panel/HBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="Bombs/Panel/HBoxContainer/VBoxContainer"]
+layout_mode = 2
+text = "Type"
+label_settings = SubResource("LabelSettings_3ht7i")
+horizontal_alignment = 1
+
+[node name="ButtonBombNormal" type="Button" parent="Bombs/Panel/HBoxContainer/VBoxContainer"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 10
+text = "Normal"
+
+[node name="ButtonBombBreakables" type="Button" parent="Bombs/Panel/HBoxContainer/VBoxContainer"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 10
+text = "Breakables"
+
+[node name="Space" type="Control" parent="Bombs/Panel/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+
+[node name="VBoxContainer2" type="VBoxContainer" parent="Bombs/Panel/HBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="Bombs/Panel/HBoxContainer/VBoxContainer2"]
+layout_mode = 2
+text = "Power"
+label_settings = SubResource("LabelSettings_s4847")
+horizontal_alignment = 1
+
+[node name="BombPower" type="ItemList" parent="Bombs/Panel/HBoxContainer/VBoxContainer2"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 10
+auto_height = true
+item_count = 4
+item_0/text = "2"
+item_1/text = "3"
+item_2/text = "4"
+item_3/text = "5"
+
+[node name="System" type="MarginContainer" parent="."]
+visible = false
+layout_mode = 2
+theme_override_constants/margin_left = 16
+theme_override_constants/margin_top = 16
+theme_override_constants/margin_right = 16
+theme_override_constants/margin_bottom = 16
+
+[node name="Panel" type="Panel" parent="System"]
+layout_mode = 2
+theme_override_styles/panel = SubResource("StyleBoxEmpty_7at3v")
+
+[node name="VBoxContainer" type="VBoxContainer" parent="System/Panel"]
+layout_mode = 1
+anchors_preset = 3
+anchor_left = 1.0
+anchor_top = 1.0
+anchor_right = 1.0
+anchor_bottom = 1.0
+offset_left = -92.0
+offset_top = -48.0
+grow_horizontal = 0
+grow_vertical = 0
+
+[node name="ButtonResume" type="Button" parent="System/Panel/VBoxContainer"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 10
+text = "Resume Game"
+
+[node name="ButtonQuit" type="Button" parent="System/Panel/VBoxContainer"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 10
+text = "Quit Game"
+
+[connection signal="pressed" from="Bombs/Panel/HBoxContainer/VBoxContainer/ButtonBombNormal" to="." method="_on_button_bomb_normal_pressed"]
+[connection signal="pressed" from="Bombs/Panel/HBoxContainer/VBoxContainer/ButtonBombBreakables" to="." method="_on_button_bomb_breakables_pressed"]
+[connection signal="item_selected" from="Bombs/Panel/HBoxContainer/VBoxContainer2/BombPower" to="." method="_on_bomb_power_item_selected"]
+[connection signal="pressed" from="System/Panel/VBoxContainer/ButtonResume" to="." method="_on_button_resume_pressed"]
+[connection signal="pressed" from="System/Panel/VBoxContainer/ButtonQuit" to="." method="_on_button_quit_pressed"]