From d0eb5c53585459e70049fb994dfda48263dc6b86 Mon Sep 17 00:00:00 2001 From: Marcelo Geldres Date: Sat, 2 Apr 2022 15:16:19 -0400 Subject: [PATCH] Fully responsive layout Some parts were not responsive to the window size. they were corrected --- game/game_logic/src/scenes/main_menu.rs | 72 +++++++++++++++---------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/game/game_logic/src/scenes/main_menu.rs b/game/game_logic/src/scenes/main_menu.rs index 2625a2a7..fa0e73e9 100644 --- a/game/game_logic/src/scenes/main_menu.rs +++ b/game/game_logic/src/scenes/main_menu.rs @@ -161,16 +161,22 @@ impl MainMenu { //Top Label draw.draw_text("Options", 25, 30, 55, Color::BLACK); - //Return Button - draw.draw_text("Return", 100, 550, 34, Color::BLACK); - if mouse_x >= 100 && mouse_y >= 550 && mouse_x <= 216 && mouse_y <= 576 { - draw.draw_text("Return", 103, 551, 34, Color::GRAY); - draw.draw_text("Return", 100, 550, 34, Color::BLACK); + //Window size storing variables + let window_height = draw.get_screen_height(); + let window_width = draw.get_screen_width(); + + //Return button variables + let button_pos_x = 100; //116 Wide + let button_pos_y = window_height - (window_height/5); //26 height + + draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK); + if mouse_x >= 100 && mouse_y >= button_pos_y && mouse_x <= 216 && mouse_y <= (window_height - (window_height/5)) + 26 { + draw.draw_text("Return", button_pos_x + 3, button_pos_y + 1, 34, Color::GRAY); + draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK); if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) { return MenuStateSignal::DoMainMenu; //Goes back to main menu } } - return MenuStateSignal::DoOptions; } @@ -192,28 +198,31 @@ impl MainMenu { draw.draw_text(&mouse_y.to_string(), 70, 5, 20, Color::BLACK); //Screen Size - // let window_height = draw.get_screen_height(); + let window_height = draw.get_screen_height(); let window_width = draw.get_screen_width(); draw.draw_text("Credits", (window_width/2) - 100, 30, 55, Color::BLACK); - draw.draw_text("Carter Tomlenovich", (window_width/2) - 170, 280, 40, Color::DARKBLUE); - draw.draw_text("Emilia Firas", (window_width/2) - 170, 120, 40, Color::DARKBLUE); - draw.draw_text("Emmet Logue", (window_width/2) - 170, 320, 40, Color::DARKBLUE); - draw.draw_text("Evan Pratten", (window_width/2) - 170, 160, 40, Color::DARKBLUE); - draw.draw_text("James Nickoli", (window_width/2) - 170, 240, 40, Color::DARKBLUE); - draw.draw_text("Marcelo Geldres", (window_width/2) - 170, 440, 40, Color::DARKBLUE); - draw.draw_text("Percy", (window_width/2) - 170, 400, 40, Color::DARKBLUE); - draw.draw_text("Silas Bartha", (window_width/2) - 170, 200, 40, Color::DARKBLUE); - draw.draw_text("Taya Armstrong", (window_width/2) - 170, 360, 40, Color::DARKBLUE); + draw.draw_text("Carter Tomlenovich", (window_width/2) - 170, 120, 40, Color::DARKBLUE); + draw.draw_text("Emilia Firas", (window_width/2) - 170, 160, 40, Color::DARKBLUE); + draw.draw_text("Emmet Logue", (window_width/2) - 170, 200, 40, Color::DARKBLUE); + draw.draw_text("Evan Pratten", (window_width/2) - 170, 240, 40, Color::DARKBLUE); + draw.draw_text("James Nickoli", (window_width/2) - 170, 280, 40, Color::DARKBLUE); + draw.draw_text("Marcelo Geldres", (window_width/2) - 170, 320, 40, Color::DARKBLUE); + draw.draw_text("Percy", (window_width/2) - 170, 360, 40, Color::DARKBLUE); + draw.draw_text("Silas Bartha", (window_width/2) - 170, 400, 40, Color::DARKBLUE); + draw.draw_text("Taya Armstrong", (window_width/2) - 170, 440, 40, Color::DARKBLUE); - //Return Button - draw.draw_text("Return", 100, 550, 34, Color::BLACK); - if mouse_x >= 100 && mouse_y >= 550 && mouse_x <= 216 && mouse_y <= 576 { - draw.draw_text("Return", 103, 551, 34, Color::GRAY); - draw.draw_text("Return", 100, 550, 34, Color::BLACK); + //Return button variables + let button_pos_x = 100; //116 Wide + let button_pos_y = window_height - (window_height/5); //26 height + + draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK); + if mouse_x >= 100 && mouse_y >= button_pos_y && mouse_x <= 216 && mouse_y <= (window_height - (window_height/5)) + 26 { + draw.draw_text("Return", button_pos_x + 3, button_pos_y + 1, 34, Color::GRAY); + draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK); if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) { - return MenuStateSignal::DoMainMenu; + return MenuStateSignal::DoMainMenu; //Goes back to main menu } } @@ -234,6 +243,10 @@ impl MainMenu { let mouse_x = draw.get_mouse_x(); let mouse_y = draw.get_mouse_y(); + //Window size storing variables + let window_height = draw.get_screen_height(); + let window_width = draw.get_screen_width(); + //Show mouse position draw.draw_text(&mouse_x.to_string(), 20, 5, 20, Color::BLACK); draw.draw_text(&mouse_y.to_string(), 70, 5, 20, Color::BLACK); @@ -241,13 +254,16 @@ impl MainMenu { let window_width = draw.get_screen_width(); draw.draw_text("Leaderboard", (window_width/2) - 176, 30, 55, Color::BLACK); - //Return Button - draw.draw_text("Return", 100, 550, 34, Color::BLACK); - if mouse_x >= 100 && mouse_y >= 550 && mouse_x <= 216 && mouse_y <= 576 { - draw.draw_text("Return", 103, 551, 34, Color::GRAY); - draw.draw_text("Return", 100, 550, 34, Color::BLACK); + //Return button variables + let button_pos_x = 100; //116 Wide + let button_pos_y = window_height - (window_height/5); //26 height + + draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK); + if mouse_x >= 100 && mouse_y >= button_pos_y && mouse_x <= 216 && mouse_y <= (window_height - (window_height/5)) + 26 { + draw.draw_text("Return", button_pos_x + 3, button_pos_y + 1, 34, Color::GRAY); + draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK); if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) { - return MenuStateSignal::DoMainMenu; + return MenuStateSignal::DoMainMenu; //Goes back to main menu } }