diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-07 08:50:05 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-07 08:50:05 -0400 |
| commit | c1adf64c1aaecd5a2b9d532d707ef35971f1aa18 (patch) | |
| tree | fc1050becd0576d75a8d6afb8be09fae80c91541 /src/ui/topbar.rs | |
| parent | 9788d9037ad7199701b1710c28559cb96bce5aec (diff) | |
| download | systemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.tar.gz systemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.tar.bz2 systemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.zip | |
begin work on body info window
Diffstat (limited to 'src/ui/topbar.rs')
| -rw-r--r-- | src/ui/topbar.rs | 151 |
1 files changed, 94 insertions, 57 deletions
diff --git a/src/ui/topbar.rs b/src/ui/topbar.rs index 296a84e..a5d92c5 100644 --- a/src/ui/topbar.rs +++ b/src/ui/topbar.rs @@ -7,84 +7,64 @@ pub struct TopBarState { pub current_system: Option<SystemId>, pub auto_tick: Option<Second>, - pub do_auto_tick: bool + pub do_auto_tick: bool, + + pub bodies_window_visible: bool, + pub fleet_window_visible: bool, +} + +#[derive(Default, Clone)] +pub struct TopBarAction +{ + pub advance_tick: Option<Second>, } impl TopBarState { pub fn render( - state: &mut TopBarState, - game_state: &RefCell<GameState>, + &mut self, + game_state: &GameState, eguictx: &EguiCtx) + -> TopBarAction { - let mut game_state = game_state.borrow_mut(); + let mut action: TopBarAction = TopBarAction::default(); + + let solar_systems = game_state.solar_systems(); + let timeman = game_state.timeman(); 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); + let selected_system_label = match self.current_system { + Some(id) => solar_systems[id].name(), + None => "" + }; - if ui.button(label.clone()).clicked() { - timeman.advance(seconds); + 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 self.current_system, + Some(i), + system.name() + ); } + }); - if ui.add(egui::Button::new(label.clone()).selected(auto_selected)).clicked() { - state.auto_tick = Some(seconds); - } + ui.horizontal(|ui| { + self.paint_empire_buttons(ui); }); }); + + self.paint_tick_buttons(&mut action, timeman, ui); + }); 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) @@ -92,5 +72,62 @@ impl TopBarState ); }); }); + action + } + + pub fn paint_empire_buttons( + &mut self, + ui: &mut egui::Ui) + { + if ui.add(egui::Button::new("Bodies").selected(self.bodies_window_visible)).clicked() { + self.bodies_window_visible = !self.bodies_window_visible; + } + if ui.add(egui::Button::new("Fleets").selected(self.fleet_window_visible)).clicked() { + self.fleet_window_visible = !self.fleet_window_visible; + } + } + + pub fn paint_tick_buttons( + &mut self, + action: &mut TopBarAction, + timeman: &TimeMan, + ui: &mut egui::Ui) + { + 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 = self.auto_tick; + + ui.vertical(|ui| { + ui.label("Manual"); + ui.checkbox(&mut self.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() { + action.advance_tick = Some(seconds); + } + + if ui.add(egui::Button::new(label.clone()).selected(auto_selected)).clicked() { + self.auto_tick = Some(seconds); + } + }); + }); } } |
