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:
@ -43,6 +43,7 @@ pub struct GlobalState {
|
|||||||
settings: Settings,
|
settings: Settings,
|
||||||
window: Window,
|
window: Window,
|
||||||
audio: AudioFrontend,
|
audio: AudioFrontend,
|
||||||
|
error_message: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalState {
|
impl GlobalState {
|
||||||
@ -116,6 +117,7 @@ fn main() {
|
|||||||
audio,
|
audio,
|
||||||
window: Window::new(&settings).expect("Failed to create window!"),
|
window: Window::new(&settings).expect("Failed to create window!"),
|
||||||
settings,
|
settings,
|
||||||
|
error_message: None,
|
||||||
};
|
};
|
||||||
let settings = &global_state.settings;
|
let settings = &global_state.settings;
|
||||||
|
|
||||||
|
@ -114,6 +114,10 @@ impl PlayState for CharSelectionState {
|
|||||||
.tick(comp::ControllerInputs::default(), clock.get_last_delta())
|
.tick(comp::ControllerInputs::default(), clock.get_last_delta())
|
||||||
{
|
{
|
||||||
error!("Failed to tick the scene: {:?}", err);
|
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;
|
return PlayStateResult::Pop;
|
||||||
}
|
}
|
||||||
self.client.borrow_mut().cleanup();
|
self.client.borrow_mut().cleanup();
|
||||||
|
@ -75,11 +75,11 @@ impl PlayState for MainMenuState {
|
|||||||
}
|
}
|
||||||
Some(Err(err)) => {
|
Some(Err(err)) => {
|
||||||
client_init = None;
|
client_init = None;
|
||||||
self.main_menu_ui.login_error(
|
global_state.error_message = Some(
|
||||||
match err {
|
match err {
|
||||||
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
||||||
InitError::InvalidAuth => "Invalid credentials",
|
InitError::InvalidAuth => "Invalid credentials",
|
||||||
InitError::ServerIsFull => "Server is Full!",
|
InitError::ServerIsFull => "Server is full",
|
||||||
InitError::ConnectionFailed(_) => "Connection failed",
|
InitError::ConnectionFailed(_) => "Connection failed",
|
||||||
InitError::ClientCrashed => "Client crashed",
|
InitError::ClientCrashed => "Client crashed",
|
||||||
}
|
}
|
||||||
@ -129,8 +129,8 @@ impl PlayState for MainMenuState {
|
|||||||
false,
|
false,
|
||||||
)));
|
)));
|
||||||
} else {
|
} else {
|
||||||
self.main_menu_ui
|
global_state.error_message =
|
||||||
.login_error("Invalid username or password".to_string());
|
Some("Invalid username or password".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainMenuEvent::CancelLoginAttempt => {
|
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.
|
// Draw the UI to the screen.
|
||||||
self.main_menu_ui.render(global_state.window.renderer_mut());
|
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)
|
.rgba(1.0, 1.0, 1.0, 1.0)
|
||||||
.font_size(25)
|
.font_size(25)
|
||||||
.font_id(self.fonts.cyri);
|
.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)
|
.rgba(0.1, 0.1, 0.1, 1.0)
|
||||||
.parent(ui_widgets.window)
|
.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);
|
.set(self.ids.login_error_bg, ui_widgets);
|
||||||
Image::new(self.imgs.info_frame)
|
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)
|
.middle_of(self.ids.login_error_bg)
|
||||||
.set(self.ids.error_frame, ui_widgets);
|
.set(self.ids.error_frame, ui_widgets);
|
||||||
text.mid_top_with_margin_on(self.ids.error_frame, 10.0)
|
text.mid_top_with_margin_on(self.ids.error_frame, 10.0)
|
||||||
.set(self.ids.login_error, ui_widgets);
|
.set(self.ids.login_error, ui_widgets);
|
||||||
if Button::image(self.imgs.button)
|
if Button::image(self.imgs.button)
|
||||||
.w_h(100.0, 30.0)
|
.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)
|
.hover_image(self.imgs.button_hover)
|
||||||
.press_image(self.imgs.button_press)
|
.press_image(self.imgs.button_press)
|
||||||
.label_y(Relative::Scalar(2.0))
|
.label_y(Relative::Scalar(2.0))
|
||||||
@ -650,7 +650,7 @@ impl MainMenuUi {
|
|||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn login_error(&mut self, msg: String) {
|
pub fn show_error(&mut self, msg: String) {
|
||||||
self.popup = Some(PopupData {
|
self.popup = Some(PopupData {
|
||||||
msg,
|
msg,
|
||||||
button_text: "Okay".to_string(),
|
button_text: "Okay".to_string(),
|
||||||
|
@ -333,6 +333,10 @@ impl PlayState for SessionState {
|
|||||||
// Perform an in-game tick.
|
// Perform an in-game tick.
|
||||||
if let Err(err) = self.tick(clock.get_avg_delta()) {
|
if let Err(err) = self.tick(clock.get_avg_delta()) {
|
||||||
error!("Failed to tick the scene: {:?}", err);
|
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;
|
return PlayStateResult::Pop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user