Chat padding, Font Colours to white, Help Window

Former-commit-id: d36a878971f92fbf16eb44d3102b4328832e6563
This commit is contained in:
Pfauenauge90 2019-04-10 22:08:25 +02:00
parent 2e14f7d559
commit 822901b08b
7 changed files with 138 additions and 107 deletions

View File

@ -7,12 +7,14 @@ pub use self::run::RunAnimation;
use crate::render::FigureBoneData; use crate::render::FigureBoneData;
// Local // Local
use super::{Bone, Skeleton}; use super::{
Skeleton,
Bone,
};
pub struct CharacterSkeleton { pub struct CharacterSkeleton {
head: Bone, head: Bone,
chest: Bone, chest: Bone,
shoulders: Bone,
belt: Bone, belt: Bone,
shorts: Bone, shorts: Bone,
l_hand: Bone, l_hand: Bone,
@ -20,8 +22,6 @@ pub struct CharacterSkeleton {
l_foot: Bone, l_foot: Bone,
r_foot: Bone, r_foot: Bone,
back: Bone, back: Bone,
eyes: Bone,
hair: Bone,
} }
impl CharacterSkeleton { impl CharacterSkeleton {
@ -29,7 +29,6 @@ impl CharacterSkeleton {
Self { Self {
head: Bone::default(), head: Bone::default(),
chest: Bone::default(), chest: Bone::default(),
shoulders: Bone::default(),
belt: Bone::default(), belt: Bone::default(),
shorts: Bone::default(), shorts: Bone::default(),
l_hand: Bone::default(), l_hand: Bone::default(),
@ -37,8 +36,6 @@ impl CharacterSkeleton {
l_foot: Bone::default(), l_foot: Bone::default(),
r_foot: Bone::default(), r_foot: Bone::default(),
back: 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.l_foot.compute_base_matrix()),
FigureBoneData::new(self.r_foot.compute_base_matrix()), FigureBoneData::new(self.r_foot.compute_base_matrix()),
FigureBoneData::new(chest_mat * self.back.compute_base_matrix()), FigureBoneData::new(chest_mat * self.back.compute_base_matrix()),
FigureBoneData::new(self.shoulders.compute_base_matrix()), FigureBoneData::default(),
FigureBoneData::new(self.eyes.compute_base_matrix()), FigureBoneData::default(),
FigureBoneData::new(self.hair.compute_base_matrix()), FigureBoneData::default(),
FigureBoneData::default(), FigureBoneData::default(),
FigureBoneData::default(), FigureBoneData::default(),
FigureBoneData::default(), FigureBoneData::default(),

View File

@ -5,7 +5,10 @@ use std::f32::consts::PI;
use vek::*; use vek::*;
// Local // Local
use super::{super::Animation, CharacterSkeleton}; use super::{
CharacterSkeleton,
super::Animation,
};
pub struct RunAnimation; pub struct RunAnimation;
@ -13,8 +16,11 @@ impl Animation for RunAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = f64;
fn update_skeleton(skeleton: &mut Self::Skeleton, time: f64) { fn update_skeleton(
/*let wave = (time as f32 * 12.0).sin(); 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_slow = (time as f32 * 6.0 + PI).sin();
let wave_dip = (wave_slow.abs() - 0.5).abs(); 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.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.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); skeleton.back.ori = Quaternion::rotation_y(2.5);
} }
} }

View File

@ -3,7 +3,7 @@ use conrod_core::{
input::Key, input::Key,
position::Dimension, position::Dimension,
text::font::Id as FontId, 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, widget_ids, Color, Colorable, Positionable, Sizeable, UiCell, Widget,
}; };
use std::collections::VecDeque; use std::collections::VecDeque;
@ -70,7 +70,12 @@ impl Chat {
fn scroll_to_bottom(&self, ui_widgets: &mut UiCell) { fn scroll_to_bottom(&self, ui_widgets: &mut UiCell) {
ui_widgets.scroll_widget(self.ids.message_box, [0.0, std::f64::MAX]); 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<String> { pub(super) fn update_layout(
&mut self,
ui_widgets: &mut UiCell,
font: FontId,
imgs: &super::Imgs,
) -> Option<String> {
// Maintain scrolling // Maintain scrolling
if self.new_messages { if self.new_messages {
self.scroll_new_messages(ui_widgets); self.scroll_new_messages(ui_widgets);
@ -102,20 +107,23 @@ impl Chat {
} }
// Message box // Message box
Rectangle::fill([470.0, 180.0]) Rectangle::fill([470.0, 160.0])
.rgba(0.0, 0.0, 0.0, 0.4) .rgba(0.0, 0.0, 0.0, 0.4)
.up_from(self.ids.input, 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, _scrollbar) = List::flow_down(self.messages.len()) 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)
.scroll_kids_vertically() .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); .set(self.ids.message_box, ui_widgets);
while let Some(item) = items.next(ui_widgets) { while let Some(item) = items.next(ui_widgets) {
item.set( item.set(
Text::new(&self.messages[item.i]) Text::new(&self.messages[item.i])
.font_size(14) .font_size(14)
.font_id(font) .font_id(font)
.rgba(0.86 , 0.86, 0.86, 1.0), .rgba(1.0, 1.0, 1.0, 1.0),
ui_widgets, ui_widgets,
) )
} }
@ -123,12 +131,12 @@ impl Chat {
// Chat Arrow // Chat Arrow
if !self.scrolled_to_bottom(ui_widgets) { if !self.scrolled_to_bottom(ui_widgets) {
if Button::image(imgs.chat_arrow) if Button::image(imgs.chat_arrow)
.w_h(22.0, 22.0) .w_h(22.0, 22.0)
.hover_image(imgs.chat_arrow_mo) .hover_image(imgs.chat_arrow_mo)
.press_image(imgs.chat_arrow_press) .press_image(imgs.chat_arrow_press)
.bottom_right_with_margins_on(self.ids.message_box_bg, 2.0, 2.0) .bottom_right_with_margins_on(self.ids.message_box_bg, 2.0, 2.0)
.set(self.ids.chat_arrow, ui_widgets) .set(self.ids.chat_arrow, ui_widgets)
.was_clicked() .was_clicked()
{ {
self.scroll_to_bottom(ui_widgets); self.scroll_to_bottom(ui_widgets);
} }

View File

@ -7,7 +7,7 @@ use crate::{
}; };
use common::assets; use common::assets;
use conrod_core::{ use conrod_core::{
color, Color, color,
image::Id as ImgId, image::Id as ImgId,
text::font::Id as FontId, text::font::Id as FontId,
widget::{Button, Image, Rectangle, Scrollbar, Text}, widget::{Button, Image, Rectangle, Scrollbar, Text},
@ -459,7 +459,7 @@ impl Hud {
typing: false, typing: false,
cursor_grabbed: true, cursor_grabbed: true,
settings_tab: SettingsTab::Interface, settings_tab: SettingsTab::Interface,
show_help: false, show_help: true,
bag_open: false, bag_open: false,
menu_open: false, menu_open: false,
map_open: false, map_open: false,
@ -511,7 +511,7 @@ impl Hud {
if self.show_help { if self.show_help {
Image::new(self.imgs.window_frame_2) Image::new(self.imgs.window_frame_2)
.top_left_with_margins_on(ui_widgets.window, 5.0, 5.0) .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); .set(self.ids.help_bg, ui_widgets);
Text::new( Text::new(
@ -522,6 +522,9 @@ impl Hud {
F1 = Toggle this Window \n\ F1 = Toggle this Window \n\
F2 = Toggle Interface \n\ F2 = Toggle Interface \n\
\n\ \n\
Enter = Open Chat \n\
Mouse Wheel= Scroll Chat\n\
\n\
M = Map \n\ M = Map \n\
B = Bag \n\ B = Bag \n\
L = Quest-Log \n\ L = Quest-Log \n\
@ -775,14 +778,14 @@ impl Hud {
// Insert actual Level here // Insert actual Level here
Text::new("1") Text::new("1")
.left_from(self.ids.xp_bar, -15.0) .left_from(self.ids.xp_bar, -15.0)
.font_size(14) .font_size(10)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(self.ids.level_text, ui_widgets); .set(self.ids.level_text, ui_widgets);
// Insert next Level here // Insert next Level here
Text::new("2") Text::new("2")
.right_from(self.ids.xp_bar, -15.0) .right_from(self.ids.xp_bar, -15.0)
.font_size(14) .font_size(10)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(self.ids.next_level_text, ui_widgets); .set(self.ids.next_level_text, ui_widgets);

View File

@ -249,7 +249,7 @@ impl MainMenuUi {
.align_middle_x_of(self.ids.address_bg) .align_middle_x_of(self.ids.address_bg)
.label("Login") .label("Login")
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
.label_font_size(28) .label_font_size(26)
.label_y(conrod_core::position::Relative::Scalar(5.0)) .label_y(conrod_core::position::Relative::Scalar(5.0))
.set(self.ids.login_button, ui_widgets) .set(self.ids.login_button, ui_widgets)
.was_clicked() .was_clicked()

View File

@ -1,12 +1,19 @@
use crate::{
anim::Skeleton,
render::{
Consts, FigureBoneData, FigureLocals, FigurePipeline, Globals, Mesh, Model, Renderer,
},
Error,
};
use specs::{Component, VecStorage}; use specs::{Component, VecStorage};
use vek::*; use vek::*;
use crate::{
Error,
render::{
Consts,
Globals,
Mesh,
Model,
Renderer,
FigurePipeline,
FigureBoneData,
FigureLocals,
},
anim::Skeleton,
};
pub struct Figure<S: Skeleton> { pub struct Figure<S: Skeleton> {
// GPU data // GPU data
@ -57,17 +64,18 @@ impl<S: Skeleton> Figure<S> {
Ok(()) Ok(())
} }
pub fn update_locals( pub fn update_locals(&mut self, renderer: &mut Renderer, locals: FigureLocals) -> Result<(), Error> {
&mut self,
renderer: &mut Renderer,
locals: FigureLocals,
) -> Result<(), Error> {
renderer.update_consts(&mut self.locals, &[locals])?; renderer.update_consts(&mut self.locals, &[locals])?;
Ok(()) Ok(())
} }
pub fn render(&self, renderer: &mut Renderer, globals: &Consts<Globals>) { pub fn render(&self, renderer: &mut Renderer, globals: &Consts<Globals>) {
renderer.render_figure(&self.model, globals, &self.locals, &self.bone_consts); renderer.render_figure(
&self.model,
globals,
&self.locals,
&self.bone_consts,
);
} }
} }

View File

@ -2,23 +2,36 @@ pub mod camera;
pub mod figure; pub mod figure;
pub mod terrain; pub mod terrain;
use self::{camera::Camera, figure::Figure, terrain::Terrain}; use vek::*;
use crate::{ use dot_vox;
anim::{ use common::{
character::{CharacterSkeleton, RunAnimation}, comp,
Animation, figure::Segment,
},
mesh::Meshable,
render::{
create_skybox_mesh, Consts, FigureLocals, Globals, Model, Renderer, SkyboxLocals,
SkyboxPipeline,
},
window::Event,
}; };
use client::Client; use client::Client;
use common::{comp, figure::Segment}; use crate::{
use dot_vox; render::{
use vek::*; 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 // TODO: Don't hard-code this
const CURSOR_PAN_SCALE: f32 = 0.005; const CURSOR_PAN_SCALE: f32 = 0.005;
@ -40,25 +53,25 @@ pub struct Scene {
// TODO: Make a proper asset loading system // TODO: Make a proper asset loading system
fn load_segment(filename: &'static str) -> Segment { fn load_segment(filename: &'static str) -> Segment {
Segment::from( Segment::from(dot_vox::load(&(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/voxel/").to_string() + filename)).unwrap())
dot_vox::load(
&(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/voxel/").to_string()
+ filename),
)
.unwrap(),
)
} }
impl Scene { impl Scene {
/// Create a new `Scene` with default parameters. /// Create a new `Scene` with default parameters.
pub fn new(renderer: &mut Renderer, client: &Client) -> Self { pub fn new(renderer: &mut Renderer, client: &Client) -> Self {
Self { Self {
globals: renderer.create_consts(&[Globals::default()]).unwrap(), globals: renderer
.create_consts(&[Globals::default()])
.unwrap(),
camera: Camera::new(), camera: Camera::new(),
skybox: Skybox { skybox: Skybox {
model: renderer.create_model(&create_skybox_mesh()).unwrap(), model: renderer
locals: renderer.create_consts(&[SkyboxLocals::default()]).unwrap(), .create_model(&create_skybox_mesh())
.unwrap(),
locals: renderer
.create_consts(&[SkyboxLocals::default()])
.unwrap(),
}, },
terrain: Terrain::new(), terrain: Terrain::new(),
@ -84,19 +97,15 @@ impl Scene {
], ],
CharacterSkeleton::new(), CharacterSkeleton::new(),
) )
.unwrap(), .unwrap(),
} }
} }
/// Get a reference to the scene's camera. /// Get a reference to the scene's camera.
pub fn camera(&self) -> &Camera { pub fn camera(&self) -> &Camera { &self.camera }
&self.camera
}
/// Get a mutable reference to the scene's camera. /// Get a mutable reference to the scene's camera.
pub fn camera_mut(&mut self) -> &mut Camera { pub fn camera_mut(&mut self) -> &mut Camera { &mut self.camera }
&mut self.camera
}
/// Handle an incoming user input event (i.e: cursor moved, key pressed, window closed, etc.). /// Handle an incoming user input event (i.e: cursor moved, key pressed, window closed, etc.).
/// ///
@ -107,17 +116,17 @@ impl Scene {
Event::Resize(dims) => { Event::Resize(dims) => {
self.camera.set_aspect_ratio(dims.x as f32 / dims.y as f32); self.camera.set_aspect_ratio(dims.x as f32 / dims.y as f32);
true true
} },
// Panning the cursor makes the camera rotate // Panning the cursor makes the camera rotate
Event::CursorPan(delta) => { Event::CursorPan(delta) => {
self.camera.rotate_by(Vec3::from(delta) * CURSOR_PAN_SCALE); self.camera.rotate_by(Vec3::from(delta) * CURSOR_PAN_SCALE);
true true
} },
// Zoom the camera when a zoom event occurs // Zoom the camera when a zoom event occurs
Event::Zoom(delta) => { Event::Zoom(delta) => {
self.camera.zoom_by(-delta); self.camera.zoom_by(-delta);
true true
} },
// All other events are unhandled // All other events are unhandled
_ => false, _ => false,
} }
@ -128,14 +137,13 @@ impl Scene {
// Get player position // Get player position
let player_pos = client let player_pos = client
.player() .player()
.and_then(|ent| { .and_then(|ent| client
client .state()
.state() .ecs_world()
.ecs_world() .read_storage::<comp::phys::Pos>()
.read_storage::<comp::phys::Pos>() .get(ent)
.get(ent) .map(|pos| pos.0)
.map(|pos| pos.0) )
})
.unwrap_or(Vec3::zero()); .unwrap_or(Vec3::zero());
// Alter camera position to match player // Alter camera position to match player
@ -145,40 +153,41 @@ impl Scene {
let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents(); let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents();
// Update global constants // Update global constants
renderer renderer.update_consts(&mut self.globals, &[Globals::new(
.update_consts( view_mat,
&mut self.globals, proj_mat,
&[Globals::new( cam_pos,
view_mat, self.camera.get_focus_pos(),
proj_mat, 10.0,
cam_pos, client.state().get_time_of_day(),
self.camera.get_focus_pos(), client.state().get_time(),
10.0, )])
client.state().get_time_of_day(),
client.state().get_time(),
)],
)
.expect("Failed to update global constants"); .expect("Failed to update global constants");
// Maintain the terrain // Maintain the terrain
self.terrain.maintain(renderer, client); self.terrain.maintain(renderer, client);
// TODO: Don't do this here // 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 // Calculate player model matrix
let model_mat = Mat4::<f32>::translation_3d(player_pos); let model_mat = Mat4::<f32>::translation_3d(player_pos);
self.test_figure self.test_figure.update_locals(renderer, FigureLocals::new(model_mat)).unwrap();
.update_locals(renderer, FigureLocals::new(model_mat))
.unwrap();
self.test_figure.update_skeleton(renderer).unwrap(); self.test_figure.update_skeleton(renderer).unwrap();
} }
/// Render the scene using the provided `Renderer` /// Render the scene using the provided `Renderer`
pub fn render_to(&self, renderer: &mut Renderer) { pub fn render_to(&self, renderer: &mut Renderer) {
// Render the skybox first (it appears over everything else so must be rendered first) // 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 // Render terrain
self.terrain.render(renderer, &self.globals); self.terrain.render(renderer, &self.globals);