/*
* 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::{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);
}
}