basic scrolling in level list

This commit is contained in:
Crispy 2024-10-10 21:36:03 +02:00
parent b5b77b89f9
commit e42e14489d
2 changed files with 19 additions and 5 deletions

View file

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

View file

@ -19,6 +19,7 @@ use util::*;
struct Game { struct Game {
levels: Vec<Level>, levels: Vec<Level>,
level_scroll: usize,
solutions: HashMap<String, Vec<Solution>>, solutions: HashMap<String, Vec<Solution>>,
open_editor: Option<Editor>, open_editor: Option<Editor>,
textures: Textures, textures: Textures,
@ -51,6 +52,7 @@ impl Game {
Self { Self {
levels: get_levels(), levels: get_levels(),
level_scroll: 0,
solutions: get_solutions(), solutions: get_solutions(),
open_editor: None, open_editor: None,
textures, textures,
@ -100,9 +102,19 @@ impl Game {
let clicked = d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT); let clicked = d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT);
let mouse_pos = d.get_mouse_position(); 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 level_entry_height = 65;
let index = i + self.level_scroll;
let y = 10 + i as i32 * level_entry_height; let y = 10 + i as i32 * level_entry_height;
let bounds = Rectangle { let bounds = Rectangle {
x: 5., x: 5.,
@ -110,12 +122,15 @@ impl Game {
width: level_list_width as f32 - 10., width: level_list_width as f32 - 10.,
height: level_entry_height as f32 - 5., 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.selected_solution = 0;
self.editing_solution_name = false; 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); d.draw_rectangle_rec(bounds, Color::DARKCYAN);
} }