Refactor HUD and MainMenu components to use Node attribute for better scene integration
This commit is contained in:
@@ -12,9 +12,9 @@ public partial class Hud : Node
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export] public HealthComponent Health { get; set; } = null!;
|
||||
[Export] public Label CoinsLabel { get; set; } = null!;
|
||||
[Export] public ProgressBar HealthBar { get; set; } = null!;
|
||||
[Export] public Label LivesLabel { get; set; } = null!;
|
||||
[Node] public Label CoinsLabel { get; set; } = null!;
|
||||
[Node] public ProgressBar HealthBar { get; set; } = null!;
|
||||
[Node] public Label LivesLabel { get; set; } = null!;
|
||||
|
||||
[Dependency] public PlayerRepository Player => this.DependOn<PlayerRepository>();
|
||||
|
||||
|
86
features/ui/hud/hud.tscn
Normal file
86
features/ui/hud/hud.tscn
Normal file
@@ -0,0 +1,86 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://byxf45ukq82pe"]
|
||||
|
||||
[ext_resource type="LabelSettings" uid="uid://rvn5ivivfvv6" path="res://resources/ui/hud_label_settings.tres" id="1_4dsh5"]
|
||||
[ext_resource type="Script" uid="uid://c1uwe5e1cfdxl" path="res://features/ui/hud/Hud.cs" id="1_m4pq7"]
|
||||
[ext_resource type="FontFile" uid="uid://xm0vbusjr7b7" path="res://fonts/PressStart2P-Regular.ttf" id="1_ygmwt"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_mmcdi"]
|
||||
bg_color = Color(0, 0, 0, 1)
|
||||
|
||||
[sub_resource type="Theme" id="Theme_auu2b"]
|
||||
default_font = ExtResource("1_ygmwt")
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_sp6hg"]
|
||||
bg_color = Color(0.47451, 0.47451, 0.47451, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_22dp1"]
|
||||
bg_color = Color(0.858824, 0.254902, 0.380392, 1)
|
||||
|
||||
[node name="HUD" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
script = ExtResource("1_m4pq7")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 16.0
|
||||
grow_horizontal = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_mmcdi")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
|
||||
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="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 8
|
||||
alignment = 1
|
||||
|
||||
[node name="Health Label" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
text = "HEALTH_LABEL"
|
||||
label_settings = ExtResource("1_4dsh5")
|
||||
uppercase = true
|
||||
|
||||
[node name="HealthBar" type="ProgressBar" parent="PanelContainer/MarginContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 1
|
||||
theme = SubResource("Theme_auu2b")
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_sp6hg")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_22dp1")
|
||||
step = 0.1
|
||||
value = 60.0
|
||||
show_percentage = false
|
||||
|
||||
[node name="LivesLabel" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "LIVES_LABEL"
|
||||
label_settings = ExtResource("1_4dsh5")
|
||||
horizontal_alignment = 1
|
||||
uppercase = true
|
||||
|
||||
[node name="CoinsLabel" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "COINS_LABEL"
|
||||
label_settings = ExtResource("1_4dsh5")
|
||||
horizontal_alignment = 1
|
||||
uppercase = true
|
@@ -12,13 +12,12 @@ public partial class MainMenu : Control
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export] public Control MainMenuControl { get; set; } = null!;
|
||||
[Export] public Button NewGameButton { get; set; } = null!;
|
||||
[Export] public Button ContinueButton { get; set; } = null!;
|
||||
[Export] public Button SettingsButton { get; set; } = null!;
|
||||
[Export] public Button CreditsButton { get; set; } = null!;
|
||||
[Export] public Button ExitButton { get; set; } = null!;
|
||||
[Export] public Label VersionLabel { get; set; } = null!;
|
||||
[Node] public Button NewGameButton { get; set; } = null!;
|
||||
[Node] public Button ContinueButton { get; set; } = null!;
|
||||
[Node] public Button SettingsButton { get; set; } = null!;
|
||||
[Node] public Button CreditsButton { get; set; } = null!;
|
||||
[Node] public Button ExitButton { get; set; } = null!;
|
||||
[Node] public Label VersionLabel { get; set; } = null!;
|
||||
[Export] public Control SettingsControl { get; set; } = null!;
|
||||
[Export] public Control CreditsControl { get; set; } = null!;
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qv2q0"]
|
||||
bg_color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="MainMenu" type="Control" node_paths=PackedStringArray("MainMenuControl", "NewGameButton", "ContinueButton", "SettingsButton", "CreditsButton", "ExitButton", "VersionLabel")]
|
||||
[node name="MainMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
@@ -13,13 +13,6 @@ anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_q8hru")
|
||||
MainMenuControl = NodePath(".")
|
||||
NewGameButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/NewGameButton")
|
||||
ContinueButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/ContinueButton")
|
||||
SettingsButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/SettingsButton")
|
||||
CreditsButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/CreditsButton")
|
||||
ExitButton = NodePath("PanelContainer/MarginContainer/VBoxContainer/QuitButton")
|
||||
VersionLabel = NodePath("PanelContainer/MarginContainer/VBoxContainer/version")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
layout_mode = 1
|
||||
@@ -53,31 +46,37 @@ layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="ContinueButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "CONTINUE_BUTTON"
|
||||
flat = true
|
||||
|
||||
[node name="NewGameButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "NEW_GAME_BUTTON"
|
||||
flat = true
|
||||
|
||||
[node name="SettingsButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "SETTINGS_BUTTON"
|
||||
flat = true
|
||||
|
||||
[node name="CreditsButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "CREDITS_BUTTON"
|
||||
flat = true
|
||||
|
||||
[node name="QuitButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
[node name="ExitButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "QUIT_BUTTON"
|
||||
flat = true
|
||||
|
||||
[node name="version" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
[node name="VersionLabel" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 8
|
||||
|
Reference in New Issue
Block a user