mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 01:13:53 +03:00
trigger CommonState actions from a bunch of modal menus
This commit is contained in:
parent
6f4252fcae
commit
10240aa478
@ -40,6 +40,7 @@ impl ABTestMode {
|
||||
ABTestMode {
|
||||
menu: ModalMenu::new(
|
||||
"A/B Test Mode",
|
||||
vec![
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::LeftBracket), "slow down sim"),
|
||||
@ -50,6 +51,9 @@ impl ABTestMode {
|
||||
(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;
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ impl DebugMode {
|
||||
fn exploring_state(ctx: &EventCtx) -> State {
|
||||
State::Exploring(ModalMenu::new(
|
||||
"Debug Mode",
|
||||
vec![
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::C), "show/hide chokepoints"),
|
||||
@ -79,6 +80,9 @@ impl DebugMode {
|
||||
(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;
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,15 @@ impl EditMode {
|
||||
CommonState::new(),
|
||||
ModalMenu::new(
|
||||
"Map Edit Mode",
|
||||
vec![
|
||||
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()));
|
||||
|
@ -50,6 +50,7 @@ impl SandboxMode {
|
||||
common: CommonState::new(),
|
||||
menu: ModalMenu::hacky_new(
|
||||
"Sandbox Mode",
|
||||
vec![
|
||||
vec![
|
||||
(Some(Key::Escape), "quit"),
|
||||
(Some(Key::LeftBracket), "slow down sim"),
|
||||
@ -69,6 +70,9 @@ impl SandboxMode {
|
||||
(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