diff --git a/src/app.rs b/src/app.rs index 9911072..612b454 100644 --- a/src/app.rs +++ b/src/app.rs @@ -275,6 +275,7 @@ impl TemplateApp { let dimensions = &mut self.dimensions; if let Some(i) = compute_landscape_image( + &self.ui_data.landscape_settings, dimensions, &self.land_records, &self.ltex_records, diff --git a/src/background/landscape.rs b/src/background/landscape.rs index b0f8f2e..2b15f92 100644 --- a/src/background/landscape.rs +++ b/src/background/landscape.rs @@ -5,12 +5,13 @@ use log::info; use tes3::esp::{Landscape, LandscapeFlags, LandscapeTexture}; use crate::{ - height_from_screen_space, overlay_colors_with_alpha, CellKey, Dimensions, DEFAULT_COLOR, - GRID_SIZE, VERTEX_CNT, + height_from_screen_space, overlay_colors_with_alpha, CellKey, Dimensions, LandscapeSettings, + DEFAULT_COLOR, GRID_SIZE, VERTEX_CNT, }; /// Compute a landscape image from the given landscape records and texture map. pub fn compute_landscape_image( + settings: &LandscapeSettings, dimensions: &Dimensions, landscape_records: &HashMap, ltex_records: &HashMap, @@ -58,27 +59,34 @@ pub fn compute_landscape_image( let index = (y * d.texture_size) + x; let mut color = texture.pixels[index]; - // blend color when under water let tx = d.tranform_to_canvas_x(cx) * d.cell_size() + gx * d.texture_size + x; let ty = d.tranform_to_canvas_y(cy) * d.cell_size() + (GRID_SIZE - 1 - gy) * d.texture_size + y; - let screenx = tx * VERTEX_CNT / d.cell_size(); - let screeny = ty * VERTEX_CNT / d.cell_size(); - if let Some(height) = height_from_screen_space( - heights, dimensions, screenx, screeny, - ) { - if height < 0_f32 { - let a = 0.5; + // blend color when under water + if settings.show_water { + let screenx = tx * VERTEX_CNT / d.cell_size(); + let screeny = ty * VERTEX_CNT / d.cell_size(); + + if let Some(height) = height_from_screen_space( + heights, dimensions, screenx, screeny, + ) { + if height < 0_f32 { + let a = 0.5; - color = overlay_colors_with_alpha( - color, - Color32::BLUE, - a, - ); + if settings.remove_water { + color = Color32::TRANSPARENT; + } else { + color = overlay_colors_with_alpha( + color, + Color32::BLUE, + a, + ); + } + } } } diff --git a/src/lib.rs b/src/lib.rs index afb58ca..b4e0582 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,8 @@ pub enum EBackground { #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct LandscapeSettings { pub texture_size: usize, // landscape + pub show_water: bool, + pub remove_water: bool, } impl Default for LandscapeSettings { @@ -56,6 +58,8 @@ impl Default for LandscapeSettings { Self { // landscape texture_size: 16, + show_water: true, + remove_water: false, } } } diff --git a/src/views/settings.rs b/src/views/settings.rs index 57b4a05..ccd2e91 100644 --- a/src/views/settings.rs +++ b/src/views/settings.rs @@ -115,16 +115,39 @@ impl TemplateApp { } fn landscape_settings_ui(&mut self, ui: &mut Ui, ctx: &egui::Context) { - let settings = &mut self.ui_data.landscape_settings; ui.label("Landscape settings"); + ui.checkbox(&mut self.ui_data.realtime_update, "Realtime update"); + let max_texture_side = ctx.input(|i| i.max_texture_side); let max_texture_resolution = self.dimensions.get_max_texture_resolution(max_texture_side); ui.add( - egui::Slider::new(&mut settings.texture_size, 2..=max_texture_resolution) - .text("Texture Resolution"), + egui::Slider::new( + &mut self.ui_data.landscape_settings.texture_size, + 2..=max_texture_resolution, + ) + .text("Texture Resolution"), ); + + if ui + .checkbox( + &mut self.ui_data.landscape_settings.show_water, + "Render water", + ) + .changed() + { + self.reload_background(ctx, None, false, false); + } + if ui + .checkbox( + &mut self.ui_data.landscape_settings.remove_water, + "Clip water", + ) + .changed() + { + self.reload_background(ctx, None, false, false); + } } fn heightmap_settings_ui(&mut self, ui: &mut Ui, ctx: &egui::Context) {