diff --git a/CHANGELOG.md b/CHANGELOG.md index 47e2c19..ca5144f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Game store page: https://crispypin.itch.io/marble-machinations ## [unreleased] ### added - option to display power direction while overlay is enabled +- show level name in end popup ### changed - hide tick timing numbers by default diff --git a/README.md b/README.md index a78b159..94d6f75 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble - more levels - packet routing? - game of life sim (width;height;steps;grid -> grid) -- show level name in end popup - shrink button #### 0.4.0 - UI layout engine diff --git a/src/editor.rs b/src/editor.rs index 87f8581..e3a34fa 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -24,7 +24,7 @@ const HEADER_HEIGHT: i32 = 40; const FOOTER_HEIGHT: i32 = 95; const SIDEBAR_WIDTH: i32 = 200 + 32 * 2 + 5 * 4; const END_POPUP_WIDTH: i32 = 320; -const END_POPUP_HEIGHT: i32 = 225; +const END_POPUP_HEIGHT: i32 = 255; const MAX_ZOOM: f32 = 8.; const MIN_ZOOM: f32 = 0.25; @@ -85,10 +85,10 @@ enum Action { SetArea(ResizeDeltas, Pos, Board, Board), } -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Debug, PartialEq, Clone)] enum Popup { None, - Success, + Success(Score), Failure, LevelInfo, PauseMenu, @@ -316,7 +316,7 @@ impl Editor { self.machine.step(); if let Some(i) = self.stage { - if matches!(self.popup, Popup::Failure | Popup::Success) { + if matches!(self.popup, Popup::Failure | Popup::Success(_)) { self.popup = Popup::None; self.dismissed_end = true; } @@ -328,15 +328,16 @@ impl Editor { self.total_steps += self.machine.step_count(); self.reset_machine(); } else { - self.popup = Popup::Success; println!("completed in {:?}", self.start_time.elapsed()); self.exit_state = ExitState::Save; self.sim_state = SimState::Stepping; - self.score = Some(Score { + let score = Score { cycles: self.total_steps + self.machine.step_count(), tiles: self.source_board.grid.count_tiles(), bounds_area: self.source_board.grid.used_bounds_area(), - }); + }; + self.score = Some(score.clone()); + self.popup = Popup::Success(score); } } else if !stage.output().as_bytes().starts_with(self.machine.output()) { self.popup = Popup::Failure; @@ -439,7 +440,7 @@ impl Editor { if globals.is_pressed(ActionId::ToggleMenu) { self.popup = match self.popup { - Popup::Success | Popup::Failure => { + Popup::Success(_) | Popup::Failure => { self.dismissed_end = true; Popup::None } @@ -666,7 +667,7 @@ impl Editor { } match self.popup { - Popup::Success | Popup::Failure => { + Popup::Success(_) | Popup::Failure => { self.draw_end_popup(d, &globals.textures); } Popup::LevelInfo => { @@ -766,38 +767,35 @@ impl Editor { fn draw_end_popup(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) { let bounds = screen_centered_rect(d, END_POPUP_WIDTH, END_POPUP_HEIGHT); let x = bounds.x as i32; - let y = bounds.y as i32; + let mut y = bounds.y as i32 + 10; d.draw_rectangle_rec(bounds, BG_DARK); - if self.popup == Popup::Success { - d.draw_text("Level Complete!", x + 45, y + 10, 30, Color::LIME); - if let Some(score) = &self.score { - d.draw_text("cycles", x + 15, y + 40, 20, Color::WHITE); - draw_usize(d, textures, score.cycles, (x + 110, y + 40), 9, 2); - d.draw_text("tiles", x + 15, y + 80, 20, Color::WHITE); - draw_usize(d, textures, score.tiles, (x + 110, y + 80), 9, 2); - d.draw_text("bounds", x + 15, y + 120, 20, Color::WHITE); - draw_usize(d, textures, score.bounds_area, (x + 110, y + 120), 9, 2); - } - let y = y + 60; - if simple_button((d, &self.mouse), x + 10, y + 110, 140, 45) { + if let Popup::Success(score) = &self.popup { + d.draw_text("Level Complete!", x + 45, y, 30, Color::LIME); + y += 30; + d.draw_text(self.level.name(), x + 10, y, 20, Color::GRAY); + y += 30; + d.draw_text("cycles", x + 15, y, 20, Color::WHITE); + draw_usize(d, textures, score.cycles, (x + 110, y), 9, 2); + y += 40; + d.draw_text("tiles", x + 15, y, 20, Color::WHITE); + draw_usize(d, textures, score.tiles, (x + 110, y), 9, 2); + y += 40; + d.draw_text("bounds", x + 15, y, 20, Color::WHITE); + draw_usize(d, textures, score.bounds_area, (x + 110, y), 9, 2); + y += 40; + if simple_button((d, &self.mouse), x + 10, y, 140, 50) { self.popup = Popup::None; self.dismissed_end = true; } - d.draw_text("continue\nediting", x + 15, y + 115, 20, Color::WHITE); + d.draw_text("continue\nediting", x + 15, y + 5, 20, Color::WHITE); - if simple_button( - (d, &self.mouse), - x + END_POPUP_WIDTH / 2 + 5, - y + 110, - 140, - 45, - ) { + if simple_button((d, &self.mouse), x + END_POPUP_WIDTH / 2 + 5, y, 140, 50) { self.exit_state = ExitState::ExitAndSave; } d.draw_text( "return to\nlevel list", x + END_POPUP_WIDTH / 2 + 10, - y + 115, + y + 5, 20, Color::WHITE, ); diff --git a/src/marble_engine/grid.rs b/src/marble_engine/grid.rs index 1a60af9..75a1475 100644 --- a/src/marble_engine/grid.rs +++ b/src/marble_engine/grid.rs @@ -285,7 +285,14 @@ impl Grid { out } - pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, scale: f32, power_directions: bool) { + pub fn draw( + &self, + d: &mut RaylibDrawHandle, + textures: &Textures, + offset: Vector2, + scale: f32, + power_directions: bool, + ) { let tile_size = (TILE_TEXTURE_SIZE * scale) as i32; let start_x = (-offset.x as i32) / tile_size - 1; @@ -304,14 +311,14 @@ impl Grid { } let texture = textures.get(texname); draw_scaled_texture(d, texture, px, py, scale); - if power_directions - { - if let Tile::Powerable(_, state) = &tile { - for dir in Direction::ALL { - if state.get_dir(dir) { - let texture = textures.get(dir.debug_arrow_texture_name()); - draw_scaled_texture(d, texture, px, py, scale); - }} + if power_directions { + if let Tile::Powerable(_, state) = &tile { + for dir in Direction::ALL { + if state.get_dir(dir) { + let texture = textures.get(dir.debug_arrow_texture_name()); + draw_scaled_texture(d, texture, px, py, scale); + } + } } } } else { diff --git a/src/solution.rs b/src/solution.rs index 9601c82..0308fb3 100644 --- a/src/solution.rs +++ b/src/solution.rs @@ -18,7 +18,7 @@ pub struct Solution { pub score: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Score { pub cycles: usize, pub tiles: usize,