mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
refactor: add gamemode enum
This commit is contained in:
@@ -76,7 +76,7 @@ pub async fn main() {
|
||||
}
|
||||
|
||||
GuiState::ModeSelection => {
|
||||
draw_mode_selection(&mut state).await;
|
||||
draw_mode_selection(&mut state, &mut context).await;
|
||||
}
|
||||
|
||||
GuiState::DificultySelection => {
|
||||
|
||||
@@ -31,22 +31,23 @@ pub async fn draw_dificulty_selection(state: &mut GuiState, context: &mut GameCo
|
||||
menu_builder.label(ui, "Difficulty Selection");
|
||||
|
||||
if menu_builder.button(ui, "Easy") {
|
||||
context.is_single = true;
|
||||
context.difficulty = crate::super_advanced_ai::BotDificulty::Easy;
|
||||
*state = GuiState::Game;
|
||||
}
|
||||
|
||||
if menu_builder.button(ui, "Medium") {
|
||||
context.is_single = true;
|
||||
context.difficulty = crate::super_advanced_ai::BotDificulty::Normal;
|
||||
*state = GuiState::Game;
|
||||
}
|
||||
|
||||
if menu_builder.button(ui, "Hard") {
|
||||
context.is_single = true;
|
||||
context.difficulty = crate::super_advanced_ai::BotDificulty::Hard;
|
||||
*state = GuiState::Game;
|
||||
}
|
||||
|
||||
if menu_builder.button(ui, "Go back") {
|
||||
*state = GuiState::ModeSelection;
|
||||
}
|
||||
});
|
||||
|
||||
next_frame().await;
|
||||
|
||||
@@ -8,10 +8,13 @@ use macroquad::{
|
||||
|
||||
use crate::ui::{
|
||||
macroquad::menu_builder::MenuBuilder,
|
||||
state::GuiState::{self, ServerSelection},
|
||||
state::{
|
||||
GameContext,
|
||||
GuiState::{self, ServerSelection},
|
||||
},
|
||||
};
|
||||
|
||||
pub async fn draw_mode_selection(state: &mut GuiState) {
|
||||
pub async fn draw_mode_selection(state: &mut GuiState, context: &mut GameContext) {
|
||||
let menu_size = vec2(screen_width() * 0.5, screen_height() * 0.5);
|
||||
let menu_pos = vec2(
|
||||
screen_width() / 2.0 - menu_size.x / 2.0,
|
||||
@@ -28,6 +31,7 @@ pub async fn draw_mode_selection(state: &mut GuiState) {
|
||||
menu_builder.label(ui, "Mode selection");
|
||||
|
||||
if menu_builder.button(ui, "Singleplayer") {
|
||||
context.gamemode = crate::ui::state::GameMode::Singleplayer;
|
||||
*state = GuiState::DificultySelection;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,20 @@ pub async fn draw_server_selection(state: &mut GuiState, context: &mut GameConte
|
||||
Group::new(hash!(), menu_size)
|
||||
.position(menu_pos)
|
||||
.ui(&mut root_ui(), |ui| {
|
||||
menu_builder.label(ui, "Host");
|
||||
if menu_builder.button(ui, "Start") {
|
||||
context.gamemode = crate::ui::state::GameMode::Multiplayer { is_hosting: true };
|
||||
}
|
||||
|
||||
menu_builder.label(ui, "Server selection");
|
||||
|
||||
menu_builder.text_input(ui, &mut context.server_url_buffer);
|
||||
//context.normalise_url();
|
||||
|
||||
if menu_builder.button(ui, "Connect") {
|
||||
context.is_single = false;
|
||||
context.gamemode = crate::ui::state::GameMode::Multiplayer { is_hosting: false };
|
||||
*state = GuiState::Game;
|
||||
// TODO Validate url before connecting or something like that
|
||||
}
|
||||
|
||||
if menu_builder.button(ui, "Go back") {
|
||||
|
||||
@@ -14,9 +14,18 @@ pub enum GuiState {
|
||||
Exit,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub enum GameMode {
|
||||
#[default]
|
||||
Singleplayer,
|
||||
Multiplayer {
|
||||
is_hosting: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct GameContext {
|
||||
pub difficulty: BotDificulty,
|
||||
pub is_single: bool,
|
||||
pub gamemode: GameMode,
|
||||
pub server_url_buffer: String,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user