Show extents in the world view
This commit is contained in:
parent
6df198b510
commit
3f216f85ae
|
@ -222,12 +222,12 @@ impl Widget for CharacterGrid<'_> {
|
|||
for x in (1..grid_width_cells).map(|i| (i as f32) * cell_size) {
|
||||
let p1 = (res.rect.min.x + x, res.rect.min.y).into();
|
||||
let p2 = (res.rect.min.x + x, res.rect.max.y).into();
|
||||
painter.line(vec![p1, p2], stroke);
|
||||
painter.line_segment([p1, p2], stroke);
|
||||
}
|
||||
for y in (1..grid_height_cells).map(|i| (i as f32) * cell_size) {
|
||||
let p1 = (res.rect.min.x, res.rect.min.y + y).into();
|
||||
let p2 = (res.rect.max.x, res.rect.min.y + y).into();
|
||||
painter.line(vec![p1, p2], stroke);
|
||||
painter.line_segment([p1, p2], stroke);
|
||||
}
|
||||
}
|
||||
if let Some(selected) = self.selected {
|
||||
|
|
|
@ -33,6 +33,7 @@ pub struct WorldWindow {
|
|||
index: usize,
|
||||
param_index: usize,
|
||||
generic_palette: bool,
|
||||
show_extents: bool,
|
||||
params: ImageParams<WorldParams>,
|
||||
scale: f32,
|
||||
}
|
||||
|
@ -57,6 +58,7 @@ impl WorldWindow {
|
|||
index: params.index,
|
||||
param_index: 0,
|
||||
generic_palette: params.generic_palette,
|
||||
show_extents: false,
|
||||
params,
|
||||
scale: 1.0,
|
||||
}
|
||||
|
@ -413,6 +415,7 @@ impl WorldWindow {
|
|||
ui.add(slider);
|
||||
});
|
||||
ui.checkbox(&mut self.generic_palette, "Generic palette");
|
||||
ui.checkbox(&mut self.show_extents, "Show extents");
|
||||
});
|
||||
});
|
||||
self.params.write(WorldParams {
|
||||
|
@ -426,7 +429,82 @@ impl WorldWindow {
|
|||
let image = Image::new("vip://world")
|
||||
.fit_to_original_size(self.scale)
|
||||
.texture_options(TextureOptions::NEAREST);
|
||||
ui.add(image);
|
||||
let res = ui.add(image);
|
||||
if self.show_extents {
|
||||
let world = {
|
||||
let worlds = self.worlds.borrow();
|
||||
let data = worlds.read(self.index);
|
||||
World::parse(&data)
|
||||
};
|
||||
if world.header.mode == WorldMode::Object {
|
||||
return;
|
||||
}
|
||||
|
||||
let lx1 = (world.dst_x - world.dst_parallax) as f32 * self.scale;
|
||||
let lx2 = lx1 + world.width as f32 * self.scale;
|
||||
let rx1 = (world.dst_x + world.dst_parallax) as f32 * self.scale;
|
||||
let rx2 = rx1 + world.width as f32 * self.scale;
|
||||
let y1 = world.dst_y as f32 * self.scale;
|
||||
let y2 = y1 + world.height as f32 * self.scale;
|
||||
|
||||
let left_color = self.params.left_color;
|
||||
let right_color = self.params.right_color;
|
||||
let both_color = Color32::from_rgb(
|
||||
left_color.r() + right_color.r(),
|
||||
left_color.g() + right_color.g(),
|
||||
left_color.b() + right_color.b(),
|
||||
);
|
||||
|
||||
let painter = ui.painter();
|
||||
let draw_rect = |x1: f32, x2: f32, color: Color32| {
|
||||
painter.line(
|
||||
vec![
|
||||
res.rect.min + (x1, y1).into(),
|
||||
res.rect.min + (x2, y1).into(),
|
||||
res.rect.min + (x2, y2).into(),
|
||||
res.rect.min + (x1, y2).into(),
|
||||
res.rect.min + (x1, y1).into(),
|
||||
],
|
||||
(2.0, color),
|
||||
)
|
||||
};
|
||||
|
||||
match (world.header.lon, world.header.ron) {
|
||||
(false, false) => {}
|
||||
(true, false) => {
|
||||
draw_rect(lx1, lx2, left_color);
|
||||
}
|
||||
(false, true) => {
|
||||
draw_rect(rx1, rx2, right_color);
|
||||
}
|
||||
(true, true) if world.dst_parallax == 0 => {
|
||||
draw_rect(lx1, lx2, both_color);
|
||||
}
|
||||
(true, true) => {
|
||||
draw_rect(lx1, lx2, left_color);
|
||||
draw_rect(rx1, rx2, right_color);
|
||||
let (x1, x2) = if world.dst_parallax < 0 {
|
||||
(lx1, rx2)
|
||||
} else {
|
||||
(rx1, lx2)
|
||||
};
|
||||
painter.line_segment(
|
||||
[
|
||||
res.rect.min + (x1, y1).into(),
|
||||
res.rect.min + (x2 + 1.0, y1).into(),
|
||||
],
|
||||
(2.0, both_color),
|
||||
);
|
||||
painter.line_segment(
|
||||
[
|
||||
res.rect.min + (x1, y2).into(),
|
||||
res.rect.min + (x2 + 1.0, y2).into(),
|
||||
],
|
||||
(2.0, both_color),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -442,7 +520,7 @@ impl AppWindow for WorldWindow {
|
|||
fn initial_viewport(&self) -> ViewportBuilder {
|
||||
ViewportBuilder::default()
|
||||
.with_title(format!("Worlds ({})", self.sim_id))
|
||||
.with_inner_size((640.0, 500.0))
|
||||
.with_inner_size((640.0, 520.0))
|
||||
}
|
||||
|
||||
fn on_init(&mut self, ctx: &Context, _render_state: &egui_wgpu::RenderState) {
|
||||
|
|
Loading…
Reference in New Issue