Added radial bars
parent
45bc3d3b41
commit
744533c05c
|
@ -27,9 +27,9 @@ fn anchor(
|
|||
trans += vec2(-dim.x, dim.y) / 2.0;
|
||||
} else if anchor == 5u { // NE NE
|
||||
trans += vec2(window_dim.x, window_dim.y) / 2.0;
|
||||
trans += vec2(dim.x, -dim.y) / 2.0;
|
||||
trans += vec2(-dim.x, -dim.y) / 2.0;
|
||||
} else { // center / center as default, since it's the most visible variant.
|
||||
trans += vec2(0.0, 0.0);
|
||||
trans += vec2(0.0, 0.0) / 2.0;
|
||||
trans += vec2(0.0, 0.0) / 2.0;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ var texture_array: binding_array<texture_2d<f32>>;
|
|||
@group(0) @binding(1)
|
||||
var sampler_array: binding_array<sampler>;
|
||||
|
||||
|
||||
// INCLUDE: anchor.wgsl
|
||||
|
||||
@vertex
|
||||
fn vertex_main(
|
||||
vertex: VertexInput,
|
||||
|
@ -43,14 +46,12 @@ fn vertex_main(
|
|||
|
||||
// Center of this radial bar, in logical pixels,
|
||||
// with (0, 0) at the center of the screen.
|
||||
if instance.anchor == u32(0) {
|
||||
out.center = instance.position + (
|
||||
(global_data.window_size / global_data.window_scale.x)
|
||||
- vec2(instance.diameter, instance.diameter)
|
||||
) / 2.0;
|
||||
} else {
|
||||
out.center = vec2(0.0, 0.0);
|
||||
}
|
||||
out.center = anchor(
|
||||
instance.anchor,
|
||||
instance.position,
|
||||
vec2(instance.diameter, instance.diameter)
|
||||
) / 2.0 * (global_data.window_size / global_data.window_scale.x);
|
||||
// ^ slight correction, since anchor gives us a different result than we need here
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
use cgmath::{Deg, InnerSpace, Point2, Rad, Vector2};
|
||||
use galactica_world::util;
|
||||
|
||||
use crate::{vertexbuffer::types::UiInstance, GPUState, PositionAnchor, RenderState};
|
||||
use crate::{
|
||||
vertexbuffer::{
|
||||
types::{RadialBarInstance, UiInstance},
|
||||
BufferObject,
|
||||
},
|
||||
GPUState, PositionAnchor, RenderState,
|
||||
};
|
||||
|
||||
impl GPUState {
|
||||
pub(super) fn hud_add_radar(&mut self, state: &RenderState, instances: &mut Vec<UiInstance>) {
|
||||
|
@ -20,15 +26,6 @@ impl GPUState {
|
|||
let ship_sprite = state.content.get_sprite_handle("ui::shipblip");
|
||||
let arrow_sprite = state.content.get_sprite_handle("ui::centerarrow");
|
||||
|
||||
instances.push(UiInstance {
|
||||
anchor: PositionAnchor::NeNe.to_int(),
|
||||
position: [0.0, 0.0],
|
||||
angle: 0.0,
|
||||
size: radar_size,
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
sprite_index: state.content.get_sprite_handle("ui::status").get_index(),
|
||||
});
|
||||
|
||||
instances.push(UiInstance {
|
||||
anchor: PositionAnchor::NwNw.to_int(),
|
||||
position: [10.0, -10.0],
|
||||
|
@ -195,4 +192,42 @@ impl GPUState {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn hud_add_status(&mut self, state: &RenderState, instances: &mut Vec<UiInstance>) {
|
||||
instances.push(UiInstance {
|
||||
anchor: PositionAnchor::NeNe.to_int(),
|
||||
position: [-10.0, -10.0],
|
||||
angle: 0.0,
|
||||
size: 200.0,
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
sprite_index: state.content.get_sprite_handle("ui::status").get_index(),
|
||||
});
|
||||
|
||||
// TODO: counters for each buffer, remove arrays
|
||||
self.queue.write_buffer(
|
||||
&self.vertex_buffers.radialbar.instances,
|
||||
RadialBarInstance::SIZE * 0,
|
||||
bytemuck::cast_slice(&[RadialBarInstance {
|
||||
position: [-19.0, -19.0],
|
||||
anchor: PositionAnchor::NeNe.to_int(),
|
||||
diameter: 182.0,
|
||||
stroke: 5.0,
|
||||
color: [0.3, 0.6, 0.8, 1.0],
|
||||
angle: -state.current_time / 2.0,
|
||||
}]),
|
||||
);
|
||||
|
||||
self.queue.write_buffer(
|
||||
&self.vertex_buffers.radialbar.instances,
|
||||
RadialBarInstance::SIZE * 1,
|
||||
bytemuck::cast_slice(&[RadialBarInstance {
|
||||
position: [-27.0, -27.0],
|
||||
anchor: PositionAnchor::NeNe.to_int(),
|
||||
diameter: 166.0,
|
||||
stroke: 5.0,
|
||||
color: [0.8, 0.7, 0.5, 1.0],
|
||||
angle: state.current_time / 5.0,
|
||||
}]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -381,6 +381,7 @@ impl GPUState {
|
|||
let mut ui_instances: Vec<UiInstance> = Vec::new();
|
||||
|
||||
self.hud_add_radar(state, &mut ui_instances);
|
||||
self.hud_add_status(state, &mut ui_instances);
|
||||
|
||||
if ui_instances.len() as u64 > galactica_constants::UI_SPRITE_INSTANCE_LIMIT {
|
||||
panic!("Ui sprite limit exceeded!")
|
||||
|
@ -545,52 +546,11 @@ impl GPUState {
|
|||
render_pass.set_pipeline(&self.ui_pipeline);
|
||||
render_pass.draw_indexed(0..SPRITE_INDICES.len() as u32, 0, 0..n_ui as _);
|
||||
|
||||
/*
|
||||
let mut i = 0;
|
||||
for b in &state.render_elements.radial_bars {
|
||||
self.queue.write_buffer(
|
||||
&self.vertex_buffers.radialbar.instances,
|
||||
RadialBarInstance::SIZE * i,
|
||||
bytemuck::cast_slice(&[RadialBarInstance {
|
||||
position: b.pos.position().clone().into(),
|
||||
anchor: b.pos.to_anchor_int(),
|
||||
diameter: b.diameter,
|
||||
stroke: b.stroke,
|
||||
color: b.color,
|
||||
angle: b.angle.0,
|
||||
}]),
|
||||
);
|
||||
i += 1;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
self.queue.write_buffer(
|
||||
&self.vertex_buffers.radialbar.instances,
|
||||
0,
|
||||
bytemuck::cast_slice(&[
|
||||
RadialBarInstance {
|
||||
position: [-23.0, -23.0],
|
||||
diameter: 274.0,
|
||||
stroke: 10.0,
|
||||
color: [0.3, 0.6, 0.8, 1.0],
|
||||
angle: -state.current_time / 2.0,
|
||||
},
|
||||
RadialBarInstance {
|
||||
position: [-35.0, -35.0],
|
||||
diameter: 250.0,
|
||||
stroke: 10.0,
|
||||
color: [0.8, 0.7, 0.5, 1.0],
|
||||
angle: -state.current_time / 5.0,
|
||||
},
|
||||
]),
|
||||
);*/
|
||||
|
||||
// Radial progress bar
|
||||
// Radial progress bars
|
||||
// TODO: do we need to do this every time?
|
||||
self.vertex_buffers.radialbar.set_in_pass(&mut render_pass);
|
||||
render_pass.set_pipeline(&self.radialbar_pipeline);
|
||||
//render_pass.draw_indexed(0..SPRITE_INDICES.len() as u32, 0, 0..2);
|
||||
render_pass.draw_indexed(0..SPRITE_INDICES.len() as u32, 0, 0..2);
|
||||
|
||||
// begin_render_pass borrows encoder mutably, so we can't call finish()
|
||||
// without dropping this variable.
|
||||
|
|
Loading…
Reference in New Issue