mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-20 21:01:33 +03:00
make ModalMenu optional for gameplay modes, now that we dont need it for unfollowing agents. stop using it in freeform and play scenario modes.
This commit is contained in:
parent
44310ffe28
commit
6bdd557c80
@ -6,44 +6,40 @@ use crate::sandbox::gameplay::{cmp_count_fewer, manage_acs, GameplayMode, Gamepl
|
|||||||
use crate::sandbox::overlays::Overlays;
|
use crate::sandbox::overlays::Overlays;
|
||||||
use crate::ui::UI;
|
use crate::ui::UI;
|
||||||
use abstutil::prettyprint_usize;
|
use abstutil::prettyprint_usize;
|
||||||
use ezgui::{hotkey, EventCtx, Key, Line, ModalMenu, Text};
|
use ezgui::{hotkey, layout, EventCtx, GfxCtx, Key, Line, ModalMenu, Text};
|
||||||
use geom::Time;
|
use geom::Time;
|
||||||
use sim::TripMode;
|
use sim::TripMode;
|
||||||
|
|
||||||
pub struct CreateGridlock {
|
pub struct CreateGridlock {
|
||||||
time: Time,
|
time: Time,
|
||||||
|
menu: ModalMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CreateGridlock {
|
impl CreateGridlock {
|
||||||
pub fn new(ctx: &mut EventCtx) -> (ModalMenu, Composite, Box<dyn GameplayState>) {
|
pub fn new(ctx: &mut EventCtx) -> (Composite, Box<dyn GameplayState>) {
|
||||||
(
|
(
|
||||||
ModalMenu::new(
|
|
||||||
"Cause gridlock",
|
|
||||||
vec![
|
|
||||||
(hotkey(Key::E), "show agent delay"),
|
|
||||||
(hotkey(Key::H), "help"),
|
|
||||||
],
|
|
||||||
ctx,
|
|
||||||
),
|
|
||||||
edit_map_panel(ctx, GameplayMode::CreateGridlock),
|
edit_map_panel(ctx, GameplayMode::CreateGridlock),
|
||||||
Box::new(CreateGridlock {
|
Box::new(CreateGridlock {
|
||||||
time: Time::START_OF_DAY,
|
time: Time::START_OF_DAY,
|
||||||
|
menu: ModalMenu::new(
|
||||||
|
"Cause gridlock",
|
||||||
|
vec![
|
||||||
|
(hotkey(Key::E), "show agent delay"),
|
||||||
|
(hotkey(Key::H), "help"),
|
||||||
|
],
|
||||||
|
ctx,
|
||||||
|
)
|
||||||
|
.set_standalone_layout(layout::ContainerOrientation::TopLeftButDownABit(150.0)),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameplayState for CreateGridlock {
|
impl GameplayState for CreateGridlock {
|
||||||
fn event(
|
fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI, _: &mut Overlays) -> Option<Transition> {
|
||||||
&mut self,
|
self.menu.event(ctx);
|
||||||
ctx: &mut EventCtx,
|
|
||||||
ui: &mut UI,
|
|
||||||
_: &mut Overlays,
|
|
||||||
menu: &mut ModalMenu,
|
|
||||||
) -> Option<Transition> {
|
|
||||||
menu.event(ctx);
|
|
||||||
manage_acs(
|
manage_acs(
|
||||||
menu,
|
&mut self.menu,
|
||||||
ctx,
|
ctx,
|
||||||
ui,
|
ui,
|
||||||
"show agent delay",
|
"show agent delay",
|
||||||
@ -53,10 +49,10 @@ impl GameplayState for CreateGridlock {
|
|||||||
|
|
||||||
if self.time != ui.primary.sim.time() {
|
if self.time != ui.primary.sim.time() {
|
||||||
self.time = ui.primary.sim.time();
|
self.time = ui.primary.sim.time();
|
||||||
menu.set_info(ctx, gridlock_panel(ui));
|
self.menu.set_info(ctx, gridlock_panel(ui));
|
||||||
}
|
}
|
||||||
|
|
||||||
if menu.action("help") {
|
if self.menu.action("help") {
|
||||||
return Some(Transition::Push(msg("Help", vec![
|
return Some(Transition::Push(msg("Help", vec![
|
||||||
"You might notice a few places in the map where gridlock forms already.",
|
"You might notice a few places in the map where gridlock forms already.",
|
||||||
"You can make things worse!",
|
"You can make things worse!",
|
||||||
@ -65,6 +61,10 @@ impl GameplayState for CreateGridlock {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw(&self, g: &mut GfxCtx, _: &UI) {
|
||||||
|
self.menu.draw(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gridlock_panel(ui: &UI) -> Text {
|
fn gridlock_panel(ui: &UI) -> Text {
|
||||||
|
@ -5,51 +5,44 @@ use crate::sandbox::gameplay::{cmp_count_more, cmp_duration_shorter, GameplayMod
|
|||||||
use crate::sandbox::overlays::Overlays;
|
use crate::sandbox::overlays::Overlays;
|
||||||
use crate::ui::UI;
|
use crate::ui::UI;
|
||||||
use abstutil::prettyprint_usize;
|
use abstutil::prettyprint_usize;
|
||||||
use ezgui::{hotkey, EventCtx, Key, Line, ModalMenu, Text};
|
use ezgui::{hotkey, layout, EventCtx, GfxCtx, Key, Line, ModalMenu, Text};
|
||||||
use geom::{Statistic, Time};
|
use geom::{Statistic, Time};
|
||||||
use sim::TripMode;
|
use sim::TripMode;
|
||||||
|
|
||||||
pub struct FasterTrips {
|
pub struct FasterTrips {
|
||||||
mode: TripMode,
|
mode: TripMode,
|
||||||
time: Time,
|
time: Time,
|
||||||
|
menu: ModalMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FasterTrips {
|
impl FasterTrips {
|
||||||
pub fn new(
|
pub fn new(trip_mode: TripMode, ctx: &mut EventCtx) -> (Composite, Box<dyn GameplayState>) {
|
||||||
trip_mode: TripMode,
|
|
||||||
ctx: &mut EventCtx,
|
|
||||||
) -> (ModalMenu, Composite, Box<dyn GameplayState>) {
|
|
||||||
(
|
(
|
||||||
ModalMenu::new(
|
|
||||||
format!("Speed up {} trips", trip_mode),
|
|
||||||
vec![(hotkey(Key::H), "help")],
|
|
||||||
ctx,
|
|
||||||
),
|
|
||||||
edit_map_panel(ctx, GameplayMode::FasterTrips(trip_mode)),
|
edit_map_panel(ctx, GameplayMode::FasterTrips(trip_mode)),
|
||||||
Box::new(FasterTrips {
|
Box::new(FasterTrips {
|
||||||
mode: trip_mode,
|
mode: trip_mode,
|
||||||
time: Time::START_OF_DAY,
|
time: Time::START_OF_DAY,
|
||||||
|
menu: ModalMenu::new(
|
||||||
|
format!("Speed up {} trips", trip_mode),
|
||||||
|
vec![(hotkey(Key::H), "help")],
|
||||||
|
ctx,
|
||||||
|
)
|
||||||
|
.set_standalone_layout(layout::ContainerOrientation::TopLeftButDownABit(150.0)),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameplayState for FasterTrips {
|
impl GameplayState for FasterTrips {
|
||||||
fn event(
|
fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI, _: &mut Overlays) -> Option<Transition> {
|
||||||
&mut self,
|
self.menu.event(ctx);
|
||||||
ctx: &mut EventCtx,
|
|
||||||
ui: &mut UI,
|
|
||||||
_: &mut Overlays,
|
|
||||||
menu: &mut ModalMenu,
|
|
||||||
) -> Option<Transition> {
|
|
||||||
menu.event(ctx);
|
|
||||||
|
|
||||||
if self.time != ui.primary.sim.time() {
|
if self.time != ui.primary.sim.time() {
|
||||||
self.time = ui.primary.sim.time();
|
self.time = ui.primary.sim.time();
|
||||||
menu.set_info(ctx, faster_trips_panel(self.mode, ui));
|
self.menu.set_info(ctx, faster_trips_panel(self.mode, ui));
|
||||||
}
|
}
|
||||||
|
|
||||||
if menu.action("help") {
|
if self.menu.action("help") {
|
||||||
return Some(Transition::Push(msg(
|
return Some(Transition::Push(msg(
|
||||||
"Help",
|
"Help",
|
||||||
vec!["How can you possibly speed up all trips of some mode?"],
|
vec!["How can you possibly speed up all trips of some mode?"],
|
||||||
@ -57,6 +50,10 @@ impl GameplayState for FasterTrips {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw(&self, g: &mut GfxCtx, _: &UI) {
|
||||||
|
self.menu.draw(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn faster_trips_panel(mode: TripMode, ui: &UI) -> Text {
|
pub fn faster_trips_panel(mode: TripMode, ui: &UI) -> Text {
|
||||||
|
@ -5,7 +5,7 @@ use crate::sandbox::gameplay::faster_trips::small_faster_trips_panel;
|
|||||||
use crate::sandbox::gameplay::{manage_overlays, GameplayMode, GameplayState};
|
use crate::sandbox::gameplay::{manage_overlays, GameplayMode, GameplayState};
|
||||||
use crate::sandbox::overlays::Overlays;
|
use crate::sandbox::overlays::Overlays;
|
||||||
use crate::ui::UI;
|
use crate::ui::UI;
|
||||||
use ezgui::{hotkey, EventCtx, Key, ModalMenu};
|
use ezgui::{hotkey, layout, EventCtx, GfxCtx, Key, ModalMenu};
|
||||||
use geom::{Duration, Statistic, Time};
|
use geom::{Duration, Statistic, Time};
|
||||||
use map_model::{IntersectionID, Map};
|
use map_model::{IntersectionID, Map};
|
||||||
use sim::{BorderSpawnOverTime, OriginDestination, Scenario, TripMode};
|
use sim::{BorderSpawnOverTime, OriginDestination, Scenario, TripMode};
|
||||||
@ -13,28 +13,27 @@ use sim::{BorderSpawnOverTime, OriginDestination, Scenario, TripMode};
|
|||||||
pub struct FixTrafficSignals {
|
pub struct FixTrafficSignals {
|
||||||
time: Time,
|
time: Time,
|
||||||
once: bool,
|
once: bool,
|
||||||
|
menu: ModalMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FixTrafficSignals {
|
impl FixTrafficSignals {
|
||||||
pub fn new(
|
pub fn new(ctx: &mut EventCtx, mode: GameplayMode) -> (Composite, Box<dyn GameplayState>) {
|
||||||
ctx: &mut EventCtx,
|
|
||||||
mode: GameplayMode,
|
|
||||||
) -> (ModalMenu, Composite, Box<dyn GameplayState>) {
|
|
||||||
(
|
(
|
||||||
ModalMenu::new(
|
|
||||||
"Fix traffic signals",
|
|
||||||
vec![
|
|
||||||
(hotkey(Key::F), "find slowest traffic signals"),
|
|
||||||
(hotkey(Key::D), "hide finished trip distribution"),
|
|
||||||
(hotkey(Key::H), "help"),
|
|
||||||
(hotkey(Key::S), "final score"),
|
|
||||||
],
|
|
||||||
ctx,
|
|
||||||
),
|
|
||||||
edit_map_panel(ctx, mode),
|
edit_map_panel(ctx, mode),
|
||||||
Box::new(FixTrafficSignals {
|
Box::new(FixTrafficSignals {
|
||||||
time: Time::START_OF_DAY,
|
time: Time::START_OF_DAY,
|
||||||
once: true,
|
once: true,
|
||||||
|
menu: ModalMenu::new(
|
||||||
|
"Fix traffic signals",
|
||||||
|
vec![
|
||||||
|
(hotkey(Key::F), "find slowest traffic signals"),
|
||||||
|
(hotkey(Key::D), "hide finished trip distribution"),
|
||||||
|
(hotkey(Key::H), "help"),
|
||||||
|
(hotkey(Key::S), "final score"),
|
||||||
|
],
|
||||||
|
ctx,
|
||||||
|
)
|
||||||
|
.set_standalone_layout(layout::ContainerOrientation::TopLeftButDownABit(150.0)),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -46,7 +45,6 @@ impl GameplayState for FixTrafficSignals {
|
|||||||
ctx: &mut EventCtx,
|
ctx: &mut EventCtx,
|
||||||
ui: &mut UI,
|
ui: &mut UI,
|
||||||
overlays: &mut Overlays,
|
overlays: &mut Overlays,
|
||||||
menu: &mut ModalMenu,
|
|
||||||
) -> Option<Transition> {
|
) -> Option<Transition> {
|
||||||
// Once is never...
|
// Once is never...
|
||||||
if self.once {
|
if self.once {
|
||||||
@ -54,11 +52,11 @@ impl GameplayState for FixTrafficSignals {
|
|||||||
self.once = false;
|
self.once = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.event(ctx);
|
self.menu.event(ctx);
|
||||||
|
|
||||||
// Technically this shows stop signs too, but mostly the bottlenecks are signals.
|
// Technically this shows stop signs too, but mostly the bottlenecks are signals.
|
||||||
if manage_overlays(
|
if manage_overlays(
|
||||||
menu,
|
&mut self.menu,
|
||||||
ctx,
|
ctx,
|
||||||
"find slowest traffic signals",
|
"find slowest traffic signals",
|
||||||
"hide slowest traffic signals",
|
"hide slowest traffic signals",
|
||||||
@ -71,7 +69,7 @@ impl GameplayState for FixTrafficSignals {
|
|||||||
*overlays = Overlays::intersection_delay(ctx, ui);
|
*overlays = Overlays::intersection_delay(ctx, ui);
|
||||||
}
|
}
|
||||||
if manage_overlays(
|
if manage_overlays(
|
||||||
menu,
|
&mut self.menu,
|
||||||
ctx,
|
ctx,
|
||||||
"show finished trip distribution",
|
"show finished trip distribution",
|
||||||
"hide finished trip distribution",
|
"hide finished trip distribution",
|
||||||
@ -86,10 +84,11 @@ impl GameplayState for FixTrafficSignals {
|
|||||||
|
|
||||||
if self.time != ui.primary.sim.time() {
|
if self.time != ui.primary.sim.time() {
|
||||||
self.time = ui.primary.sim.time();
|
self.time = ui.primary.sim.time();
|
||||||
menu.set_info(ctx, small_faster_trips_panel(TripMode::Drive, ui));
|
self.menu
|
||||||
|
.set_info(ctx, small_faster_trips_panel(TripMode::Drive, ui));
|
||||||
}
|
}
|
||||||
|
|
||||||
if menu.action("help") {
|
if self.menu.action("help") {
|
||||||
return Some(Transition::Push(msg(
|
return Some(Transition::Push(msg(
|
||||||
"Help",
|
"Help",
|
||||||
vec![
|
vec![
|
||||||
@ -98,7 +97,7 @@ impl GameplayState for FixTrafficSignals {
|
|||||||
])));
|
])));
|
||||||
}
|
}
|
||||||
|
|
||||||
if menu.action("final score") {
|
if self.menu.action("final score") {
|
||||||
return Some(Transition::Push(msg("Final score", final_score(ui))));
|
return Some(Transition::Push(msg("Final score", final_score(ui))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +108,10 @@ impl GameplayState for FixTrafficSignals {
|
|||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw(&self, g: &mut GfxCtx, _: &UI) {
|
||||||
|
self.menu.draw(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn final_score(ui: &UI) -> Vec<String> {
|
fn final_score(ui: &UI) -> Vec<String> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::edit::EditMode;
|
use crate::edit::EditMode;
|
||||||
use crate::game::{msg, State, Transition, WizardState};
|
use crate::game::{State, Transition, WizardState};
|
||||||
use crate::helpers::ID;
|
use crate::helpers::ID;
|
||||||
use crate::managed::Composite;
|
use crate::managed::Composite;
|
||||||
use crate::sandbox::gameplay::{change_scenario, spawner, GameplayMode, GameplayState};
|
use crate::sandbox::gameplay::{change_scenario, spawner, GameplayMode, GameplayState};
|
||||||
@ -7,8 +7,8 @@ use crate::sandbox::overlays::Overlays;
|
|||||||
use crate::sandbox::SandboxMode;
|
use crate::sandbox::SandboxMode;
|
||||||
use crate::ui::UI;
|
use crate::ui::UI;
|
||||||
use ezgui::{
|
use ezgui::{
|
||||||
hotkey, lctrl, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget,
|
hotkey, lctrl, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget, Text,
|
||||||
ModalMenu, Text, VerticalAlignment,
|
VerticalAlignment,
|
||||||
};
|
};
|
||||||
use map_model::IntersectionID;
|
use map_model::IntersectionID;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
@ -20,9 +20,8 @@ pub struct Freeform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Freeform {
|
impl Freeform {
|
||||||
pub fn new(ctx: &mut EventCtx, ui: &UI) -> (ModalMenu, Composite, Box<dyn GameplayState>) {
|
pub fn new(ctx: &mut EventCtx, ui: &UI) -> (Composite, Box<dyn GameplayState>) {
|
||||||
(
|
(
|
||||||
ModalMenu::new("Freeform mode", vec![(hotkey(Key::H), "help")], ctx),
|
|
||||||
freeform_controller(ctx, ui, GameplayMode::Freeform, "empty scenario"),
|
freeform_controller(ctx, ui, GameplayMode::Freeform, "empty scenario"),
|
||||||
Box::new(Freeform {
|
Box::new(Freeform {
|
||||||
spawn_pts: BTreeSet::new(),
|
spawn_pts: BTreeSet::new(),
|
||||||
@ -32,17 +31,7 @@ impl Freeform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GameplayState for Freeform {
|
impl GameplayState for Freeform {
|
||||||
fn event(
|
fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI, _: &mut Overlays) -> Option<Transition> {
|
||||||
&mut self,
|
|
||||||
ctx: &mut EventCtx,
|
|
||||||
ui: &mut UI,
|
|
||||||
_: &mut Overlays,
|
|
||||||
menu: &mut ModalMenu,
|
|
||||||
) -> Option<Transition> {
|
|
||||||
menu.event(ctx);
|
|
||||||
if 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."])));
|
|
||||||
}
|
|
||||||
if let Some(new_state) = spawner::AgentSpawner::new(ctx, ui) {
|
if let Some(new_state) = spawner::AgentSpawner::new(ctx, ui) {
|
||||||
return Some(Transition::Push(new_state));
|
return Some(Transition::Push(new_state));
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,13 @@ use crate::sandbox::overlays::Overlays;
|
|||||||
use crate::sandbox::SandboxMode;
|
use crate::sandbox::SandboxMode;
|
||||||
use crate::ui::UI;
|
use crate::ui::UI;
|
||||||
use abstutil::{prettyprint_usize, Timer};
|
use abstutil::{prettyprint_usize, Timer};
|
||||||
use ezgui::{layout, Color, EventCtx, GfxCtx, Line, ModalMenu, TextSpan, Wizard};
|
use ezgui::{Color, EventCtx, GfxCtx, Line, ModalMenu, TextSpan, Wizard};
|
||||||
use geom::Duration;
|
use geom::Duration;
|
||||||
use map_model::{EditCmd, Map, MapEdits};
|
use map_model::{EditCmd, Map, MapEdits};
|
||||||
use sim::{Analytics, Scenario, TripMode};
|
use sim::{Analytics, Scenario, TripMode};
|
||||||
|
|
||||||
pub struct GameplayRunner {
|
pub struct GameplayRunner {
|
||||||
pub mode: GameplayMode,
|
pub mode: GameplayMode,
|
||||||
pub menu: ModalMenu,
|
|
||||||
controller: Composite,
|
controller: Composite,
|
||||||
state: Box<dyn GameplayState>,
|
state: Box<dyn GameplayState>,
|
||||||
}
|
}
|
||||||
@ -46,9 +45,8 @@ pub trait GameplayState: downcast_rs::Downcast {
|
|||||||
ctx: &mut EventCtx,
|
ctx: &mut EventCtx,
|
||||||
ui: &mut UI,
|
ui: &mut UI,
|
||||||
overlays: &mut Overlays,
|
overlays: &mut Overlays,
|
||||||
menu: &mut ModalMenu,
|
|
||||||
) -> Option<Transition>;
|
) -> Option<Transition>;
|
||||||
fn draw(&self, _: &mut GfxCtx, _: &UI) {}
|
fn draw(&self, g: &mut GfxCtx, ui: &UI);
|
||||||
}
|
}
|
||||||
downcast_rs::impl_downcast!(GameplayState);
|
downcast_rs::impl_downcast!(GameplayState);
|
||||||
|
|
||||||
@ -135,7 +133,7 @@ impl GameplayMode {
|
|||||||
|
|
||||||
impl GameplayRunner {
|
impl GameplayRunner {
|
||||||
pub fn initialize(mode: GameplayMode, ui: &mut UI, ctx: &mut EventCtx) -> GameplayRunner {
|
pub fn initialize(mode: GameplayMode, ui: &mut UI, ctx: &mut EventCtx) -> GameplayRunner {
|
||||||
let (menu, controller, state) = match mode.clone() {
|
let (controller, state) = match mode.clone() {
|
||||||
GameplayMode::Freeform => freeform::Freeform::new(ctx, ui),
|
GameplayMode::Freeform => freeform::Freeform::new(ctx, ui),
|
||||||
GameplayMode::PlayScenario(scenario) => {
|
GameplayMode::PlayScenario(scenario) => {
|
||||||
play_scenario::PlayScenario::new(&scenario, ctx, ui)
|
play_scenario::PlayScenario::new(&scenario, ctx, ui)
|
||||||
@ -179,8 +177,6 @@ impl GameplayRunner {
|
|||||||
ui.set_prebaked(Some(prebaked));
|
ui.set_prebaked(Some(prebaked));
|
||||||
GameplayRunner {
|
GameplayRunner {
|
||||||
mode,
|
mode,
|
||||||
menu: menu
|
|
||||||
.set_standalone_layout(layout::ContainerOrientation::TopLeftButDownABit(150.0)),
|
|
||||||
controller,
|
controller,
|
||||||
state,
|
state,
|
||||||
}
|
}
|
||||||
@ -199,11 +195,10 @@ impl GameplayRunner {
|
|||||||
Some(Outcome::Clicked(_)) => unreachable!(),
|
Some(Outcome::Clicked(_)) => unreachable!(),
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
self.state.event(ctx, ui, overlays, &mut self.menu)
|
self.state.event(ctx, ui, overlays)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||||
self.menu.draw(g);
|
|
||||||
self.controller.draw(g);
|
self.controller.draw(g);
|
||||||
self.state.draw(g, ui);
|
self.state.draw(g, ui);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use crate::sandbox::gameplay::{
|
|||||||
use crate::sandbox::overlays::Overlays;
|
use crate::sandbox::overlays::Overlays;
|
||||||
use crate::sandbox::SandboxMode;
|
use crate::sandbox::SandboxMode;
|
||||||
use crate::ui::UI;
|
use crate::ui::UI;
|
||||||
use ezgui::{hotkey, Choice, EventCtx, Key, Line, ModalMenu, Text};
|
use ezgui::{hotkey, layout, Choice, EventCtx, GfxCtx, Key, Line, ModalMenu, Text};
|
||||||
use geom::{Statistic, Time};
|
use geom::{Statistic, Time};
|
||||||
use map_model::BusRouteID;
|
use map_model::BusRouteID;
|
||||||
|
|
||||||
@ -14,6 +14,7 @@ pub struct OptimizeBus {
|
|||||||
route: BusRouteID,
|
route: BusRouteID,
|
||||||
time: Time,
|
time: Time,
|
||||||
stat: Statistic,
|
stat: Statistic,
|
||||||
|
menu: ModalMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OptimizeBus {
|
impl OptimizeBus {
|
||||||
@ -21,25 +22,26 @@ impl OptimizeBus {
|
|||||||
route_name: String,
|
route_name: String,
|
||||||
ctx: &mut EventCtx,
|
ctx: &mut EventCtx,
|
||||||
ui: &UI,
|
ui: &UI,
|
||||||
) -> (ModalMenu, crate::managed::Composite, Box<dyn GameplayState>) {
|
) -> (crate::managed::Composite, Box<dyn GameplayState>) {
|
||||||
let route = ui.primary.map.get_bus_route(&route_name).unwrap();
|
let route = ui.primary.map.get_bus_route(&route_name).unwrap();
|
||||||
(
|
(
|
||||||
ModalMenu::new(
|
|
||||||
format!("Optimize {}", route_name),
|
|
||||||
vec![
|
|
||||||
(hotkey(Key::E), "show bus route"),
|
|
||||||
(hotkey(Key::T), "show delays over time"),
|
|
||||||
(hotkey(Key::P), "show bus passengers"),
|
|
||||||
(hotkey(Key::S), "change statistic"),
|
|
||||||
(hotkey(Key::H), "help"),
|
|
||||||
],
|
|
||||||
ctx,
|
|
||||||
),
|
|
||||||
edit_map_panel(ctx, GameplayMode::OptimizeBus(route_name.clone())),
|
edit_map_panel(ctx, GameplayMode::OptimizeBus(route_name.clone())),
|
||||||
Box::new(OptimizeBus {
|
Box::new(OptimizeBus {
|
||||||
route: route.id,
|
route: route.id,
|
||||||
time: Time::START_OF_DAY,
|
time: Time::START_OF_DAY,
|
||||||
stat: Statistic::Max,
|
stat: Statistic::Max,
|
||||||
|
menu: ModalMenu::new(
|
||||||
|
format!("Optimize {}", route_name),
|
||||||
|
vec![
|
||||||
|
(hotkey(Key::E), "show bus route"),
|
||||||
|
(hotkey(Key::T), "show delays over time"),
|
||||||
|
(hotkey(Key::P), "show bus passengers"),
|
||||||
|
(hotkey(Key::S), "change statistic"),
|
||||||
|
(hotkey(Key::H), "help"),
|
||||||
|
],
|
||||||
|
ctx,
|
||||||
|
)
|
||||||
|
.set_standalone_layout(layout::ContainerOrientation::TopLeftButDownABit(150.0)),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -51,11 +53,10 @@ impl GameplayState for OptimizeBus {
|
|||||||
ctx: &mut EventCtx,
|
ctx: &mut EventCtx,
|
||||||
ui: &mut UI,
|
ui: &mut UI,
|
||||||
overlays: &mut Overlays,
|
overlays: &mut Overlays,
|
||||||
menu: &mut ModalMenu,
|
|
||||||
) -> Option<Transition> {
|
) -> Option<Transition> {
|
||||||
menu.event(ctx);
|
self.menu.event(ctx);
|
||||||
if manage_overlays(
|
if manage_overlays(
|
||||||
menu,
|
&mut self.menu,
|
||||||
ctx,
|
ctx,
|
||||||
"show bus route",
|
"show bus route",
|
||||||
"hide bus route",
|
"hide bus route",
|
||||||
@ -68,7 +69,7 @@ impl GameplayState for OptimizeBus {
|
|||||||
*overlays = Overlays::show_bus_route(self.route, ctx, ui);
|
*overlays = Overlays::show_bus_route(self.route, ctx, ui);
|
||||||
}
|
}
|
||||||
if manage_overlays(
|
if manage_overlays(
|
||||||
menu,
|
&mut self.menu,
|
||||||
ctx,
|
ctx,
|
||||||
"show delays over time",
|
"show delays over time",
|
||||||
"hide delays over time",
|
"hide delays over time",
|
||||||
@ -81,7 +82,7 @@ impl GameplayState for OptimizeBus {
|
|||||||
*overlays = Overlays::delays_over_time(self.route, ctx, ui);
|
*overlays = Overlays::delays_over_time(self.route, ctx, ui);
|
||||||
}
|
}
|
||||||
if manage_overlays(
|
if manage_overlays(
|
||||||
menu,
|
&mut self.menu,
|
||||||
ctx,
|
ctx,
|
||||||
"show bus passengers",
|
"show bus passengers",
|
||||||
"hide bus passengers",
|
"hide bus passengers",
|
||||||
@ -97,10 +98,11 @@ impl GameplayState for OptimizeBus {
|
|||||||
// TODO Expensive
|
// TODO Expensive
|
||||||
if self.time != ui.primary.sim.time() {
|
if self.time != ui.primary.sim.time() {
|
||||||
self.time = ui.primary.sim.time();
|
self.time = ui.primary.sim.time();
|
||||||
menu.set_info(ctx, bus_route_panel(self.route, self.stat, ui));
|
self.menu
|
||||||
|
.set_info(ctx, bus_route_panel(self.route, self.stat, ui));
|
||||||
}
|
}
|
||||||
|
|
||||||
if menu.action("change statistic") {
|
if self.menu.action("change statistic") {
|
||||||
return Some(Transition::Push(WizardState::new(Box::new(
|
return Some(Transition::Push(WizardState::new(Box::new(
|
||||||
move |wiz, ctx, _| {
|
move |wiz, ctx, _| {
|
||||||
// TODO Filter out existing. Make this kind of thing much easier.
|
// TODO Filter out existing. Make this kind of thing much easier.
|
||||||
@ -127,7 +129,7 @@ impl GameplayState for OptimizeBus {
|
|||||||
},
|
},
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
if menu.action("help") {
|
if self.menu.action("help") {
|
||||||
return Some(Transition::Push(msg(
|
return Some(Transition::Push(msg(
|
||||||
"Help",
|
"Help",
|
||||||
vec![
|
vec![
|
||||||
@ -140,6 +142,10 @@ impl GameplayState for OptimizeBus {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw(&self, g: &mut GfxCtx, _: &UI) {
|
||||||
|
self.menu.draw(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bus_route_panel(id: BusRouteID, stat: Statistic, ui: &UI) -> Text {
|
fn bus_route_panel(id: BusRouteID, stat: Statistic, ui: &UI) -> Text {
|
||||||
|
@ -1,25 +1,16 @@
|
|||||||
use crate::game::{msg, Transition};
|
use crate::game::Transition;
|
||||||
use crate::managed::Composite;
|
use crate::managed::Composite;
|
||||||
use crate::sandbox::gameplay::freeform::freeform_controller;
|
use crate::sandbox::gameplay::freeform::freeform_controller;
|
||||||
use crate::sandbox::gameplay::{GameplayMode, GameplayState};
|
use crate::sandbox::gameplay::{GameplayMode, GameplayState};
|
||||||
use crate::sandbox::overlays::Overlays;
|
use crate::sandbox::overlays::Overlays;
|
||||||
use crate::ui::UI;
|
use crate::ui::UI;
|
||||||
use ezgui::{hotkey, EventCtx, Key, ModalMenu};
|
use ezgui::{EventCtx, GfxCtx};
|
||||||
|
|
||||||
pub struct PlayScenario;
|
pub struct PlayScenario;
|
||||||
|
|
||||||
impl PlayScenario {
|
impl PlayScenario {
|
||||||
pub fn new(
|
pub fn new(name: &String, ctx: &mut EventCtx, ui: &UI) -> (Composite, Box<dyn GameplayState>) {
|
||||||
name: &String,
|
|
||||||
ctx: &mut EventCtx,
|
|
||||||
ui: &UI,
|
|
||||||
) -> (ModalMenu, Composite, Box<dyn GameplayState>) {
|
|
||||||
(
|
(
|
||||||
ModalMenu::new(
|
|
||||||
format!("Playing {}", name),
|
|
||||||
vec![(hotkey(Key::H), "help")],
|
|
||||||
ctx,
|
|
||||||
),
|
|
||||||
freeform_controller(ctx, ui, GameplayMode::PlayScenario(name.to_string()), name),
|
freeform_controller(ctx, ui, GameplayMode::PlayScenario(name.to_string()), name),
|
||||||
Box::new(PlayScenario),
|
Box::new(PlayScenario),
|
||||||
)
|
)
|
||||||
@ -27,24 +18,9 @@ impl PlayScenario {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GameplayState for PlayScenario {
|
impl GameplayState for PlayScenario {
|
||||||
fn event(
|
fn event(&mut self, _: &mut EventCtx, _: &mut UI, _: &mut Overlays) -> Option<Transition> {
|
||||||
&mut self,
|
|
||||||
ctx: &mut EventCtx,
|
|
||||||
_: &mut UI,
|
|
||||||
_: &mut Overlays,
|
|
||||||
menu: &mut ModalMenu,
|
|
||||||
) -> Option<Transition> {
|
|
||||||
menu.event(ctx);
|
|
||||||
if menu.action("help") {
|
|
||||||
return Some(Transition::Push(msg(
|
|
||||||
"Help",
|
|
||||||
vec![
|
|
||||||
"Do things seem a bit quiet?",
|
|
||||||
"The simulation starts at midnight, so you might need to wait a bit.",
|
|
||||||
"Try using the speed controls on the left.",
|
|
||||||
],
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw(&self, _: &mut GfxCtx, _: &UI) {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user