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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* 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 connecting: bool,
pub username: String,
pub email: String,
pub password: String,
pub password_confirm: String,
pub error: String,
}
#[derive(Default)]
pub enum ConnectState {
#[default]
Login,
LoggingIn,
Register,
Registering,
}
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));
});
if !data.error.is_empty() {
ui.label(egui::RichText::new(&data.error).color(egui::Color32::RED));
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
if ui.button("Login").clicked() {
data.error.clear();
// yoink
}
});
ui.vertical_centered(|ui| {
ui.label("I don't have an account:");
if ui.link("Register").clicked() {
*data = ConnectScreenData::default();
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));
});
if !data.error.is_empty() {
ui.label(egui::RichText::new(&data.error).color(egui::Color32::RED));
}
ui.add_enabled_ui(data.password == data.password_confirm, |ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
if ui.button("Register").clicked() {
data.error.clear();
// yoink
}
});
});
ui.vertical_centered(|ui| {
ui.label("I have an account:");
if ui.link("Login").clicked() {
*data = ConnectScreenData::default();
data.state = ConnectState::Login;
}
});
}
_ => {
ui.spinner();
}
}
},
);
}