From 6ffa5fbf6e31f22e1eb630567823a0db1b39637d Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 30 Oct 2019 10:26:44 -0700 Subject: [PATCH] move savestating under a save menu --- game/assets/ui/save.png | Bin 0 -> 835 bytes game/src/sandbox/mod.rs | 110 +++++++++++++++++++++++----------------- game/src/ui.rs | 2 + 3 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 game/assets/ui/save.png diff --git a/game/assets/ui/save.png b/game/assets/ui/save.png new file mode 100644 index 0000000000000000000000000000000000000000..f6d18fcedbae7e1d6cc62c6545e33f07cb1c08dd GIT binary patch literal 835 zcmV-J1HAl+P)}b0K@`V-ITJ|~i651fU!`cJt%Yb|R4fGT0$PZb zrm#`OTm-u`78X_^2!a-(_*Dp^wIYIwrP0Dl2|=Qfd|AwHI4^HzZfECqZujN~%iX@2 zeLMT#H*fZ4=O7Y^L?YcwkD+W3IGudI2h6m;ImM$BU=Vl@Y)|&5f!n~}0@{>^eqcB1 zW?cckxjMQCESG$n2e#QRw5G8ivK?3gdVw3ZN;(0m!e(0qod6#_HzX8OwhFx(yOiu+ z1FtmoN0ZMnYm@S$JJ)_-sLAFW;dNFgmAavRTBitf=Q_*kHc#4|RVfGj5o`mtgLGXW zFE!u@DlGHz26zrES?c{3Y{3K=0v>zxcMN!HspAv@u?w`JApp;SNP-LQYKQRF0hQl zQ0QBLB4&C_WbOu4iU4pBz*i11%`O*7*GE9+p|ENKbbSOw0R&s2!(eEFjRGk?Cq`XH zme>UZTcHt_XeU0@#J`hlZ@-S~^NDqWxl_4w%hi30%tJsEmvPCj|Q!;1sI=w?xQMz%}!q1g;78S(GS0vp6eT z1nfb-=wTT6kkw&`2ylJc+k#4Z>xHs0;DL+NvP3{1a39zqlsyElyE-n50OPD?3OJ9)9Ao;wz&l`Pvi}36d<`}8l5PVn z?yvRG)&*cM@Y#c}6^i=DNV9OQinkH9&S(a>3VhAchDan5i9{m*^AF}*AZ%fB%0>VH N002ovPDHLkV1howYJ>m) literal 0 HcmV?d00001 diff --git a/game/src/sandbox/mod.rs b/game/src/sandbox/mod.rs index 764e413ccd..e33f6e937a 100644 --- a/game/src/sandbox/mod.rs +++ b/game/src/sandbox/mod.rs @@ -21,6 +21,7 @@ pub struct SandboxMode { speed: SpeedControls, info_tools: MenuUnderButton, general_tools: MenuUnderButton, + save_tools: MenuUnderButton, agent_tools: AgentTools, pub time_travel: time_travel::InactiveTimeTravel, trip_stats: trip_stats::TripStats, @@ -56,6 +57,18 @@ impl SandboxMode { 0.2, ctx, ), + save_tools: MenuUnderButton::new( + "assets/ui/save.png", + "Savestates", + vec![ + (hotkey(Key::O), "save sim state"), + (hotkey(Key::Y), "load previous sim state"), + (hotkey(Key::U), "load next sim state"), + (None, "pick a savestate to load"), + ], + 0.35, + ctx, + ), agent_tools: AgentTools::new(), time_travel: time_travel::InactiveTimeTravel::new(), trip_stats: trip_stats::TripStats::new( @@ -66,10 +79,6 @@ impl SandboxMode { menu: ModalMenu::new( "Sandbox Mode", vec![ - (hotkey(Key::O), "save sim state"), - (hotkey(Key::Y), "load previous sim state"), - (hotkey(Key::U), "load next sim state"), - (None, "pick a savestate to load"), (hotkey(Key::X), "reset sim"), (hotkey(Key::S), "start a scenario"), (hotkey(Key::T), "start time traveling"), @@ -96,6 +105,7 @@ impl State for SandboxMode { self.menu.event(ctx); self.info_tools.event(ctx); self.general_tools.event(ctx); + self.save_tools.event(ctx); ctx.canvas.handle_event(ctx.input); if ctx.redo_mouseover() { @@ -165,6 +175,54 @@ impl State for SandboxMode { } } + if self.save_tools.action("save sim state") { + self.speed.pause(ctx); + ctx.loading_screen("savestate", |_, timer| { + timer.start("save sim state"); + ui.primary.sim.save(); + timer.stop("save sim state"); + }); + } + if self.save_tools.action("load previous sim state") { + self.speed.pause(ctx); + ctx.loading_screen("load previous savestate", |ctx, mut timer| { + let prev_state = ui + .primary + .sim + .find_previous_savestate(ui.primary.sim.time()); + match prev_state + .clone() + .and_then(|path| Sim::load_savestate(path, &mut timer).ok()) + { + Some(new_sim) => { + ui.primary.sim = new_sim; + ui.recalculate_current_selection(ctx); + } + None => println!("Couldn't load previous savestate {:?}", prev_state), + } + }); + } + if self.save_tools.action("load next sim state") { + self.speed.pause(ctx); + ctx.loading_screen("load next savestate", |ctx, mut timer| { + let next_state = ui.primary.sim.find_next_savestate(ui.primary.sim.time()); + match next_state + .clone() + .and_then(|path| Sim::load_savestate(path, &mut timer).ok()) + { + Some(new_sim) => { + ui.primary.sim = new_sim; + ui.recalculate_current_selection(ctx); + } + None => println!("Couldn't load next savestate {:?}", next_state), + } + }); + } + if self.save_tools.action("pick a savestate to load") { + self.speed.pause(ctx); + return Transition::Push(WizardState::new(Box::new(load_savestate))); + } + if let Some(dt) = self.speed.event(ctx, ui.primary.sim.time()) { // If speed is too high, don't be unresponsive for too long. // TODO This should probably match the ezgui framerate. @@ -179,49 +237,6 @@ impl State for SandboxMode { ui.primary.reset_sim(); return Transition::Replace(Box::new(SandboxMode::new(ctx, ui))); } - if self.menu.action("save sim state") { - ctx.loading_screen("savestate", |_, timer| { - timer.start("save sim state"); - ui.primary.sim.save(); - timer.stop("save sim state"); - }); - } - if self.menu.action("load previous sim state") { - ctx.loading_screen("load previous savestate", |ctx, mut timer| { - let prev_state = ui - .primary - .sim - .find_previous_savestate(ui.primary.sim.time()); - match prev_state - .clone() - .and_then(|path| Sim::load_savestate(path, &mut timer).ok()) - { - Some(new_sim) => { - ui.primary.sim = new_sim; - ui.recalculate_current_selection(ctx); - } - None => println!("Couldn't load previous savestate {:?}", prev_state), - } - }); - } - if self.menu.action("load next sim state") { - ctx.loading_screen("load next savestate", |ctx, mut timer| { - let next_state = ui.primary.sim.find_next_savestate(ui.primary.sim.time()); - match next_state - .clone() - .and_then(|path| Sim::load_savestate(path, &mut timer).ok()) - { - Some(new_sim) => { - ui.primary.sim = new_sim; - ui.recalculate_current_selection(ctx); - } - None => println!("Couldn't load next savestate {:?}", next_state), - } - }); - } - if self.menu.action("pick a savestate to load") { - return Transition::Push(WizardState::new(Box::new(load_savestate))); - } if let Some(t) = time_controls(ctx, ui, &mut self.speed.menu) { return t; @@ -254,6 +269,7 @@ impl State for SandboxMode { self.speed.draw(g); self.info_tools.draw(g); self.general_tools.draw(g); + self.save_tools.draw(g); } fn on_suspend(&mut self, ctx: &mut EventCtx, _: &mut UI) { diff --git a/game/src/ui.rs b/game/src/ui.rs index fe71fa8acc..1cfce3243b 100644 --- a/game/src/ui.rs +++ b/game/src/ui.rs @@ -29,6 +29,8 @@ impl UI { ("assets/ui/hide.png", TextureType::Stretch), ("assets/ui/info.png", TextureType::Stretch), ("assets/ui/location.png", TextureType::Stretch), + // I feel so conflicted about perp + ("assets/ui/save.png", TextureType::Stretch), ("assets/ui/show.png", TextureType::Stretch), ]; let skip_textures = if flags.textures {