summaryrefslogtreecommitdiffstats
path: root/src/window/ui.rs
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-04-15 16:53:58 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-04-15 16:53:58 -0400
commitb5ced3af46c96ceb959fbbf1addfeba3bd4f76d5 (patch)
tree06d06fc9562dc99eede655b53635576f67c37e3b /src/window/ui.rs
downloadsystemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.tar.gz
systemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.tar.bz2
systemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.zip
first commit. working body rendering
Diffstat (limited to 'src/window/ui.rs')
-rw-r--r--src/window/ui.rs96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/window/ui.rs b/src/window/ui.rs
new file mode 100644
index 0000000..4d13740
--- /dev/null
+++ b/src/window/ui.rs
@@ -0,0 +1,96 @@
+use std::cell::RefCell;
+
+use cgmath::Vector3;
+
+use crate::{GameState, eguictx::EguiCtx, solar_system, timeman::{Second, TimeMan}};
+
+#[derive(Default, Clone)]
+pub struct GameWindowUiState
+{
+ pub current_system: Option<solar_system::SystemId>,
+ pub camera_scale: f32,
+ pub camera_target: Option<solar_system::BodyId>,
+ pub auto_time: Option<Second>,
+ pub do_auto_tick: bool
+}
+
+impl GameWindowUiState
+{
+ pub fn render(
+ old_state: &GameWindowUiState,
+ game_state: &RefCell<GameState>,
+ eguictx: &EguiCtx)
+ -> Self
+ {
+ let mut new_state = old_state.clone();
+
+ { GameWindowUiState::render_topbar(&mut new_state, game_state, eguictx); }
+
+ new_state
+ }
+
+ fn render_topbar(
+ state: &mut GameWindowUiState,
+ 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| {
+ ui.menu_button("File", |ui| {
+
+ });
+ });
+
+ ui.horizontal(|ui| {
+ let solar_systems = game_state.solar_systems();
+ let selected_label = match state.current_system {
+ Some(id) => solar_systems[id].name(),
+ None => ""
+ };
+
+ egui::ComboBox::from_label("Current System")
+ .selected_text(selected_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.horizontal(|ui| {
+ ui.label(format!("Time: {}", TimeMan::format_duration(game_state.timeman().seconds())));
+
+ let button_seconds = [1, 5, 30, 60, 60*5, 60*30, 60*60, 60*60*24, 60*60*24*5, 60*60*24*30];
+ 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);
+ }
+ });
+ });
+ });
+ });
+ }
+}