option to hide grid and marble direction/value

This commit is contained in:
Crispy 2024-12-10 21:50:46 +01:00
parent 5b1b923c73
commit 59aeeff5b6
3 changed files with 59 additions and 24 deletions

View file

@ -17,7 +17,7 @@ use crate::{
tile::{Claim, Direction, GateType, MathOp, MirrorType, OpenTile, PTile, Tile, WireType},
Machine,
},
simple_button, simple_option_button, slider,
simple_button, simple_option_button, simple_toggle_button, slider,
solution::{Score, Solution},
text_input, texture_option_button,
theme::*,
@ -65,6 +65,7 @@ pub struct Editor {
max_step_time: u128,
start_time: Instant,
pasting_board: Option<Board>,
draw_overlay: bool,
}
#[derive(Debug, PartialEq)]
@ -144,6 +145,7 @@ impl Editor {
max_step_time: 0,
start_time: Instant::now(),
pasting_board: None,
draw_overlay: true,
}
}
@ -192,9 +194,7 @@ impl Editor {
if self.popup != EndPopup::None {
self.popup = EndPopup::Dismissed;
}
if !self.level.outputs().is_empty()
&& self.popup == EndPopup::None
{
if !self.level.outputs().is_empty() && self.popup == EndPopup::None {
if self.level.outputs() == self.machine.output() {
self.popup = EndPopup::Success;
println!("completed in {:?}", self.start_time.elapsed());
@ -432,14 +432,17 @@ impl Editor {
self.machine
.board()
.draw(d, textures, self.view_offset, self.zoom);
if self.draw_overlay {
self.machine
.draw_marble_values(d, textures, self.view_offset, self.zoom);
}
}
}
pub fn draw(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) {
d.clear_background(Color::new(64, 64, 64, 255));
if self.draw_overlay {
let tile_size = (16 << self.zoom) as f32;
let grid_spill_x = (self.view_offset.x).rem(tile_size) - tile_size;
let grid_spill_y = (self.view_offset.y).rem(tile_size) - tile_size;
@ -454,6 +457,7 @@ impl Editor {
tile_size,
1,
);
}
self.draw_board(d, textures);
self.board_overlay(d, textures);
@ -592,6 +596,8 @@ impl Editor {
d.draw_text("save", 90, 10, 20, Color::WHITE);
}
simple_toggle_button(d, &mut self.draw_overlay, 235, 4, 20, 32, 4);
match self.sim_state {
SimState::Editing => {
if simple_button(d, 260, 4, 32, 32) {

View file

@ -57,10 +57,7 @@ impl Solution {
pub fn score_text(&self) -> String {
if let Some(score) = &self.score {
format!(
"C: {} T: {}",
score.cycles, score.tiles
)
format!("C: {} T: {}", score.cycles, score.tiles)
} else {
"unsolved".into()
}

View file

@ -44,6 +44,38 @@ pub fn simple_button(d: &mut RaylibDrawHandle, x: i32, y: i32, width: i32, heigh
pressed
}
pub fn simple_toggle_button(
d: &mut RaylibDrawHandle,
state: &mut bool,
x: i32,
y: i32,
width: i32,
height: i32,
margin: i32,
) {
let mouse_pos = d.get_mouse_position();
let bounds = Rectangle {
x: x as f32,
y: y as f32,
width: width as f32,
height: height as f32,
};
let hover = bounds.check_collision_point_rec(mouse_pos);
d.draw_rectangle(x, y, width, height, widget_bg(hover));
if *state {
d.draw_rectangle(
x + margin,
y + margin,
width - margin * 2,
height - margin * 2,
BG_DARK,
);
}
if hover && d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) {
*state = !*state;
}
}
pub fn simple_option_button<T>(
d: &mut RaylibDrawHandle,
x: i32,