use std::f32::consts::TAU; use crate::{ datastructs::RenderState, vertexbuffer::{ types::{RadialBarInstance, UiInstance}, BufferObject, }, PositionAnchor, RenderInput, }; use super::UiElement; pub(super) struct Status {} impl Status { pub fn new() -> Self { Self {} } } impl UiElement for Status { fn draw(&mut self, input: &RenderInput, state: &mut RenderState) { if state.vertex_buffers.ui_counter as u64 > galactica_constants::UI_SPRITE_INSTANCE_LIMIT { // TODO: no panic, handle this better. panic!("UI limit exceeded!") } let player_world_object = input.systemsim.get_ship(input.player_data).unwrap(); let data = input .data .get_ship(player_world_object.data_handle) .unwrap(); let max_shields = data.get_outfits().get_shield_strength(); let current_shields = data.get_shields(); let current_hull = data.get_hull(); let max_hull = input.content.get_ship(data.get_content()).hull; state.queue.write_buffer( &state.vertex_buffers.ui.instances, UiInstance::SIZE * state.vertex_buffers.ui_counter, bytemuck::cast_slice(&[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: input.content.get_sprite_handle("ui::status").get_index(), }]), ); state.vertex_buffers.ui_counter += 1; // We add two items here, so +2 if state.vertex_buffers.radialbar_counter as u64 + 2 > galactica_constants::RADIALBAR_SPRITE_INSTANCE_LIMIT { // TODO: no panic, handle this better. panic!("Radialbar limit exceeded!") } state.queue.write_buffer( &state.vertex_buffers.radialbar.instances, RadialBarInstance::SIZE * state.vertex_buffers.radialbar_counter, 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: (current_shields / max_shields) * TAU, }]), ); state.vertex_buffers.radialbar_counter += 1; state.queue.write_buffer( &state.vertex_buffers.radialbar.instances, RadialBarInstance::SIZE * state.vertex_buffers.radialbar_counter, 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: (current_hull / max_hull) * TAU, }]), ); state.vertex_buffers.radialbar_counter += 1; } }