2024-01-11 22:28:02 -08:00
|
|
|
use galactica_system::data::ShipState;
|
2024-01-10 18:53:19 -08:00
|
|
|
use galactica_util::constants::{RADIALBAR_SPRITE_INSTANCE_LIMIT, UI_SPRITE_INSTANCE_LIMIT};
|
2024-01-12 14:34:31 -08:00
|
|
|
use std::f32::consts::TAU;
|
2024-01-10 18:53:19 -08:00
|
|
|
|
2024-01-10 17:53:27 -08:00
|
|
|
use crate::{
|
|
|
|
datastructs::RenderState,
|
|
|
|
vertexbuffer::{
|
|
|
|
types::{RadialBarInstance, UiInstance},
|
|
|
|
BufferObject,
|
|
|
|
},
|
|
|
|
PositionAnchor, RenderInput,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub(super) struct Status {}
|
|
|
|
impl Status {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-10 18:53:19 -08:00
|
|
|
impl Status {
|
|
|
|
pub fn draw(&mut self, input: &RenderInput, state: &mut RenderState) {
|
|
|
|
if state.vertex_buffers.ui_counter as u64 > UI_SPRITE_INSTANCE_LIMIT {
|
2024-01-10 17:53:27 -08:00
|
|
|
// TODO: no panic, handle this better.
|
|
|
|
panic!("UI limit exceeded!")
|
|
|
|
}
|
|
|
|
|
2024-01-11 20:21:07 -08:00
|
|
|
let max_shields;
|
|
|
|
let current_shields;
|
|
|
|
let current_hull;
|
|
|
|
let max_hull;
|
2024-01-12 14:34:31 -08:00
|
|
|
let player_ship = input
|
|
|
|
.systemsim
|
|
|
|
.get_ship(&galactica_system::phys::PhysSimShipHandle(
|
|
|
|
input.player.ship.unwrap(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
2024-01-11 22:10:36 -08:00
|
|
|
|
|
|
|
match player_ship.data.get_state() {
|
2024-01-12 14:34:31 -08:00
|
|
|
ShipState::Landed { .. } | ShipState::Collapsing { .. } | ShipState::Flying => {
|
2024-01-11 22:10:36 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2024-01-10 17:53:27 -08:00
|
|
|
|
|
|
|
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],
|
2024-01-10 22:44:22 -08:00
|
|
|
sprite_index: input.ct.get_sprite_handle("ui::status").get_index(),
|
2024-01-10 17:53:27 -08:00
|
|
|
}]),
|
|
|
|
);
|
|
|
|
state.vertex_buffers.ui_counter += 1;
|
|
|
|
|
|
|
|
// We add two items here, so +2
|
2024-01-10 18:53:19 -08:00
|
|
|
if state.vertex_buffers.radialbar_counter as u64 + 2 > RADIALBAR_SPRITE_INSTANCE_LIMIT {
|
2024-01-10 17:53:27 -08:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|