basic scrolling in blueprint list

This commit is contained in:
Crispy 2024-10-10 21:56:36 +02:00
parent e42e14489d
commit ce90a22ea0
2 changed files with 33 additions and 7 deletions

View file

@ -14,7 +14,6 @@ fix bag tiles only counting power in one direction at once
tooltips
lock tile types for early levels to make it less overwhelming
make a gui alternative to pressing R to rotate between tile variants
scroll blueprint list
make marble movement more consistent (`>o o<` depends on internal marble order)
decide on marble data size (u32 or byte?)
blueprint rotation?

View file

@ -55,6 +55,7 @@ pub struct Editor {
score: Option<Score>,
blueprints: Vec<Blueprint>,
selected_blueprint: usize,
blueprint_scroll: usize,
}
#[derive(Debug, PartialEq)]
@ -123,6 +124,7 @@ impl Editor {
score: solution.score,
blueprints: get_blueprints(),
selected_blueprint: usize::MAX,
blueprint_scroll: 0,
}
}
@ -358,11 +360,17 @@ impl Editor {
}
}
if rl.get_mouse_wheel_move() > 0. {
self.zoom_in(rl);
}
if rl.get_mouse_wheel_move() < 0. {
self.zoom_out(rl);
let mouse_pos = rl.get_mouse_position();
if self.active_tool != Tool::Blueprint
|| self.sim_state != SimState::Editing
|| mouse_pos.x > SIDEBAR_WIDTH as f32
{
if rl.get_mouse_wheel_move() > 0. {
self.zoom_in(rl);
}
if rl.get_mouse_wheel_move() < 0. {
self.zoom_out(rl);
}
}
if rl.is_mouse_button_down(MouseButton::MOUSE_BUTTON_MIDDLE) {
self.view_offset += rl.get_mouse_delta();
@ -423,7 +431,16 @@ impl Editor {
);
d.draw_text("Blueprints", 10, HEADER_HEIGHT + 30, 20, Color::WHITE);
let mut y = HEADER_HEIGHT + 60;
for (i, b) in self.blueprints.iter_mut().enumerate() {
let blueprints_shown = (sidebar_height as usize - 45) / 37;
let end = self
.blueprints
.len()
.min(blueprints_shown + self.blueprint_scroll);
for (i, b) in self.blueprints[self.blueprint_scroll..end]
.iter_mut()
.enumerate()
{
let i = i + self.blueprint_scroll;
if simple_button(d, 5, y, 32, 32) {
b.remove_file();
self.blueprints.remove(i);
@ -793,6 +810,7 @@ impl Editor {
fn board_overlay(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) {
let footer_top = (d.get_screen_height() - FOOTER_HEIGHT) as f32;
let mouse_pos = d.get_mouse_position();
let scroll_delta = d.get_mouse_wheel_move();
let tile_scale = (1 << self.zoom) as f32;
let tile_size = 16 << self.zoom;
if self.sim_state == SimState::Editing {
@ -936,6 +954,15 @@ impl Editor {
offset += view_offset;
bp.convert_board().draw(d, textures, offset, self.zoom);
}
if mouse_pos.x < SIDEBAR_WIDTH as f32 {
if scroll_delta < 0.
&& self.blueprint_scroll < self.blueprints.len().saturating_sub(5)
{
self.blueprint_scroll += 1;
} else if scroll_delta > 0. && self.blueprint_scroll > 0 {
self.blueprint_scroll -= 1;
}
}
}
}
// draw selection