DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 655bd78123ab545bed91974a69dfba956f4c273d deck-builder/sdbclient/src/plugins/menu/mainmenuscreen.rs -rw-r--r-- 2.1 KiB
655bd781Jonni Liljamo WIP(sdbclient): create game UI and API call 1 year, 8 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
/*
 * This file is part of sdbclient
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use bevy::{app::AppExit, prelude::*};
use iyes_loopless::prelude::*;

use belly::prelude::*;

use crate::cfg::CfgUser;

use super::MenuState;

pub(super) struct ToAccountEvent;
pub(super) struct ExitEvent;

pub(super) fn main_menu_setup(mut commands: Commands) {
    // TODO: Change the title to a fancy image logo thingy
    commands.add(eml! {
        <body>
            <div c:menu>
                <span c:mainmenutitle>
                    "Deck Builder"
                </span>
                <button c:menubutton s:width="250px" on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(MenuState::Play))
                })>
                    "Play"
                </button>
                <button c:menubutton s:width="250px" on:press=connect!(|ctx| {
                    ctx.send_event(ToAccountEvent)
                })>
                    "Account"
                </button>
                <button c:menubutton s:width="250px" on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(MenuState::Settings))
                })>
                    "Settings"
                </button>
                <button c:menubutton s:width="250px" on:press=connect!(|ctx| {
                    ctx.send_event(ExitEvent)
                })>
                    "Exit"
                </button>
            </div>
        </body>
    });
}

pub(super) fn handle_to_account_event(
    mut events: EventReader<ToAccountEvent>,
    mut commands: Commands,
    cfg_user: Res<CfgUser>,
) {
    for _event in events.iter() {
        if cfg_user.logged_in {
            commands.insert_resource(NextState(MenuState::AccountLoggedIn))
        } else {
            commands.insert_resource(NextState(MenuState::AccountLoggedOut))
        }
    }
}

pub(super) fn handle_exit_event(
    mut events: EventReader<ExitEvent>,
    mut app_exit_event_writer: EventWriter<AppExit>,
) {
    for _event in events.iter() {
        app_exit_event_writer.send(AppExit);
    }
}