mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Make name labels work
Former-commit-id: 633905535d2842b320d347e368a28ac967a8469a
This commit is contained in:
parent
8c4c14f749
commit
b828bffba9
@ -26,8 +26,7 @@ void main() {
|
||||
// In-game element
|
||||
gl_Position =
|
||||
proj_mat *
|
||||
view_mat *
|
||||
(w_pos + vec4(v_pos, 40.0, 1.0));
|
||||
(view_mat * w_pos + vec4(v_pos, 0.0, 0.0));
|
||||
} else {
|
||||
// Interface element
|
||||
gl_Position = vec4(v_pos, 0.0, 1.0);
|
||||
|
@ -38,6 +38,7 @@ use conrod_core::{
|
||||
};
|
||||
use specs::Join;
|
||||
use std::collections::VecDeque;
|
||||
use vek::*;
|
||||
|
||||
const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0);
|
||||
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0);
|
||||
@ -272,7 +273,7 @@ impl Hud {
|
||||
|
||||
// Nametags
|
||||
let ecs = client.state().ecs();
|
||||
/* {
|
||||
{
|
||||
let actor_read_storage = ecs.read_storage::<comp::Actor>();
|
||||
let pos_read_storage = ecs.read_storage::<comp::phys::Pos>();
|
||||
let num = (&actor_read_storage, &pos_read_storage).join().count();
|
||||
@ -286,16 +287,26 @@ impl Hud {
|
||||
})
|
||||
.enumerate()
|
||||
{
|
||||
Ingame::from_primitive(pos, Text::new(&name))
|
||||
.set(self.ids.name_tags[i], ui_widgets);
|
||||
Ingame::from_primitive(
|
||||
pos + Vec3::new(0.0, 0.0, 3.0),
|
||||
Text::new(&name)
|
||||
.font_size(15)
|
||||
.color(Color::Rgba(1.0, 1.0, 1.0, 1.0)),
|
||||
)
|
||||
.resolution(50.0)
|
||||
.set(self.ids.name_tags[i], ui_widgets);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
// test
|
||||
Ingame::from_primitive(
|
||||
[0.0, 25.0, 25.0].into(),
|
||||
Rectangle::fill_with([1.0, 1.0], Color::Rgba(0.2, 0.0, 0.4, 1.0)),
|
||||
//Rectangle::fill_with([1.0, 1.0], Color::Rgba(0.2, 0.0, 0.4, 1.0)),
|
||||
Text::new("Squarefection")
|
||||
.font_size(20)
|
||||
.color(TEXT_COLOR)
|
||||
.font_id(self.fonts.opensans),
|
||||
)
|
||||
.x_y(0.0, 0.0)
|
||||
.resolution(40.0)
|
||||
.set(self.ids.temp, ui_widgets);
|
||||
|
||||
// Display debug window.
|
||||
|
@ -33,7 +33,7 @@ gfx_defines! {
|
||||
scissor: gfx::Scissor = (),
|
||||
|
||||
tgt_color: gfx::BlendTarget<WinColorFmt> = ("tgt_color", gfx::state::ColorMask::all(), gfx::preset::blend::ALPHA),
|
||||
tgt_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
||||
tgt_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::LESS_EQUAL_TEST,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ use conrod_core::{
|
||||
render::{Primitive, PrimitiveKind},
|
||||
text::{self, font},
|
||||
widget::{self, id::Generator},
|
||||
Ui as CrUi, UiBuilder, UiCell,
|
||||
Rect, UiBuilder, UiCell,
|
||||
};
|
||||
use graphic::Id as GraphicId;
|
||||
use scale::Scale;
|
||||
@ -82,7 +82,7 @@ impl assets::Asset for Font {
|
||||
}
|
||||
|
||||
pub struct Ui {
|
||||
ui: CrUi,
|
||||
ui: conrod_core::Ui,
|
||||
image_map: Map<GraphicId>,
|
||||
cache: Cache,
|
||||
// Draw commands for the next render
|
||||
@ -282,7 +282,7 @@ impl Ui {
|
||||
}
|
||||
|
||||
match in_world {
|
||||
Some(0) => {
|
||||
Some((0, _)) => {
|
||||
in_world = None;
|
||||
p_scale_factor = self.scale.scale_factor_physical();
|
||||
// Finish current state
|
||||
@ -294,19 +294,19 @@ impl Ui {
|
||||
// Push new position command
|
||||
self.draw_commands.push(DrawCommand::WorldPos(None));
|
||||
}
|
||||
Some(n) => in_world = Some(n - 1),
|
||||
Some((n, res)) => in_world = Some((n - 1, res)),
|
||||
None => (),
|
||||
}
|
||||
|
||||
// Functions for converting for conrod scalar coords to GL vertex coords (-1.0 to 1.0).
|
||||
let (ui_win_w, ui_win_h) = if in_world.is_some() {
|
||||
(2.0, 2.0)
|
||||
let (ui_win_w, ui_win_h) = if let Some((_, res)) = in_world {
|
||||
(res as f64, res as f64)
|
||||
} else {
|
||||
(self.ui.win_w, self.ui.win_h)
|
||||
};
|
||||
let vx = |x: f64| (x / ui_win_w * 2.0) as f32;
|
||||
let vy = |y: f64| (y / ui_win_h * 2.0) as f32;
|
||||
let gl_aabr = |rect: conrod_core::Rect| {
|
||||
let gl_aabr = |rect: Rect| {
|
||||
let (l, r, b, t) = rect.l_r_b_t();
|
||||
Aabr {
|
||||
min: Vec2::new(vx(l), vy(b)),
|
||||
@ -434,12 +434,16 @@ impl Ui {
|
||||
};
|
||||
let rect = Aabr {
|
||||
min: Vec2::new(
|
||||
vx(screen_rect.min.x as f64 / p_scale_factor) - 1.0,
|
||||
1.0 - vy(screen_rect.max.y as f64 / p_scale_factor),
|
||||
vx(screen_rect.min.x as f64 / p_scale_factor
|
||||
- self.ui.win_w / 2.0),
|
||||
vy(self.ui.win_h / 2.0
|
||||
- screen_rect.max.y as f64 / p_scale_factor),
|
||||
),
|
||||
max: Vec2::new(
|
||||
vx(screen_rect.max.x as f64 / p_scale_factor) - 1.0,
|
||||
1.0 - vy(screen_rect.min.y as f64 / p_scale_factor),
|
||||
vx(screen_rect.max.x as f64 / p_scale_factor
|
||||
- self.ui.win_w / 2.0),
|
||||
vy(self.ui.win_h / 2.0
|
||||
- screen_rect.min.y as f64 / p_scale_factor),
|
||||
),
|
||||
};
|
||||
mesh.push_quad(create_ui_quad(rect, uv, color, UiMode::Text));
|
||||
@ -496,11 +500,11 @@ impl Ui {
|
||||
PrimitiveKind::Other(container) => {
|
||||
if container.type_id == std::any::TypeId::of::<widgets::ingame::State>() {
|
||||
// Retrieve world position
|
||||
let pos = container
|
||||
let (pos, res) = container
|
||||
.state_and_style::<widgets::ingame::State, widgets::ingame::Style>()
|
||||
.unwrap()
|
||||
.state
|
||||
.pos;
|
||||
.pos_res();
|
||||
// Finish current state
|
||||
self.draw_commands.push(match current_state {
|
||||
State::Plain => DrawCommand::plain(start..mesh.vertices().len()),
|
||||
@ -512,8 +516,8 @@ impl Ui {
|
||||
renderer.create_consts(&[pos.into()]).unwrap(),
|
||||
)));
|
||||
|
||||
in_world = Some(1);
|
||||
p_scale_factor = self.scale.dpi_factor();
|
||||
in_world = Some((1, res));
|
||||
p_scale_factor = 1.0;
|
||||
}
|
||||
}
|
||||
_ => {} // TODO: Add this.
|
||||
|
@ -1,5 +1,5 @@
|
||||
use conrod_core::{
|
||||
image,
|
||||
builder_methods, image,
|
||||
position::Dimension,
|
||||
widget::{self, button},
|
||||
widget_ids, Color, Position, Positionable, Rect, Sizeable, Ui, Widget, WidgetCommon,
|
||||
@ -15,6 +15,10 @@ where
|
||||
common: widget::CommonBuilder,
|
||||
widget: W,
|
||||
pos: Vec3<f32>,
|
||||
// Number of pixels per 1 unit in world coordinates (ie a voxel)
|
||||
// Used for widgets that are rasterized before being sent to the gpu (text & images)
|
||||
// Potentially make this autmatic based on distance to camera?
|
||||
res: f32,
|
||||
}
|
||||
|
||||
// TODO: add convenience function to this trait
|
||||
@ -37,7 +41,14 @@ widget_ids! {
|
||||
|
||||
pub struct State {
|
||||
ids: Ids,
|
||||
pub pos: Vec3<f32>,
|
||||
pos: Vec3<f32>,
|
||||
res: f32,
|
||||
}
|
||||
impl State {
|
||||
// retrieve the postion and resolution as a tuple
|
||||
pub fn pos_res(&self) -> (Vec3<f32>, f32) {
|
||||
(self.pos, self.res)
|
||||
}
|
||||
}
|
||||
|
||||
pub type Style = ();
|
||||
@ -48,8 +59,12 @@ impl<W: Widget + Primitive> Ingame<W> {
|
||||
common: widget::CommonBuilder::default(),
|
||||
pos,
|
||||
widget,
|
||||
res: 1.0,
|
||||
}
|
||||
}
|
||||
builder_methods! {
|
||||
pub resolution { res = f32 }
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: Widget> Widget for Ingame<W> {
|
||||
@ -61,6 +76,7 @@ impl<W: Widget> Widget for Ingame<W> {
|
||||
State {
|
||||
ids: Ids::new(id_gen),
|
||||
pos: Vec3::default(),
|
||||
res: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,15 +86,21 @@ impl<W: Widget> Widget for Ingame<W> {
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs { id, state, ui, .. } = args;
|
||||
let Ingame { widget, pos, .. } = self;
|
||||
let Ingame {
|
||||
widget, pos, res, ..
|
||||
} = self;
|
||||
|
||||
// Update pos if it has changed
|
||||
if state.pos != pos {
|
||||
state.update(|s| s.pos = pos);
|
||||
if state.pos != pos || state.res != res {
|
||||
state.update(|s| {
|
||||
s.pos = pos;
|
||||
s.res = res;
|
||||
});
|
||||
}
|
||||
|
||||
widget
|
||||
.graphics_for(ui.window)
|
||||
.x_y(0.0, 0.0)
|
||||
.parent(id) // is this needed
|
||||
.set(state.ids.prim, ui);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user