woops, wasnt keeping menu state synced when pausing externally

This commit is contained in:
Dustin Carlino 2019-10-08 11:20:26 -07:00
parent 258f3d4528
commit ee5462e7c4
5 changed files with 18 additions and 12 deletions

View File

@ -223,8 +223,8 @@ impl State for ABTestMode {
self.primary_agent_tools.draw(g, ui);
}
fn on_suspend(&mut self, _: &mut UI) {
self.speed.pause();
fn on_suspend(&mut self, ctx: &mut EventCtx, _: &mut UI) {
self.speed.pause(ctx);
}
fn on_destroy(&mut self, ctx: &mut EventCtx, ui: &mut UI) {

View File

@ -99,9 +99,8 @@ impl SpeedControls {
ref mut last_measurement,
ref mut last_measurement_sim,
} => {
if self.menu.consume_action("pause", ctx) {
self.state = State::Paused;
self.menu.add_action(hotkey(Key::Space), "resume", ctx);
if self.menu.action("pause") {
self.pause(ctx);
} else if ctx.input.nonblocking_is_update_event() {
ctx.input.use_update_event();
let dt = Duration::seconds(elapsed_seconds(*last_step)) * desired_speed;
@ -128,8 +127,12 @@ impl SpeedControls {
self.menu.draw(g);
}
pub fn pause(&mut self) {
self.state = State::Paused;
pub fn pause(&mut self, ctx: &mut EventCtx) {
if !self.is_paused() {
self.state = State::Paused;
self.menu.remove_action("pause", ctx);
self.menu.add_action(hotkey(Key::Space), "resume", ctx);
}
}
pub fn is_paused(&self) -> bool {

View File

@ -58,7 +58,10 @@ impl GUI for Game {
EventLoopMode::InputOnly
}
Transition::PushWithMode(state, evmode) => {
self.states.last_mut().unwrap().on_suspend(&mut self.ui);
self.states
.last_mut()
.unwrap()
.on_suspend(ctx, &mut self.ui);
self.states.push(state);
evmode
}
@ -122,7 +125,7 @@ pub trait State: downcast_rs::Downcast {
}
// Before we push a new state on top of this one, call this.
fn on_suspend(&mut self, _: &mut UI) {}
fn on_suspend(&mut self, _: &mut EventCtx, _: &mut UI) {}
// Before this state is popped or replaced, call this.
fn on_destroy(&mut self, _: &mut EventCtx, _: &mut UI) {}
// We don't need an on_enter -- the constructor for the state can just do it.

View File

@ -251,8 +251,8 @@ impl State for SandboxMode {
self.speed.draw(g);
}
fn on_suspend(&mut self, _: &mut UI) {
self.speed.pause();
fn on_suspend(&mut self, ctx: &mut EventCtx, _: &mut UI) {
self.speed.pause(ctx);
}
}

View File

@ -64,7 +64,7 @@ impl State for SplashScreen {
self.wizard.draw(g);
}
fn on_suspend(&mut self, _: &mut UI) {
fn on_suspend(&mut self, _: &mut EventCtx, _: &mut UI) {
self.wizard.reset();
self.maybe_screensaver = None;
}