mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 11:10:48 +01:00
feat: add amazing textures
This commit is contained in:
BIN
assets/background.png
Normal file
BIN
assets/background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 533 KiB |
@@ -1,8 +1,12 @@
|
|||||||
use checkers::ui::{macroquad::main_menu::draw_main_menu, state::GuiState};
|
use checkers::ui::{macroquad::main_menu::draw_main_menu, state::GuiState};
|
||||||
use macroquad::{
|
use macroquad::{
|
||||||
color::{BLUE, RED},
|
color::{BLACK, BLUE, RED, WHITE},
|
||||||
|
math::vec2,
|
||||||
miniquad::{self, conf::LinuxBackend::WaylandWithX11Fallback},
|
miniquad::{self, conf::LinuxBackend::WaylandWithX11Fallback},
|
||||||
window::{Conf, clear_background, next_frame},
|
prelude::ImageFormat,
|
||||||
|
texture::{DrawTextureParams, Image, Texture2D, draw_texture, draw_texture_ex, load_texture},
|
||||||
|
ui::{Skin, root_ui},
|
||||||
|
window::{Conf, clear_background, next_frame, screen_height, screen_width},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn window_conf() -> Conf {
|
fn window_conf() -> Conf {
|
||||||
@@ -23,9 +27,41 @@ pub async fn main() {
|
|||||||
|
|
||||||
let mut state = Default::default();
|
let mut state = Default::default();
|
||||||
|
|
||||||
|
let background = load_texture("assets/background.png").await.unwrap();
|
||||||
|
|
||||||
|
let style = root_ui()
|
||||||
|
.style_builder()
|
||||||
|
.text_color(WHITE)
|
||||||
|
.font_size(64)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let button_style = root_ui()
|
||||||
|
.style_builder()
|
||||||
|
.text_color(BLACK)
|
||||||
|
.font_size(32)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let skin = Skin {
|
||||||
|
label_style: style,
|
||||||
|
button_style: button_style,
|
||||||
|
..root_ui().default_skin()
|
||||||
|
};
|
||||||
|
|
||||||
|
root_ui().push_skin(&skin);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match state {
|
match state {
|
||||||
GuiState::MainMenu => {
|
GuiState::MainMenu => {
|
||||||
|
draw_texture_ex(
|
||||||
|
&background,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
WHITE,
|
||||||
|
DrawTextureParams {
|
||||||
|
dest_size: Some(vec2(screen_width(), screen_height())),
|
||||||
|
..DrawTextureParams::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
draw_main_menu(&mut state).await;
|
draw_main_menu(&mut state).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,64 @@
|
|||||||
use macroquad::{
|
use macroquad::{
|
||||||
color::WHITE,
|
color::WHITE,
|
||||||
math::vec2,
|
math::{Rect, Vec2, vec2},
|
||||||
ui::{hash, root_ui},
|
prelude::ImageFormat,
|
||||||
|
texture::Image,
|
||||||
|
ui::{Layout, Skin, Ui, hash, root_ui, widgets::Button},
|
||||||
window::{next_frame, screen_height, screen_width},
|
window::{next_frame, screen_height, screen_width},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::ui::state::GuiState;
|
use crate::ui::state::GuiState;
|
||||||
|
|
||||||
pub async fn draw_main_menu(state: &mut GuiState) {
|
pub struct MenuBuilder {
|
||||||
let _style = root_ui().style_builder().text_color(WHITE).font_size(64);
|
center_x: f32,
|
||||||
let _text_style = root_ui().style_builder().text_color(WHITE).font_size(32);
|
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(
|
root_ui().window(
|
||||||
hash!(),
|
hash!(),
|
||||||
vec2(screen_width() / 2.0, screen_height() / 2.0),
|
vec2(screen_width() / 2.0, screen_height() / 2.0),
|
||||||
window_size,
|
window_size,
|
||||||
|ui| {
|
|ui| {
|
||||||
ui.label(vec2(80.0, -34.0), "Main Menu");
|
ui.label(None, "Main Menu");
|
||||||
if ui.button(vec2(65.0, 25.0), "Play") {
|
|
||||||
|
if menu_builder.button(ui, "Play") {
|
||||||
*state = GuiState::Game;
|
*state = GuiState::Game;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui.button(vec2(65.0, 25.0), "Settings") {
|
if menu_builder.button(ui, "Settings") {
|
||||||
*state = GuiState::Settings;
|
*state = GuiState::Settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui.button(vec2(65.0, 125.0), "Quit") {
|
if menu_builder.button(ui, "Quit") {
|
||||||
*state = GuiState::Exit;
|
*state = GuiState::Exit;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
0
src/ui/macroquad/menu_builder.rs
Normal file
0
src/ui/macroquad/menu_builder.rs
Normal file
Reference in New Issue
Block a user