From f30e42cb312e43cd0234071639b4f765de5222b1 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sun, 6 Oct 2024 20:12:02 +0200 Subject: [PATCH] display level descriptions, increased font sizes in level selection --- levels/00_zeroes.json | 2 +- src/level.rs | 15 ------------- src/main.rs | 50 +++++++++++++++++++++++++++---------------- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/levels/00_zeroes.json b/levels/00_zeroes.json index 42467fc..2094e3b 100644 --- a/levels/00_zeroes.json +++ b/levels/00_zeroes.json @@ -1,7 +1,7 @@ { "id": "00_zeroes", "name": "Zeroes", - "description": "learn how to output data", + "description": "learn how to output data\nthis is a multi-line test", "init_board": null, "inputs": [], "outputs": [0, 0, 0, 0, 0, 0, 0, 0] diff --git a/src/level.rs b/src/level.rs index fa72dcf..803a42c 100644 --- a/src/level.rs +++ b/src/level.rs @@ -11,17 +11,6 @@ pub struct Level { } impl Level { - pub fn new_sandbox() -> Self { - Self { - id: "sandbox".into(), - name: "Sandbox".into(), - description: String::new(), - init_board: None, - inputs: Vec::new(), - outputs: Vec::new(), - } - } - pub fn id(&self) -> &str { &self.id } @@ -34,10 +23,6 @@ impl Level { &self.description } - // pub fn init_board(&self) -> Option { - // self.init_board.as_deref().map(Board::parse) - // } - pub fn init_board(&self)->Option{ self.init_board.clone() } diff --git a/src/main.rs b/src/main.rs index 6fab1ea..8e9ed0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,7 +98,7 @@ impl Game { let mouse_pos = d.get_mouse_position(); for (i, level) in self.levels.iter().enumerate() { - let level_entry_height = 48; + let level_entry_height = 65; let y = 10 + i as i32 * level_entry_height; let bounds = Rectangle { x: 5., @@ -114,7 +114,7 @@ impl Game { if self.selected_level == i { d.draw_rectangle_rec(bounds, Color::DARKCYAN); } - d.draw_text(level.name(), 10, y, 20, Color::WHITE); + d.draw_text(level.name(), 10, y, 30, Color::WHITE); let solution_count = self .solutions .get(level.id()) @@ -126,23 +126,29 @@ impl Game { } else { Color::LIGHTGRAY }; - d.draw_text(&subtext, 10, y + 20, 10, subtext_color); + d.draw_text(&subtext, 10, y + 30, 20, subtext_color); } if let Some(level) = self.levels.get(self.selected_level) { - d.draw_text(level.name(), level_list_width + 10, 10, 30, Color::CYAN); - d.draw_text(level.id(), level_list_width + 10, 40, 10, Color::GRAY); + d.draw_text(level.name(), level_list_width + 10, 10, 40, Color::CYAN); + d.draw_text(level.id(), level_list_width + 10, 50, 10, Color::GRAY); + + let mut y = 70; + for line in level.description().lines() { + d.draw_text(line, level_list_width + 10, y, 20, Color::WHITE); + y += 30; + } - let mut y = 60; if let Some(solutions) = self.solutions.get_mut(level.id()) { let solution_entry_height = 40; - let solution_entry_width = 200; + let entry_width = 200; + let mut solution_y = y; for (solution_index, solution) in solutions.iter().enumerate() { if simple_option_button( d, level_list_width + 10, - y, - solution_entry_width, + solution_y, + entry_width, solution_entry_height, solution_index, &mut self.selected_solution, @@ -154,33 +160,39 @@ impl Game { } else { Color::ORANGE }; - d.draw_text(&solution.name, level_list_width + 15, y + 5, 20, name_color); + d.draw_text( + &solution.name, + level_list_width + 15, + solution_y + 5, + 20, + name_color, + ); d.draw_text( &solution.score_text(), level_list_width + 15, - y + 25, + solution_y + 25, 10, Color::WHITE, ); - y += solution_entry_height + 10; + solution_y += solution_entry_height + 10; } - if simple_button(d, level_list_width + 10, y, solution_entry_width, 30) { + if simple_button(d, level_list_width + 10, solution_y, entry_width, 30) { let n = solutions.len(); solutions.push(Solution::new(&level, n)); } d.draw_text( "new solution", level_list_width + 15, - y + 5, + solution_y + 5, 20, Color::WHITE, ); if let Some(solution) = solutions.get_mut(self.selected_solution) { let bounds = Rectangle { - x: (level_list_width + 10 + solution_entry_width + 10) as f32, - y: 60., + x: (level_list_width + 10 + entry_width + 10) as f32, + y: y as f32, width: 220., height: 30., }; @@ -191,11 +203,11 @@ impl Game { &mut self.editing_solution_name, ); - let button_x = level_list_width + solution_entry_width + 20; - if simple_button(d, button_x, 100, 220, 30) { + let button_x = level_list_width + entry_width + 20; + if simple_button(d, button_x, y + 40, 220, 30) { self.open_editor = Some(Editor::new(solution.clone(), level.clone())); } - d.draw_text("edit", button_x + 5, 105, 20, Color::WHITE); + d.draw_text("edit", button_x + 5, y + 45, 20, Color::WHITE); } } else { self.solutions.insert(level.id().to_owned(), Vec::new());