DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 506419d0e21bb692061a0b992e9484bccf915e0f deck-builder/client/src/plugins/menu/mod.rs -rw-r--r-- 2.8 KiB
506419d0Jonni Liljamo feat!(client, shared): move api calls to shared, dep shuffle, 1 year, 7 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * 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 iyes_loopless::prelude::*;

use crate::{remove_ui, GameState};

mod mainmenuscreen;
use mainmenuscreen::*;

mod settingsscreen;
use settingsscreen::*;

//mod accountscreenloggedout;
//use accountscreenloggedout::*;

//mod accountscreenloggedin;
//use accountscreenloggedin::*;

//mod accountlogin;
//mod accountregister;

//mod play;

pub struct MenuPlugin;

impl Plugin for MenuPlugin {
    fn build(&self, app: &mut App) {
        app.
            // Start with no menu. The menu is loaded when the GameState::MainMenu is entered.
            add_loopless_state(MenuState::None)
            .add_enter_system(GameState::MainMenu, menu_setup)
            // Systems for main menu screen
            .add_enter_system(MenuState::Main, remove_ui.label("msm_enter_first"))
            .add_enter_system(MenuState::Main, main_menu_setup.before("msm_enter_first"))
            .add_exit_system(MenuState::Main, remove_ui)
            .add_event::<ToAccountEvent>()
            .add_event::<ExitEvent>()
            .add_system_set(
                ConditionSet::new()
                    .run_in_state(MenuState::Main)
                    .with_system(handle_to_account_event.run_on_event::<ToAccountEvent>())
                    .with_system(handle_exit_event.run_on_event::<ExitEvent>())
                    .into()
            );
        // Systems for the settings screen
        //.add_enter_system(MenuState::Settings, settings_setup)
        //.add_exit_system(MenuState::Settings, remove_ui)
        // Systems for account loggedout screen
        //.add_enter_system(MenuState::AccountLoggedOut, account_loggedout_setup)
        //.add_exit_system(MenuState::AccountLoggedOut, remove_ui)
        // Systems for account loggedin screen
        //.add_enter_system(MenuState::AccountLoggedIn, account_loggedin_setup)
        //.add_exit_system(MenuState::AccountLoggedIn, remove_ui)
        //.add_event::<LogoutEvent>()
        //.add_system_set(
        //    ConditionSet::new()
        //        .run_in_state(MenuState::AccountLoggedIn)
        //        .with_system(handle_logout_event.run_on_event::<LogoutEvent>())
        //        .into()
        //);

        //app.add_plugin(accountregister::AccountRegisterPlugin)
        //    .add_plugin(accountlogin::AccountLoginPlugin);

        //app.add_plugin(play::PlayMenuPlugin);
    }
}

/// Menu State
#[derive(Clone, Eq, PartialEq, Debug, Hash)]
pub enum MenuState {
    None,
    Main,
    Play,
    Settings,
    AccountLoggedIn,
    AccountLoggedOut,
    AccountLogin,
    AccountRegister,
}

fn menu_setup(mut commands: Commands) {
    commands.insert_resource(NextState(MenuState::Main))
}