Rebase and Login Error

Former-commit-id: 1865dd58d43ae0a7d78b61ca3a9684ca76fce02d
This commit is contained in:
Pfauenauge90 2019-04-17 19:41:22 +02:00
parent 69c01a92a5
commit 93fedf3b86
6 changed files with 64 additions and 86 deletions

View File

@ -1,11 +1,10 @@
use crate::ui::Ui; use crate::ui::Ui;
use conrod_core::{ use conrod_core::{
color,
input::Key, input::Key,
position::Dimension, position::Dimension,
text::font::Id as FontId, text::font::Id as FontId,
widget::{Button, Id, List, Rectangle, Text, TextEdit}, widget::{Button, Id, List, Rectangle, Text, TextEdit},
widget_ids, Colorable, Positionable, Sizeable, UiCell, Widget, widget_ids, Color, Colorable, Positionable, Sizeable, UiCell, Widget,
}; };
use std::collections::VecDeque; use std::collections::VecDeque;
@ -85,59 +84,48 @@ impl Chat {
// Chat input with rectangle as background // Chat input with rectangle as background
let text_edit = TextEdit::new(&self.input) let text_edit = TextEdit::new(&self.input)
.w(460.0)
.restrict_to_height(false)
.line_spacing(2.0)
.font_size(15)
.font_id(font);
let y = match text_edit.get_y_dimension(ui_widgets) {
Dimension::Absolute(y) => y + 6.0,
_ => 0.0,
};
Rectangle::fill([470.0, y])
.rgba(0.0, 0.0, 0.0, 0.8)
.bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0)
.w(470.0) .w(470.0)
.restrict_to_height(false)
.font_size(15)
.font_id(font)
.bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0);
let dims = match (
text_edit.get_x_dimension(ui_widgets),
text_edit.get_y_dimension(ui_widgets),
) {
(Dimension::Absolute(x), Dimension::Absolute(y)) => [x, y],
_ => [0.0, 0.0],
};
Rectangle::fill(dims)
.rgba(0.0, 0.0, 0.0, 0.8)
.x_position(text_edit.get_x_position(ui_widgets))
.y_position(text_edit.get_y_position(ui_widgets))
.set(self.ids.input_bg, ui_widgets); .set(self.ids.input_bg, ui_widgets);
if let Some(str) = text_edit if let Some(str) = text_edit.set(self.ids.input, ui_widgets) {
.top_left_with_margins_on(self.ids.input_bg, 1.0, 1.0)
.set(self.ids.input, ui_widgets)
{
self.input = str.to_string(); self.input = str.to_string();
self.input.retain(|c| c != '\n'); self.input.retain(|c| c != '\n');
} }
// Message box // Message box
Rectangle::fill([470.0, 174.0]) Rectangle::fill([470.0, 167.0])
.rgba(0.0, 0.0, 0.0, 0.4) .rgba(0.0, 0.0, 0.0, 0.4)
.up_from(self.ids.input_bg, 0.0) .up_from(self.ids.input, 0.0)
.set(self.ids.message_box_bg, ui_widgets); .set(self.ids.message_box_bg, ui_widgets);
let (mut items, _) = List::flow_down(self.messages.len() + 1) let (mut items, scrollbar) = List::flow_down(self.messages.len())
.top_left_of(self.ids.message_box_bg) .top_left_with_margins_on(self.ids.message_box_bg, 0.0, 5.0)
.w_h(470.0, 174.0) .w_h(460.0, 160.0)
.scroll_kids_vertically() .scrollbar_next_to()
.scrollbar_thickness(18.0)
.scrollbar_color(Color::Rgba(0.0, 0.0, 0.0, 1.0))
.set(self.ids.message_box, ui_widgets); .set(self.ids.message_box, ui_widgets);
while let Some(item) = items.next(ui_widgets) { while let Some(item) = items.next(ui_widgets) {
// This would be easier if conrod used the v-metrics from rusttype item.set(
let widget = if item.i < self.messages.len() { Text::new(&self.messages[item.i])
let text = Text::new(&self.messages[item.i])
.font_size(15) .font_size(15)
.font_id(font) .font_id(font)
.w(470.0) .rgba(1.0, 1.0, 1.0, 1.0),
.rgba(1.0, 1.0, 1.0, 1.0) ui_widgets,
.line_spacing(2.0); )
// Add space between messages
let y = match text.get_y_dimension(ui_widgets) {
Dimension::Absolute(y) => y + 2.0,
_ => 0.0,
};
text.h(y)
} else {
// Spacer at bottom of the last message so that it is not cut off
// Needs to be larger than the space above
Text::new("").font_size(6).font_id(font).w(470.0)
};
item.set(widget, ui_widgets);
} }
// Chat Arrow // Chat Arrow

