Adding UI boxes
This commit is contained in:
parent
83aaa01133
commit
eff489d9ff
@ -2,7 +2,7 @@ use raylib::prelude::*;
|
||||
|
||||
use crate::{
|
||||
gamecore::{GameCore, GameState},
|
||||
lib::wrappers::audio::player::AudioPlayer,
|
||||
lib::{utils::button::OnScreenButton, wrappers::audio::player::AudioPlayer},
|
||||
};
|
||||
|
||||
use super::screen::Screen;
|
||||
@ -127,7 +127,8 @@ impl Screen for PauseMenuScreen {
|
||||
Color::BLACK,
|
||||
);
|
||||
|
||||
// Close and quit buttons
|
||||
// Bottom buttons
|
||||
|
||||
let bottom_left_button_dimensions = Rectangle {
|
||||
x: (win_width as f32 / 2.0) - (SCREEN_PANEL_SIZE.x / 2.0) + 5.0,
|
||||
y: (win_height as f32 / 2.0) + (SCREEN_PANEL_SIZE.y / 2.0) - 50.0,
|
||||
@ -141,49 +142,34 @@ impl Screen for PauseMenuScreen {
|
||||
height: bottom_left_button_dimensions.height,
|
||||
};
|
||||
|
||||
// Check if the mouse is over either button
|
||||
let mouse_over_bottom_left_button =
|
||||
bottom_left_button_dimensions.check_collision_point_rec(mouse_position);
|
||||
let mouse_over_bottom_right_button =
|
||||
bottom_right_button_dimensions.check_collision_point_rec(mouse_position);
|
||||
|
||||
// Render buttons
|
||||
draw_handle.draw_rectangle_lines_ex(
|
||||
let menu_button = OnScreenButton::new(
|
||||
"Menu".to_string(),
|
||||
bottom_left_button_dimensions,
|
||||
3,
|
||||
match mouse_over_bottom_left_button {
|
||||
true => Color::GRAY,
|
||||
false => Color::BLACK,
|
||||
},
|
||||
);
|
||||
draw_handle.draw_text(
|
||||
"Menu",
|
||||
bottom_left_button_dimensions.x as i32 + 15,
|
||||
bottom_left_button_dimensions.y as i32 + 5,
|
||||
30,
|
||||
Color::WHITE,
|
||||
Color::BLACK,
|
||||
Color::GRAY,
|
||||
30,
|
||||
true,
|
||||
);
|
||||
draw_handle.draw_rectangle_lines_ex(
|
||||
let close_button = OnScreenButton::new(
|
||||
"Close".to_string(),
|
||||
bottom_right_button_dimensions,
|
||||
3,
|
||||
match mouse_over_bottom_right_button {
|
||||
true => Color::GRAY,
|
||||
false => Color::BLACK,
|
||||
},
|
||||
);
|
||||
draw_handle.draw_text(
|
||||
"Close",
|
||||
bottom_right_button_dimensions.x as i32 + 15,
|
||||
bottom_right_button_dimensions.y as i32 + 5,
|
||||
30,
|
||||
Color::WHITE,
|
||||
Color::BLACK,
|
||||
Color::GRAY,
|
||||
30,
|
||||
true,
|
||||
);
|
||||
|
||||
// Render both
|
||||
menu_button.render(draw_handle);
|
||||
close_button.render(draw_handle);
|
||||
|
||||
// Handle click actions on the buttons
|
||||
if draw_handle.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
|
||||
if mouse_over_bottom_left_button {
|
||||
if menu_button.is_hovered(draw_handle) {
|
||||
return Some(GameState::MainMenu);
|
||||
} else if mouse_over_bottom_right_button {
|
||||
} else if menu_button.is_hovered(draw_handle) {
|
||||
return Some(game_core.last_state);
|
||||
}
|
||||
}
|
||||
|
@ -9,16 +9,6 @@ use super::screen::Screen;
|
||||
|
||||
const SCREEN_PANEL_SIZE: Vector2 = Vector2 { x: 300.0, y: 380.0 };
|
||||
|
||||
pub struct Item {
|
||||
x_pose: i32,
|
||||
y_pose: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
cost: u8,
|
||||
level: u8,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ShopScreen {
|
||||
// shop_items: Vec<Item>,
|
||||
@ -31,14 +21,39 @@ impl ShopScreen {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_buy_section(
|
||||
fn render_shop(
|
||||
&mut self,
|
||||
draw_handle: &mut RaylibDrawHandle,
|
||||
_thread: &RaylibThread,
|
||||
audio_system: &mut AudioPlayer,
|
||||
game_core: &mut GameCore,
|
||||
draw_bounds: Rectangle
|
||||
bounds: Rectangle,
|
||||
) -> Option<GameState> {
|
||||
// Render background
|
||||
draw_handle.draw_rectangle_rec(bounds, Color::WHITE);
|
||||
draw_handle.draw_rectangle_lines_ex(bounds, 3, Color::BLACK);
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
fn render_stats(
|
||||
&mut self,
|
||||
draw_handle: &mut RaylibDrawHandle,
|
||||
game_core: &mut GameCore,
|
||||
bounds: Rectangle,
|
||||
) {
|
||||
// Render background
|
||||
draw_handle.draw_rectangle_rec(bounds, Color::WHITE);
|
||||
draw_handle.draw_rectangle_lines_ex(bounds, 3, Color::BLACK);
|
||||
|
||||
// Coins
|
||||
draw_handle.draw_text(
|
||||
&format!("Fish: {}", game_core.player.coins.min(99)),
|
||||
bounds.x as i32 + 5,
|
||||
bounds.y as i32 + 5,
|
||||
20,
|
||||
Color::BLACK,
|
||||
);
|
||||
}
|
||||
|
||||
// // Creates all the items
|
||||
@ -82,7 +97,7 @@ impl Screen for ShopScreen {
|
||||
fn render(
|
||||
&mut self,
|
||||
draw_handle: &mut RaylibDrawHandle,
|
||||
_thread: &RaylibThread,
|
||||
thread: &RaylibThread,
|
||||
audio_system: &mut AudioPlayer,
|
||||
game_core: &mut GameCore,
|
||||
) -> Option<GameState> {
|
||||
@ -90,9 +105,32 @@ impl Screen for ShopScreen {
|
||||
draw_handle.clear_background(Color::GRAY);
|
||||
// TODO: Maybe we can stick some art here?
|
||||
|
||||
// Window dimensions
|
||||
let win_height = draw_handle.get_screen_height();
|
||||
let win_width = draw_handle.get_screen_width();
|
||||
|
||||
// Build a rect for the shop UI to sit inside
|
||||
let shop_ui_bounds = Rectangle {
|
||||
x: win_width as f32 - (win_width as f32 / 5.0),
|
||||
y: 0.0,
|
||||
width: win_width as f32 / 5.0,
|
||||
height: win_height as f32,
|
||||
};
|
||||
let stats_ui_bounds = Rectangle {
|
||||
x: win_width as f32 - (win_width as f32 / 5.0) - 100.0,
|
||||
y: 10.0,
|
||||
width: 90.0,
|
||||
height: 120.0,
|
||||
};
|
||||
|
||||
return None;
|
||||
// Render the shop UI
|
||||
let next_state =
|
||||
self.render_shop(draw_handle, thread, audio_system, game_core, shop_ui_bounds);
|
||||
|
||||
// Render the stats UI
|
||||
self.render_stats(draw_handle, game_core, stats_ui_bounds);
|
||||
|
||||
return next_state;
|
||||
}
|
||||
}
|
||||
// pub fn render_shop(
|
||||
|
Reference in New Issue
Block a user