From fb83c836a1e7100de92ebdf9d4533e07c21a3e79 Mon Sep 17 00:00:00 2001 From: Imbris Date: Thu, 4 Apr 2019 09:49:31 -0400 Subject: [PATCH 1/9] make to_server() blocking, post fixes & cleanup, use server address Former-commit-id: 7debc790e158a996ed58271d3307214e42b850bd --- .gitignore | 4 +- assets/voxygen | 2 +- common/src/net/error.rs | 74 ------- common/src/net/postbox.rs | 270 -------------------------- common/src/net/postoffice.rs | 150 -------------- voxygen/src/hud/mod.rs | 41 ++-- voxygen/src/menu/char_selection/ui.rs | 29 ++- voxygen/src/menu/main/ui.rs | 28 +-- 8 files changed, 50 insertions(+), 548 deletions(-) delete mode 100644 common/src/net/error.rs delete mode 100644 common/src/net/postbox.rs delete mode 100644 common/src/net/postoffice.rs diff --git a/.gitignore b/.gitignore index 782816ee6f..4c5213199c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,5 @@ **/server_conf.toml **/keybinds.toml assets/voxygen -UI3.rar -assets.rar *.rar -assets/voxygen + diff --git a/assets/voxygen b/assets/voxygen index e3083ec8e8..6b64a65356 160000 --- a/assets/voxygen +++ b/assets/voxygen @@ -1 +1 @@ -Subproject commit e3083ec8e8e634af8c9daed00ea82435da195979 +Subproject commit 6b64a65356c1fb4c77ad0295908f4006f75a5448 diff --git a/common/src/net/error.rs b/common/src/net/error.rs deleted file mode 100644 index c3dd162fc9..0000000000 --- a/common/src/net/error.rs +++ /dev/null @@ -1,74 +0,0 @@ -#[derive(Debug)] -pub enum PostError { - InvalidMessage, - InternalError, - Disconnected, -} - -#[derive(Debug)] -pub enum PostErrorInternal { - Io(std::io::Error), - Serde(bincode::Error), - ChannelRecv(std::sync::mpsc::TryRecvError), - ChannelSend, // Empty because I couldn't figure out how to handle generic type in mpsc::TrySendError properly - MsgSizeLimitExceeded, - MioError, -} - -impl<'a, T: Into<&'a PostErrorInternal>> From for PostError { - fn from(err: T) -> Self { - match err.into() { - // TODO: Are I/O errors always disconnect errors? - PostErrorInternal::Io(_) => PostError::Disconnected, - PostErrorInternal::Serde(_) => PostError::InvalidMessage, - PostErrorInternal::MsgSizeLimitExceeded => PostError::InvalidMessage, - PostErrorInternal::MioError => PostError::InternalError, - PostErrorInternal::ChannelRecv(_) => PostError::InternalError, - PostErrorInternal::ChannelSend => PostError::InternalError, - } - } -} - -impl From for PostError { - fn from(err: PostErrorInternal) -> Self { - (&err).into() - } -} - -impl From for PostErrorInternal { - fn from(err: std::io::Error) -> Self { - PostErrorInternal::Io(err) - } -} - -impl From for PostErrorInternal { - fn from(err: bincode::Error) -> Self { - PostErrorInternal::Serde(err) - } -} - -impl From for PostErrorInternal { - fn from(err: std::sync::mpsc::TryRecvError) -> Self { - PostErrorInternal::ChannelRecv(err) - } -} - - - -impl From for PostError { - fn from(err: std::io::Error) -> Self { - (&PostErrorInternal::from(err)).into() - } -} - -impl From for PostError { - fn from(err: bincode::Error) -> Self { - (&PostErrorInternal::from(err)).into() - } -} - -impl From for PostError { - fn from(err: std::sync::mpsc::TryRecvError) -> Self { - (&PostErrorInternal::from(err)).into() - } -} diff --git a/common/src/net/postbox.rs b/common/src/net/postbox.rs deleted file mode 100644 index 21d9466637..0000000000 --- a/common/src/net/postbox.rs +++ /dev/null @@ -1,270 +0,0 @@ -// Standard -use std::{ - collections::VecDeque, - convert::TryFrom, - io::{ - ErrorKind, - Read, - }, - net::SocketAddr, - thread, - time::Duration, - sync::mpsc::TryRecvError, -}; - -// External -use bincode; -use mio::{net::TcpStream, Events, Poll, PollOpt, Ready, Token}; -use mio_extras::channel::{channel, Receiver, Sender}; - -// Crate -use super::{ - data::ControlMsg, - error::{ - PostError, - PostErrorInternal, - }, - PostRecv, - PostSend, -}; - -// Constants -const CTRL_TOKEN: Token = Token(0); // Token for thread control messages -const DATA_TOKEN: Token = Token(1); // Token for thread data exchange -const CONN_TOKEN: Token = Token(2); // Token for TcpStream for the PostBox child thread -const MESSAGE_SIZE_CAP: u64 = 1 << 20; // Maximum accepted length of a packet - -/// A high-level wrapper of [`TcpStream`](mio::net::TcpStream). -/// [`PostBox`] takes care of serializing sent packets and deserializing received packets in the background, providing a simple API for sending and receiving objects over network. -pub struct PostBox -where - S: PostSend, - R: PostRecv, -{ - handle: Option>, - ctrl: Sender, - recv: Receiver>, - send: Sender, - poll: Poll, - err: Option, -} - -impl PostBox -where - S: PostSend, - R: PostRecv, -{ - /// Creates a new [`PostBox`] connected to specified address, meant to be used by the client - pub fn to_server>(addr: A) -> Result, PostError> { - let connection = TcpStream::connect(&addr.into())?; - Self::from_tcpstream(connection) - } - - /// Creates a new [`PostBox`] from an existing connection, meant to be used by [`PostOffice`](super::PostOffice) on the server - pub fn from_tcpstream(connection: TcpStream) -> Result, PostError> { - let (ctrl_tx, ctrl_rx) = channel(); // Control messages - let (send_tx, send_rx) = channel(); // main thread -[data to be serialized and sent]> worker thread - let (recv_tx, recv_rx) = channel(); // main thread <[received and deserialized data]- worker thread - let thread_poll = Poll::new().unwrap(); - let postbox_poll = Poll::new().unwrap(); - thread_poll - .register(&connection, CONN_TOKEN, Ready::readable(), PollOpt::edge()) - .unwrap(); - thread_poll - .register(&ctrl_rx, CTRL_TOKEN, Ready::readable(), PollOpt::edge()) - .unwrap(); - thread_poll - .register(&send_rx, DATA_TOKEN, Ready::readable(), PollOpt::edge()) - .unwrap(); - postbox_poll - .register(&recv_rx, DATA_TOKEN, Ready::readable(), PollOpt::edge()) - .unwrap(); - let handle = thread::Builder::new() - .name("postbox_worker".into()) - .spawn(move || postbox_thread(connection, ctrl_rx, send_rx, recv_tx, thread_poll))?; - Ok(PostBox { - handle: Some(handle), - ctrl: ctrl_tx, - recv: recv_rx, - send: send_tx, - poll: postbox_poll, - err: None, - }) - } - - /// Return an `Option` indicating the current status of the `PostBox`. - pub fn status(&self) -> Option { - self.err.as_ref().map(|err| err.into()) - } - - /// Non-blocking sender method - pub fn send(&mut self, data: S) -> Result<(), PostError> { - match &mut self.err { - err @ None => if let Err(_) = self.send.send(data) { - *err = Some(PostErrorInternal::MioError); - Err(err.as_ref().unwrap().into()) - } else { - Ok(()) - }, - err => Err(err.as_ref().unwrap().into()), - } - } - - /// Non-blocking receiver method returning an iterator over already received and deserialized objects - /// # Errors - /// If the other side disconnects PostBox won't realize that until you try to send something - pub fn new_messages(&mut self) -> impl ExactSizeIterator { - let mut events = Events::with_capacity(4096); - let mut items = VecDeque::new(); - - // If an error occured, or previously occured, just give up - if let Some(_) = self.err { - return items.into_iter(); - } else if let Err(err) = self.poll.poll(&mut events, Some(Duration::new(0, 0))) { - self.err = Some(err.into()); - return items.into_iter(); - } - - for event in events { - match event.token() { - DATA_TOKEN => loop { - match self.recv.try_recv() { - Ok(Ok(item)) => items.push_back(item), - Err(TryRecvError::Empty) => break, - Err(err) => self.err = Some(err.into()), - Ok(Err(err)) => self.err = Some(err.into()), - } - }, - _ => (), - } - } - - items.into_iter() - } -} - -fn postbox_thread( - mut connection: TcpStream, - ctrl_rx: Receiver, - send_rx: Receiver, - recv_tx: Sender>, - poll: Poll, -) where - S: PostSend, - R: PostRecv, -{ - // Receiving related variables - let mut events = Events::with_capacity(64); - let mut recv_buff = Vec::new(); - let mut recv_nextlen: u64 = 0; - loop { - let mut disconnected = false; - poll.poll(&mut events, Some(Duration::from_millis(20))) - .expect("Failed to execute poll(), most likely fault of the OS"); - println!("FINISHED POLL!"); - for event in events.iter() { - println!("EVENT!"); - match event.token() { - CTRL_TOKEN => match ctrl_rx.try_recv().unwrap() { - ControlMsg::Shutdown => return, - }, - CONN_TOKEN => match connection.read_to_end(&mut recv_buff) { - Ok(_) => {} - // Returned when all the data has been read - Err(ref e) if e.kind() == ErrorKind::WouldBlock => {} - Err(e) => recv_tx.send(Err(e.into())).unwrap(), - }, - DATA_TOKEN => { - let msg = send_rx.try_recv().unwrap(); - println!("Send: {:?}", msg); - let mut packet = bincode::serialize(&msg).unwrap(); - packet.splice(0..0, (packet.len() as u64).to_be_bytes().iter().cloned()); - match connection.write_bufs(&[packet.as_slice().into()]) { - Ok(_) => { println!("Sent!"); } - Err(e) => { - println!("Send error!"); - recv_tx.send(Err(e.into())).unwrap(); - } - }; - } - _ => {} - } - } - loop { - if recv_nextlen == 0 && recv_buff.len() >= 8 { - println!("Read nextlen"); - recv_nextlen = u64::from_be_bytes( - <[u8; 8]>::try_from(recv_buff.drain(0..8).collect::>().as_slice()).unwrap(), - ); - if recv_nextlen > MESSAGE_SIZE_CAP { - recv_tx.send(Err(PostErrorInternal::MsgSizeLimitExceeded)).unwrap(); - connection.shutdown(std::net::Shutdown::Both).unwrap(); - recv_buff.drain(..); - recv_nextlen = 0; - break; - } - } - if recv_buff.len() as u64 >= recv_nextlen && recv_nextlen != 0 { - match bincode::deserialize(recv_buff - .drain( - 0..usize::try_from(recv_nextlen) - .expect("Message size was larger than usize (insane message size and 32 bit OS)"), - ) - .collect::>() - .as_slice()) { - Ok(msg) => { - println!("Recv: {:?}", msg); - recv_tx - .send(Ok(msg)) - .unwrap(); - recv_nextlen = 0; - } - Err(e) => { - println!("Recv error: {:?}", e); - recv_tx.send(Err(e.into())).unwrap(); - recv_nextlen = 0; - } - } - } else { - break; - } - } - match connection.take_error().unwrap() { - Some(e) => { - if e.kind() == ErrorKind::BrokenPipe { - disconnected = true; - } - recv_tx.send(Err(e.into())).unwrap(); - } - None => {} - } - if disconnected == true { - break; - } - } - - // Loop after disconnected - loop { - poll.poll(&mut events, None) - .expect("Failed to execute poll(), most likely fault of the OS"); - for event in events.iter() { - match event.token() { - CTRL_TOKEN => match ctrl_rx.try_recv().unwrap() { - ControlMsg::Shutdown => return, - }, - _ => {} - } - } - } -} - -impl Drop for PostBox -where - S: PostSend, - R: PostRecv, -{ - fn drop(&mut self) { - self.ctrl.send(ControlMsg::Shutdown).unwrap_or(()); - self.handle.take().map(|handle| handle.join()); - } -} diff --git a/common/src/net/postoffice.rs b/common/src/net/postoffice.rs deleted file mode 100644 index e8d70330ad..0000000000 --- a/common/src/net/postoffice.rs +++ /dev/null @@ -1,150 +0,0 @@ -// Standard -use core::time::Duration; -use std::{ - collections::VecDeque, - net::SocketAddr, - thread, - sync::mpsc::TryRecvError, -}; - -// External -use mio::{net::TcpListener, Events, Poll, PollOpt, Ready, Token}; -use mio_extras::channel::{channel, Receiver, Sender}; - -// Crate -use super::{ - data::ControlMsg, - error::{ - PostError, - PostErrorInternal, - }, - postbox::PostBox, - PostRecv, - PostSend, -}; - -// Constants -const CTRL_TOKEN: Token = Token(0); // Token for thread control messages -const DATA_TOKEN: Token = Token(1); // Token for thread data exchange -const CONN_TOKEN: Token = Token(2); // Token for TcpStream for the PostBox child thread - -/// A high-level wrapper of [`TcpListener`](mio::net::TcpListener). -/// [`PostOffice`] listens for incoming connections in the background and wraps them into [`PostBox`]es, providing a simple non-blocking API for receiving them. -pub struct PostOffice -where - S: PostSend, - R: PostRecv, -{ - handle: Option>, - ctrl: Sender, - recv: Receiver, PostErrorInternal>>, - poll: Poll, - err: Option, -} - -impl PostOffice -where - S: PostSend, - R: PostRecv, -{ - /// Creates a new [`PostOffice`] listening on specified address - pub fn new>(addr: A) -> Result { - let listener = TcpListener::bind(&addr.into())?; - let (ctrl_tx, ctrl_rx) = channel(); - let (recv_tx, recv_rx) = channel(); - - let thread_poll = Poll::new()?; - let postbox_poll = Poll::new()?; - thread_poll.register(&listener, CONN_TOKEN, Ready::readable(), PollOpt::edge())?; - thread_poll.register(&ctrl_rx, CTRL_TOKEN, Ready::readable(), PollOpt::edge())?; - postbox_poll.register(&recv_rx, DATA_TOKEN, Ready::readable(), PollOpt::edge())?; - - let handle = thread::Builder::new() - .name("postoffice_worker".into()) - .spawn(move || postoffice_thread(listener, ctrl_rx, recv_tx, thread_poll))?; - - Ok(PostOffice { - handle: Some(handle), - ctrl: ctrl_tx, - recv: recv_rx, - poll: postbox_poll, - err: None, - }) - } - - /// Return an `Option` indicating the current status of the `PostOffice`. - pub fn status(&self) -> Option { - self.err.as_ref().map(|err| err.into()) - } - - /// Non-blocking method returning an iterator over new connections wrapped in [`PostBox`]es - pub fn new_connections( - &mut self, - ) -> impl ExactSizeIterator> { - let mut events = Events::with_capacity(256); - let mut conns = VecDeque::new(); - - // If an error occured, or previously occured, just give up - if let Some(_) = self.err { - return conns.into_iter(); - } else if let Err(err) = self.poll.poll(&mut events, Some(Duration::new(0, 0))) { - self.err = Some(err.into()); - return conns.into_iter(); - } - - for event in events { - match event.token() { - DATA_TOKEN => loop { - match self.recv.try_recv() { - Ok(Ok(conn)) => conns.push_back(conn), - Err(TryRecvError::Empty) => break, - Err(err) => self.err = Some(err.into()), - Ok(Err(err)) => self.err = Some(err.into()), - } - }, - _ => (), - } - } - conns.into_iter() - } -} - -fn postoffice_thread( - listener: TcpListener, - ctrl_rx: Receiver, - recv_tx: Sender, PostErrorInternal>>, - poll: Poll, -) where - S: PostSend, - R: PostRecv, -{ - let mut events = Events::with_capacity(256); - loop { - poll.poll(&mut events, None).expect("Failed to execute recv_poll.poll() in PostOffce receiver thread, most likely fault of the OS."); - for event in events.iter() { - match event.token() { - CTRL_TOKEN => match ctrl_rx.try_recv().unwrap() { - ControlMsg::Shutdown => return, - }, - CONN_TOKEN => { - let (conn, _addr) = listener.accept().unwrap(); - recv_tx.send(PostBox::from_tcpstream(conn) - // TODO: Is it okay to count a failure to create a postbox here as an 'internal error'? - .map_err(|_| PostErrorInternal::MioError)).unwrap(); - } - _ => (), - } - } - } -} - -impl Drop for PostOffice -where - S: PostSend, - R: PostRecv, -{ - fn drop(&mut self) { - self.ctrl.send(ControlMsg::Shutdown).unwrap_or(()); // If this fails the thread is dead already - self.handle.take().map(|handle| handle.join()); - } -} diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 3b4369019d..c6fe0a1aa3 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -7,11 +7,11 @@ use crate::{ }; use common::assets; use conrod_core::{ - color, Color, + color, image::Id as ImgId, text::font::Id as FontId, widget::{Button, Image, Rectangle, Scrollbar, Text}, - widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, + widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, }; widget_ids! { @@ -246,13 +246,13 @@ pub(self) struct Imgs { impl Imgs { fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs { let mut load = |filename| { - let fullpath: String = [ - "/voxygen/", - filename, - ].concat(); + let fullpath: String = ["/voxygen/", filename].concat(); let image = image::load_from_memory( - assets::load(fullpath.as_str()).expect("Error loading file").as_slice() - ).unwrap(); + assets::load(fullpath.as_str()) + .expect("Error loading file") + .as_slice(), + ) + .unwrap(); ui.new_image(renderer, &image).unwrap() }; Imgs { @@ -422,7 +422,7 @@ pub struct Hud { //#[inline] //pub fn rgba_bytes(r: u8, g: u8, b: u8, a: f32) -> Color { - //Color::Rgba(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, a) +//Color::Rgba(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, a) //} impl Hud { @@ -479,12 +479,11 @@ impl Hud { let mut events = Vec::new(); let ref mut ui_widgets = self.ui.set_widgets(); - const TEXT_COLOR: Color = Color::Rgba(0.86, 0.86, 0.86, 0.8); + const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); const HP_COLOR: Color = Color::Rgba(0.33, 0.63, 0.0, 1.0); const MANA_COLOR: Color = Color::Rgba(0.42, 0.41, 0.66, 1.0); const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0); - if self.show_ui { // Add Bag-Space Button if self.inventorytest_button { @@ -753,7 +752,6 @@ impl Hud { .top_right_with_margins_on(self.ids.health_bar, 5.0, 0.0) .set(self.ids.health_bar_color, ui_widgets); - // Mana Bar Image::new(self.imgs.mana_bar) .w_h(1120.0 / 6.0, 96.0 / 6.0) @@ -766,7 +764,6 @@ impl Hud { .top_left_with_margins_on(self.ids.mana_bar, 5.0, 0.0) .set(self.ids.mana_bar_color, ui_widgets); - // Buffs/Debuffs // Buffs @@ -1561,39 +1558,39 @@ impl Hud { true } WinEvent::KeyDown(key) if !self.typing => match key { - Key::Map => { + Key::Map => { self.toggle_map(); true } - Key::Bag => { + Key::Bag => { self.toggle_bag(); true } - Key::QuestLog => { + Key::QuestLog => { self.toggle_questlog(); true } - Key::CharacterWindow => { + Key::CharacterWindow => { self.toggle_charwindow(); true } - Key::Social => { + Key::Social => { self.toggle_social(); true } - Key::Spellbook => { + Key::Spellbook => { self.toggle_spellbook(); true } - Key::Settings => { + Key::Settings => { self.toggle_settings(); true } - Key::Help => { + Key::Help => { self.toggle_help(); true } - Key::Interface => { + Key::Interface => { self.toggle_ui(); true } diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index ce89996f42..8becdd8b24 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -225,13 +225,13 @@ struct Imgs { impl Imgs { fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs { let mut load = |filename| { - let fullpath: String = [ - "/voxygen/", - filename, - ].concat(); + let fullpath: String = ["/voxygen/", filename].concat(); let image = image::load_from_memory( - assets::load(fullpath.as_str()).expect("Error loading file").as_slice() - ).unwrap(); + assets::load(fullpath.as_str()) + .expect("Error loading file") + .as_slice(), + ) + .unwrap(); ui.new_image(renderer, &image).unwrap() }; Imgs { @@ -345,7 +345,7 @@ pub enum Event { Play, } -const TEXT_COLOR: Color = Color::Rgba(0.86, 0.86, 0.86, 0.8); +const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); pub struct CharSelectionUi { ui: Ui, @@ -463,7 +463,7 @@ impl CharSelectionUi { .set(self.ids.test_char_l_button, ui_widgets) .was_clicked() { - self.selected_char_no = Some(1); + self.selected_char_no = Some(1); } // Veloren Logo and Alpha Version @@ -477,7 +477,7 @@ impl CharSelectionUi { .label_x(conrod_core::position::Relative::Scalar(-100.0)) .set(self.ids.v_logo, ui_widgets); - if let Some(no) = self.selected_char_no { + if let Some(no) = self.selected_char_no { // Selection_Window Image::new(self.imgs.selection_window) .w_h(522.0, 722.0) @@ -495,7 +495,6 @@ impl CharSelectionUi { .color(TEXT_COLOR) .set(self.ids.char_level, ui_widgets); - // Selected Character if no == 1 { Image::new(self.imgs.test_char_l_big) @@ -872,11 +871,11 @@ impl CharSelectionUi { Their greatest strengths are their adaptability and intelligence, which makes them allrounders in many fields."; const ORC_DESC: &str = "They are considered brutal, rude and combative. \n\ - But once you gained their trust they will be loyal friends \n\ - that follow a strict code of honor in all of their actions. \n\ - \n\ - Their warriors are masters of melee combat, but their true power \ - comes from the magical rituals of their powerful shamans."; + But once you gained their trust they will be loyal friends \n\ + that follow a strict code of honor in all of their actions. \n\ + \n\ + Their warriors are masters of melee combat, but their true power \ + comes from the magical rituals of their powerful shamans."; const DWARF_DESC: &str = "Smoking chimneys, the sound of countless hammers and hoes. \ Infinite tunnel systems to track down even the last chunk of metal in the ground. \n\ diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index 66126c6f0a..2f92fd4fa8 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -10,8 +10,7 @@ use conrod_core::{ position::Dimension, text::font::Id as FontId, widget::{text_box::Event as TextBoxEvent, Button, Image, Rectangle, Text, TextBox}, - widget_ids, Borderable, Color, - Colorable, Labelable, Positionable, Sizeable, Widget, + widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, Widget, }; widget_ids! { @@ -58,13 +57,13 @@ impl Imgs { fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs { // TODO: update paths let mut load = |filename| { - let fullpath: String = [ - "/voxygen/", - filename, - ].concat(); + let fullpath: String = ["/voxygen/", filename].concat(); let image = image::load_from_memory( - assets::load(fullpath.as_str()).expect("Error loading file").as_slice() - ).unwrap(); + assets::load(fullpath.as_str()) + .expect("Error loading file") + .as_slice(), + ) + .unwrap(); ui.new_image(renderer, &image).unwrap() }; Imgs { @@ -170,7 +169,7 @@ impl MainMenuUi { }); }; } - const TEXT_COLOR: Color = Color::Rgba(0.94, 0.94, 0.94, 0.8); + const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); // Username // TODO: get a lower resolution and cleaner input_bg.png Image::new(self.imgs.input_bg) @@ -193,7 +192,9 @@ impl MainMenuUi { // Note: TextBox limits the input string length to what fits in it self.username = username.to_string(); } - TextBoxEvent::Enter => { login!(); } + TextBoxEvent::Enter => { + login!(); + } } } // Login error @@ -211,8 +212,7 @@ impl MainMenuUi { .parent(ui_widgets.window) .up_from(self.ids.username_bg, 35.0) .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); } // Server address @@ -235,7 +235,9 @@ impl MainMenuUi { TextBoxEvent::Update(server_address) => { self.server_address = server_address.to_string(); } - TextBoxEvent::Enter => { login!(); } + TextBoxEvent::Enter => { + login!(); + } } } // Login button From 07a4cb268e6781a6cad2cefec619e2f9ae39ed73 Mon Sep 17 00:00:00 2001 From: Imbris Date: Mon, 8 Apr 2019 22:57:02 -0400 Subject: [PATCH 2/9] new bones, update asset repo Former-commit-id: 4dbed55af4a9532051025a797349e77bd937dff2 --- voxygen/src/anim/character/mod.rs | 17 +++-- voxygen/src/anim/character/run.rs | 14 +--- voxygen/src/scene/figure.rs | 34 ++++----- voxygen/src/scene/mod.rs | 123 ++++++++++++++---------------- 4 files changed, 84 insertions(+), 104 deletions(-) diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 367cdf32ed..54fe67b811 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -7,14 +7,12 @@ pub use self::run::RunAnimation; use crate::render::FigureBoneData; // Local -use super::{ - Skeleton, - Bone, -}; +use super::{Bone, Skeleton}; pub struct CharacterSkeleton { head: Bone, chest: Bone, + shoulders: Bone, belt: Bone, shorts: Bone, l_hand: Bone, @@ -22,6 +20,8 @@ pub struct CharacterSkeleton { l_foot: Bone, r_foot: Bone, back: Bone, + eyes: Bone, + hair: Bone, } impl CharacterSkeleton { @@ -29,6 +29,7 @@ impl CharacterSkeleton { Self { head: Bone::default(), chest: Bone::default(), + shoulders: Bone::default(), belt: Bone::default(), shorts: Bone::default(), l_hand: Bone::default(), @@ -36,6 +37,8 @@ impl CharacterSkeleton { l_foot: Bone::default(), r_foot: Bone::default(), back: Bone::default(), + eyes: Bone::default(), + hair: Bone::default(), } } } @@ -54,9 +57,9 @@ impl Skeleton for CharacterSkeleton { FigureBoneData::new(self.l_foot.compute_base_matrix()), FigureBoneData::new(self.r_foot.compute_base_matrix()), FigureBoneData::new(chest_mat * self.back.compute_base_matrix()), - FigureBoneData::default(), - FigureBoneData::default(), - FigureBoneData::default(), + FigureBoneData::new(self.shoulders.compute_base_matrix()), + FigureBoneData::new(self.eyes.compute_base_matrix()), + FigureBoneData::new(self.hair.compute_base_matrix()), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 015feb8d89..1b7cc14bf6 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -5,10 +5,7 @@ use std::f32::consts::PI; use vek::*; // Local -use super::{ - CharacterSkeleton, - super::Animation, -}; +use super::{super::Animation, CharacterSkeleton}; pub struct RunAnimation; @@ -16,11 +13,8 @@ impl Animation for RunAnimation { type Skeleton = CharacterSkeleton; type Dependency = f64; - fn update_skeleton( - skeleton: &mut Self::Skeleton, - time: f64, - ) { - let wave = (time as f32 * 12.0).sin(); + fn update_skeleton(skeleton: &mut Self::Skeleton, time: f64) { + /*let wave = (time as f32 * 12.0).sin(); let wave_slow = (time as f32 * 6.0 + PI).sin(); let wave_dip = (wave_slow.abs() - 0.5).abs(); @@ -44,7 +38,7 @@ impl Animation for RunAnimation { skeleton.r_foot.offset = Vec3::new(3.5, 1.0 + wave * 8.0, 3.5 - wave_dip * 4.0); skeleton.r_foot.ori = Quaternion::rotation_x(wave + 1.0); - skeleton.back.offset = Vec3::new(-9.0, 5.0, 18.0); + skeleton.back.offset = Vec3::new(-9.0, 5.0, 18.0);*/ skeleton.back.ori = Quaternion::rotation_y(2.5); } } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 8418ab5850..7da880f683 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -1,19 +1,12 @@ +use crate::{ + anim::Skeleton, + render::{ + Consts, FigureBoneData, FigureLocals, FigurePipeline, Globals, Mesh, Model, Renderer, + }, + Error, +}; use specs::{Component, VecStorage}; use vek::*; -use crate::{ - Error, - render::{ - Consts, - Globals, - Mesh, - Model, - Renderer, - FigurePipeline, - FigureBoneData, - FigureLocals, - }, - anim::Skeleton, -}; pub struct Figure { // GPU data @@ -64,18 +57,17 @@ impl Figure { Ok(()) } - pub fn update_locals(&mut self, renderer: &mut Renderer, locals: FigureLocals) -> Result<(), Error> { + pub fn update_locals( + &mut self, + renderer: &mut Renderer, + locals: FigureLocals, + ) -> Result<(), Error> { renderer.update_consts(&mut self.locals, &[locals])?; Ok(()) } pub fn render(&self, renderer: &mut Renderer, globals: &Consts) { - renderer.render_figure( - &self.model, - globals, - &self.locals, - &self.bone_consts, - ); + renderer.render_figure(&self.model, globals, &self.locals, &self.bone_consts); } } diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 9513b6f602..1f15c8575c 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -2,36 +2,23 @@ pub mod camera; pub mod figure; pub mod terrain; -use vek::*; -use dot_vox; -use common::{ - comp, - figure::Segment, -}; -use client::Client; +use self::{camera::Camera, figure::Figure, terrain::Terrain}; use crate::{ + anim::{ + character::{CharacterSkeleton, RunAnimation}, + Animation, + }, + mesh::Meshable, render::{ - Consts, - Globals, - Model, - Renderer, + create_skybox_mesh, Consts, FigureLocals, Globals, Model, Renderer, SkyboxLocals, SkyboxPipeline, - SkyboxLocals, - FigureLocals, - create_skybox_mesh, }, window::Event, - mesh::Meshable, - anim::{ - Animation, - character::{CharacterSkeleton, RunAnimation}, - }, -}; -use self::{ - camera::Camera, - figure::Figure, - terrain::Terrain, }; +use client::Client; +use common::{comp, figure::Segment}; +use dot_vox; +use vek::*; // TODO: Don't hard-code this const CURSOR_PAN_SCALE: f32 = 0.005; @@ -53,25 +40,25 @@ pub struct Scene { // TODO: Make a proper asset loading system fn load_segment(filename: &'static str) -> Segment { - Segment::from(dot_vox::load(&(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/voxel/").to_string() + filename)).unwrap()) + Segment::from( + dot_vox::load( + &(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/voxel/").to_string() + + filename), + ) + .unwrap(), + ) } impl Scene { /// Create a new `Scene` with default parameters. pub fn new(renderer: &mut Renderer, client: &Client) -> Self { Self { - globals: renderer - .create_consts(&[Globals::default()]) - .unwrap(), + globals: renderer.create_consts(&[Globals::default()]).unwrap(), camera: Camera::new(), skybox: Skybox { - model: renderer - .create_model(&create_skybox_mesh()) - .unwrap(), - locals: renderer - .create_consts(&[SkyboxLocals::default()]) - .unwrap(), + model: renderer.create_model(&create_skybox_mesh()).unwrap(), + locals: renderer.create_consts(&[SkyboxLocals::default()]).unwrap(), }, terrain: Terrain::new(), @@ -97,15 +84,19 @@ impl Scene { ], CharacterSkeleton::new(), ) - .unwrap(), + .unwrap(), } } /// Get a reference to the scene's camera. - pub fn camera(&self) -> &Camera { &self.camera } + pub fn camera(&self) -> &Camera { + &self.camera + } /// Get a mutable reference to the scene's camera. - pub fn camera_mut(&mut self) -> &mut Camera { &mut self.camera } + pub fn camera_mut(&mut self) -> &mut Camera { + &mut self.camera + } /// Handle an incoming user input event (i.e: cursor moved, key pressed, window closed, etc.). /// @@ -116,17 +107,17 @@ impl Scene { Event::Resize(dims) => { self.camera.set_aspect_ratio(dims.x as f32 / dims.y as f32); true - }, + } // Panning the cursor makes the camera rotate Event::CursorPan(delta) => { self.camera.rotate_by(Vec3::from(delta) * CURSOR_PAN_SCALE); true - }, + } // Zoom the camera when a zoom event occurs Event::Zoom(delta) => { self.camera.zoom_by(-delta); true - }, + } // All other events are unhandled _ => false, } @@ -137,13 +128,14 @@ impl Scene { // Get player position let player_pos = client .player() - .and_then(|ent| client - .state() - .ecs_world() - .read_storage::() - .get(ent) - .map(|pos| pos.0) - ) + .and_then(|ent| { + client + .state() + .ecs_world() + .read_storage::() + .get(ent) + .map(|pos| pos.0) + }) .unwrap_or(Vec3::zero()); // Alter camera position to match player @@ -153,41 +145,40 @@ impl Scene { let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents(); // Update global constants - renderer.update_consts(&mut self.globals, &[Globals::new( - view_mat, - proj_mat, - cam_pos, - self.camera.get_focus_pos(), - 10.0, - client.state().get_time_of_day(), - client.state().get_time(), - )]) + renderer + .update_consts( + &mut self.globals, + &[Globals::new( + view_mat, + proj_mat, + cam_pos, + self.camera.get_focus_pos(), + 10.0, + client.state().get_time_of_day(), + client.state().get_time(), + )], + ) .expect("Failed to update global constants"); // Maintain the terrain self.terrain.maintain(renderer, client); // TODO: Don't do this here - RunAnimation::update_skeleton( - &mut self.test_figure.skeleton, - client.state().get_time(), - ); + RunAnimation::update_skeleton(&mut self.test_figure.skeleton, client.state().get_time()); // Calculate player model matrix let model_mat = Mat4::::translation_3d(player_pos); - self.test_figure.update_locals(renderer, FigureLocals::new(model_mat)).unwrap(); + self.test_figure + .update_locals(renderer, FigureLocals::new(model_mat)) + .unwrap(); self.test_figure.update_skeleton(renderer).unwrap(); } /// Render the scene using the provided `Renderer` pub fn render_to(&self, renderer: &mut Renderer) { // Render the skybox first (it appears over everything else so must be rendered first) - renderer.render_skybox( - &self.skybox.model, - &self.globals, - &self.skybox.locals, - ); + renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals); // Render terrain self.terrain.render(renderer, &self.globals); From 2e14f7d559958765a5a0bb73e5c0350a327abcbd Mon Sep 17 00:00:00 2001 From: Imbris Date: Tue, 9 Apr 2019 00:27:27 -0400 Subject: [PATCH 3/9] update colors to match gamma scaling Former-commit-id: 461b5cf751d329a219250bc8090b016f54f3ec96 --- voxygen/src/hud/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index c6fe0a1aa3..0241142a92 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -7,7 +7,7 @@ use crate::{ }; use common::assets; use conrod_core::{ - color, + color, Color, image::Id as ImgId, text::font::Id as FontId, widget::{Button, Image, Rectangle, Scrollbar, Text}, From 822901b08bb61cd79ccce050b5a3929cf8d38b8a Mon Sep 17 00:00:00 2001 From: Pfauenauge90 <44173739+Pfauenauge90@users.noreply.github.com> Date: Wed, 10 Apr 2019 22:08:25 +0200 Subject: [PATCH 4/9] Chat padding, Font Colours to white, Help Window Former-commit-id: d36a878971f92fbf16eb44d3102b4328832e6563 --- voxygen/src/anim/character/mod.rs | 17 ++-- voxygen/src/anim/character/run.rs | 14 +++- voxygen/src/hud/chat.rs | 34 +++++--- voxygen/src/hud/mod.rs | 13 +-- voxygen/src/menu/main/ui.rs | 2 +- voxygen/src/scene/figure.rs | 34 +++++--- voxygen/src/scene/mod.rs | 131 ++++++++++++++++-------------- 7 files changed, 138 insertions(+), 107 deletions(-) diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 54fe67b811..367cdf32ed 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -7,12 +7,14 @@ pub use self::run::RunAnimation; use crate::render::FigureBoneData; // Local -use super::{Bone, Skeleton}; +use super::{ + Skeleton, + Bone, +}; pub struct CharacterSkeleton { head: Bone, chest: Bone, - shoulders: Bone, belt: Bone, shorts: Bone, l_hand: Bone, @@ -20,8 +22,6 @@ pub struct CharacterSkeleton { l_foot: Bone, r_foot: Bone, back: Bone, - eyes: Bone, - hair: Bone, } impl CharacterSkeleton { @@ -29,7 +29,6 @@ impl CharacterSkeleton { Self { head: Bone::default(), chest: Bone::default(), - shoulders: Bone::default(), belt: Bone::default(), shorts: Bone::default(), l_hand: Bone::default(), @@ -37,8 +36,6 @@ impl CharacterSkeleton { l_foot: Bone::default(), r_foot: Bone::default(), back: Bone::default(), - eyes: Bone::default(), - hair: Bone::default(), } } } @@ -57,9 +54,9 @@ impl Skeleton for CharacterSkeleton { FigureBoneData::new(self.l_foot.compute_base_matrix()), FigureBoneData::new(self.r_foot.compute_base_matrix()), FigureBoneData::new(chest_mat * self.back.compute_base_matrix()), - FigureBoneData::new(self.shoulders.compute_base_matrix()), - FigureBoneData::new(self.eyes.compute_base_matrix()), - FigureBoneData::new(self.hair.compute_base_matrix()), + FigureBoneData::default(), + FigureBoneData::default(), + FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), FigureBoneData::default(), diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 1b7cc14bf6..015feb8d89 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -5,7 +5,10 @@ use std::f32::consts::PI; use vek::*; // Local -use super::{super::Animation, CharacterSkeleton}; +use super::{ + CharacterSkeleton, + super::Animation, +}; pub struct RunAnimation; @@ -13,8 +16,11 @@ impl Animation for RunAnimation { type Skeleton = CharacterSkeleton; type Dependency = f64; - fn update_skeleton(skeleton: &mut Self::Skeleton, time: f64) { - /*let wave = (time as f32 * 12.0).sin(); + fn update_skeleton( + skeleton: &mut Self::Skeleton, + time: f64, + ) { + let wave = (time as f32 * 12.0).sin(); let wave_slow = (time as f32 * 6.0 + PI).sin(); let wave_dip = (wave_slow.abs() - 0.5).abs(); @@ -38,7 +44,7 @@ impl Animation for RunAnimation { skeleton.r_foot.offset = Vec3::new(3.5, 1.0 + wave * 8.0, 3.5 - wave_dip * 4.0); skeleton.r_foot.ori = Quaternion::rotation_x(wave + 1.0); - skeleton.back.offset = Vec3::new(-9.0, 5.0, 18.0);*/ + skeleton.back.offset = Vec3::new(-9.0, 5.0, 18.0); skeleton.back.ori = Quaternion::rotation_y(2.5); } } diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index 400d42ddf6..9f4eb67a8b 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -3,7 +3,7 @@ use conrod_core::{ input::Key, position::Dimension, text::font::Id as FontId, - widget::{Id, Button, List, Rectangle, Text, TextEdit}, + widget::{Button, Id, List, Rectangle, Text, TextEdit}, widget_ids, Color, Colorable, Positionable, Sizeable, UiCell, Widget, }; use std::collections::VecDeque; @@ -70,7 +70,12 @@ impl Chat { fn scroll_to_bottom(&self, ui_widgets: &mut UiCell) { ui_widgets.scroll_widget(self.ids.message_box, [0.0, std::f64::MAX]); } - pub(super) fn update_layout(&mut self, ui_widgets: &mut UiCell, font: FontId, imgs: &super::Imgs) -> Option { + pub(super) fn update_layout( + &mut self, + ui_widgets: &mut UiCell, + font: FontId, + imgs: &super::Imgs, + ) -> Option { // Maintain scrolling if self.new_messages { self.scroll_new_messages(ui_widgets); @@ -102,20 +107,23 @@ impl Chat { } // Message box - Rectangle::fill([470.0, 180.0]) + Rectangle::fill([470.0, 160.0]) .rgba(0.0, 0.0, 0.0, 0.4) .up_from(self.ids.input, 0.0) .set(self.ids.message_box_bg, ui_widgets); - let (mut items, _scrollbar) = List::flow_down(self.messages.len()) - .middle_of(self.ids.message_box_bg) - .scroll_kids_vertically() + let (mut items, scrollbar) = List::flow_down(self.messages.len()) + .top_left_with_margins_on(self.ids.message_box_bg, 0.0, 5.0) + .w_h(460.0, 160.0) + .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); while let Some(item) = items.next(ui_widgets) { item.set( Text::new(&self.messages[item.i]) .font_size(14) .font_id(font) - .rgba(0.86 , 0.86, 0.86, 1.0), + .rgba(1.0, 1.0, 1.0, 1.0), ui_widgets, ) } @@ -123,12 +131,12 @@ impl Chat { // Chat Arrow if !self.scrolled_to_bottom(ui_widgets) { if Button::image(imgs.chat_arrow) - .w_h(22.0, 22.0) - .hover_image(imgs.chat_arrow_mo) - .press_image(imgs.chat_arrow_press) - .bottom_right_with_margins_on(self.ids.message_box_bg, 2.0, 2.0) - .set(self.ids.chat_arrow, ui_widgets) - .was_clicked() + .w_h(22.0, 22.0) + .hover_image(imgs.chat_arrow_mo) + .press_image(imgs.chat_arrow_press) + .bottom_right_with_margins_on(self.ids.message_box_bg, 2.0, 2.0) + .set(self.ids.chat_arrow, ui_widgets) + .was_clicked() { self.scroll_to_bottom(ui_widgets); } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 0241142a92..b92d6dcd06 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -7,7 +7,7 @@ use crate::{ }; use common::assets; use conrod_core::{ - color, Color, + color, image::Id as ImgId, text::font::Id as FontId, widget::{Button, Image, Rectangle, Scrollbar, Text}, @@ -459,7 +459,7 @@ impl Hud { typing: false, cursor_grabbed: true, settings_tab: SettingsTab::Interface, - show_help: false, + show_help: true, bag_open: false, menu_open: false, map_open: false, @@ -511,7 +511,7 @@ impl Hud { if self.show_help { Image::new(self.imgs.window_frame_2) .top_left_with_margins_on(ui_widgets.window, 5.0, 5.0) - .w_h(300.0, 300.0) + .w_h(300.0, 370.0) .set(self.ids.help_bg, ui_widgets); Text::new( @@ -522,6 +522,9 @@ impl Hud { F1 = Toggle this Window \n\ F2 = Toggle Interface \n\ \n\ + Enter = Open Chat \n\ + Mouse Wheel= Scroll Chat\n\ + \n\ M = Map \n\ B = Bag \n\ L = Quest-Log \n\ @@ -775,14 +778,14 @@ impl Hud { // Insert actual Level here Text::new("1") .left_from(self.ids.xp_bar, -15.0) - .font_size(14) + .font_size(10) .color(TEXT_COLOR) .set(self.ids.level_text, ui_widgets); // Insert next Level here Text::new("2") .right_from(self.ids.xp_bar, -15.0) - .font_size(14) + .font_size(10) .color(TEXT_COLOR) .set(self.ids.next_level_text, ui_widgets); diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index 2f92fd4fa8..c63794a1fb 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -249,7 +249,7 @@ impl MainMenuUi { .align_middle_x_of(self.ids.address_bg) .label("Login") .label_color(TEXT_COLOR) - .label_font_size(28) + .label_font_size(26) .label_y(conrod_core::position::Relative::Scalar(5.0)) .set(self.ids.login_button, ui_widgets) .was_clicked() diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 7da880f683..8418ab5850 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -1,12 +1,19 @@ -use crate::{ - anim::Skeleton, - render::{ - Consts, FigureBoneData, FigureLocals, FigurePipeline, Globals, Mesh, Model, Renderer, - }, - Error, -}; use specs::{Component, VecStorage}; use vek::*; +use crate::{ + Error, + render::{ + Consts, + Globals, + Mesh, + Model, + Renderer, + FigurePipeline, + FigureBoneData, + FigureLocals, + }, + anim::Skeleton, +}; pub struct Figure { // GPU data @@ -57,17 +64,18 @@ impl Figure { Ok(()) } - pub fn update_locals( - &mut self, - renderer: &mut Renderer, - locals: FigureLocals, - ) -> Result<(), Error> { + pub fn update_locals(&mut self, renderer: &mut Renderer, locals: FigureLocals) -> Result<(), Error> { renderer.update_consts(&mut self.locals, &[locals])?; Ok(()) } pub fn render(&self, renderer: &mut Renderer, globals: &Consts) { - renderer.render_figure(&self.model, globals, &self.locals, &self.bone_consts); + renderer.render_figure( + &self.model, + globals, + &self.locals, + &self.bone_consts, + ); } } diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 1f15c8575c..9513b6f602 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -2,23 +2,36 @@ pub mod camera; pub mod figure; pub mod terrain; -use self::{camera::Camera, figure::Figure, terrain::Terrain}; -use crate::{ - anim::{ - character::{CharacterSkeleton, RunAnimation}, - Animation, - }, - mesh::Meshable, - render::{ - create_skybox_mesh, Consts, FigureLocals, Globals, Model, Renderer, SkyboxLocals, - SkyboxPipeline, - }, - window::Event, +use vek::*; +use dot_vox; +use common::{ + comp, + figure::Segment, }; use client::Client; -use common::{comp, figure::Segment}; -use dot_vox; -use vek::*; +use crate::{ + render::{ + Consts, + Globals, + Model, + Renderer, + SkyboxPipeline, + SkyboxLocals, + FigureLocals, + create_skybox_mesh, + }, + window::Event, + mesh::Meshable, + anim::{ + Animation, + character::{CharacterSkeleton, RunAnimation}, + }, +}; +use self::{ + camera::Camera, + figure::Figure, + terrain::Terrain, +}; // TODO: Don't hard-code this const CURSOR_PAN_SCALE: f32 = 0.005; @@ -40,25 +53,25 @@ pub struct Scene { // TODO: Make a proper asset loading system fn load_segment(filename: &'static str) -> Segment { - Segment::from( - dot_vox::load( - &(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/voxel/").to_string() - + filename), - ) - .unwrap(), - ) + Segment::from(dot_vox::load(&(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/voxel/").to_string() + filename)).unwrap()) } impl Scene { /// Create a new `Scene` with default parameters. pub fn new(renderer: &mut Renderer, client: &Client) -> Self { Self { - globals: renderer.create_consts(&[Globals::default()]).unwrap(), + globals: renderer + .create_consts(&[Globals::default()]) + .unwrap(), camera: Camera::new(), skybox: Skybox { - model: renderer.create_model(&create_skybox_mesh()).unwrap(), - locals: renderer.create_consts(&[SkyboxLocals::default()]).unwrap(), + model: renderer + .create_model(&create_skybox_mesh()) + .unwrap(), + locals: renderer + .create_consts(&[SkyboxLocals::default()]) + .unwrap(), }, terrain: Terrain::new(), @@ -84,19 +97,15 @@ impl Scene { ], CharacterSkeleton::new(), ) - .unwrap(), + .unwrap(), } } /// Get a reference to the scene's camera. - pub fn camera(&self) -> &Camera { - &self.camera - } + pub fn camera(&self) -> &Camera { &self.camera } /// Get a mutable reference to the scene's camera. - pub fn camera_mut(&mut self) -> &mut Camera { - &mut self.camera - } + pub fn camera_mut(&mut self) -> &mut Camera { &mut self.camera } /// Handle an incoming user input event (i.e: cursor moved, key pressed, window closed, etc.). /// @@ -107,17 +116,17 @@ impl Scene { Event::Resize(dims) => { self.camera.set_aspect_ratio(dims.x as f32 / dims.y as f32); true - } + }, // Panning the cursor makes the camera rotate Event::CursorPan(delta) => { self.camera.rotate_by(Vec3::from(delta) * CURSOR_PAN_SCALE); true - } + }, // Zoom the camera when a zoom event occurs Event::Zoom(delta) => { self.camera.zoom_by(-delta); true - } + }, // All other events are unhandled _ => false, } @@ -128,14 +137,13 @@ impl Scene { // Get player position let player_pos = client .player() - .and_then(|ent| { - client - .state() - .ecs_world() - .read_storage::() - .get(ent) - .map(|pos| pos.0) - }) + .and_then(|ent| client + .state() + .ecs_world() + .read_storage::() + .get(ent) + .map(|pos| pos.0) + ) .unwrap_or(Vec3::zero()); // Alter camera position to match player @@ -145,40 +153,41 @@ impl Scene { let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents(); // Update global constants - renderer - .update_consts( - &mut self.globals, - &[Globals::new( - view_mat, - proj_mat, - cam_pos, - self.camera.get_focus_pos(), - 10.0, - client.state().get_time_of_day(), - client.state().get_time(), - )], - ) + renderer.update_consts(&mut self.globals, &[Globals::new( + view_mat, + proj_mat, + cam_pos, + self.camera.get_focus_pos(), + 10.0, + client.state().get_time_of_day(), + client.state().get_time(), + )]) .expect("Failed to update global constants"); // Maintain the terrain self.terrain.maintain(renderer, client); // TODO: Don't do this here - RunAnimation::update_skeleton(&mut self.test_figure.skeleton, client.state().get_time()); + RunAnimation::update_skeleton( + &mut self.test_figure.skeleton, + client.state().get_time(), + ); // Calculate player model matrix let model_mat = Mat4::::translation_3d(player_pos); - self.test_figure - .update_locals(renderer, FigureLocals::new(model_mat)) - .unwrap(); + self.test_figure.update_locals(renderer, FigureLocals::new(model_mat)).unwrap(); self.test_figure.update_skeleton(renderer).unwrap(); } /// Render the scene using the provided `Renderer` pub fn render_to(&self, renderer: &mut Renderer) { // Render the skybox first (it appears over everything else so must be rendered first) - renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals); + renderer.render_skybox( + &self.skybox.model, + &self.globals, + &self.skybox.locals, + ); // Render terrain self.terrain.render(renderer, &self.globals); From a45e9e708c750bb9824f822a8e61f9dc976f7669 Mon Sep 17 00:00:00 2001 From: Pfauenauge90 <44173739+Pfauenauge90@users.noreply.github.com> Date: Wed, 10 Apr 2019 22:13:42 +0200 Subject: [PATCH 5/9] Help window, chat padding, font colours Former-commit-id: 18643504fd8e94ed991c137e9ea91dfa094686c7 --- voxygen/src/hud/chat.rs | 28 ++++++++----------- voxygen/src/hud/mod.rs | 40 +++++++++++++-------------- voxygen/src/menu/char_selection/ui.rs | 17 ++++++------ voxygen/src/menu/main/mod.rs | 9 ++++-- voxygen/src/menu/main/ui.rs | 4 +-- 5 files changed, 48 insertions(+), 50 deletions(-) diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index 9f4eb67a8b..916a7e4bf5 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -3,7 +3,7 @@ use conrod_core::{ input::Key, position::Dimension, text::font::Id as FontId, - widget::{Button, Id, List, Rectangle, Text, TextEdit}, + widget::{Id, Button, List, Rectangle, Text, TextEdit}, widget_ids, Color, Colorable, Positionable, Sizeable, UiCell, Widget, }; use std::collections::VecDeque; @@ -70,12 +70,7 @@ impl Chat { fn scroll_to_bottom(&self, ui_widgets: &mut UiCell) { ui_widgets.scroll_widget(self.ids.message_box, [0.0, std::f64::MAX]); } - pub(super) fn update_layout( - &mut self, - ui_widgets: &mut UiCell, - font: FontId, - imgs: &super::Imgs, - ) -> Option { + pub(super) fn update_layout(&mut self, ui_widgets: &mut UiCell, font: FontId, imgs: &super::Imgs) -> Option { // Maintain scrolling if self.new_messages { self.scroll_new_messages(ui_widgets); @@ -107,13 +102,12 @@ impl Chat { } // Message box - Rectangle::fill([470.0, 160.0]) + Rectangle::fill([470.0, 180.0]) .rgba(0.0, 0.0, 0.0, 0.4) .up_from(self.ids.input, 0.0) .set(self.ids.message_box_bg, ui_widgets); let (mut items, scrollbar) = List::flow_down(self.messages.len()) - .top_left_with_margins_on(self.ids.message_box_bg, 0.0, 5.0) - .w_h(460.0, 160.0) + .middle_of(self.ids.message_box_bg) .scrollbar_next_to() .scrollbar_thickness(18.0) .scrollbar_color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) @@ -123,7 +117,7 @@ impl Chat { Text::new(&self.messages[item.i]) .font_size(14) .font_id(font) - .rgba(1.0, 1.0, 1.0, 1.0), + .rgba(0.86 , 0.86, 0.86, 1.0), ui_widgets, ) } @@ -131,12 +125,12 @@ impl Chat { // Chat Arrow if !self.scrolled_to_bottom(ui_widgets) { if Button::image(imgs.chat_arrow) - .w_h(22.0, 22.0) - .hover_image(imgs.chat_arrow_mo) - .press_image(imgs.chat_arrow_press) - .bottom_right_with_margins_on(self.ids.message_box_bg, 2.0, 2.0) - .set(self.ids.chat_arrow, ui_widgets) - .was_clicked() + .w_h(22.0, 22.0) + .hover_image(imgs.chat_arrow_mo) + .press_image(imgs.chat_arrow_press) + .bottom_right_with_margins_on(self.ids.message_box_bg, 2.0, 2.0) + .set(self.ids.chat_arrow, ui_widgets) + .was_clicked() { self.scroll_to_bottom(ui_widgets); } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index b92d6dcd06..5c5688be8d 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -7,11 +7,11 @@ use crate::{ }; use common::assets; use conrod_core::{ - color, + color, Color, image::Id as ImgId, text::font::Id as FontId, widget::{Button, Image, Rectangle, Scrollbar, Text}, - widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, + widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, }; widget_ids! { @@ -422,7 +422,7 @@ pub struct Hud { //#[inline] //pub fn rgba_bytes(r: u8, g: u8, b: u8, a: f32) -> Color { -//Color::Rgba(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, a) + //Color::Rgba(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, a) //} impl Hud { @@ -459,7 +459,7 @@ impl Hud { typing: false, cursor_grabbed: true, settings_tab: SettingsTab::Interface, - show_help: true, + show_help: false, bag_open: false, menu_open: false, map_open: false, @@ -479,11 +479,12 @@ impl Hud { let mut events = Vec::new(); let ref mut ui_widgets = self.ui.set_widgets(); - const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); + const TEXT_COLOR: Color = Color::Rgba(0.86, 0.86, 0.86, 0.8); const HP_COLOR: Color = Color::Rgba(0.33, 0.63, 0.0, 1.0); const MANA_COLOR: Color = Color::Rgba(0.42, 0.41, 0.66, 1.0); const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0); + if self.show_ui { // Add Bag-Space Button if self.inventorytest_button { @@ -511,7 +512,7 @@ impl Hud { if self.show_help { Image::new(self.imgs.window_frame_2) .top_left_with_margins_on(ui_widgets.window, 5.0, 5.0) - .w_h(300.0, 370.0) + .w_h(300.0, 300.0) .set(self.ids.help_bg, ui_widgets); Text::new( @@ -522,9 +523,6 @@ impl Hud { F1 = Toggle this Window \n\ F2 = Toggle Interface \n\ \n\ - Enter = Open Chat \n\ - Mouse Wheel= Scroll Chat\n\ - \n\ M = Map \n\ B = Bag \n\ L = Quest-Log \n\ @@ -755,6 +753,7 @@ impl Hud { .top_right_with_margins_on(self.ids.health_bar, 5.0, 0.0) .set(self.ids.health_bar_color, ui_widgets); + // Mana Bar Image::new(self.imgs.mana_bar) .w_h(1120.0 / 6.0, 96.0 / 6.0) @@ -767,6 +766,7 @@ impl Hud { .top_left_with_margins_on(self.ids.mana_bar, 5.0, 0.0) .set(self.ids.mana_bar_color, ui_widgets); + // Buffs/Debuffs // Buffs @@ -778,14 +778,14 @@ impl Hud { // Insert actual Level here Text::new("1") .left_from(self.ids.xp_bar, -15.0) - .font_size(10) + .font_size(14) .color(TEXT_COLOR) .set(self.ids.level_text, ui_widgets); // Insert next Level here Text::new("2") .right_from(self.ids.xp_bar, -15.0) - .font_size(10) + .font_size(14) .color(TEXT_COLOR) .set(self.ids.next_level_text, ui_widgets); @@ -1561,39 +1561,39 @@ impl Hud { true } WinEvent::KeyDown(key) if !self.typing => match key { - Key::Map => { + Key::Map => { self.toggle_map(); true } - Key::Bag => { + Key::Bag => { self.toggle_bag(); true } - Key::QuestLog => { + Key::QuestLog => { self.toggle_questlog(); true } - Key::CharacterWindow => { + Key::CharacterWindow => { self.toggle_charwindow(); true } - Key::Social => { + Key::Social => { self.toggle_social(); true } - Key::Spellbook => { + Key::Spellbook => { self.toggle_spellbook(); true } - Key::Settings => { + Key::Settings => { self.toggle_settings(); true } - Key::Help => { + Key::Help => { self.toggle_help(); true } - Key::Interface => { + Key::Interface => { self.toggle_ui(); true } diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index 8becdd8b24..ffd1b47156 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -345,7 +345,7 @@ pub enum Event { Play, } -const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); +const TEXT_COLOR: Color = Color::Rgba(0.86, 0.86, 0.86, 0.8); pub struct CharSelectionUi { ui: Ui, @@ -463,7 +463,7 @@ impl CharSelectionUi { .set(self.ids.test_char_l_button, ui_widgets) .was_clicked() { - self.selected_char_no = Some(1); + self.selected_char_no = Some(1); } // Veloren Logo and Alpha Version @@ -477,7 +477,7 @@ impl CharSelectionUi { .label_x(conrod_core::position::Relative::Scalar(-100.0)) .set(self.ids.v_logo, ui_widgets); - if let Some(no) = self.selected_char_no { + if let Some(no) = self.selected_char_no { // Selection_Window Image::new(self.imgs.selection_window) .w_h(522.0, 722.0) @@ -495,6 +495,7 @@ impl CharSelectionUi { .color(TEXT_COLOR) .set(self.ids.char_level, ui_widgets); + // Selected Character if no == 1 { Image::new(self.imgs.test_char_l_big) @@ -871,11 +872,11 @@ impl CharSelectionUi { Their greatest strengths are their adaptability and intelligence, which makes them allrounders in many fields."; const ORC_DESC: &str = "They are considered brutal, rude and combative. \n\ - But once you gained their trust they will be loyal friends \n\ - that follow a strict code of honor in all of their actions. \n\ - \n\ - Their warriors are masters of melee combat, but their true power \ - comes from the magical rituals of their powerful shamans."; + But once you gained their trust they will be loyal friends \n\ + that follow a strict code of honor in all of their actions. \n\ + \n\ + Their warriors are masters of melee combat, but their true power \ + comes from the magical rituals of their powerful shamans."; const DWARF_DESC: &str = "Smoking chimneys, the sound of countless hammers and hoes. \ Infinite tunnel systems to track down even the last chunk of metal in the ground. \n\ diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 0dfe93880d..4b95bb6d46 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -6,7 +6,10 @@ use crate::{ GlobalState, PlayState, PlayStateResult, }; use client::{self, Client}; -use common::clock::Clock; +use common::{ + comp, + clock::Clock, +}; use std::time::Duration; use ui::{Event as MainMenuEvent, MainMenuUi}; use vek::*; @@ -67,12 +70,12 @@ impl PlayState for MainMenuState { Ok(mut socket_adders) => { while let Some(socket_addr) = socket_adders.next() { // TODO: handle error - match Client::new(socket_addr) { + match Client::new(socket_addr, comp::Player::new(username.clone()), Some(comp::Character::test())) { Ok(client) => { return PlayStateResult::Push( Box::new(CharSelectionState::new( &mut global_state.window, - std::rc::Rc::new(std::cell::RefCell::new(client.with_test_state())) // <--- TODO: Remove this + std::rc::Rc::new(std::cell::RefCell::new(client)) // <--- TODO: Remove this )) ); } diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index c63794a1fb..eaeb8d78bd 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -169,7 +169,7 @@ impl MainMenuUi { }); }; } - const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); + const TEXT_COLOR: Color = Color::Rgba(0.94, 0.94, 0.94, 0.8); // Username // TODO: get a lower resolution and cleaner input_bg.png Image::new(self.imgs.input_bg) @@ -249,7 +249,7 @@ impl MainMenuUi { .align_middle_x_of(self.ids.address_bg) .label("Login") .label_color(TEXT_COLOR) - .label_font_size(26) + .label_font_size(28) .label_y(conrod_core::position::Relative::Scalar(5.0)) .set(self.ids.login_button, ui_widgets) .was_clicked() From bc420e41d64a667f3ac2935e1788fb0529d705d9 Mon Sep 17 00:00:00 2001 From: Pfauenauge90 <44173739+Pfauenauge90@users.noreply.github.com> Date: Wed, 10 Apr 2019 22:23:49 +0200 Subject: [PATCH 6/9] help window, chat padding, font colours Former-commit-id: 8d42f8e05cd11f669e4e56873e31a8530272b3b2 --- voxygen/src/hud/chat.rs | 32 ++++++++++++--------- voxygen/src/hud/mod.rs | 40 +++++++++++++-------------- voxygen/src/menu/char_selection/ui.rs | 17 ++++++------ voxygen/src/menu/main/mod.rs | 9 ++---- voxygen/src/menu/main/ui.rs | 4 +-- 5 files changed, 52 insertions(+), 50 deletions(-) diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index 916a7e4bf5..c92e3d631e 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -3,7 +3,7 @@ use conrod_core::{ input::Key, position::Dimension, text::font::Id as FontId, - widget::{Id, Button, List, Rectangle, Text, TextEdit}, + widget::{Button, Id, List, Rectangle, Text, TextEdit}, widget_ids, Color, Colorable, Positionable, Sizeable, UiCell, Widget, }; use std::collections::VecDeque; @@ -70,7 +70,12 @@ impl Chat { fn scroll_to_bottom(&self, ui_widgets: &mut UiCell) { ui_widgets.scroll_widget(self.ids.message_box, [0.0, std::f64::MAX]); } - pub(super) fn update_layout(&mut self, ui_widgets: &mut UiCell, font: FontId, imgs: &super::Imgs) -> Option { + pub(super) fn update_layout( + &mut self, + ui_widgets: &mut UiCell, + font: FontId, + imgs: &super::Imgs, + ) -> Option { // Maintain scrolling if self.new_messages { self.scroll_new_messages(ui_widgets); @@ -81,7 +86,7 @@ impl Chat { let text_edit = TextEdit::new(&self.input) .w(470.0) .restrict_to_height(false) - .font_size(14) + .font_size(15) .font_id(font) .bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0); let dims = match ( @@ -102,12 +107,13 @@ impl Chat { } // Message box - Rectangle::fill([470.0, 180.0]) + Rectangle::fill([470.0, 160.0]) .rgba(0.0, 0.0, 0.0, 0.4) .up_from(self.ids.input, 0.0) .set(self.ids.message_box_bg, ui_widgets); let (mut items, scrollbar) = List::flow_down(self.messages.len()) - .middle_of(self.ids.message_box_bg) + .top_left_with_margins_on(self.ids.message_box_bg, 0.0, 5.0) + .w_h(460.0, 160.0) .scrollbar_next_to() .scrollbar_thickness(18.0) .scrollbar_color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) @@ -115,9 +121,9 @@ impl Chat { while let Some(item) = items.next(ui_widgets) { item.set( Text::new(&self.messages[item.i]) - .font_size(14) + .font_size(15) .font_id(font) - .rgba(0.86 , 0.86, 0.86, 1.0), + .rgba(1.0, 1.0, 1.0, 1.0), ui_widgets, ) } @@ -125,12 +131,12 @@ impl Chat { // Chat Arrow if !self.scrolled_to_bottom(ui_widgets) { if Button::image(imgs.chat_arrow) - .w_h(22.0, 22.0) - .hover_image(imgs.chat_arrow_mo) - .press_image(imgs.chat_arrow_press) - .bottom_right_with_margins_on(self.ids.message_box_bg, 2.0, 2.0) - .set(self.ids.chat_arrow, ui_widgets) - .was_clicked() + .w_h(22.0, 22.0) + .hover_image(imgs.chat_arrow_mo) + .press_image(imgs.chat_arrow_press) + .bottom_right_with_margins_on(self.ids.message_box_bg, 2.0, 2.0) + .set(self.ids.chat_arrow, ui_widgets) + .was_clicked() { self.scroll_to_bottom(ui_widgets); } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 5c5688be8d..4e36a72a4b 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -7,11 +7,11 @@ use crate::{ }; use common::assets; use conrod_core::{ - color, Color, + color, image::Id as ImgId, text::font::Id as FontId, widget::{Button, Image, Rectangle, Scrollbar, Text}, - widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, + widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, }; widget_ids! { @@ -422,7 +422,7 @@ pub struct Hud { //#[inline] //pub fn rgba_bytes(r: u8, g: u8, b: u8, a: f32) -> Color { - //Color::Rgba(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, a) +//Color::Rgba(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, a) //} impl Hud { @@ -459,7 +459,7 @@ impl Hud { typing: false, cursor_grabbed: true, settings_tab: SettingsTab::Interface, - show_help: false, + show_help: true, bag_open: false, menu_open: false, map_open: false, @@ -479,12 +479,11 @@ impl Hud { let mut events = Vec::new(); let ref mut ui_widgets = self.ui.set_widgets(); - const TEXT_COLOR: Color = Color::Rgba(0.86, 0.86, 0.86, 0.8); + const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); const HP_COLOR: Color = Color::Rgba(0.33, 0.63, 0.0, 1.0); const MANA_COLOR: Color = Color::Rgba(0.42, 0.41, 0.66, 1.0); const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0); - if self.show_ui { // Add Bag-Space Button if self.inventorytest_button { @@ -512,7 +511,7 @@ impl Hud { if self.show_help { Image::new(self.imgs.window_frame_2) .top_left_with_margins_on(ui_widgets.window, 5.0, 5.0) - .w_h(300.0, 300.0) + .w_h(300.0, 370.0) .set(self.ids.help_bg, ui_widgets); Text::new( @@ -523,6 +522,9 @@ impl Hud { F1 = Toggle this Window \n\ F2 = Toggle Interface \n\ \n\ + Enter = Open Chat \n\ + Mouse Wheel = Scroll Chat\n\ + \n\ M = Map \n\ B = Bag \n\ L = Quest-Log \n\ @@ -753,7 +755,6 @@ impl Hud { .top_right_with_margins_on(self.ids.health_bar, 5.0, 0.0) .set(self.ids.health_bar_color, ui_widgets); - // Mana Bar Image::new(self.imgs.mana_bar) .w_h(1120.0 / 6.0, 96.0 / 6.0) @@ -766,7 +767,6 @@ impl Hud { .top_left_with_margins_on(self.ids.mana_bar, 5.0, 0.0) .set(self.ids.mana_bar_color, ui_widgets); - // Buffs/Debuffs // Buffs @@ -778,14 +778,14 @@ impl Hud { // Insert actual Level here Text::new("1") .left_from(self.ids.xp_bar, -15.0) - .font_size(14) + .font_size(10) .color(TEXT_COLOR) .set(self.ids.level_text, ui_widgets); // Insert next Level here Text::new("2") .right_from(self.ids.xp_bar, -15.0) - .font_size(14) + .font_size(10) .color(TEXT_COLOR) .set(self.ids.next_level_text, ui_widgets); @@ -1561,39 +1561,39 @@ impl Hud { true } WinEvent::KeyDown(key) if !self.typing => match key { - Key::Map => { + Key::Map => { self.toggle_map(); true } - Key::Bag => { + Key::Bag => { self.toggle_bag(); true } - Key::QuestLog => { + Key::QuestLog => { self.toggle_questlog(); true } - Key::CharacterWindow => { + Key::CharacterWindow => { self.toggle_charwindow(); true } - Key::Social => { + Key::Social => { self.toggle_social(); true } - Key::Spellbook => { + Key::Spellbook => { self.toggle_spellbook(); true } - Key::Settings => { + Key::Settings => { self.toggle_settings(); true } - Key::Help => { + Key::Help => { self.toggle_help(); true } - Key::Interface => { + Key::Interface => { self.toggle_ui(); true } diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index ffd1b47156..8becdd8b24 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -345,7 +345,7 @@ pub enum Event { Play, } -const TEXT_COLOR: Color = Color::Rgba(0.86, 0.86, 0.86, 0.8); +const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); pub struct CharSelectionUi { ui: Ui, @@ -463,7 +463,7 @@ impl CharSelectionUi { .set(self.ids.test_char_l_button, ui_widgets) .was_clicked() { - self.selected_char_no = Some(1); + self.selected_char_no = Some(1); } // Veloren Logo and Alpha Version @@ -477,7 +477,7 @@ impl CharSelectionUi { .label_x(conrod_core::position::Relative::Scalar(-100.0)) .set(self.ids.v_logo, ui_widgets); - if let Some(no) = self.selected_char_no { + if let Some(no) = self.selected_char_no { // Selection_Window Image::new(self.imgs.selection_window) .w_h(522.0, 722.0) @@ -495,7 +495,6 @@ impl CharSelectionUi { .color(TEXT_COLOR) .set(self.ids.char_level, ui_widgets); - // Selected Character if no == 1 { Image::new(self.imgs.test_char_l_big) @@ -872,11 +871,11 @@ impl CharSelectionUi { Their greatest strengths are their adaptability and intelligence, which makes them allrounders in many fields."; const ORC_DESC: &str = "They are considered brutal, rude and combative. \n\ - But once you gained their trust they will be loyal friends \n\ - that follow a strict code of honor in all of their actions. \n\ - \n\ - Their warriors are masters of melee combat, but their true power \ - comes from the magical rituals of their powerful shamans."; + But once you gained their trust they will be loyal friends \n\ + that follow a strict code of honor in all of their actions. \n\ + \n\ + Their warriors are masters of melee combat, but their true power \ + comes from the magical rituals of their powerful shamans."; const DWARF_DESC: &str = "Smoking chimneys, the sound of countless hammers and hoes. \ Infinite tunnel systems to track down even the last chunk of metal in the ground. \n\ diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 4b95bb6d46..0dfe93880d 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -6,10 +6,7 @@ use crate::{ GlobalState, PlayState, PlayStateResult, }; use client::{self, Client}; -use common::{ - comp, - clock::Clock, -}; +use common::clock::Clock; use std::time::Duration; use ui::{Event as MainMenuEvent, MainMenuUi}; use vek::*; @@ -70,12 +67,12 @@ impl PlayState for MainMenuState { Ok(mut socket_adders) => { while let Some(socket_addr) = socket_adders.next() { // TODO: handle error - match Client::new(socket_addr, comp::Player::new(username.clone()), Some(comp::Character::test())) { + match Client::new(socket_addr) { Ok(client) => { return PlayStateResult::Push( Box::new(CharSelectionState::new( &mut global_state.window, - std::rc::Rc::new(std::cell::RefCell::new(client)) // <--- TODO: Remove this + std::rc::Rc::new(std::cell::RefCell::new(client.with_test_state())) // <--- TODO: Remove this )) ); } diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index eaeb8d78bd..c63794a1fb 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -169,7 +169,7 @@ impl MainMenuUi { }); }; } - const TEXT_COLOR: Color = Color::Rgba(0.94, 0.94, 0.94, 0.8); + const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); // Username // TODO: get a lower resolution and cleaner input_bg.png Image::new(self.imgs.input_bg) @@ -249,7 +249,7 @@ impl MainMenuUi { .align_middle_x_of(self.ids.address_bg) .label("Login") .label_color(TEXT_COLOR) - .label_font_size(28) + .label_font_size(26) .label_y(conrod_core::position::Relative::Scalar(5.0)) .set(self.ids.login_button, ui_widgets) .was_clicked() From 51047236a07503b2e28ca8bcf000f8b7e0f18443 Mon Sep 17 00:00:00 2001 From: Pfauenauge90 <44173739+Pfauenauge90@users.noreply.github.com> Date: Wed, 10 Apr 2019 22:41:34 +0200 Subject: [PATCH 7/9] chat changes Former-commit-id: c2a5ae0d34e1e93d8f6feb4a9e5cf69045db7275 --- voxygen/src/hud/chat.rs | 2 +- voxygen/src/menu/main/ui.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index c92e3d631e..ef6c3bdd83 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -107,7 +107,7 @@ impl Chat { } // Message box - Rectangle::fill([470.0, 160.0]) + Rectangle::fill([470.0, 167.0]) .rgba(0.0, 0.0, 0.0, 0.4) .up_from(self.ids.input, 0.0) .set(self.ids.message_box_bg, ui_widgets); diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index c63794a1fb..991ad22983 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -249,7 +249,7 @@ impl MainMenuUi { .align_middle_x_of(self.ids.address_bg) .label("Login") .label_color(TEXT_COLOR) - .label_font_size(26) + .label_font_size(24) .label_y(conrod_core::position::Relative::Scalar(5.0)) .set(self.ids.login_button, ui_widgets) .was_clicked() From 6b32d2bcb6065b2eea0a9cb4ad590b496bd3497d Mon Sep 17 00:00:00 2001 From: Pfauenauge90 <44173739+Pfauenauge90@users.noreply.github.com> Date: Thu, 11 Apr 2019 20:28:47 +0200 Subject: [PATCH 8/9] Updated race descriptions Former-commit-id: 2384a6f01a27000d39ba9e399468e1d7897b6b1f --- voxygen/src/menu/char_selection/ui.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index 8becdd8b24..6d6dfe60b2 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -868,14 +868,23 @@ impl CharSelectionUi { const HUMAN_DESC: &str = "The former nomads were only recently able to gain a foothold in the world of Veloren. \n\ \n\ - Their greatest strengths are their adaptability and intelligence, which makes them allrounders in many fields."; + Their greatest strengths are their adaptability and intelligence, which makes them allrounders in many fields.\n\ + \n\ + Humans are extremely diverse. \n\ + Some become wicked witches, slimy scoundrels, and members of the underworld, while others become witch-hunters, sages, and noble knights. \n\ + This diversity however creates constant conflict and antagonism between humans themselves, rather than with the other races of Veloren."; const ORC_DESC: &str = "They are considered brutal, rude and combative. \n\ But once you gained their trust they will be loyal friends \n\ that follow a strict code of honor in all of their actions. \n\ \n\ Their warriors are masters of melee combat, but their true power \ - comes from the magical rituals of their powerful shamans."; + comes from the magical rituals of their powerful shamans. \n\ + \n\ + They are divided into three clans. \n\ + Two of them are led by the conflicting descendants of the recently deceased High-Warlord. \n\ + The third clan was formed by a group of Shamans to prevent the bloodshed caused by the rivaling groups and to secure their source of magic: \n\ + A powerful nature crystal, stolen from the Brushwood Elves..."; const DWARF_DESC: &str = "Smoking chimneys, the sound of countless hammers and hoes. \ Infinite tunnel systems to track down even the last chunk of metal in the ground. \n\ @@ -900,6 +909,8 @@ impl CharSelectionUi { \n\ Gold Elves that hunger for political power in their massive city states. \n\ \n\ + Dark Elves, seeking war to brutalize their enemies, with ‘honor.’\n\ + \n\ And many more!"; const DANARI_DESC: &str = "The white domes and towers of their underwater kingdom are often mistaken for coral reefs from above the water. \n\ From 8e694645884bb0883850e83a5bdf7a2b85148db3 Mon Sep 17 00:00:00 2001 From: Pfauenauge90 <44173739+Pfauenauge90@users.noreply.github.com> Date: Fri, 12 Apr 2019 10:57:20 +0200 Subject: [PATCH 9/9] Charselection Help Text Former-commit-id: 463a3aad1c8d0b8e98f0b5464103016c401d1d32 --- voxygen/src/menu/char_selection/ui.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index 6d6dfe60b2..cb25d3f4a1 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -78,6 +78,8 @@ widget_ids! { //test_chars test_char_l_button, test_char_l_big, + help_text_bg, + help_text, //test_char_m_button, //test_char_r_button, @@ -181,6 +183,7 @@ struct Imgs { color_picker_bg: ImgId, slider_range: ImgId, slider_indicator: ImgId, + window_frame_2: ImgId, //test_char_m_button: ImgId, //test_char_r_button: ImgId, @@ -262,6 +265,7 @@ impl Imgs { color_picker_bg: load("element/misc_backgrounds/color_picker_blank.png"), slider_range: load("element/slider/track.png"), slider_indicator: load("element/slider/indicator.png"), + window_frame_2: load("element/frames/window_2.png"), // Weapon Icons daggers: load("element/icons/daggers.png"), @@ -346,6 +350,7 @@ pub enum Event { } const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); +const TEXT_BG: Color = Color::Rgba(0.0, 0.0, 0.0, 1.0); pub struct CharSelectionUi { ui: Ui, @@ -476,6 +481,16 @@ impl CharSelectionUi { .label_y(conrod_core::position::Relative::Scalar(-40.0)) .label_x(conrod_core::position::Relative::Scalar(-100.0)) .set(self.ids.v_logo, ui_widgets); + // Click Character to Login <-- Temporary! + Image::new(self.imgs.window_frame_2) + .mid_top_with_margin_on(self.ids.bg_selection, 60.0) + .w_h(700.0, 70.0) + .set(self.ids.help_text_bg, ui_widgets); + Text::new("Click character to select it") + .middle_of(self.ids.help_text_bg) + .font_size(40) + .color(TEXT_COLOR) + .set(self.ids.help_text, ui_widgets); if let Some(no) = self.selected_char_no { // Selection_Window