From 3d3864171785c589872bf23faaaa3a421f56ee4e Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Wed, 22 Apr 2026 10:51:13 -0400 Subject: complete orbit camera. add most large solar bodies --- src/ui.rs | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/ui.rs (limited to 'src/ui.rs') diff --git a/src/ui.rs b/src/ui.rs new file mode 100644 index 0000000..f6f7721 --- /dev/null +++ b/src/ui.rs @@ -0,0 +1,114 @@ +pub mod camera_info; + +use std::cell::RefCell; + +use cgmath::Vector3; + +use crate::{GameState, eguictx::EguiCtx, solar_system, timeman::{self, Second, TimeMan}, ui::camera_info::CameraWindowState}; + +mod ui { + pub use super::camera_info; +} + +#[derive(Default, Clone)] +pub struct State +{ + pub current_system: Option, + pub auto_time: Option, + pub do_auto_tick: bool, + + pub camera_info: CameraWindowState +} + +impl State +{ + pub fn render( + &mut self, + game_state: &RefCell, + eguictx: &EguiCtx) + { + State::render_topbar(self, game_state, eguictx); + + CameraWindowState::render( + self, + game_state, + eguictx); + } + + fn render_topbar( + state: &mut State, + game_state: &RefCell, + eguictx: &EguiCtx) + { + let mut game_state = game_state.borrow_mut(); + + egui::TopBottomPanel::top("topbar").show( + eguictx.context(), + |ui| { + + ui.horizontal(|ui| { + let solar_systems = game_state.solar_systems(); + let selected_system_label = match state.current_system { + Some(id) => solar_systems[id].name(), + None => "" + }; + + egui::ComboBox::from_label("Current System") + .selected_text(selected_system_label) + .show_ui(ui, |ui| { + + for (i, system) in solar_systems.iter().enumerate() { + ui.selectable_value( + &mut state.current_system, + Some(i), + system.name() + ); + } + }); + + let current_system = match state.current_system { + Some(id) => &solar_systems[id], + None => return + }; + }); + + ui.horizontal(|ui| { + ui.label(format!("Time: {: <16}", TimeMan::format_duration(game_state.timeman().seconds()))); + + let button_seconds = [ + 1, + 5, + 30, + timeman::MINUTE, + timeman::MINUTE * 5, + timeman::MINUTE * 30, + timeman::HOUR, + timeman::DAY, + timeman::DAY * 5, + timeman::YEAR + ]; + let selected_button = state.auto_time; + + button_seconds.iter().for_each(|&seconds| { + ui.vertical(|ui| { + let auto_selected = match selected_button { + Some(o) => o == seconds, + None => false + }; + let label = TimeMan::format_duration(seconds); + + if ui.button(label.clone()).clicked() { + game_state.timeman_mut().advance(seconds); + } + + if ui.add(egui::Button::new(label.clone()).selected(auto_selected)).clicked() { + state.auto_time = Some(seconds); + } + }); + }); + + ui.checkbox(&mut state.do_auto_tick, "Auto"); + }); + }); + } +} -- cgit v1.2.3