improved menu navigation
This commit is contained in:
parent
bed3f407d6
commit
1bc5aa966d
@ -1,6 +1,10 @@
|
|||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{gamecore::{GameCore, GameState}, lib::wrappers::audio::player::AudioPlayer, pallette::WATER_DARK};
|
use crate::{
|
||||||
|
gamecore::{GameCore, GameState},
|
||||||
|
lib::wrappers::audio::player::AudioPlayer,
|
||||||
|
pallette::WATER_DARK,
|
||||||
|
};
|
||||||
|
|
||||||
use super::screen::Screen;
|
use super::screen::Screen;
|
||||||
|
|
||||||
@ -40,8 +44,10 @@ impl Screen for MainMenuScreen {
|
|||||||
let mouse_position = draw_handle.get_mouse_position();
|
let mouse_position = draw_handle.get_mouse_position();
|
||||||
let hovering_play_button = mouse_position.y > (win_width as f32 / 4.0)
|
let hovering_play_button = mouse_position.y > (win_width as f32 / 4.0)
|
||||||
&& mouse_position.y < (win_width as f32 / 4.0) + 60.0;
|
&& mouse_position.y < (win_width as f32 / 4.0) + 60.0;
|
||||||
let hovering_quit_button = mouse_position.y > (win_width as f32 / 4.0) + 100.0
|
let hovering_shop_button = mouse_position.y > (win_width as f32 / 4.0) + 100.0
|
||||||
&& mouse_position.y < (win_width as f32 / 4.0) + 160.0;
|
&& mouse_position.y < (win_width as f32 / 4.0) + 160.0;
|
||||||
|
let hovering_quit_button = mouse_position.y > (win_width as f32 / 4.0) + 200.0
|
||||||
|
&& mouse_position.y < (win_width as f32 / 4.0) + 260.0;
|
||||||
|
|
||||||
// Play and quit
|
// Play and quit
|
||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
@ -54,10 +60,20 @@ impl Screen for MainMenuScreen {
|
|||||||
false => Color::BLACK,
|
false => Color::BLACK,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
draw_handle.draw_text(
|
||||||
|
"Shop",
|
||||||
|
(win_height / 2) + 120,
|
||||||
|
(win_width / 4) + 100,
|
||||||
|
60,
|
||||||
|
match hovering_shop_button {
|
||||||
|
true => Color::GREEN,
|
||||||
|
false => Color::BLACK,
|
||||||
|
},
|
||||||
|
);
|
||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
"Quit",
|
"Quit",
|
||||||
(win_height / 2) + 130,
|
(win_height / 2) + 130,
|
||||||
(win_width / 4) + 100,
|
(win_width / 4) + 200,
|
||||||
60,
|
60,
|
||||||
match hovering_quit_button {
|
match hovering_quit_button {
|
||||||
true => Color::GREEN,
|
true => Color::GREEN,
|
||||||
@ -72,6 +88,8 @@ impl Screen for MainMenuScreen {
|
|||||||
if mouse_clicked {
|
if mouse_clicked {
|
||||||
if hovering_play_button {
|
if hovering_play_button {
|
||||||
return Some(GameState::InGame);
|
return Some(GameState::InGame);
|
||||||
|
} else if hovering_shop_button {
|
||||||
|
return Some(GameState::InShop);
|
||||||
}else if hovering_quit_button {
|
}else if hovering_quit_button {
|
||||||
return Some(GameState::GameQuit);
|
return Some(GameState::GameQuit);
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ impl Screen for PauseMenuScreen {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
"Quit",
|
"Menu",
|
||||||
bottom_left_button_dimensions.x as i32 + 15,
|
bottom_left_button_dimensions.x as i32 + 15,
|
||||||
bottom_left_button_dimensions.y as i32 + 5,
|
bottom_left_button_dimensions.y as i32 + 5,
|
||||||
30,
|
30,
|
||||||
@ -182,7 +182,7 @@ impl Screen for PauseMenuScreen {
|
|||||||
// Handle click actions on the buttons
|
// Handle click actions on the buttons
|
||||||
if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
|
if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
|
||||||
if mouse_over_bottom_left_button {
|
if mouse_over_bottom_left_button {
|
||||||
return Some(GameState::GameQuit);
|
return Some(GameState::MainMenu);
|
||||||
} else if mouse_over_bottom_right_button {
|
} else if mouse_over_bottom_right_button {
|
||||||
return Some(game_core.last_state);
|
return Some(game_core.last_state);
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ impl Screen for ShopScreen {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
"Quit",
|
"Menu",
|
||||||
bottom_left_button_dimensions.x as i32 + 15,
|
bottom_left_button_dimensions.x as i32 + 15,
|
||||||
bottom_left_button_dimensions.y as i32 + 5,
|
bottom_left_button_dimensions.y as i32 + 5,
|
||||||
30,
|
30,
|
||||||
@ -159,7 +159,7 @@ impl Screen for ShopScreen {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
"Close",
|
"Play",
|
||||||
bottom_right_button_dimensions.x as i32 + 15,
|
bottom_right_button_dimensions.x as i32 + 15,
|
||||||
bottom_right_button_dimensions.y as i32 + 5,
|
bottom_right_button_dimensions.y as i32 + 5,
|
||||||
30,
|
30,
|
||||||
@ -169,9 +169,9 @@ impl Screen for ShopScreen {
|
|||||||
// Handle click actions on the buttons
|
// Handle click actions on the buttons
|
||||||
if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
|
if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
|
||||||
if mouse_over_bottom_left_button {
|
if mouse_over_bottom_left_button {
|
||||||
return Some(GameState::GameQuit);
|
return Some(GameState::MainMenu);
|
||||||
} else if mouse_over_bottom_right_button {
|
} else if mouse_over_bottom_right_button {
|
||||||
return Some(game_core.last_state);
|
return Some(GameState::InGame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user