main menu fixes

This commit is contained in:
2026-01-24 06:12:15 +01:00
parent 0a6a2317bf
commit ed1edb2010
4 changed files with 66 additions and 30 deletions

View File

@@ -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();
}
}

View File

@@ -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);
}
}