From 538b549e6aaaffe4b8401592bfe9995d0b5c19d2 Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sun, 5 May 2024 20:22:03 -0400 Subject: [PATCH] Show the currently-selected material in the GUI --- client/src/graphics/gui.rs | 16 ++++++++++++++-- client/src/graphics/window.rs | 4 +++- client/src/sim.rs | 4 ++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/client/src/graphics/gui.rs b/client/src/graphics/gui.rs index e0fc2351..14353cc6 100644 --- a/client/src/graphics/gui.rs +++ b/client/src/graphics/gui.rs @@ -1,4 +1,8 @@ -use yakui::{align, colored_box, Alignment, Color}; +use yakui::{ + align, colored_box, colored_box_container, label, pad, widgets::Pad, Alignment, Color, +}; + +use crate::Sim; pub struct GuiState { show_gui: bool, @@ -16,7 +20,7 @@ impl GuiState { /// Prepare the GUI for rendering. This should be called between /// Yakui::start and Yakui::finish. - pub fn run(&self) { + pub fn run(&self, sim: &Sim) { if !self.show_gui { return; } @@ -24,5 +28,13 @@ impl GuiState { 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/window.rs b/client/src/graphics/window.rs index cf27dba0..e4302df5 100644 --- a/client/src/graphics/window.rs +++ b/client/src/graphics/window.rs @@ -366,7 +366,9 @@ impl Window { [extent.width as f32, extent.height as f32].into(), )); self.yak.start(); - self.gui_state.run(); + if let Some(sim) = self.sim.as_ref() { + self.gui_state.run(sim); + } self.yak.finish(); // Render the frame draw.draw( diff --git a/client/src/sim.rs b/client/src/sim.rs index 8abfe08c..9f59582f 100644 --- a/client/src/sim.rs +++ b/client/src/sim.rs @@ -161,6 +161,10 @@ impl Sim { self.selected_material = *MATERIAL_PALETTE.get(idx).unwrap_or(&MATERIAL_PALETTE[0]); } + pub fn selected_material(&self) -> Material { + self.selected_material + } + pub fn set_break_block_pressed_true(&mut self) { self.break_block_pressed = true; }