Error Window

Former-commit-id: e58ba8be94bb6f6b39c713f44dec20089c20b348
This commit is contained in:
Pfauenauge90 2019-04-15 22:51:32 +02:00
parent f32852054d
commit 858055b8c4
2 changed files with 24 additions and 10 deletions

View File

@ -60,7 +60,7 @@ impl PlayState for MainMenuState {
global_state.window.renderer_mut().clear(BG_COLOR);
// Poll client creation
match client_init.as_ref().and_then(|init| init.poll()) {
match client_init.as_ref().and_then(|init| init.poll()) {
Some(Ok(client)) => {
self.main_menu_ui.connected();
return PlayStateResult::Push(Box::new(CharSelectionState::new(
@ -70,11 +70,14 @@ impl PlayState for MainMenuState {
}
Some(Err(err)) => {
client_init = None;
self.main_menu_ui.login_error(match err {
InitError::BadAddress(_) | InitError::NoAddress => "No such host is known",
InitError::ConnectionFailed(_) => "Could not connect to address",
}.to_string());
},
self.main_menu_ui.login_error(
match err {
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
InitError::ConnectionFailed(_) => "Connection failed",
}
.to_string(),
);
}
None => {}
}

View File

@ -36,6 +36,8 @@ widget_ids! {
servers_button,
settings_button,
quit_button,
// Error
error_frame,
}
}
@ -52,6 +54,8 @@ struct Imgs {
button: ImgId,
button_hover: ImgId,
button_press: ImgId,
error_frame: ImgId,
}
impl Imgs {
fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs {
@ -82,6 +86,9 @@ impl Imgs {
button: load("element/buttons/button.png"),
button_hover: load("element/buttons/button_hover.png"),
button_press: load("element/buttons/button_press.png"),
//Error
error_frame: load("element/frames/skin_eyes.png"),
}
}
}
@ -203,20 +210,24 @@ impl MainMenuUi {
// Login error
if let Some(msg) = &self.login_error {
let text = Text::new(&msg)
.rgba(0.5, 0.0, 0.0, 1.0)
.rgba(1.0, 1.0, 1.0, 1.0)
.font_size(30)
.font_id(self.font_opensans);
let x = match text.get_x_dimension(ui_widgets) {
Dimension::Absolute(x) => x + 10.0,
_ => 0.0,
};
Rectangle::fill([x, 40.0])
.rgba(0.2, 0.3, 0.3, 0.7)
Rectangle::fill([x, 60.0])
.rgba(0.1, 0.1, 0.1, 1.0)
.parent(ui_widgets.window)
.up_from(self.ids.username_bg, 35.0)
.mid_bottom_with_margin_on(self.ids.username_bg, 0.0)
.set(self.ids.login_error_bg, ui_widgets);
text.middle_of(self.ids.login_error_bg)
.set(self.ids.login_error, ui_widgets);
Image::new(self.imgs.error_frame)
.h(60.0)
.middle_of(self.ids.login_error)
.set(self.ids.error_frame, ui_widgets);
}
// Server address
Image::new(self.imgs.input_bg)