feat: add amazing textures

This commit is contained in:
2026-08-19 19:25:31 +02:00
parent 2d89cf7725
commit 3720a0640a
4 changed files with 79 additions and 12 deletions

View File

@@ -1,33 +1,64 @@
use macroquad::{
color::WHITE,
math::vec2,
ui::{hash, root_ui},
math::{Rect, Vec2, vec2},
prelude::ImageFormat,
texture::Image,
ui::{Layout, Skin, Ui, hash, root_ui, widgets::Button},
window::{next_frame, screen_height, screen_width},
};
use crate::ui::state::GuiState;
pub async fn draw_main_menu(state: &mut GuiState) {
let _style = root_ui().style_builder().text_color(WHITE).font_size(64);
let _text_style = root_ui().style_builder().text_color(WHITE).font_size(32);
pub struct MenuBuilder {
center_x: f32,
current_y: f32,
button_size: Vec2,
spacing: f32,
}
let window_size = vec2(370.0, 320.0);
impl MenuBuilder {
pub fn new(window_width: f32, start_y: f32) -> Self {
let button_size = vec2(200.0, 50.0);
Self {
center_x: (window_width - button_size.x) / 2.0,
current_y: start_y,
button_size,
spacing: 15.0,
}
}
pub fn button(&mut self, ui: &mut Ui, label: &str) -> bool {
let clicked = Button::new(label)
.position(vec2(self.center_x, self.current_y))
.size(self.button_size)
.ui(ui);
self.current_y += self.button_size.y + self.spacing;
clicked
}
}
pub async fn draw_main_menu(state: &mut GuiState) {
let window_size = vec2(1200.0, 620.0);
let mut menu_builder = MenuBuilder::new(screen_width(), 10.0);
root_ui().window(
hash!(),
vec2(screen_width() / 2.0, screen_height() / 2.0),
window_size,
|ui| {
ui.label(vec2(80.0, -34.0), "Main Menu");
if ui.button(vec2(65.0, 25.0), "Play") {
ui.label(None, "Main Menu");
if menu_builder.button(ui, "Play") {
*state = GuiState::Game;
}
if ui.button(vec2(65.0, 25.0), "Settings") {
if menu_builder.button(ui, "Settings") {
*state = GuiState::Settings;
}
if ui.button(vec2(65.0, 125.0), "Quit") {
if menu_builder.button(ui, "Quit") {
*state = GuiState::Exit;
}
},

View File