DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

0522364de6a5077493be00fd91faaadd181ab620 — Jonni Liljamo 1 year, 9 months ago 8f50406
feat!(client): add new connect ui, and menu stub
M client/src/plugins/menu/mod.rs => client/src/plugins/menu/mod.rs +7 -6
@@ 11,6 11,7 @@ use iyes_loopless::prelude::*;

use crate::GameState;

mod ui;

pub struct MenuPlugin;



@@ 20,6 21,9 @@ impl Plugin for MenuPlugin {
            // 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)
            .insert_resource(ui::connect::ConnectScreenData::default())
            .add_system(ui::connect::ui.run_in_state(MenuState::Connect))
            .add_system(ui::menu::ui.run_in_state(MenuState::Menu));
    }
}



@@ 27,15 31,12 @@ impl Plugin for MenuPlugin {
#[derive(Clone, Eq, PartialEq, Debug, Hash)]
pub enum MenuState {
    None,
    Main,
    Connect,
    Menu,
    Play,
    Settings,
    AccountLoggedIn,
    AccountLoggedOut,
    AccountLogin,
    AccountRegister,
}

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

A client/src/plugins/menu/ui/connect.rs => client/src/plugins/menu/ui/connect.rs +94 -0
@@ 0,0 1,94 @@
/*
 * 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::ecs::{system::ResMut, system::Resource};
use bevy_inspector_egui::bevy_egui::{egui, EguiContext};

use crate::util::egui::{menuwindow, password};

#[derive(Default, Resource)]
pub struct ConnectScreenData {
    pub state: ConnectState,
    pub username: String,
    pub email: String,
    pub password: String,
    pub password_confirm: String,
}

#[derive(Default)]
pub enum ConnectState {
    #[default]
    Login,
    Register,
}

pub fn ui(mut egui_context: ResMut<EguiContext>, mut data: ResMut<ConnectScreenData>) {
    menuwindow(
        egui_context.ctx_mut(),
        "Connect",
        &egui::Vec2::new(400., 600.),
        |ui| {
            match data.state {
                ConnectState::Login => {
                    ui.horizontal(|ui| {
                        ui.label("Email:");
                        ui.text_edit_singleline(&mut data.email)
                    });
                    ui.horizontal(|ui| {
                        ui.label("Password:");
                        ui.add(password(&mut data.password));
                    });

                    ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
                        if ui.button("Login").clicked() {
                            // yoink
                        }
                    });

                    ui.vertical_centered(|ui| {
                        ui.label("I don't have an account:");
                        if ui.link("Register").clicked() {
                            data.state = ConnectState::Register;
                        }
                    });
                }
                ConnectState::Register => {
                    ui.horizontal(|ui| {
                        ui.label("Username:");
                        ui.text_edit_singleline(&mut data.username)
                    });
                    ui.horizontal(|ui| {
                        ui.label("Email:");
                        ui.text_edit_singleline(&mut data.email)
                    });
                    ui.horizontal(|ui| {
                        ui.label("Password:");
                        ui.add(password(&mut data.password));
                    });
                    ui.horizontal(|ui| {
                        ui.label("Confirm password:");
                        ui.add(password(&mut data.password_confirm));
                    });

                    ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
                        if ui.button("Register").clicked() {
                            // yoink
                        }
                    });

                    ui.vertical_centered(|ui| {
                        ui.label("I have an account:");
                        if ui.link("Login").clicked() {
                            data.state = ConnectState::Login;
                        }
                    });
                }
            }
        },
    );
}

A client/src/plugins/menu/ui/menu.rs => client/src/plugins/menu/ui/menu.rs +23 -0
@@ 0,0 1,23 @@
/*
 * 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::ecs::system::ResMut;
use bevy_inspector_egui::bevy_egui::{egui, EguiContext};

use crate::util::egui::menuwindow;

pub fn ui(mut egui_context: ResMut<EguiContext>) {
    menuwindow(
        egui_context.ctx_mut(),
        "Connect",
        &egui::Vec2::new(400., 600.),
        |ui| {
            ui.label("wow, menu!");
        },
    );
}

A client/src/plugins/menu/ui/mod.rs => client/src/plugins/menu/ui/mod.rs +11 -0
@@ 0,0 1,11 @@
/*
 * 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.
 */

pub mod menu;

pub mod connect;