Skip to content

Commit

Permalink
Show the currently-selected material in the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
patowen authored and Ralith committed May 10, 2024
1 parent 93a4041 commit 538b549
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 14 additions & 2 deletions client/src/graphics/gui.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,13 +20,21 @@ 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;
}

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()));
});
});
});
}
}
4 changes: 3 additions & 1 deletion client/src/graphics/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions client/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 538b549

Please sign in to comment.