use std::cell::RefCell; use crate::{GameState, eguictx::EguiCtx, solar_system::{SolarSystem, SystemId}, timeman::{self, Second, TimeMan}}; #[derive(Default, Clone)] pub struct TopBarState { pub current_system: Option, pub auto_tick: Option, pub do_auto_tick: bool } impl TopBarState { pub fn render( state: &mut TopBarState, 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() ); } }); ui.separator(); 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_tick; let timeman = game_state.timeman_mut(); ui.vertical(|ui| { ui.label("Manual"); ui.checkbox(&mut state.do_auto_tick, "Auto"); }); 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() { timeman.advance(seconds); } if ui.add(egui::Button::new(label.clone()).selected(auto_selected)).clicked() { state.auto_tick = Some(seconds); } }); }); }); ui.vertical_centered_justified(|ui| { let timeman = game_state.timeman_mut(); let time_str = TimeMan::format_duration(timeman.seconds()); ui.label( egui::RichText::new(time_str) .font(egui::FontId::monospace(16.0)) ); }); }); } }