From 4bab96d766de25e1ce3c66416b2d9ca48c90ede6 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Tue, 31 Jan 2023 13:51:08 +0200 Subject: [PATCH] feat(sdbclient): new account UIs --- .../src/plugins/menu/accountscreenloggedin.rs | 168 ++++++------------ .../plugins/menu/accountscreenloggedout.rs | 129 ++++---------- sdbclient/src/plugins/menu/mod.rs | 106 ++--------- 3 files changed, 97 insertions(+), 306 deletions(-) diff --git a/sdbclient/src/plugins/menu/accountscreenloggedin.rs b/sdbclient/src/plugins/menu/accountscreenloggedin.rs index 3d57784..d175b36 100644 --- a/sdbclient/src/plugins/menu/accountscreenloggedin.rs +++ b/sdbclient/src/plugins/menu/accountscreenloggedin.rs @@ -1,133 +1,69 @@ /* * This file is part of sdbclient - * Copyright (C) 2022 Jonni Liljamo + * Copyright (C) 2023 Jonni Liljamo * * Licensed under GPL-3.0-only. * See LICENSE for licensing information. */ -use bevy::{ - prelude::*, - ui::{JustifyContent, Size, Style, Val}, +use bevy::prelude::*; +use iyes_loopless::prelude::*; + +use belly::prelude::*; + +use crate::{ + cfg::CfgUser, + plugins::config::{SaveEvent, SaveEventValue}, }; -use crate::{cfg::CfgUser, constants::TEXT_COLOR}; +use super::MenuState; -use super::{MenuButtonAction, NORMAL_BUTTON}; +pub(super) struct LogoutEvent; -/// Tag component for tagging entities on settings menu screen -#[derive(Component)] -pub struct OnAccountLoggedInScreen; +pub(super) fn account_loggedin_setup(mut commands: Commands, cfg_user: Res) { + let username = cfg_user.username.clone(); + + commands.add(eml! { + +
+ + "Account" + + + "Logged in as:" + + + { username } + + + +
+ + }); +} -pub fn account_loggedin_setup( +pub(super) fn handle_logout_event( + mut events: EventReader, mut commands: Commands, - asset_server: Res, - cfg_user: ResMut, + mut cfg_user: ResMut, + mut save_event_writer: EventWriter, ) { - let font = asset_server.load("fonts/FiraMono-Regular.ttf"); - let font_bold = asset_server.load("fonts/FiraMono-Bold.ttf"); + for _event in events.iter() { + // Reset CfgUser to default + *cfg_user = CfgUser::default(); - let button_style = Style { - size: Size::new(Val::Px(200.0), Val::Px(65.0)), - margin: UiRect::all(Val::Px(20.0)), - justify_content: JustifyContent::Center, - align_items: AlignItems::Center, - ..default() - }; - - let button_text_style = TextStyle { - font: font.clone(), - font_size: 40.0, - color: TEXT_COLOR, - }; - - commands - .spawn(( - NodeBundle { - style: Style { - size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), - align_items: AlignItems::Center, - justify_content: JustifyContent::Center, - flex_direction: FlexDirection::Column, - ..default() - }, - ..default() - }, - OnAccountLoggedInScreen, - )) - .with_children(|parent| { - parent.spawn( - TextBundle::from_section( - "Account", - TextStyle { - font: font.clone(), - font_size: 60.0, - color: TEXT_COLOR, - }, - ) - .with_style(Style { - margin: UiRect::all(Val::Px(50.)), - ..Default::default() - }), - ); - parent.spawn( - TextBundle::from_section( - "Logged in as: ", - TextStyle { - font: font.clone(), - font_size: 25.0, - color: TEXT_COLOR, - }, - ) - .with_style(Style { - ..Default::default() - }), - ); - parent.spawn( - TextBundle::from_section( - cfg_user.username.clone(), - TextStyle { - font: font_bold.clone(), - font_size: 40.0, - color: TEXT_COLOR, - }, - ) - .with_style(Style { - margin: UiRect::bottom(Val::Px(25.)), - ..Default::default() - }), - ); - parent - .spawn(NodeBundle { - style: Style { - flex_direction: FlexDirection::Column, - align_items: AlignItems::Center, - ..default() - }, - background_color: Color::GRAY.into(), - ..default() - }) - .with_children(|parent| { - for (action, text) in [ - (MenuButtonAction::AccountLogout, "Logout"), - (MenuButtonAction::BackToMainMenu, "Back"), - ] { - parent - .spawn(( - ButtonBundle { - style: button_style.clone(), - background_color: NORMAL_BUTTON.into(), - ..default() - }, - action, - )) - .with_children(|parent| { - parent.spawn(TextBundle::from_section( - text, - button_text_style.clone(), - )); - }); - } - }); + save_event_writer.send(SaveEvent { + value: SaveEventValue::User(cfg_user.clone()), }); + + commands.insert_resource(NextState(MenuState::AccountLoggedOut)); + } } diff --git a/sdbclient/src/plugins/menu/accountscreenloggedout.rs b/sdbclient/src/plugins/menu/accountscreenloggedout.rs index 6696350..8339155 100644 --- a/sdbclient/src/plugins/menu/accountscreenloggedout.rs +++ b/sdbclient/src/plugins/menu/accountscreenloggedout.rs @@ -1,102 +1,43 @@ /* * This file is part of sdbclient - * Copyright (C) 2022 Jonni Liljamo + * Copyright (C) 2023 Jonni Liljamo * * Licensed under GPL-3.0-only. * See LICENSE for licensing information. */ -use bevy::{ - prelude::*, - ui::{JustifyContent, Size, Style, Val}, -}; - -use crate::constants::TEXT_COLOR; - -use super::{MenuButtonAction, NORMAL_BUTTON}; - -/// Tag component for tagging entities on settings menu screen -#[derive(Component)] -pub struct OnAccountLoggedOutScreen; - -pub fn account_loggedout_setup(mut commands: Commands, asset_server: Res) { - let font = asset_server.load("fonts/FiraMono-Regular.ttf"); - - let button_style = Style { - size: Size::new(Val::Px(200.0), Val::Px(65.0)), - margin: UiRect::all(Val::Px(20.0)), - justify_content: JustifyContent::Center, - align_items: AlignItems::Center, - ..default() - }; - - let button_text_style = TextStyle { - font: font.clone(), - font_size: 40.0, - color: TEXT_COLOR, - }; - - commands - .spawn(( - NodeBundle { - style: Style { - size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), - align_items: AlignItems::Center, - justify_content: JustifyContent::Center, - flex_direction: FlexDirection::Column, - ..default() - }, - ..default() - }, - OnAccountLoggedOutScreen, - )) - .with_children(|parent| { - parent.spawn( - TextBundle::from_section( - "Account", - TextStyle { - font: font.clone(), - font_size: 60.0, - color: TEXT_COLOR, - }, - ) - .with_style(Style { - margin: UiRect::all(Val::Px(50.)), - ..Default::default() - }), - ); - parent - .spawn(NodeBundle { - style: Style { - flex_direction: FlexDirection::Column, - align_items: AlignItems::Center, - ..default() - }, - background_color: Color::GRAY.into(), - ..default() - }) - .with_children(|parent| { - for (action, text) in [ - (MenuButtonAction::AccountLogin, "Login"), - (MenuButtonAction::AccountRegister, "Register"), - (MenuButtonAction::BackToMainMenu, "Back"), - ] { - parent - .spawn(( - ButtonBundle { - style: button_style.clone(), - background_color: NORMAL_BUTTON.into(), - ..default() - }, - action, - )) - .with_children(|parent| { - parent.spawn(TextBundle::from_section( - text, - button_text_style.clone(), - )); - }); - } - }); - }); +use bevy::prelude::*; +use iyes_loopless::prelude::*; + +use belly::prelude::*; + +use super::{accountlogin::LoginState, accountregister::RegisterState, MenuState}; + +pub(super) fn account_loggedout_setup(mut commands: Commands) { + commands.add(eml! { + +
+ + "Account" + + + + +
+ + }); } diff --git a/sdbclient/src/plugins/menu/mod.rs b/sdbclient/src/plugins/menu/mod.rs index 2b40c24..716a871 100644 --- a/sdbclient/src/plugins/menu/mod.rs +++ b/sdbclient/src/plugins/menu/mod.rs @@ -9,9 +9,7 @@ use bevy::prelude::*; use iyes_loopless::prelude::*; -use crate::cfg::CfgUser; - -use crate::{despawn_screen, remove_ui, GameState}; +use crate::{remove_ui, GameState}; mod mainmenuscreen; use mainmenuscreen::*; @@ -28,8 +26,6 @@ use accountscreenloggedin::*; mod playscreen; use playscreen::*; -use super::config::{SaveEvent, SaveEventValue}; - mod accountlogin; mod accountregister; @@ -58,21 +54,20 @@ impl Plugin for MenuPlugin { .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, despawn_screen::) + .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, despawn_screen::) - // Systems for play screen - .add_enter_system(MenuState::Play, play_setup) - .add_exit_system(MenuState::Play, remove_ui) - // Common systems + .add_exit_system(MenuState::AccountLoggedIn, remove_ui) + .add_event::() .add_system_set( ConditionSet::new() - .run_in_state(GameState::MainMenu) - .with_system(menu_action) - .with_system(button_system) + .run_in_state(MenuState::AccountLoggedIn) + .with_system(handle_logout_event.run_on_event::()) .into() - ); + ) + // Systems for play screen + .add_enter_system(MenuState::Play, play_setup) + .add_exit_system(MenuState::Play, remove_ui); app.add_plugin(accountregister::AccountRegisterPlugin) .add_plugin(accountlogin::AccountLoginPlugin); @@ -95,87 +90,6 @@ pub enum MenuState { AccountRegister, } -/// Tag component for tagging entities on account screen -#[derive(Component)] -struct OnAccountScreen; - -const NORMAL_BUTTON: Color = Color::rgb(0.15, 0.15, 0.15); -const HOVERED_BUTTON: Color = Color::rgb(0.25, 0.25, 0.25); -const HOVERED_PRESSED_BUTTON: Color = Color::rgb(0.25, 0.65, 0.25); -const PRESSED_BUTTON: Color = Color::rgb(0.35, 0.75, 0.35); - -/// Tag component for tagging currently selected settings tab -#[derive(Component)] -struct SelectedSettingsTab; - -/// All button actions -#[derive(Component)] -enum MenuButtonAction { - AccountLogin, - AccountRegister, - AccountLogout, - BackToMainMenu, -} - -fn menu_action( - mut commands: Commands, - interaction_query: Query< - (&Interaction, &MenuButtonAction), - (Changed, With