toolbar gui parts

This commit is contained in:
Crispy 2024-10-05 15:19:27 +02:00
parent 5a23dde43a
commit 1257388168
3 changed files with 94 additions and 11 deletions

View file

@ -41,6 +41,19 @@ enum SimState {
Stepping,
}
fn load_textures_from(folder: &str, rl: &mut RaylibHandle, thread:&RaylibThread,textures:&mut HashMap<String,Texture2D>){
for d in read_dir(folder).unwrap().flatten() {
let path = d.path();
if path.is_file() {
let name = path.file_stem().unwrap().to_string_lossy();
let texture = rl
.load_texture(&thread, &format!("{folder}/{name}.png"))
.unwrap();
textures.insert(name.to_string(), texture);
}
}
}
fn main() {
let (mut rl, thread) = raylib::init()
.resizable()
@ -50,16 +63,9 @@ fn main() {
rl.set_exit_key(None);
let mut textures: HashMap<String, Texture2D> = HashMap::new();
for d in read_dir("assets/tiles").unwrap().flatten() {
let path = d.path();
if path.is_file() {
let name = path.file_stem().unwrap().to_string_lossy();
let texture = rl
.load_texture(&thread, &format!("assets/tiles/{name}.png"))
.unwrap();
textures.insert(name.to_string(), texture);
}
}
load_textures_from("assets", &mut rl, &thread, &mut textures);
load_textures_from("assets/tiles", &mut rl, &thread, &mut textures);
let mut game = Game::new_sandbox();
let board = parse(&read_to_string("boards/adder.mbl").unwrap());
game.load_board(board);
@ -210,5 +216,40 @@ impl Game {
self.machine.set_input(input_text.into_bytes());
}
let mut tool_button = |(row, col): (i32, i32), texture: &str, tool_option: Tool| {
let border = 4.;
let gap = 2.;
let bound_offset = 32. + gap * 2. + border * 2.;
texture_button(
d,
Vector2 {
x: 300. + col as f32 * bound_offset,
y: footer_top + 5. + row as f32 * bound_offset,
},
textures.get(texture),
tool_option,
&mut self.active_tool,
32.,
border,
);
};
tool_button((0, -1), "", Tool::None);
tool_button((1, -1), "eraser", Tool::SetTile(tile_to_char(' ')));
tool_button((0, 0), "block", Tool::SetTile(tile_to_char('#')));
tool_button((0, 1), "bag_off", Tool::SetTile(tile_to_char('B')));
tool_button((0, 2), "trigger_off", Tool::SetTile(tile_to_char('*')));
tool_button(
(1, 0),
"wire_horizontal_off",
Tool::SetTile(tile_to_char('-')),
);
tool_button(
(1, 1),
"wire_vertical_off",
Tool::SetTile(tile_to_char('|')),
);
tool_button((1, 2), "wire_cross_off", Tool::SetTile(tile_to_char('+')));
}
}