View File

@ -515,7 +515,6 @@ impl Hud {
Text::new( Text::new(
"Tab = Free Cursor \n\ "Tab = Free Cursor \n\
Esc = Open/Close Menus \n\ Esc = Open/Close Menus \n\
Q = Back to Login \n\
\n\ \n\
F1 = Toggle this Window \n\ F1 = Toggle this Window \n\
F2 = Toggle Interface \n\ F2 = Toggle Interface \n\

View File

@ -45,10 +45,7 @@ impl PlayState for CharSelectionState {
// Handle window events // Handle window events
for event in global_state.window.fetch_events() { for event in global_state.window.fetch_events() {
match event { match event {
Event::Close => { Event::Close => return PlayStateResult::Shutdown,
global_state.singleplayer = None;
return PlayStateResult::Shutdown;
},
// Pass events to ui // Pass events to ui
Event::Ui(event) => { Event::Ui(event) => {
self.char_selection_ui.handle_event(event); self.char_selection_ui.handle_event(event);
@ -63,10 +60,7 @@ impl PlayState for CharSelectionState {
// Maintain the UI // Maintain the UI
for event in self.char_selection_ui.maintain(global_state.window.renderer_mut()) { for event in self.char_selection_ui.maintain(global_state.window.renderer_mut()) {
match event { match event {
ui::Event::Logout => { ui::Event::Logout => return PlayStateResult::Pop,
global_state.singleplayer = None;
return PlayStateResult::Pop;
},
ui::Event::Play => return PlayStateResult::Push( ui::Event::Play => return PlayStateResult::Push(
Box::new(SessionState::new(&mut global_state.window, self.client.clone())) Box::new(SessionState::new(&mut global_state.window, self.client.clone()))
), ),

View File

@ -22,10 +22,10 @@ pub struct ClientInit {
impl ClientInit { impl ClientInit {
pub fn new( pub fn new(
connection_args: (String, u16, bool), connection_args: (String, u16, bool),
client_args: (comp::Player, Option<comp::Character>, Option<comp::Animation>, u64), client_args: (comp::Player, Option<comp::Character>, u64),
) -> Self { ) -> Self {
let (server_address, default_port, prefer_ipv6) = connection_args; let (server_address, default_port, prefer_ipv6) = connection_args;
let (player, character, animation, view_distance) = client_args; let (player, character, view_distance) = client_args;
let (tx, rx) = channel(); let (tx, rx) = channel();

View File

@ -5,12 +5,10 @@ use super::char_selection::CharSelectionState;
use crate::{ use crate::{
window::{Event, Window}, window::{Event, Window},
GlobalState, PlayState, PlayStateResult, GlobalState, PlayState, PlayStateResult,
singleplayer::Singleplayer,
}; };
use client_init::{ClientInit, Error as InitError}; use client_init::{ClientInit, Error as InitError};
use common::{clock::Clock, comp}; use common::{clock::Clock, comp};
use std::time::Duration; use std::time::Duration;
use std::thread;
use ui::{Event as MainMenuEvent, MainMenuUi}; use ui::{Event as MainMenuEvent, MainMenuUi};
use vek::*; use vek::*;
@ -100,14 +98,10 @@ impl PlayState for MainMenuState {
( (
comp::Player::new(username.clone()), comp::Player::new(username.clone()),
Some(comp::Character::test()), Some(comp::Character::test()),
Some(comp::Animation::Idle),
300, 300,
), ),
))); )));
} }
MainMenuEvent::StartSingleplayer => {
global_state.singleplayer = Some(Singleplayer::new());
}
MainMenuEvent::Quit => return PlayStateResult::Shutdown, MainMenuEvent::Quit => return PlayStateResult::Shutdown,
} }
} }

View File

@ -1,11 +1,12 @@
use crate::{ use crate::{
DEFAULT_PUBLIC_SERVER,
render::Renderer, render::Renderer,
ui::{self, ScaleMode, Ui}, ui::{self, ScaleMode, Ui},
window::Window, window::Window,
}; };
use common::assets; use common::assets;
use conrod_core::{ use conrod_core::{
color,
color::BLACK,
color::TRANSPARENT, color::TRANSPARENT,
image::Id as ImgId, image::Id as ImgId,
position::{Dimension, Relative}, position::{Dimension, Relative},
@ -23,8 +24,6 @@ widget_ids! {
// Login, Singleplayer // Login, Singleplayer
login_button, login_button,
login_text, login_text,
login_error,
login_error_bg,
address_text, address_text,
address_bg, address_bg,
address_field, address_field,
@ -39,6 +38,9 @@ widget_ids! {
quit_button, quit_button,
// Error // Error
error_frame, error_frame,
button_ok,
login_error,
login_error_bg,
} }
} }
@ -57,6 +59,9 @@ struct Imgs {
button_press: ImgId, button_press: ImgId,
error_frame: ImgId, error_frame: ImgId,
button_dark: ImgId,
button_dark_hover: ImgId,
button_dark_press: ImgId,
} }
impl Imgs { impl Imgs {
fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs { fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs {
@ -90,6 +95,9 @@ impl Imgs {
//Error //Error
error_frame: load("element/frames/skin_eyes.png"), error_frame: load("element/frames/skin_eyes.png"),
button_dark: load("element/buttons/button_dark.png"),
button_dark_hover: load("element/buttons/button_dark_hover.png"),
button_dark_press: load("element/buttons/button_dark_press.png"),
} }
} }
} }
@ -99,7 +107,6 @@ pub enum Event {
username: String, username: String,
server_address: String, server_address: String,
}, },
StartSingleplayer,
Quit, Quit,
} }
@ -146,7 +153,7 @@ impl MainMenuUi {
font_metamorph, font_metamorph,
font_opensans, font_opensans,
username: "Username".to_string(), username: "Username".to_string(),
server_address: DEFAULT_PUBLIC_SERVER.to_string(), server_address: "veloren.mac94.de".to_string(),
login_error: None, login_error: None,
connecting: None, connecting: None,
} }
@ -181,18 +188,6 @@ impl MainMenuUi {
}); });
}; };
} }
macro_rules! singleplayer {
() => {
self.login_error = None;
events.push(Event::StartSingleplayer);
events.push(Event::LoginAttempt {
username: "singleplayer".to_string(),
server_address: "localhost".to_string(),
});
};
}
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
// Username // Username
// TODO: get a lower resolution and cleaner input_bg.png // TODO: get a lower resolution and cleaner input_bg.png
@ -227,22 +222,30 @@ impl MainMenuUi {
.rgba(1.0, 1.0, 1.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) {
Dimension::Absolute(x) => x + 10.0, Rectangle::fill_with([200.0, 100.0], color::BLACK)
_ => 0.0,
};
Rectangle::fill([x, 60.0])
.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)
.mid_bottom_with_margin_on(self.ids.username_bg, 0.0) .up_from(self.ids.username_bg, 35.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.mid_top_with_margin_on(self.ids.login_error_bg, 10.0)
.set(self.ids.login_error, ui_widgets); .set(self.ids.login_error, ui_widgets);
Image::new(self.imgs.error_frame) Image::new(self.imgs.error_frame)
.h(60.0)
.middle_of(self.ids.login_error) .middle_of(self.ids.login_error)
.set(self.ids.error_frame, ui_widgets); .set(self.ids.error_frame, ui_widgets);
} if Button::image(self.imgs.button_dark)
.w_h(50.0, 30.0)
.mid_top_with_margin_on(self.ids.login_error_bg, 20.0)
.hover_image(self.imgs.button_dark_hover)
.press_image(self.imgs.button_dark_press)
.label("Ok")
.label_font_size(10)
.label_color(TEXT_COLOR)
.set(self.ids.button_ok, ui_widgets)
.was_clicked()
{}
};
// Server address // Server address
Image::new(self.imgs.input_bg) Image::new(self.imgs.input_bg)
.w_h(337.0, 67.0) .w_h(337.0, 67.0)
@ -321,7 +324,7 @@ impl MainMenuUi {
.set(self.ids.singleplayer_button, ui_widgets) .set(self.ids.singleplayer_button, ui_widgets)
.was_clicked() .was_clicked()
{ {
singleplayer!(); login!();
} }
// Quit // Quit
if Button::image(self.imgs.button) if Button::image(self.imgs.button)