From 9b82e7288bae3d31767ffd61bf8a4c7810fcec4a Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 7 Nov 2019 10:00:44 -0800 Subject: [PATCH] move load map functionality into freeform/scenario mode. hide other things that players shouldn't see yet --- game/src/game.rs | 2 +- game/src/main.rs | 3 +- game/src/sandbox/gameplay.rs | 35 ++++++++++- game/src/splash_screen.rs | 110 +++++++++++++---------------------- game/src/ui.rs | 2 +- 5 files changed, 78 insertions(+), 74 deletions(-) diff --git a/game/src/game.rs b/game/src/game.rs index 125114fc4a..d9808e7ba3 100644 --- a/game/src/game.rs +++ b/game/src/game.rs @@ -14,7 +14,7 @@ pub struct Game { impl Game { pub fn new(flags: Flags, ctx: &mut EventCtx) -> Game { - let splash = flags.splash && !flags.sim_flags.load.contains("data/save"); + let splash = !flags.dev && !flags.sim_flags.load.contains("data/save"); let mut ui = UI::new(flags, ctx, splash); let states: Vec> = if splash { vec![Box::new(SplashScreen::new_with_screensaver(ctx, &ui))] diff --git a/game/src/main.rs b/game/src/main.rs index 48a9c89581..6c7a0e2605 100644 --- a/game/src/main.rs +++ b/game/src/main.rs @@ -30,11 +30,10 @@ fn main() { kml: args.optional("--kml"), draw_lane_markings: !args.enabled("--dont_draw_lane_markings"), num_agents: args.optional_parse("--num_agents", |s| s.parse()), - splash: !args.enabled("--no_splash"), textures: args.enabled("--textures"), + dev: args.enabled("--dev"), }; if args.enabled("--dev") { - flags.splash = false; flags.sim_flags.rng_seed = Some(42); } let mut settings = ezgui::Settings::new("A/B Street", (1800.0, 800.0)); diff --git a/game/src/sandbox/gameplay.rs b/game/src/sandbox/gameplay.rs index 0a4541d2a5..2b70c58c6c 100644 --- a/game/src/sandbox/gameplay.rs +++ b/game/src/sandbox/gameplay.rs @@ -7,7 +7,7 @@ use crate::sandbox::{bus_explorer, spawner, SandboxMode}; use crate::ui::UI; use abstutil::{prettyprint_usize, Timer}; use ezgui::{ - hotkey, Choice, Color, EventCtx, GfxCtx, Key, Line, ModalMenu, Text, TextSpan, Wizard, + hotkey, lctrl, Choice, Color, EventCtx, GfxCtx, Key, Line, ModalMenu, Text, TextSpan, Wizard, }; use geom::{Duration, Statistic}; use map_model::BusRouteID; @@ -69,6 +69,7 @@ impl GameplayState { "Freeform mode", vec![ (hotkey(Key::S), "start a scenario"), + (lctrl(Key::L), "load another map"), (hotkey(Key::H), "help"), ], ctx, @@ -86,6 +87,7 @@ impl GameplayState { &format!("Playing {}", scenario), vec![ (hotkey(Key::S), "start another scenario"), + (lctrl(Key::L), "load another map"), (hotkey(Key::H), "help"), ], ctx, @@ -215,6 +217,9 @@ impl GameplayState { change_scenario, )))); } + if self.menu.action("load another map") { + return Some(Transition::Push(WizardState::new(Box::new(load_map)))); + } if self.menu.action("help") { return Some(Transition::Push(msg("Help", vec!["This simulation is empty by default.", "Try right-clicking an intersection and choosing to spawn agents (or just hover over it and press Z).", "You can also spawn agents from buildings or lanes.", "You can also start a full scenario to get realistic traffic."]))); } @@ -232,6 +237,9 @@ impl GameplayState { change_scenario, )))); } + if self.menu.action("load another map") { + return Some(Transition::Push(WizardState::new(Box::new(load_map)))); + } if self.menu.action("help") { return Some(Transition::Push(msg( "Help", @@ -531,6 +539,31 @@ fn change_scenario(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option< )))) } +fn load_map(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option { + if let Some(name) = wiz.wrap(ctx).choose_string("Load which map?", || { + let current_map = ui.primary.map.get_name(); + abstutil::list_all_objects("maps", "") + .into_iter() + .filter(|n| n != current_map) + .collect() + }) { + ctx.canvas.save_camera_state(ui.primary.map.get_name()); + let mut flags = ui.primary.current_flags.clone(); + flags.sim_flags.load = abstutil::path_map(&name); + *ui = UI::new(flags, ctx, false); + Some(Transition::PopThenReplace(Box::new(SandboxMode::new( + ctx, + ui, + // TODO If we were playing a scenario, load that one... + GameplayMode::Freeform, + )))) + } else if wiz.aborted() { + Some(Transition::Pop) + } else { + None + } +} + // Must call menu.event first. Returns true if the caller should set the overlay to the custom // thing. fn manage_overlays( diff --git a/game/src/splash_screen.rs b/game/src/splash_screen.rs index 517700471c..9224e9c64d 100644 --- a/game/src/splash_screen.rs +++ b/game/src/splash_screen.rs @@ -1,6 +1,6 @@ use crate::abtest::setup::PickABTest; use crate::challenges::challenges_picker; -use crate::game::{State, Transition}; +use crate::game::{State, Transition, WizardState}; use crate::mission::MissionEditMode; use crate::sandbox::{GameplayMode, SandboxMode}; use crate::tutorial::TutorialMode; @@ -50,7 +50,7 @@ impl State for SplashScreen { EventLoopMode::InputOnly }; - if let Some(t) = splash_screen(&mut self.wizard, ctx, ui, &mut self.maybe_screensaver) { + if let Some(t) = splash_screen(&mut self.wizard, ctx, ui) { t } else if self.wizard.aborted() { Transition::PopWithMode(evmode) @@ -114,40 +114,44 @@ impl Screensaver { } } -fn splash_screen( - raw_wizard: &mut Wizard, - ctx: &mut EventCtx, - ui: &mut UI, - maybe_screensaver: &mut Option<(Screensaver, XorShiftRng)>, -) -> Option { +fn splash_screen(raw_wizard: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option { let mut wizard = raw_wizard.wrap(ctx); let sandbox = "Sandbox mode"; let challenge = "Challenge mode"; - let load_map = "Load another map"; - let abtest = "A/B Test Mode"; + let abtest = "A/B Test Mode (internal/unfinished)"; let tutorial = "Tutorial (unfinished)"; let mission = "Internal developer tools"; let about = "About"; let quit = "Quit"; - let evmode = if maybe_screensaver.is_some() { - EventLoopMode::Animation - } else { - EventLoopMode::InputOnly - }; + let dev = ui.primary.current_flags.dev; match wizard .choose("Welcome to A/B Street!", || { vec![ - Choice::new(sandbox, ()).key(Key::S), - Choice::new(challenge, ()).key(Key::C), - Choice::new(load_map, ()).key(Key::L), - Choice::new(abtest, ()).key(Key::A), - Choice::new(tutorial, ()).key(Key::T), - Choice::new(mission, ()).key(Key::M), - Choice::new(about, ()), - Choice::new(quit, ()), + Some(Choice::new(sandbox, ()).key(Key::S)), + Some(Choice::new(challenge, ()).key(Key::C)), + if dev { + Some(Choice::new(abtest, ()).key(Key::A)) + } else { + None + }, + if dev { + Some(Choice::new(tutorial, ()).key(Key::T)) + } else { + None + }, + if dev { + Some(Choice::new(mission, ()).key(Key::M)) + } else { + None + }, + Some(Choice::new(about, ())), + Some(Choice::new(quit, ())), ] + .into_iter() + .flatten() + .collect() })? .0 .as_str() @@ -158,55 +162,23 @@ fn splash_screen( GameplayMode::Freeform, )))), x if x == challenge => Some(Transition::Push(challenges_picker())), - x if x == load_map => { - if let Some(name) = wizard.choose_string("Load which map?", || { - let current_map = ui.primary.map.get_name(); - abstutil::list_all_objects("maps", "") - .into_iter() - .filter(|n| n != current_map) - .collect() - }) { - ctx.canvas.save_camera_state(ui.primary.map.get_name()); - // This retains no state, but that's probably fine. - let mut flags = ui.primary.current_flags.clone(); - flags.sim_flags.load = abstutil::path_map(&name); - *ui = UI::new(flags, ctx, false); - // TODO want to clear wizard and screensaver as we leave this state. - Some(Transition::Push(Box::new(SandboxMode::new( - ctx, - ui, - GameplayMode::Freeform, - )))) - } else if wizard.aborted() { - Some(Transition::ReplaceWithMode( - Box::new(SplashScreen { - wizard: Wizard::new(), - maybe_screensaver: maybe_screensaver.take(), - }), - evmode, - )) - } else { - None - } - } x if x == abtest => Some(Transition::Push(PickABTest::new())), x if x == tutorial => Some(Transition::Push(Box::new(TutorialMode::new(ctx)))), x if x == mission => Some(Transition::Push(Box::new(MissionEditMode::new(ctx)))), - x if x == about => { - wizard.acknowledge("About A/B Street", || { - vec![ - "Author: Dustin Carlino (dabreegster@gmail.com)", - "http://github.com/dabreegster/abstreet", - "Map data from OpenStreetMap and King County GIS", - "", - "Press ENTER to continue", - ] - })?; - Some(Transition::Replace(Box::new(SplashScreen { - wizard: Wizard::new(), - maybe_screensaver: maybe_screensaver.take(), - }))) - } + x if x == about => Some(Transition::Push(WizardState::new(Box::new( + |wiz, ctx, _| { + wiz.wrap(ctx).acknowledge("About A/B Street", || { + vec![ + "Author: Dustin Carlino (dabreegster@gmail.com)", + "http://github.com/dabreegster/abstreet", + "Map data from OpenStreetMap and King County GIS", + "", + "Press ENTER to continue", + ] + })?; + Some(Transition::Pop) + }, + )))), x if x == quit => Some(Transition::Pop), _ => unreachable!(), } diff --git a/game/src/ui.rs b/game/src/ui.rs index b019e418d4..bd1dff9b56 100644 --- a/game/src/ui.rs +++ b/game/src/ui.rs @@ -451,8 +451,8 @@ pub struct Flags { // Number of agents to generate when requested. If unspecified, trips to/from borders will be // included. pub num_agents: Option, - pub splash: bool, pub textures: bool, + pub dev: bool, } // All of the state that's bound to a specific map+edit has to live here.