83 lines
2.1 KiB
Rust

use galactica_system::data::ShipState;
use std::f32::consts::TAU;
use crate::{
vertexbuffer::types::{RadialBarInstance, UiInstance},
PositionAnchor, RenderInput, RenderState,
};
pub(super) struct Status {}
impl Status {
pub fn new() -> Self {
Self {}
}
}
impl Status {
pub fn draw(&mut self, input: &RenderInput, state: &mut RenderState) {
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.get_data().get_state() {
ShipState::Dead => {
current_shields = 0.0;
current_hull = 0.0;
max_shields = player_ship.get_data().get_outfits().get_shield_strength();
max_hull = input.ct.get_ship(player_ship.get_data().get_content()).hull;
}
ShipState::UnLanding { .. }
| ShipState::Landing { .. }
| ShipState::Landed { .. }
| ShipState::Collapsing { .. }
| ShipState::Flying { .. } => {
current_shields = player_ship.get_data().get_shields();
current_hull = player_ship.get_data().get_hull();
max_shields = player_ship.get_data().get_outfits().get_shield_strength();
max_hull = input.ct.get_ship(player_ship.get_data().get_content()).hull;
}
}
let sprite = input
.ct
.get_sprite(input.ct.get_sprite_handle("ui::status"));
let texture_a = sprite.get_first_frame(); // ANIMATE
state.push_ui_buffer(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],
texture_index: [texture_a, texture_a],
texture_fade: 1.0,
mask_index: [0, 0],
});
state.push_radialbar_buffer(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.push_radialbar_buffer(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,
});
}
}