mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
trigger CommonState actions from a bunch of modal menus
This commit is contained in:
parent
6f4252fcae
commit
10240aa478
@ -41,15 +41,19 @@ impl ABTestMode {
|
||||
menu: ModalMenu::new(
|
||||
"A/B Test Mode",
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::LeftBracket), "slow down sim"),
|
||||
(Some(Key::RightBracket), "speed up sim"),
|
||||
(Some(Key::Space), "run/pause sim"),
|
||||
(Some(Key::M), "run one step of sim"),
|
||||
(Some(Key::S), "swap"),
|
||||
(Some(Key::D), "diff all trips"),
|
||||
(Some(Key::B), "stop diffing trips"),
|
||||
],
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::LeftBracket), "slow down sim"),
|
||||
(Some(Key::RightBracket), "speed up sim"),
|
||||
(Some(Key::Space), "run/pause sim"),
|
||||
(Some(Key::M), "run one step of sim"),
|
||||
(Some(Key::S), "swap"),
|
||||
(Some(Key::D), "diff all trips"),
|
||||
(Some(Key::B), "stop diffing trips"),
|
||||
],
|
||||
CommonState::modal_menu_entries(),
|
||||
]
|
||||
.concat(),
|
||||
ctx,
|
||||
),
|
||||
desired_speed: 1.0,
|
||||
@ -101,7 +105,7 @@ impl ABTestMode {
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
);
|
||||
if let Some(evmode) = mode.common.event(ctx, &state.ui) {
|
||||
if let Some(evmode) = mode.common.event(ctx, &state.ui, &mut mode.menu) {
|
||||
return evmode;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,8 @@ use crate::render::DrawOptions;
|
||||
use crate::ui::UI;
|
||||
use abstutil::elapsed_seconds;
|
||||
use ezgui::{
|
||||
Color, EventCtx, EventLoopMode, GfxCtx, HorizontalAlignment, Key, Text, VerticalAlignment,
|
||||
Color, EventCtx, EventLoopMode, GfxCtx, HorizontalAlignment, Key, ModalMenu, Text,
|
||||
VerticalAlignment,
|
||||
};
|
||||
use geom::{Line, Pt2D};
|
||||
use std::time::Instant;
|
||||
@ -30,16 +31,30 @@ impl CommonState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modal_menu_entries() -> Vec<(Option<Key>, &'static str)> {
|
||||
vec![
|
||||
(Some(Key::J), "warp"),
|
||||
// TODO This definitely conflicts with some modes.
|
||||
(Some(Key::K), "navigate"),
|
||||
(Some(Key::F1), "take a screenshot"),
|
||||
]
|
||||
}
|
||||
|
||||
// If this returns something, then this common state should prevent other things from
|
||||
// happening.
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI) -> Option<EventLoopMode> {
|
||||
pub fn event(
|
||||
&mut self,
|
||||
ctx: &mut EventCtx,
|
||||
ui: &UI,
|
||||
menu: &mut ModalMenu,
|
||||
) -> Option<EventLoopMode> {
|
||||
if let Some(ref mut warp) = self.warp {
|
||||
if let Some(evmode) = warp.event(ctx, ui) {
|
||||
return Some(evmode);
|
||||
}
|
||||
self.warp = None;
|
||||
}
|
||||
if ctx.input.unimportant_key_pressed(Key::J, "warp") {
|
||||
if menu.action("warp") {
|
||||
self.warp = Some(warp::WarpState::new());
|
||||
}
|
||||
if let Some(ref mut navigate) = self.navigate {
|
||||
@ -48,18 +63,13 @@ impl CommonState {
|
||||
}
|
||||
self.navigate = None;
|
||||
}
|
||||
// TODO This definitely conflicts with some modes.
|
||||
if ctx.input.unimportant_key_pressed(Key::K, "navigate") {
|
||||
if menu.action("navigate") {
|
||||
self.navigate = Some(navigate::Navigator::new(ui));
|
||||
}
|
||||
|
||||
self.associated.event(ui);
|
||||
self.turn_cycler.event(ctx, ui);
|
||||
// TODO How to reserve and explain this key?
|
||||
if ctx
|
||||
.input
|
||||
.unimportant_key_pressed(Key::F1, "screenshot just this")
|
||||
{
|
||||
if menu.action("take a screenshot") {
|
||||
return Some(EventLoopMode::ScreenCaptureCurrentShot);
|
||||
}
|
||||
None
|
||||
|
@ -33,7 +33,7 @@ impl TurnCyclerState {
|
||||
self.state = State::ShowLane(id);
|
||||
} else if ctx
|
||||
.input
|
||||
.key_pressed(Key::Z, "cycle through this lane's turns")
|
||||
.contextual_action(Key::Z, "cycle through this lane's turns")
|
||||
{
|
||||
self.state = State::CycleTurns(id, idx + 1);
|
||||
}
|
||||
@ -42,7 +42,7 @@ impl TurnCyclerState {
|
||||
if !ui.primary.map.get_turns_from_lane(id).is_empty()
|
||||
&& ctx
|
||||
.input
|
||||
.key_pressed(Key::Z, "cycle through this lane's turns")
|
||||
.contextual_action(Key::Z, "cycle through this lane's turns")
|
||||
{
|
||||
self.state = State::CycleTurns(id, 0);
|
||||
}
|
||||
@ -66,7 +66,7 @@ impl TurnCyclerState {
|
||||
// TODO How to tell the user that holding control and shift is sometimes useful?
|
||||
if ctx
|
||||
.input
|
||||
.unimportant_key_pressed(Key::LeftShift, "show full traffic signal diagram")
|
||||
.contextual_action(Key::LeftShift, "show full traffic signal diagram")
|
||||
{
|
||||
self.shift_key_held = true;
|
||||
}
|
||||
|
@ -63,22 +63,26 @@ impl DebugMode {
|
||||
State::Exploring(ModalMenu::new(
|
||||
"Debug Mode",
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::C), "show/hide chokepoints"),
|
||||
(Some(Key::O), "clear original roads shown"),
|
||||
(Some(Key::K), "unhide everything"),
|
||||
(Some(Key::Num1), "show/hide buildings"),
|
||||
(Some(Key::Num2), "show/hide intersections"),
|
||||
(Some(Key::Num3), "show/hide lanes"),
|
||||
(Some(Key::Num4), "show/hide areas"),
|
||||
(Some(Key::Num5), "show/hide extra shapes"),
|
||||
(Some(Key::Num6), "show/hide geometry debug mode"),
|
||||
(None, "screenshot everything"),
|
||||
(Some(Key::Slash), "search OSM metadata"),
|
||||
(Some(Key::M), "clear OSM search results"),
|
||||
(Some(Key::S), "configure colors"),
|
||||
(Some(Key::N), "show/hide neighborhood summaries"),
|
||||
],
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::C), "show/hide chokepoints"),
|
||||
(Some(Key::O), "clear original roads shown"),
|
||||
(Some(Key::K), "unhide everything"),
|
||||
(Some(Key::Num1), "show/hide buildings"),
|
||||
(Some(Key::Num2), "show/hide intersections"),
|
||||
(Some(Key::Num3), "show/hide lanes"),
|
||||
(Some(Key::Num4), "show/hide areas"),
|
||||
(Some(Key::Num5), "show/hide extra shapes"),
|
||||
(Some(Key::Num6), "show/hide geometry debug mode"),
|
||||
(None, "screenshot everything"),
|
||||
(Some(Key::Slash), "search OSM metadata"),
|
||||
(Some(Key::M), "clear OSM search results"),
|
||||
(Some(Key::S), "configure colors"),
|
||||
(Some(Key::N), "show/hide neighborhood summaries"),
|
||||
],
|
||||
CommonState::modal_menu_entries(),
|
||||
]
|
||||
.concat(),
|
||||
ctx,
|
||||
))
|
||||
}
|
||||
@ -123,7 +127,7 @@ impl DebugMode {
|
||||
menu.handle_event(ctx, Some(txt));
|
||||
|
||||
ctx.canvas.handle_event(ctx.input);
|
||||
if let Some(evmode) = mode.common.event(ctx, &state.ui) {
|
||||
if let Some(evmode) = mode.common.event(ctx, &state.ui, menu) {
|
||||
return evmode;
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,14 @@ impl EditMode {
|
||||
ModalMenu::new(
|
||||
"Map Edit Mode",
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::S), "save edits"),
|
||||
(Some(Key::L), "load different edits"),
|
||||
],
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::S), "save edits"),
|
||||
(Some(Key::L), "load different edits"),
|
||||
],
|
||||
CommonState::modal_menu_entries(),
|
||||
]
|
||||
.concat(),
|
||||
ctx,
|
||||
),
|
||||
)
|
||||
@ -47,11 +51,6 @@ impl EditMode {
|
||||
txt.add_line(state.ui.primary.map.get_edits().describe());
|
||||
txt.add_line("Right-click a lane or intersection to start editing".to_string());
|
||||
menu.handle_event(ctx, Some(txt));
|
||||
if menu.action("quit") {
|
||||
// TODO Warn about unsaved edits
|
||||
state.mode = Mode::SplashScreen(Wizard::new(), None);
|
||||
return EventLoopMode::InputOnly;
|
||||
}
|
||||
|
||||
ctx.canvas.handle_event(ctx.input);
|
||||
|
||||
@ -66,10 +65,15 @@ impl EditMode {
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
);
|
||||
if let Some(evmode) = common.event(ctx, &state.ui) {
|
||||
if let Some(evmode) = common.event(ctx, &state.ui, menu) {
|
||||
return evmode;
|
||||
}
|
||||
|
||||
if menu.action("quit") {
|
||||
// TODO Warn about unsaved edits
|
||||
state.mode = Mode::SplashScreen(Wizard::new(), None);
|
||||
return EventLoopMode::InputOnly;
|
||||
}
|
||||
// TODO Only if current edits are unsaved
|
||||
if menu.action("save edits") {
|
||||
state.mode = Mode::Edit(EditMode::Saving(Wizard::new()));
|
||||
|
@ -51,24 +51,28 @@ impl SandboxMode {
|
||||
menu: ModalMenu::hacky_new(
|
||||
"Sandbox Mode",
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::LeftBracket), "slow down sim"),
|
||||
(Some(Key::RightBracket), "speed up sim"),
|
||||
(Some(Key::O), "save sim state"),
|
||||
(Some(Key::Y), "load previous sim state"),
|
||||
(Some(Key::U), "load next sim state"),
|
||||
(Some(Key::Space), "run/pause sim"),
|
||||
(Some(Key::M), "run one step of sim"),
|
||||
(Some(Key::X), "reset sim"),
|
||||
(Some(Key::S), "seed the sim with agents"),
|
||||
// TODO Strange to always have this. Really it's a case of stacked modal?
|
||||
(Some(Key::F), "stop following agent"),
|
||||
(Some(Key::R), "stop showing agent's route"),
|
||||
// TODO This should probably be a debug thing instead
|
||||
(Some(Key::L), "show/hide route for all agents"),
|
||||
(Some(Key::A), "show/hide active traffic"),
|
||||
(Some(Key::T), "start time traveling"),
|
||||
],
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::LeftBracket), "slow down sim"),
|
||||
(Some(Key::RightBracket), "speed up sim"),
|
||||
(Some(Key::O), "save sim state"),
|
||||
(Some(Key::Y), "load previous sim state"),
|
||||
(Some(Key::U), "load next sim state"),
|
||||
(Some(Key::Space), "run/pause sim"),
|
||||
(Some(Key::M), "run one step of sim"),
|
||||
(Some(Key::X), "reset sim"),
|
||||
(Some(Key::S), "seed the sim with agents"),
|
||||
// TODO Strange to always have this. Really it's a case of stacked modal?
|
||||
(Some(Key::F), "stop following agent"),
|
||||
(Some(Key::R), "stop showing agent's route"),
|
||||
// TODO This should probably be a debug thing instead
|
||||
(Some(Key::L), "show/hide route for all agents"),
|
||||
(Some(Key::A), "show/hide active traffic"),
|
||||
(Some(Key::T), "start time traveling"),
|
||||
],
|
||||
CommonState::modal_menu_entries(),
|
||||
]
|
||||
.concat(),
|
||||
canvas,
|
||||
),
|
||||
}
|
||||
@ -132,7 +136,7 @@ impl SandboxMode {
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
);
|
||||
if let Some(evmode) = mode.common.event(ctx, &state.ui) {
|
||||
if let Some(evmode) = mode.common.event(ctx, &state.ui, &mut mode.menu) {
|
||||
return evmode;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user