From b2b7d0767c9940fd17775e87affe724b3e5b63a8 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 1 May 2019 11:31:53 -0700 Subject: [PATCH] use a modal menu for tutorial mode --- docs/TODO_game.md | 1 - editor/src/game.rs | 1 + editor/src/tutorial.rs | 60 ++++++++++++++++++------------------------ 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/docs/TODO_game.md b/docs/TODO_game.md index 05956a4dea..035b07135d 100644 --- a/docs/TODO_game.md +++ b/docs/TODO_game.md @@ -16,7 +16,6 @@ - big vertical road. some neighborhoods off to the side. everyone trying to go nrth or south. one driving, one parkign lane. a bus that makes a loop. some horizontal roads connected to borders that force the vertical road to not be fast. just make a dedicated bus lane! oops,except some of the bus stops are at narrow places, so traffic has to slow down anyway for the bus. maybe there's a bypass road through a neighborhood? - introduce elements gradually... fix a silly traffic signal with just cars, then add peds and bikes... -- use a modalish menu to display instructions and also give the 'escape' option - spawn cars somewhere - run sim, pause, change speed, reset diff --git a/editor/src/game.rs b/editor/src/game.rs index d2903a254f..f9830993b4 100644 --- a/editor/src/game.rs +++ b/editor/src/game.rs @@ -207,6 +207,7 @@ impl GUI for GameState { "A/B Test Editor", vec![(Key::Escape, "quit"), (Key::R, "run A/B test")], ), + ModalMenu::new("Tutorial", vec![(Key::Escape, "quit")]), ] } diff --git a/editor/src/tutorial.rs b/editor/src/tutorial.rs index 4be708eb36..1f80f93918 100644 --- a/editor/src/tutorial.rs +++ b/editor/src/tutorial.rs @@ -1,9 +1,7 @@ use crate::game::{GameState, Mode}; use crate::render::DrawOptions; use crate::ui::ShowEverything; -use ezgui::{ - EventCtx, EventLoopMode, GfxCtx, HorizontalAlignment, Key, Text, VerticalAlignment, Wizard, -}; +use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard}; use geom::Pt2D; // Does CommonState make sense? @@ -16,24 +14,40 @@ impl TutorialMode { pub fn event(state: &mut GameState, ctx: &mut EventCtx) -> EventLoopMode { ctx.canvas.handle_event(ctx.input); + let mut txt = Text::new(); + txt.add_styled_line("Tutorial".to_string(), None, Some(Color::BLUE), None); match state.mode { Mode::Tutorial(TutorialMode::Part1(orig_center)) => { + txt.add_line("Click and drag to pan around".to_string()); + // TODO Zooming also changes this. :( - if ctx.canvas.center_to_map_pt() != orig_center - && ctx.input.key_pressed(Key::Enter, "next step of tutorial") - { - state.mode = Mode::Tutorial(TutorialMode::Part2(ctx.canvas.cam_zoom)); + if ctx.canvas.center_to_map_pt() != orig_center { + txt.add_line("".to_string()); + txt.add_line("Great! Press ENTER to continue.".to_string()); + if ctx.input.key_pressed(Key::Enter, "next step of tutorial") { + state.mode = Mode::Tutorial(TutorialMode::Part2(ctx.canvas.cam_zoom)); + } } } Mode::Tutorial(TutorialMode::Part2(orig_cam_zoom)) => { - if ctx.canvas.cam_zoom != orig_cam_zoom - && ctx.input.key_pressed(Key::Enter, "next step of tutorial") - { - state.mode = Mode::SplashScreen(Wizard::new(), None); + txt.add_line("Use your mouse wheel or touchpad to zoom in and out".to_string()); + + if ctx.canvas.cam_zoom != orig_cam_zoom { + txt.add_line("".to_string()); + txt.add_line("Great! Press ENTER to continue.".to_string()); + if ctx.input.key_pressed(Key::Enter, "next step of tutorial") { + state.mode = Mode::SplashScreen(Wizard::new(), None); + } } } _ => unreachable!(), } + ctx.input + .set_mode_with_new_prompt("Tutorial", txt, ctx.canvas); + + if ctx.input.modal_action("quit") { + state.mode = Mode::SplashScreen(Wizard::new(), None); + } EventLoopMode::InputOnly } @@ -45,29 +59,5 @@ impl TutorialMode { &state.ui.primary.sim, &ShowEverything::new(), ); - - let mut txt = Text::new(); - match state.mode { - Mode::Tutorial(TutorialMode::Part1(orig_center)) => { - txt.add_line("Click and drag to pan around".to_string()); - if g.canvas.center_to_map_pt() != orig_center { - txt.add_line("".to_string()); - txt.add_line("Great! Press ENTER to continue.".to_string()); - } - } - Mode::Tutorial(TutorialMode::Part2(orig_cam_zoom)) => { - txt.add_line("Use your mouse wheel or touchpad to zoom in and out".to_string()); - if g.canvas.cam_zoom != orig_cam_zoom { - txt.add_line("".to_string()); - txt.add_line("Great! Press ENTER to continue.".to_string()); - } - } - _ => unreachable!(), - } - // TODO Get rid of top menu and OSD and then put this somewhere more sensible. :) - g.draw_blocking_text( - &txt, - (HorizontalAlignment::Right, VerticalAlignment::Center), - ); } }