Added basic planet ui
parent
0570a13f1b
commit
7334ebd00e
|
@ -1,17 +1,21 @@
|
|||
use galactica_content::Content;
|
||||
use galactica_system::{data::ShipState, phys::PhysSimShipHandle};
|
||||
use glyphon::TextArea;
|
||||
|
||||
use super::{fpsindicator::FpsIndicator, radar::Radar, status::Status};
|
||||
use crate::{datastructs::RenderState, RenderInput};
|
||||
use super::{fpsindicator::FpsIndicator, planet::Planet, radar::Radar, status::Status};
|
||||
use crate::{RenderInput, RenderState};
|
||||
|
||||
pub struct UiManager {
|
||||
radar: Radar,
|
||||
status: Status,
|
||||
fps: FpsIndicator,
|
||||
planet: Planet,
|
||||
}
|
||||
|
||||
impl UiManager {
|
||||
pub fn new(state: &mut RenderState) -> Self {
|
||||
pub fn new(ct: &Content, state: &mut RenderState) -> Self {
|
||||
Self {
|
||||
planet: Planet::new(ct, state),
|
||||
radar: Radar::new(),
|
||||
status: Status::new(),
|
||||
fps: FpsIndicator::new(state),
|
||||
|
@ -20,12 +24,48 @@ impl UiManager {
|
|||
|
||||
/// Draw all ui elements
|
||||
pub fn draw(&mut self, input: &RenderInput, state: &mut RenderState) {
|
||||
self.radar.draw(input, state);
|
||||
self.status.draw(input, state);
|
||||
let ship_handle = input.player.ship.unwrap();
|
||||
let ship = input
|
||||
.systemsim
|
||||
.get_ship(&PhysSimShipHandle(ship_handle))
|
||||
.unwrap();
|
||||
|
||||
self.fps.update(input, state);
|
||||
|
||||
match ship.data.get_state() {
|
||||
ShipState::Collapsing
|
||||
| ShipState::Dead
|
||||
| ShipState::Flying { .. }
|
||||
| ShipState::Landing { .. }
|
||||
| ShipState::UnLanding { .. } => {
|
||||
self.radar.draw(input, state);
|
||||
self.status.draw(input, state);
|
||||
}
|
||||
|
||||
ShipState::Landed { .. } => {
|
||||
self.planet.draw(input, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_textareas(&self) -> [TextArea; 1] {
|
||||
[self.fps.get_textarea()]
|
||||
pub fn get_textareas(&self, input: &RenderInput, state: &RenderState) -> Vec<TextArea> {
|
||||
let mut v = Vec::with_capacity(5);
|
||||
|
||||
let ship_handle = input.player.ship.unwrap();
|
||||
let ship = input
|
||||
.systemsim
|
||||
.get_ship(&PhysSimShipHandle(ship_handle))
|
||||
.unwrap();
|
||||
match ship.data.get_state() {
|
||||
ShipState::Collapsing
|
||||
| ShipState::Dead
|
||||
| ShipState::Flying { .. }
|
||||
| ShipState::Landing { .. }
|
||||
| ShipState::UnLanding { .. } => v.push(self.fps.get_textarea()),
|
||||
|
||||
ShipState::Landed { .. } => v.extend(self.planet.get_textarea(input, state)),
|
||||
};
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
mod fpsindicator;
|
||||
mod manager;
|
||||
mod planet;
|
||||
mod radar;
|
||||
mod status;
|
||||
mod util;
|
||||
|
||||
pub use manager::UiManager;
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
use galactica_content::{Content, SystemObject, SystemObjectHandle};
|
||||
use galactica_system::{data::ShipState, phys::PhysSimShipHandle};
|
||||
use galactica_util::to_radians;
|
||||
use glyphon::{cosmic_text::Align, Attrs, Color, Metrics, TextArea, Weight};
|
||||
use nalgebra::{Point2, Vector2};
|
||||
|
||||
use super::util::{SpriteRect, UiImage, UiTextArea};
|
||||
use crate::{vertexbuffer::types::UiInstance, PositionAnchor, RenderInput, RenderState};
|
||||
|
||||
pub(super) struct Planet {
|
||||
// UI elements
|
||||
planet_desc: UiTextArea,
|
||||
planet_name: UiTextArea,
|
||||
landscape: UiImage,
|
||||
|
||||
// Height of whole element,in logical pixels
|
||||
size: f32,
|
||||
|
||||
/// What object we're displaying currently.
|
||||
/// Whenever this changes, we need to reflow text.
|
||||
current_object: Option<SystemObjectHandle>,
|
||||
}
|
||||
|
||||
// TODO: no scroll
|
||||
// TODO: animate in/out
|
||||
|
||||
impl Planet {
|
||||
pub fn new(ct: &Content, state: &mut RenderState) -> Self {
|
||||
let size = 800.0;
|
||||
let s = Self {
|
||||
// height of element in logical pixels
|
||||
size,
|
||||
current_object: None,
|
||||
|
||||
planet_desc: UiTextArea::new(
|
||||
state,
|
||||
ct.get_sprite_handle("ui::planet"),
|
||||
Point2::new(0.0, 0.0),
|
||||
size,
|
||||
SpriteRect {
|
||||
pos: Point2::new(25.831, 284.883) / 512.0,
|
||||
dim: Vector2::new(433.140, 97.220) / 512.0,
|
||||
},
|
||||
Metrics::new(16.0, 18.0),
|
||||
Color::rgb(255, 255, 255),
|
||||
Align::Left,
|
||||
),
|
||||
|
||||
planet_name: UiTextArea::new(
|
||||
state,
|
||||
ct.get_sprite_handle("ui::planet"),
|
||||
Point2::new(0.0, 0.0),
|
||||
size,
|
||||
SpriteRect {
|
||||
pos: Point2::new(165.506, 82.0) / 512.0,
|
||||
dim: Vector2::new(74.883, 17.0) / 512.0,
|
||||
},
|
||||
Metrics::new(19.0, 19.0),
|
||||
Color::rgb(255, 255, 255),
|
||||
Align::Center,
|
||||
),
|
||||
|
||||
landscape: UiImage::new(
|
||||
ct.get_sprite_handle("ui::planet"),
|
||||
Point2::new(0.0, 0.0),
|
||||
size,
|
||||
ct.get_sprite_handle("ui::landscape::test"),
|
||||
ct.get_sprite_handle("ui::landscapemask"),
|
||||
SpriteRect {
|
||||
pos: Point2::new(32.031, 75.587) / 512.0,
|
||||
dim: Vector2::new(342.811, 171.402) / 512.0,
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
impl Planet {
|
||||
fn reflow(&mut self, planet: &SystemObject, state: &mut RenderState) {
|
||||
self.planet_desc.set_text(
|
||||
state,
|
||||
&planet.desc,
|
||||
Attrs::new()
|
||||
.weight(Weight::NORMAL)
|
||||
.family(glyphon::Family::SansSerif),
|
||||
);
|
||||
|
||||
self.planet_name.set_text(
|
||||
state,
|
||||
&planet.name,
|
||||
Attrs::new()
|
||||
.weight(Weight::BOLD)
|
||||
.family(glyphon::Family::Serif),
|
||||
);
|
||||
self.current_object = Some(planet.handle);
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, input: &RenderInput, state: &mut RenderState) {
|
||||
// Get required data
|
||||
let ship_handle = input.player.ship.unwrap();
|
||||
let ship_data = input
|
||||
.systemsim
|
||||
.get_ship(&PhysSimShipHandle(ship_handle))
|
||||
.unwrap();
|
||||
let planet_handle = match ship_data.data.get_state() {
|
||||
ShipState::Landed { target } => *target,
|
||||
_ => unreachable!("tried to draw planet interface while not landed!"),
|
||||
};
|
||||
let planet = input.ct.get_system_object(planet_handle);
|
||||
|
||||
// Reconfigure for new planet if necessary
|
||||
if self
|
||||
.current_object
|
||||
.map(|x| x != planet_handle)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
self.reflow(planet, state);
|
||||
}
|
||||
|
||||
// Draw elements
|
||||
self.landscape.push_to_buffer(state);
|
||||
state.push_ui_buffer(UiInstance {
|
||||
anchor: PositionAnchor::CC.to_int(),
|
||||
position: [0.0, 0.0],
|
||||
angle: to_radians(90.0),
|
||||
size: self.size,
|
||||
color: [1.0, 1.0, 1.0, 1.0],
|
||||
sprite_index: input.ct.get_sprite_handle("ui::planet").get_index(),
|
||||
mask_index: [0, 0],
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_textarea(&self, _input: &RenderInput, state: &RenderState) -> [TextArea; 2] {
|
||||
[
|
||||
self.planet_desc.get_textarea(state),
|
||||
self.planet_name.get_textarea(state),
|
||||
]
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ use nalgebra::{Point2, Vector2};
|
|||
use super::SpriteRect;
|
||||
use crate::{vertexbuffer::types::UiInstance, PositionAnchor, RenderState};
|
||||
|
||||
pub struct SpriteImage {
|
||||
pub struct UiImage {
|
||||
parent: SpriteHandle,
|
||||
parent_position: Point2<f32>,
|
||||
parent_size: f32,
|
||||
|
@ -15,7 +15,7 @@ pub struct SpriteImage {
|
|||
rect: SpriteRect,
|
||||
}
|
||||
|
||||
impl SpriteImage {
|
||||
impl UiImage {
|
||||
pub fn new(
|
||||
parent: SpriteHandle,
|
||||
parent_position: Point2<f32>,
|
|
@ -1,8 +1,8 @@
|
|||
mod spriteimage;
|
||||
mod spritetextarea;
|
||||
mod image;
|
||||
mod textarea;
|
||||
|
||||
pub(super) use spriteimage::SpriteImage;
|
||||
pub(super) use spritetextarea::SpriteTextArea;
|
||||
pub(super) use image::UiImage;
|
||||
pub(super) use textarea::UiTextArea;
|
||||
|
||||
use nalgebra::{Point2, Vector2};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use super::SpriteRect;
|
|||
use crate::RenderState;
|
||||
|
||||
/// Represents a text area inside a sprite.
|
||||
pub(crate) struct SpriteTextArea {
|
||||
pub(crate) struct UiTextArea {
|
||||
/// Parent sprite
|
||||
sprite: SpriteHandle,
|
||||
|
||||
|
@ -30,7 +30,7 @@ pub(crate) struct SpriteTextArea {
|
|||
align: Align,
|
||||
}
|
||||
|
||||
impl SpriteTextArea {
|
||||
impl UiTextArea {
|
||||
pub fn new(
|
||||
state: &mut RenderState,
|
||||
sprite: SpriteHandle,
|
Loading…
Reference in New Issue