summaryrefslogtreecommitdiffstats
path: root/src/ui/contact.rs
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-05-24 13:04:10 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-05-24 13:04:10 -0400
commit0b428d94e751dc4a5fbe19418bfb5994cebfa54c (patch)
treebe9c338ec6b5e40ddb96d2d8ecb498b362851a2f /src/ui/contact.rs
parent14ca7b5fc15eb2618b46bde0cac85e37ebc9ebd9 (diff)
downloadsystemic4x-main.tar.gz
systemic4x-main.tar.bz2
systemic4x-main.zip
major ui reworkHEADmain
Diffstat (limited to 'src/ui/contact.rs')
-rw-r--r--src/ui/contact.rs100
1 files changed, 100 insertions, 0 deletions
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<BodyId>
+ {
+ match self.obj_type {
+ ContactType::Body => Some(self.id),
+ _ => None
+ }
+ }
+
+ pub fn fleet(&self)
+ -> Option<FleetId>
+ {
+ 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<Kilometers>
+ {
+ 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<Kilometers>
+ {
+ match self.obj_type {
+ ContactType::Body =>
+ star_system.body(self.id).offset_position(time),
+ ContactType::Fleet =>
+ *fleets_man.fleet(self.id).unwrap().offset_position()
+ }
+ }
+}