mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
move load map functionality into freeform/scenario mode. hide other
things that players shouldn't see yet
This commit is contained in:
parent
53d1067414
commit
9b82e7288b
@ -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<Box<dyn State>> = if splash {
|
||||
vec![Box::new(SplashScreen::new_with_screensaver(ctx, &ui))]
|
||||
|
@ -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));
|
||||
|
@ -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<Transition> {
|
||||
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(
|
||||
|
@ -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<Transition> {
|
||||
fn splash_screen(raw_wizard: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Transition> {
|
||||
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!(),
|
||||
}
|
||||
|
@ -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<usize>,
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user