Error Window

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

View File

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

View File

@ -37,6 +37,8 @@ widget_ids! {
servers_button, servers_button,
settings_button, settings_button,
quit_button, quit_button,
// Error
error_frame,
} }
} }
@ -53,6 +55,8 @@ struct Imgs {
button: ImgId, button: ImgId,
button_hover: ImgId, button_hover: ImgId,
button_press: ImgId, button_press: ImgId,
error_frame: ImgId,
} }
impl Imgs { impl Imgs {
fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs { fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs {
@ -83,6 +87,9 @@ impl Imgs {
button: load("element/buttons/button.png"), button: load("element/buttons/button.png"),
button_hover: load("element/buttons/button_hover.png"), button_hover: load("element/buttons/button_hover.png"),
button_press: load("element/buttons/button_press.png"), button_press: load("element/buttons/button_press.png"),
//Error
error_frame: load("element/frames/skin_eyes.png"),
} }
} }
} }
@ -217,20 +224,24 @@ impl MainMenuUi {
// Login error // Login error
if let Some(msg) = &self.login_error { if let Some(msg) = &self.login_error {
let text = Text::new(&msg) 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_size(30)
.font_id(self.font_opensans); .font_id(self.font_opensans);
let x = match text.get_x_dimension(ui_widgets) { let x = match text.get_x_dimension(ui_widgets) {
Dimension::Absolute(x) => x + 10.0, Dimension::Absolute(x) => x + 10.0,
_ => 0.0, _ => 0.0,
}; };
Rectangle::fill([x, 40.0]) Rectangle::fill([x, 60.0])
.rgba(0.2, 0.3, 0.3, 0.7) .rgba(0.1, 0.1, 0.1, 1.0)
.parent(ui_widgets.window) .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); .set(self.ids.login_error_bg, ui_widgets);
text.middle_of(self.ids.login_error_bg) text.middle_of(self.ids.login_error_bg)
.set(self.ids.login_error, ui_widgets); .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 // Server address
Image::new(self.imgs.input_bg) Image::new(self.imgs.input_bg)