show fail popup when output is wrong
This commit is contained in:
parent
14b87e6971
commit
70c745117f
1 changed files with 42 additions and 25 deletions
|
@ -56,8 +56,7 @@ pub struct Editor {
|
||||||
time_since_step: f32,
|
time_since_step: f32,
|
||||||
exit_state: ExitState,
|
exit_state: ExitState,
|
||||||
exit_menu: bool,
|
exit_menu: bool,
|
||||||
complete_popup: Popup,
|
popup: EndPopup,
|
||||||
// fail_popup: Popup,
|
|
||||||
score: Option<Score>,
|
score: Option<Score>,
|
||||||
blueprints: Vec<Blueprint>,
|
blueprints: Vec<Blueprint>,
|
||||||
selected_blueprint: usize,
|
selected_blueprint: usize,
|
||||||
|
@ -69,9 +68,10 @@ pub struct Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum Popup {
|
enum EndPopup {
|
||||||
Start,
|
None,
|
||||||
Visible,
|
Success,
|
||||||
|
Failure,
|
||||||
Dismissed,
|
Dismissed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,8 +135,7 @@ impl Editor {
|
||||||
level,
|
level,
|
||||||
exit_state: ExitState::Dont,
|
exit_state: ExitState::Dont,
|
||||||
exit_menu: false,
|
exit_menu: false,
|
||||||
complete_popup: Popup::Start,
|
popup: EndPopup::None,
|
||||||
// fail_popup: Popup::Start,
|
|
||||||
score: solution.score,
|
score: solution.score,
|
||||||
blueprints: get_blueprints(),
|
blueprints: get_blueprints(),
|
||||||
selected_blueprint: usize::MAX,
|
selected_blueprint: usize::MAX,
|
||||||
|
@ -190,21 +189,25 @@ impl Editor {
|
||||||
fn step(&mut self) {
|
fn step(&mut self) {
|
||||||
self.machine.step();
|
self.machine.step();
|
||||||
|
|
||||||
if self.complete_popup == Popup::Visible {
|
if self.popup != EndPopup::None {
|
||||||
self.complete_popup = Popup::Dismissed;
|
self.popup = EndPopup::Dismissed;
|
||||||
}
|
}
|
||||||
if !self.level.outputs().is_empty()
|
if !self.level.outputs().is_empty()
|
||||||
&& self.level.outputs() == self.machine.output()
|
&& self.popup == EndPopup::None
|
||||||
&& self.complete_popup == Popup::Start
|
|
||||||
{
|
{
|
||||||
self.complete_popup = Popup::Visible;
|
if self.level.outputs() == self.machine.output() {
|
||||||
println!("completed in {:?}", self.start_time.elapsed());
|
self.popup = EndPopup::Success;
|
||||||
self.exit_state = ExitState::Save;
|
println!("completed in {:?}", self.start_time.elapsed());
|
||||||
self.sim_state = SimState::Stepping;
|
self.exit_state = ExitState::Save;
|
||||||
self.score = Some(Score {
|
self.sim_state = SimState::Stepping;
|
||||||
cycles: self.machine.step_count(),
|
self.score = Some(Score {
|
||||||
tiles: self.source_board.count_tiles(),
|
cycles: self.machine.step_count(),
|
||||||
});
|
tiles: self.source_board.count_tiles(),
|
||||||
|
});
|
||||||
|
} else if !self.level.outputs().starts_with(self.machine.output()) {
|
||||||
|
self.popup = EndPopup::Failure;
|
||||||
|
self.sim_state = SimState::Stepping;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +335,7 @@ impl Editor {
|
||||||
pub fn update(&mut self, rl: &RaylibHandle) {
|
pub fn update(&mut self, rl: &RaylibHandle) {
|
||||||
if rl.is_key_pressed(KeyboardKey::KEY_ESCAPE) {
|
if rl.is_key_pressed(KeyboardKey::KEY_ESCAPE) {
|
||||||
self.sim_state = SimState::Editing;
|
self.sim_state = SimState::Editing;
|
||||||
self.complete_popup = Popup::Start;
|
self.popup = EndPopup::None;
|
||||||
}
|
}
|
||||||
if self.sim_state == SimState::Running {
|
if self.sim_state == SimState::Running {
|
||||||
self.time_since_step += rl.get_frame_time();
|
self.time_since_step += rl.get_frame_time();
|
||||||
|
@ -373,7 +376,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
SimState::Running => {
|
SimState::Running => {
|
||||||
self.sim_state = SimState::Editing;
|
self.sim_state = SimState::Editing;
|
||||||
self.complete_popup = Popup::Start;
|
self.popup = EndPopup::None;
|
||||||
}
|
}
|
||||||
SimState::Stepping => self.sim_state = SimState::Running,
|
SimState::Stepping => self.sim_state = SimState::Running,
|
||||||
}
|
}
|
||||||
|
@ -510,7 +513,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.complete_popup == Popup::Visible {
|
if self.popup == EndPopup::Success {
|
||||||
let width = 320;
|
let width = 320;
|
||||||
let height = 165;
|
let height = 165;
|
||||||
let x = d.get_screen_width() / 2 - width / 2;
|
let x = d.get_screen_width() / 2 - width / 2;
|
||||||
|
@ -524,7 +527,7 @@ impl Editor {
|
||||||
draw_usize(d, textures, score.tiles, x + 210, y + 70, 5, 2);
|
draw_usize(d, textures, score.tiles, x + 210, y + 70, 5, 2);
|
||||||
}
|
}
|
||||||
if simple_button(d, x + 10, y + 110, 140, 45) {
|
if simple_button(d, x + 10, y + 110, 140, 45) {
|
||||||
self.complete_popup = Popup::Dismissed;
|
self.popup = EndPopup::Dismissed;
|
||||||
}
|
}
|
||||||
d.draw_text("continue\nediting", x + 15, y + 115, 20, Color::WHITE);
|
d.draw_text("continue\nediting", x + 15, y + 115, 20, Color::WHITE);
|
||||||
|
|
||||||
|
@ -539,6 +542,20 @@ impl Editor {
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.popup == EndPopup::Failure {
|
||||||
|
let width = 320;
|
||||||
|
let height = 165;
|
||||||
|
let x = d.get_screen_width() / 2 - width / 2;
|
||||||
|
let y = d.get_screen_height() / 2 - height / 2;
|
||||||
|
d.draw_rectangle(x, y, width, height, BG_DARK);
|
||||||
|
d.draw_text("Level Failed!", x + 45, y + 10, 30, Color::RED);
|
||||||
|
d.draw_text("incorrect output", x + 45, y + 45, 20, Color::WHITE);
|
||||||
|
if simple_button(d, x + 10, y + 110, 300, 25) {
|
||||||
|
self.popup = EndPopup::Dismissed;
|
||||||
|
}
|
||||||
|
d.draw_text("ok :(", x + 15, y + 115, 20, Color::WHITE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_top_bar(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) {
|
fn draw_top_bar(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) {
|
||||||
|
@ -590,7 +607,7 @@ impl Editor {
|
||||||
draw_scaled_texture(d, textures.get("pause"), 260, 4, 2.);
|
draw_scaled_texture(d, textures.get("pause"), 260, 4, 2.);
|
||||||
if simple_button(d, 296, 4, 32, 32) {
|
if simple_button(d, 296, 4, 32, 32) {
|
||||||
self.sim_state = SimState::Editing;
|
self.sim_state = SimState::Editing;
|
||||||
self.complete_popup = Popup::Start;
|
self.popup = EndPopup::None;
|
||||||
}
|
}
|
||||||
draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.);
|
draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.);
|
||||||
}
|
}
|
||||||
|
@ -601,7 +618,7 @@ impl Editor {
|
||||||
draw_scaled_texture(d, textures.get("play"), 260, 4, 2.);
|
draw_scaled_texture(d, textures.get("play"), 260, 4, 2.);
|
||||||
if simple_button(d, 296, 4, 32, 32) {
|
if simple_button(d, 296, 4, 32, 32) {
|
||||||
self.sim_state = SimState::Editing;
|
self.sim_state = SimState::Editing;
|
||||||
self.complete_popup = Popup::Start;
|
self.popup = EndPopup::None;
|
||||||
}
|
}
|
||||||
draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.);
|
draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue