Skip to content

Commit

Permalink
Add display tile id toggle (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs authored May 27, 2024
1 parent 392a9cb commit 66c8e1c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
28 changes: 28 additions & 0 deletions crates/components/src/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub struct MapView {

pub darken_unselected_layers: bool,

/// Whether to display the tile IDs on the map
pub display_tile_ids: bool,

pub scale: f32,
pub previous_scale: f32,

Expand Down Expand Up @@ -161,6 +164,8 @@ impl MapView {

selected_event_is_hovered: false,

display_tile_ids: false,

scale,
previous_scale: scale,

Expand Down Expand Up @@ -611,6 +616,29 @@ impl MapView {
);
}

// FIXME: If we want to be fast, we should be rendering all the tile ids to a texture once and then just rendering that texture here
if self.display_tile_ids {
if let SelectedLayer::Tiles(layer) = self.selected_layer {
for (i, id) in map.data.layer_as_slice(layer).iter().copied().enumerate() {
let x = i % map.data.xsize();
let y = i / map.data.xsize();

let tile_x = x as f32 * tile_size;
let tile_y = y as f32 * tile_size;
let tile_pos = egui::Pos2::new(tile_x, tile_y)
+ egui::Vec2::splat(tile_size / 2.0)
+ map_rect.min.to_vec2();
ui.painter().text(
tile_pos,
egui::Align2::CENTER_CENTER,
id.to_string(),
egui::FontId::monospace(12. * scale),
egui::Color32::WHITE,
);
}
}
}

// Do we display the visible region?
if self.visible_display {
// Determine the visible region.
Expand Down
29 changes: 18 additions & 11 deletions crates/ui/src/tabs/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl luminol_core::Tab for Tab {
self.brush_density = update_state.toolbar.brush_density;

// Display the toolbar.
// FIXME: find a proper place for this toolbar! it looks very out of place right now.
egui::TopBottomPanel::top(format!("map_{}_toolbar", self.id)).show_inside(ui, |ui| {
ui.horizontal_wrapped(|ui| {
ui.add(
Expand Down Expand Up @@ -285,17 +286,23 @@ impl luminol_core::Tab for Tab {

ui.separator();

ui.checkbox(&mut self.view.visible_display, "Display visible area")
.on_hover_text("Display the visible area in-game (640x480)");
ui.checkbox(&mut self.view.move_preview, "Preview event move routes")
.on_hover_text("Preview event page move routes");
ui.checkbox(&mut self.view.snap_to_grid, "Snap to grid")
.on_hover_text("Snaps the viewport to the tile grid");
ui.checkbox(
&mut self.view.darken_unselected_layers,
"Darken unselected layers",
)
.on_hover_text("Toggles darkening unselected layers");
ui.menu_button("Display options ⏷", |ui| {
ui.checkbox(&mut self.view.visible_display, "Display visible area")
.on_hover_text("Display the visible area in-game (640x480)");
ui.checkbox(&mut self.view.move_preview, "Preview event move routes")
.on_hover_text("Preview event page move routes");
ui.checkbox(&mut self.view.snap_to_grid, "Snap to grid")
.on_hover_text("Snaps the viewport to the tile grid");
ui.checkbox(
&mut self.view.darken_unselected_layers,
"Darken unselected layers",
)
.on_hover_text("Toggles darkening unselected layers");
ui.checkbox(&mut self.view.display_tile_ids, "Display tile IDs")
.on_disabled_hover_text(
"Display the tile IDs of the currently selected layer",
);
});

/*
if ui.button("Save map preview").clicked() {
Expand Down

0 comments on commit 66c8e1c

Please sign in to comment.