/*
* This file is part of laurelin_client
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* Licensed under GPL-3.0-only.
* See LICENSE for licensing information.
*/
use bevy::prelude::*;
use crate::{api::game::Game, AppState};
mod ui;
pub struct MenuPlugin;
impl Plugin for MenuPlugin {
fn build(&self, app: &mut App) {
app.add_state::<MenuState>()
.insert_resource(MenuData::default())
.add_system(menu_setup.in_schedule(OnEnter(AppState::Menu)))
.add_system(ui::ui.run_if(not(in_state(MenuState::None))));
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, States)]
enum MenuState {
#[default]
None,
Visible,
}
#[derive(Resource)]
pub struct MenuData {
pub ui_state: MenuUIState,
pub browse_state: BrowseState,
/// true if waiting on some request
pub waiting: bool,
pub forming_games: Vec<Game>,
pub my_games: Vec<Game>,
error: String,
login_email: String,
login_password: String,
register_username: String,
register_email: String,
register_password: String,
register_password_confirm: String,
}
impl Default for MenuData {
fn default() -> Self {
Self {
ui_state: MenuUIState::Login,
browse_state: BrowseState::Forming,
waiting: false,
forming_games: vec![],
my_games: vec![],
error: String::from(""),
login_email: String::from(""),
login_password: String::from(""),
register_username: String::from(""),
register_email: String::from(""),
register_password: String::from(""),
register_password_confirm: String::from(""),
}
}
}
#[derive(Debug)]
pub enum MenuUIState {
Loading, // for waiting for requests to finish
Login,
Register,
Main,
Browse,
}
#[derive(Debug, PartialEq)]
pub enum BrowseState {
Forming,
InProgress,
Finished,
}
fn menu_setup(mut commands: Commands) {
commands.insert_resource(NextState(Some(MenuState::Visible)));
}