main menu fixes
This commit is contained in:
@@ -97,25 +97,34 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 1, 0, 1)
|
||||
|
||||
[node name="Label" type="Label" parent="Ui/Win"]
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Ui/Win"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -11.5
|
||||
offset_right = 20.0
|
||||
offset_bottom = 11.5
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 32
|
||||
theme_override_constants/margin_top = 32
|
||||
theme_override_constants/margin_right = 32
|
||||
theme_override_constants/margin_bottom = 32
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Ui/Win/MarginContainer"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="Label" type="Label" parent="Ui/Win/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 72
|
||||
text = "Light Weight"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
uppercase = true
|
||||
|
||||
[node name="Next day" type="Button" parent="Ui/Win/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Next day"
|
||||
|
||||
[node name="Lose" type="ColorRect" parent="Ui"]
|
||||
visible = false
|
||||
anchors_preset = 15
|
||||
@@ -125,23 +134,40 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(1, 0, 0, 1)
|
||||
|
||||
[node name="Label" type="Label" parent="Ui/Lose"]
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Ui/Lose"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -11.5
|
||||
offset_right = 20.0
|
||||
offset_bottom = 11.5
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 32
|
||||
theme_override_constants/margin_top = 32
|
||||
theme_override_constants/margin_right = 32
|
||||
theme_override_constants/margin_bottom = 32
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Ui/Lose/MarginContainer"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="Label" type="Label" parent="Ui/Lose/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 72
|
||||
text = "Failure"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
uppercase = true
|
||||
|
||||
[node name="Restart" type="Button" parent="Ui/Lose/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Restart"
|
||||
|
||||
[node name="Menu" type="Button" parent="Ui/Lose/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Go to menu"
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
|
||||
[connection signal="pressed" from="Ui/Win/MarginContainer/VBoxContainer/Next day" to="Systems/GameManager" method="on_next_day_pressed"]
|
||||
[connection signal="pressed" from="Ui/Lose/MarginContainer/VBoxContainer/Restart" to="Systems/GameManager" method="on_retry_pressed"]
|
||||
[connection signal="pressed" from="Ui/Lose/MarginContainer/VBoxContainer/Menu" to="Systems/GameManager" method="on_menu_pressed"]
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bg4uaukekjbx"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://xtm08af0e82g" path="res://Scenes/main.tscn" id="1_28flt"]
|
||||
[gd_scene format=3 uid="uid://bg4uaukekjbx"]
|
||||
|
||||
[node name="MainMenu" type="MainMenu" node_paths=PackedStringArray("mute_button")]
|
||||
game_scene = ExtResource("1_28flt")
|
||||
game_scene_path = "res://Scenes/main.tscn"
|
||||
mute_button = NodePath("VBoxContainer/MuteButton")
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
@@ -60,3 +58,4 @@ text = "Mute"
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/PlayButton" to="." method="on_play_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/QuitButton" to="." method="on_quit_pressed"]
|
||||
[connection signal="toggled" from="VBoxContainer/MuteButton" to="." method="on_mute_toggled"]
|
||||
|
||||
@@ -183,10 +183,12 @@ impl GameManager {
|
||||
let idx = self.current_day_index;
|
||||
self.base_mut()
|
||||
.call_deferred("start_day", &[idx.to_variant()]);
|
||||
godot_print!("GameManager: Starting day {}", idx);
|
||||
}
|
||||
|
||||
#[func]
|
||||
pub fn on_retry_pressed(&mut self) {
|
||||
godot_print!("GameManager: Retrying day {}", self.current_day_index);
|
||||
let idx = self.current_day_index;
|
||||
self.base_mut()
|
||||
.call_deferred("start_day", &[idx.to_variant()]);
|
||||
@@ -195,12 +197,14 @@ impl GameManager {
|
||||
#[func]
|
||||
pub fn on_menu_pressed(&mut self) {
|
||||
if let Some(menu) = &self.main_menu_scene {
|
||||
godot_print!("GameManager: Returning to main menu");
|
||||
let menu_ref = menu.clone();
|
||||
self.base()
|
||||
.get_tree()
|
||||
.unwrap()
|
||||
.change_scene_to_packed(&menu_ref);
|
||||
} else {
|
||||
godot_error!("GameManager: No main menu scene assigned");
|
||||
self.base().get_tree().unwrap().quit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use godot::{
|
||||
#[class(base=Control)]
|
||||
pub struct MainMenu {
|
||||
#[export]
|
||||
game_scene: Option<Gd<PackedScene>>,
|
||||
game_scene_path: GString,
|
||||
|
||||
#[export]
|
||||
mute_button: Option<Gd<CheckButton>>,
|
||||
@@ -19,7 +19,7 @@ pub struct MainMenu {
|
||||
impl IControl for MainMenu {
|
||||
fn init(base: Base<Control>) -> Self {
|
||||
Self {
|
||||
game_scene: None,
|
||||
game_scene_path: GString::new(),
|
||||
mute_button: None,
|
||||
base,
|
||||
}
|
||||
@@ -36,10 +36,17 @@ impl IControl for MainMenu {
|
||||
impl MainMenu {
|
||||
#[func]
|
||||
fn on_play_pressed(&mut self) {
|
||||
if let Some(scene) = &self.game_scene {
|
||||
if let Some(mut tree) = self.base().get_tree() {
|
||||
tree.change_scene_to_packed(&scene.clone());
|
||||
if self.game_scene_path.is_empty() {
|
||||
godot_error!("MainMenu: Game Scene Path is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
let path = self.game_scene_path.clone();
|
||||
|
||||
let scene = load::<PackedScene>(&path);
|
||||
|
||||
if let Some(mut tree) = self.base().get_tree() {
|
||||
tree.change_scene_to_packed(&scene);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user