mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
feat: show errors in main menu when client fails
Instead of `[ERROR] Failed to tick the scene: Network(Bincode(Io(Custom { kind: UnexpectedEof, error: "failed to fill whole buffer" })))`
This commit is contained in:
parent
3b24af76ab
commit
21f126acd4
@ -43,6 +43,7 @@ pub struct GlobalState {
|
||||
settings: Settings,
|
||||
window: Window,
|
||||
audio: AudioFrontend,
|
||||
error_message: Option<String>,
|
||||
}
|
||||
|
||||
impl GlobalState {
|
||||
@ -116,6 +117,7 @@ fn main() {
|
||||
audio,
|
||||
window: Window::new(&settings).expect("Failed to create window!"),
|
||||
settings,
|
||||
error_message: None,
|
||||
};
|
||||
let settings = &global_state.settings;
|
||||
|
||||
|
@ -114,6 +114,10 @@ impl PlayState for CharSelectionState {
|
||||
.tick(comp::ControllerInputs::default(), clock.get_last_delta())
|
||||
{
|
||||
error!("Failed to tick the scene: {:?}", err);
|
||||
global_state.error_message = Some(
|
||||
"Connection lost!\nDid the server restart?\nIs the client up to date?"
|
||||
.to_owned(),
|
||||
);
|
||||
return PlayStateResult::Pop;
|
||||
}
|
||||
self.client.borrow_mut().cleanup();
|
||||
|
@ -75,11 +75,11 @@ impl PlayState for MainMenuState {
|
||||
}
|
||||
Some(Err(err)) => {
|
||||
client_init = None;
|
||||
self.main_menu_ui.login_error(
|
||||
global_state.error_message = Some(
|
||||
match err {
|
||||
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
||||
InitError::InvalidAuth => "Invalid credentials",
|
||||
InitError::ServerIsFull => "Server is Full!",
|
||||
InitError::ServerIsFull => "Server is full",
|
||||
InitError::ConnectionFailed(_) => "Connection failed",
|
||||
InitError::ClientCrashed => "Client crashed",
|
||||
}
|
||||
@ -129,8 +129,8 @@ impl PlayState for MainMenuState {
|
||||
false,
|
||||
)));
|
||||
} else {
|
||||
self.main_menu_ui
|
||||
.login_error("Invalid username or password".to_string());
|
||||
global_state.error_message =
|
||||
Some("Invalid username or password".to_string());
|
||||
}
|
||||
}
|
||||
MainMenuEvent::CancelLoginAttempt => {
|
||||
@ -152,6 +152,10 @@ impl PlayState for MainMenuState {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(error) = global_state.error_message.take() {
|
||||
self.main_menu_ui.show_error(error);
|
||||
}
|
||||
|
||||
// Draw the UI to the screen.
|
||||
self.main_menu_ui.render(global_state.window.renderer_mut());
|
||||
|
||||
|
@ -425,20 +425,20 @@ impl MainMenuUi {
|
||||
.rgba(1.0, 1.0, 1.0, 1.0)
|
||||
.font_size(25)
|
||||
.font_id(self.fonts.cyri);
|
||||
Rectangle::fill_with([65.0 * 6.0, 100.0], color::TRANSPARENT)
|
||||
Rectangle::fill_with([65.0 * 6.0, 140.0], color::TRANSPARENT)
|
||||
.rgba(0.1, 0.1, 0.1, 1.0)
|
||||
.parent(ui_widgets.window)
|
||||
.up_from(self.ids.banner_top, 20.0)
|
||||
.up_from(self.ids.banner_top, 15.0)
|
||||
.set(self.ids.login_error_bg, ui_widgets);
|
||||
Image::new(self.imgs.info_frame)
|
||||
.w_h(65.0 * 6.0, 100.0)
|
||||
.w_h(65.0 * 6.0, 140.0)
|
||||
.middle_of(self.ids.login_error_bg)
|
||||
.set(self.ids.error_frame, ui_widgets);
|
||||
text.mid_top_with_margin_on(self.ids.error_frame, 10.0)
|
||||
.set(self.ids.login_error, ui_widgets);
|
||||
if Button::image(self.imgs.button)
|
||||
.w_h(100.0, 30.0)
|
||||
.mid_bottom_with_margin_on(self.ids.login_error_bg, 5.0)
|
||||
.mid_bottom_with_margin_on(self.ids.login_error_bg, 10.0)
|
||||
.hover_image(self.imgs.button_hover)
|
||||
.press_image(self.imgs.button_press)
|
||||
.label_y(Relative::Scalar(2.0))
|
||||
@ -650,7 +650,7 @@ impl MainMenuUi {
|
||||
events
|
||||
}
|
||||
|
||||
pub fn login_error(&mut self, msg: String) {
|
||||
pub fn show_error(&mut self, msg: String) {
|
||||
self.popup = Some(PopupData {
|
||||
msg,
|
||||
button_text: "Okay".to_string(),
|
||||
|
@ -333,6 +333,10 @@ impl PlayState for SessionState {
|
||||
// Perform an in-game tick.
|
||||
if let Err(err) = self.tick(clock.get_avg_delta()) {
|
||||
error!("Failed to tick the scene: {:?}", err);
|
||||
global_state.error_message = Some(
|
||||
"Connection lost!\nDid the server restart?\nIs the client up to date?"
|
||||
.to_owned(),
|
||||
);
|
||||
return PlayStateResult::Pop;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user