diff --git a/client/src/graphics/draw.rs b/client/src/graphics/draw.rs index ba11e129..52c97dd4 100644 --- a/client/src/graphics/draw.rs +++ b/client/src/graphics/draw.rs @@ -5,8 +5,8 @@ use ash::vk; use common::traversal; use lahar::Staged; use metrics::histogram; -use yakui::Color; +use super::gui::{self, GuiState}; use super::{fog, voxels, Base, Fog, Frustum, GltfScene, Meshes, Voxels}; use crate::{Asset, Config, Loader, Sim}; use common::proto::{Character, Position}; @@ -271,9 +271,11 @@ impl Draw { /// /// Submits commands that wait on `image_acquired` before writing to `framebuffer`'s color /// attachment. + #[allow(clippy::too_many_arguments)] // Every argument is of a different type, making this less of a problem. pub unsafe fn draw( &mut self, mut sim: Option<&mut Sim>, + gui_state: &GuiState, framebuffer: vk::Framebuffer, depth_view: vk::ImageView, extent: vk::Extent2D, @@ -304,18 +306,7 @@ impl Draw { self.yak.start(); if let Some(sim) = sim.as_ref() { - // Cursor - yakui::align(yakui::Alignment::CENTER, || { - yakui::colored_box(yakui::Color::BLACK.with_alpha(0.9), [5.0, 5.0]); - }); - - yakui::align(yakui::Alignment::TOP_LEFT, || { - yakui::pad(yakui::widgets::Pad::all(8.0), || { - yakui::colored_box_container(Color::BLACK.with_alpha(0.7), || { - yakui::label(format!("Selected material: {:?}", sim.selected_material())); - }); - }); - }); + gui::gui(gui_state, sim); } self.yak.finish(); diff --git a/client/src/graphics/gui.rs b/client/src/graphics/gui.rs new file mode 100644 index 00000000..ecd51f97 --- /dev/null +++ b/client/src/graphics/gui.rs @@ -0,0 +1,37 @@ +use yakui::{ + align, colored_box, colored_box_container, label, pad, widgets::Pad, Alignment, Color, +}; + +use crate::Sim; + +pub struct GuiState { + show_gui: bool, +} + +impl GuiState { + pub fn new() -> Self { + GuiState { show_gui: true } + } + + pub fn toggle_gui(&mut self) { + self.show_gui = !self.show_gui; + } +} + +pub fn gui(gui_state: &GuiState, sim: &Sim) { + if !gui_state.show_gui { + return; + } + + align(Alignment::CENTER, || { + colored_box(Color::BLACK.with_alpha(0.9), [5.0, 5.0]); + }); + + align(Alignment::TOP_LEFT, || { + pad(Pad::all(8.0), || { + colored_box_container(Color::BLACK.with_alpha(0.7), || { + label(format!("Selected material: {:?}", sim.selected_material())); + }); + }); + }); +} diff --git a/client/src/graphics/mod.rs b/client/src/graphics/mod.rs index 83622d0c..d39cd9ae 100644 --- a/client/src/graphics/mod.rs +++ b/client/src/graphics/mod.rs @@ -6,6 +6,7 @@ mod draw; mod fog; mod frustum; mod gltf_mesh; +mod gui; mod meshes; mod png_array; pub mod voxels; diff --git a/client/src/graphics/window.rs b/client/src/graphics/window.rs index 005c461e..c9b806a5 100644 --- a/client/src/graphics/window.rs +++ b/client/src/graphics/window.rs @@ -15,6 +15,7 @@ use winit::{ window::{CursorGrabMode, Window as WinitWindow, WindowBuilder}, }; +use super::gui::GuiState; use super::{Base, Core, Draw, Frustum}; use crate::Net; use crate::{net, Config, Sim}; @@ -57,6 +58,7 @@ pub struct Window { swapchain_needs_update: bool, draw: Option, sim: Option, + gui_state: GuiState, net: Net, } @@ -93,6 +95,7 @@ impl Window { swapchain_needs_update: false, draw: None, sim: None, + gui_state: GuiState::new(), net, } } @@ -261,6 +264,9 @@ impl Window { sim.toggle_no_clip(); } } + KeyCode::F1 if state == ElementState::Pressed => { + self.gui_state.toggle_gui(); + } KeyCode::Escape => { let _ = self.window.set_cursor_grab(CursorGrabMode::None); self.window.set_cursor_visible(true); @@ -352,6 +358,7 @@ impl Window { // Render the frame draw.draw( self.sim.as_mut(), + &self.gui_state, frame.buffer, frame.depth_view, swapchain.state.extent,