diff --git a/README.md b/README.md index aed599b..46000d9 100644 --- a/README.md +++ b/README.md @@ -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 level list scroll blueprint list make marble movement more consistent (`>o o<` depends on internal marble order) decide on marble data size (u32 or byte?) diff --git a/src/main.rs b/src/main.rs index 43d43c7..05f9485 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ use util::*; struct Game { levels: Vec, + level_scroll: usize, solutions: HashMap>, open_editor: Option, textures: Textures, @@ -51,6 +52,7 @@ impl Game { Self { levels: get_levels(), + level_scroll: 0, solutions: get_solutions(), open_editor: None, textures, @@ -100,9 +102,19 @@ impl Game { let clicked = d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT); let mouse_pos = d.get_mouse_position(); + let scroll_delta = d.get_mouse_wheel_move(); - for (i, level) in self.levels.iter().enumerate() { + if mouse_pos.x < level_list_width as f32 { + if scroll_delta < 0. && self.level_scroll < self.levels.len().saturating_sub(5) { + self.level_scroll += 1; + } else if scroll_delta > 0. && self.level_scroll > 0 { + self.level_scroll -= 1; + } + } + + for (i, level) in self.levels[self.level_scroll..].iter().enumerate() { let level_entry_height = 65; + let index = i + self.level_scroll; let y = 10 + i as i32 * level_entry_height; let bounds = Rectangle { x: 5., @@ -110,12 +122,15 @@ impl Game { width: level_list_width as f32 - 10., height: level_entry_height as f32 - 5., }; - if clicked && bounds.check_collision_point_rec(mouse_pos) && self.selected_level != i { + if clicked + && bounds.check_collision_point_rec(mouse_pos) + && self.selected_level != index + { self.selected_solution = 0; self.editing_solution_name = false; - self.selected_level = i; + self.selected_level = index; } - if self.selected_level == i { + if self.selected_level == index { d.draw_rectangle_rec(bounds, Color::DARKCYAN); }