DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 4a51f61f3d0d4261eb49b01f13121524e9079693 deck-builder/client/src/plugins/menu/mod.rs -rw-r--r-- 1.6 KiB
4a51f61fJonni Liljamo feat: basic login and register windows 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * 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::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 {
    ui_state: MenuUIState,

    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,

            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,

}

fn menu_setup(mut commands: Commands) {
    commands.insert_resource(NextState(Some(MenuState::Visible)));
}