summaryrefslogtreecommitdiff
path: root/src/renderer/ui.rs
blob: 2e4ebc42f9a6fe8c890c5b31c966e79887e87e34 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use egui::{Color32, Stroke, Ui, epaint::CircleShape};

use crate::{
    Camera, Config, Diagnostics, Input,
    sim::{materials::MaterialId, world::World},
};

pub fn draw_egui<'a>(
    ui: &mut Ui,
    config: &mut Config,
    camera: &mut Camera,
    diagnostics: &Diagnostics,
    input: &Input,
    world: &World,
) {
    puffin::profile_function!();
    ui.heading("Config");
    ui.add(egui::Slider::new(&mut config.brush_radius, 1.0..=100.0).text("Brush radius"));

    let material = config.brush_material.def();

    // material combobox
    egui::ComboBox::from_label("Select a material")
        .selected_text(format!(
            "Material: [{}, d={}]",
            material.name, material.density,
        ))
        .icon(move |ui, rect, _, _| {
            ui.painter().add(egui::Shape::Circle(CircleShape {
                center: rect.center(),
                radius: rect.height() / 2.0,
                stroke: Stroke::NONE,
                fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2),
            }));
        })
        .show_ui(ui, |ui| {
            for material_id in MaterialId::ALL {
                ui.selectable_value(
                    &mut config.brush_material,
                    material_id,
                    material_id.def().name,
                );
            }
        });

    ui.checkbox(&mut config.use_threading, "Use multithreading");
    ui.label(format!("Real FPS: {}", diagnostics.fps));
    ui.heading("Camera");
    ui.add(egui::Slider::new(&mut camera.zoom, 0.0..=10.0).text("Zoom"));
    ui.heading("Input");

    input.last_mouse_pos_on_screen.map(|p| {
        ui.label(format!(
            "Mouse: x,y=({x}, {y}), lmb_pressed={lmb}",
            x = p.0,
            y = p.1,
            lmb = input.is_lmb_pressed
        ))
    });

    if let Some((x, y)) = input.last_mouse_world_pos {
        ui.heading("Entity");
        ui.label(format!("x,y=({x}, {y})"));
        if let Some(cell) = world.get_cell_from_game_position(x.round() as i32, y.round() as i32) {
            let material = cell.material.def();
            let cell_label = ui.label(
                egui::RichText::new(format!("Cell: {}", material.name)).color(Color32::LIGHT_BLUE),
            );
            ui.painter().add(egui::Shape::Circle(CircleShape {
                center: cell_label.rect.right_center() + egui::vec2(10.0, 0.0),
                radius: cell_label.rect.height() / 2.5,
                stroke: Stroke::NONE,
                fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2),
            }));
            ui.label(
                egui::RichText::new(format!("Flags: {:b}", cell.flags)).color(Color32::YELLOW),
            );
            ui.label(egui::RichText::new(format!("Data: {:b}", cell.data)).color(Color32::RED));
        }
    }
}