DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: d575e76d9acbc73756fc0d55cca3a90a617cad6f deck-builder/client-old-for-ref/src/plugins/menu_old/mainmenuscreen.rs -rw-r--r-- 2.4 KiB
d575e76dJonni Liljamo feat(client): move platform down, do y0 is on top of it 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
/*
 * 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, cfg_user: Res<CfgUser>) {
    let logged_in = cfg_user.logged_in.clone();

    // 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| {
                    // FIXME: I guess hiding the button would be better, but this is something for
                    // now.
                    if logged_in {
                        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);
    }
}