summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-05-03 17:31:47 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-05-03 17:31:47 -0400
commit759d5d27c7773c7fe8b165ce08b57204db990b74 (patch)
treeb9fd06e7b76490ba15dd3a87d83253a7b0bd68cf /src/ui
parentb14dd1c1f3e198137fa8b9e0c4f5e56949b11cd0 (diff)
downloadsystemic4x-759d5d27c7773c7fe8b165ce08b57204db990b74.tar.gz
systemic4x-759d5d27c7773c7fe8b165ce08b57204db990b74.tar.bz2
systemic4x-759d5d27c7773c7fe8b165ce08b57204db990b74.zip
move topbar ui rendering into it's own module
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/camera_info.rs5
-rw-r--r--src/ui/topbar.rs91
2 files changed, 94 insertions, 2 deletions
diff --git a/src/ui/camera_info.rs b/src/ui/camera_info.rs
index ccd06c5..a7bc80b 100644
--- a/src/ui/camera_info.rs
+++ b/src/ui/camera_info.rs
@@ -19,14 +19,15 @@ impl CameraWindowState
game_state: &RefCell<GameState>,
eguictx: &EguiCtx)
{
- if ui_state.current_system.is_none() {
+ let topbar_state = &ui_state.topbar_sate;
+ if topbar_state.current_system.is_none() {
return;
}
let camera_state = &mut ui_state.camera_info;
let game_state = game_state.borrow();
- let current_system = &game_state.solar_systems()[ui_state.current_system.unwrap()];
+ let current_system = &game_state.solar_systems()[topbar_state.current_system.unwrap()];
egui::Window::new("Debug Camera Info")
.title_bar(false)
diff --git a/src/ui/topbar.rs b/src/ui/topbar.rs
new file mode 100644
index 0000000..07c20a1
--- /dev/null
+++ b/src/ui/topbar.rs
@@ -0,0 +1,91 @@
+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<SystemId>,
+ pub auto_tick: Option<Second>,
+ pub do_auto_tick: bool
+}
+
+impl TopBarState
+{
+ pub fn render(
+ state: &mut TopBarState,
+ game_state: &RefCell<GameState>,
+ 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 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();
+ 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.checkbox(&mut state.do_auto_tick, "Auto");
+ });
+ 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))
+ );
+ });
+ });
+ }
+}