summaryrefslogtreecommitdiffstats
path: root/src/ui/camera_info.rs
blob: fa46f500b3dd6bd26854267465776e4130b4fca6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::cell::RefCell;

use crate::{GameState, eguictx::EguiCtx, solar_system, ui};


#[derive(Default, Clone)]
pub struct CameraWindowState
{
    pub camera_scale: f32,
    pub camera_pos: Option<cgmath::Vector3<f64>>,
    pub camera_rot: Option<cgmath::Vector2<cgmath::Rad<f32>>>,
    pub target: Option<solar_system::BodyId>,
}

impl CameraWindowState
{
    pub fn render(
        ui_state: &mut ui::State,
        game_state: &RefCell<GameState>,
        eguictx: &EguiCtx)
    {
        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()[topbar_state.current_system.unwrap()];

        egui::Window::new("Debug Camera Info")
            .title_bar(false)
            .show(eguictx.context(), |ui| {
            ui.vertical(|ui| {
                let selected_body_label = match camera_state.target {
                    Some(id) => current_system.bodies()[id].name(),
                    None => ""
                };

                ui.separator();

                egui::ComboBox::from_label("Camera Target")
                    .selected_text(selected_body_label)
                    .show_ui(ui, |ui| {

                    for (i, body) in current_system.bodies().iter().enumerate() {
                        ui.selectable_value(
                            &mut camera_state.target,
                            Some(i),
                            body.name());
                    }
                });

                ui.label(format!("Scale: {}", camera_state.camera_scale));
            });
        });
    }
}