From 0b428d94e751dc4a5fbe19418bfb5994cebfa54c Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Sun, 24 May 2026 13:04:10 -0400 Subject: major ui rework --- src/ui/contact.rs | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/ui/contact.rs (limited to 'src/ui/contact.rs') diff --git a/src/ui/contact.rs b/src/ui/contact.rs new file mode 100644 index 0000000..e525541 --- /dev/null +++ b/src/ui/contact.rs @@ -0,0 +1,100 @@ +use crate::body::BodyId; +use crate::fleet::{Fleet, FleetId, FleetsManager}; +use crate::solar_system::{Kilometers, SolarSystem}; +use crate::solar_system::body::OrbitalBody; +use crate::timeman::Second; + +#[derive(Copy, Clone, Eq, PartialEq)] +pub enum ContactType +{ + Body, + Fleet +} + +#[derive(Copy, Clone, Eq, PartialEq)] +pub struct MapContact +{ + obj_type: ContactType, + id: usize +} + +impl MapContact +{ + pub fn from_body( + id: BodyId) + -> Self { + Self { + obj_type: ContactType::Body, + id: id + } + } + + pub fn from_fleet( + id: FleetId) + -> Self { + Self { + obj_type: ContactType::Fleet, + id: id + } + } + + pub fn body(&self) + -> Option + { + match self.obj_type { + ContactType::Body => Some(self.id), + _ => None + } + } + + pub fn fleet(&self) + -> Option + { + match self.obj_type { + ContactType::Fleet => Some(self.id), + _ => None + } + } + + pub fn name<'ss>( + &self, + star_system: &'ss SolarSystem, + fleets_man: &'ss FleetsManager) + -> &'ss String + { + match self.obj_type { + ContactType::Body => star_system.body(self.id).name(), + ContactType::Fleet => fleets_man.fleet(self.id).unwrap().name() + } + } + + pub fn origin_position<'ss>( + &self, + star_system: &'ss SolarSystem, + fleets_man: &'ss FleetsManager, + time: Second) + -> cgmath::Vector3 + { + match self.obj_type { + ContactType::Body => + star_system.body(self.id).origin_position(star_system, time), + ContactType::Fleet => + *fleets_man.fleet(self.id).unwrap().origin_position() + } + } + + pub fn offset_position<'ss>( + &self, + star_system: &'ss SolarSystem, + fleets_man: &'ss FleetsManager, + time: Second) + -> cgmath::Vector3 + { + match self.obj_type { + ContactType::Body => + star_system.body(self.id).offset_position(time), + ContactType::Fleet => + *fleets_man.fleet(self.id).unwrap().offset_position() + } + } +} -- cgit v1.2.3