use galactica_system::data::ShipState; use galactica_util::constants::{RADIALBAR_SPRITE_INSTANCE_LIMIT, UI_SPRITE_INSTANCE_LIMIT}; use std::f32::consts::TAU; use crate::{ datastructs::RenderState, vertexbuffer::{ types::{RadialBarInstance, UiInstance}, BufferObject, }, PositionAnchor, RenderInput, }; pub(super) struct Status {} impl Status { pub fn new() -> Self { Self {} } } impl Status { pub fn draw(&mut self, input: &RenderInput, state: &mut RenderState) { if state.vertex_buffers.ui_counter as u64 > UI_SPRITE_INSTANCE_LIMIT { // TODO: no panic, handle this better. panic!("UI limit exceeded!") } let max_shields; let current_shields; let current_hull; let max_hull; let player_ship = input .systemsim .get_ship(&galactica_system::phys::PhysSimShipHandle( input.player.ship.unwrap(), )) .unwrap(); match player_ship.data.get_state() { ShipState::Landed { .. } | ShipState::Collapsing { .. } | ShipState::Flying => { max_shields = player_ship.data.get_outfits().get_shield_strength(); current_shields = player_ship.data.get_shields(); current_hull = player_ship.data.get_hull(); max_hull = input.ct.get_ship(player_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.ct.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 > 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; } }