From 3547c2cf1ba2a887b5b7a22292adb3d3fe326958 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 18 Dec 2019 15:14:59 -0800 Subject: [PATCH] move some sandox menu items to tool panel for the moment --- data/MANIFEST.txt | 10 ++--- game/src/abtest/mod.rs | 2 +- game/src/common/panels.rs | 15 ++------ game/src/debug/mod.rs | 2 +- game/src/edit/mod.rs | 2 +- game/src/managed.rs | 2 +- game/src/mission/scenario.rs | 2 +- game/src/sandbox/bus_explorer.rs | 30 ++++++--------- game/src/sandbox/mod.rs | 65 +++++++++++++++++++++----------- 9 files changed, 67 insertions(+), 63 deletions(-) diff --git a/data/MANIFEST.txt b/data/MANIFEST.txt index cbc4898fc6..e78419aad7 100644 --- a/data/MANIFEST.txt +++ b/data/MANIFEST.txt @@ -1,5 +1,5 @@ a5e849fa8883569519976ebfef3ae269 data/system/night_colors.json -bb88577b253c978e4d08435a525f2b39 data/system/override_colors.json +1909af5ebfefe7ad4102335c9e789d24 data/system/override_colors.json 395df98242f9fd7bd2fc8545f0bbc908 data/system/maps/huge_seattle.bin 5dbca78c451a3552502cb185edbee1ec data/system/maps/ballard.bin b5fb2ec706d444f7f6ee23f63f4f44b4 data/system/maps/downtown.bin @@ -15,7 +15,7 @@ c54a90163d461aa495ed83cdd8b8aa23 data/system/scenarios/downtown/weekday_typical 4627ad77a372041371ecd49ae2463168 data/system/scenarios/huge_seattle/weekday_typical_traffic_from_psrc.bin cb730a393826acf17dd65e5fb202e329 data/system/scenarios/caphill/weekday_typical_traffic_from_psrc.bin 5d720b255d1b63ca67a67f64f84b6387 data/system/scenarios/montlake/weekday_typical_traffic_from_psrc.bin -0abb70b9ff5753ef7ef318b2a2374948 data/system/prebaked_results/23rd/weekday_typical_traffic_from_psrc.bin -9571e8d7779db30dd16e2619057b6f0b data/system/prebaked_results/signal_single/tutorial lvl1.bin -524914e59a21a5e29d4053e22624a8cf data/system/prebaked_results/signal_single/tutorial lvl2.bin -d9a3ab9d67207d29f1cc660c6e3ad3b5 data/system/prebaked_results/montlake/weekday_typical_traffic_from_psrc.bin +cd00432a82d198d2077b5a0ac346a81b data/system/prebaked_results/23rd/weekday_typical_traffic_from_psrc.bin +4bd6932b24539a6fb0d3896c0b72186e data/system/prebaked_results/signal_single/tutorial lvl1.bin +bc80d17d4d11cde80a9393f2493ff432 data/system/prebaked_results/signal_single/tutorial lvl2.bin +da0e8ebce442bd9ece172d76deb2fe65 data/system/prebaked_results/montlake/weekday_typical_traffic_from_psrc.bin diff --git a/game/src/abtest/mod.rs b/game/src/abtest/mod.rs index c81a355fea..1a7d6631df 100644 --- a/game/src/abtest/mod.rs +++ b/game/src/abtest/mod.rs @@ -47,7 +47,7 @@ impl ABTestMode { diff_trip: None, diff_all: None, common: CommonState::new(), - tool_panel: tool_panel(ctx, None), + tool_panel: tool_panel(ctx, Vec::new()), test_name: test_name.to_string(), flipped: false, } diff --git a/game/src/common/panels.rs b/game/src/common/panels.rs index e3d6d6c617..3dd79bc82a 100644 --- a/game/src/common/panels.rs +++ b/game/src/common/panels.rs @@ -1,10 +1,11 @@ use crate::common::{navigate, shortcuts}; use crate::game::Transition; -use crate::managed::{Callback, Composite, ManagedWidget}; +use crate::managed::{Composite, ManagedWidget}; use crate::options; use ezgui::{hotkey, Button, Color, EventCtx, Key, RewriteColor, ScreenPt}; -pub fn tool_panel(ctx: &EventCtx, layers_callback: Option) -> Composite { +// TODO Rethink this API. +pub fn tool_panel(ctx: &EventCtx, extra_buttons: Vec) -> Composite { let mut row = vec![ // TODO Maybe this is confusing -- it doesn't jump to the title screen necessarily. // Caller has to handle this one @@ -40,15 +41,7 @@ pub fn tool_panel(ctx: &EventCtx, layers_callback: Option) -> Composit Box::new(|_, _| Some(Transition::Push(shortcuts::ChoosingShortcut::new()))), ), ]; - if let Some(cb) = layers_callback { - row.push(ManagedWidget::svg_button( - ctx, - "assets/tools/layers.svg", - "change overlay", - hotkey(Key::L), - cb, - )); - } + row.extend(extra_buttons); Composite::minimal_size( ManagedWidget::row(row) diff --git a/game/src/debug/mod.rs b/game/src/debug/mod.rs index 23dc9cb519..c609e142b6 100644 --- a/game/src/debug/mod.rs +++ b/game/src/debug/mod.rs @@ -55,7 +55,7 @@ impl DebugMode { ctx, ), common: CommonState::new(), - tool_panel: tool_panel(ctx, None), + tool_panel: tool_panel(ctx, Vec::new()), associated: associated::ShowAssociatedState::Inactive, connected_roads: connected_roads::ShowConnectedRoads::new(), objects: objects::ObjectDebugger::new(), diff --git a/game/src/edit/mod.rs b/game/src/edit/mod.rs index 6adfddd91f..a5175317d2 100644 --- a/game/src/edit/mod.rs +++ b/game/src/edit/mod.rs @@ -33,7 +33,7 @@ impl EditMode { pub fn new(ctx: &EventCtx, mode: GameplayMode) -> EditMode { EditMode { common: CommonState::new(), - tool_panel: tool_panel(ctx, None), + tool_panel: tool_panel(ctx, Vec::new()), menu: ModalMenu::new( "Map Edit Mode", vec![ diff --git a/game/src/managed.rs b/game/src/managed.rs index d2cdbbd247..e86d4ebf63 100644 --- a/game/src/managed.rs +++ b/game/src/managed.rs @@ -11,7 +11,7 @@ use stretch::geometry::{Rect, Size}; use stretch::node::{Node, Stretch}; use stretch::style::{AlignItems, Dimension, FlexDirection, FlexWrap, JustifyContent, Style}; -pub type Callback = Box Option>; +type Callback = Box Option>; pub struct ManagedWidget { widget: WidgetType, diff --git a/game/src/mission/scenario.rs b/game/src/mission/scenario.rs index 2ece2ba357..84f38bce9a 100644 --- a/game/src/mission/scenario.rs +++ b/game/src/mission/scenario.rs @@ -125,7 +125,7 @@ impl ScenarioManager { ctx, ), common: CommonState::new(), - tool_panel: tool_panel(ctx, None), + tool_panel: tool_panel(ctx, Vec::new()), scenario, trips_from_bldg, trips_to_bldg, diff --git a/game/src/sandbox/bus_explorer.rs b/game/src/sandbox/bus_explorer.rs index 06fda599d6..e0c9c1d21c 100644 --- a/game/src/sandbox/bus_explorer.rs +++ b/game/src/sandbox/bus_explorer.rs @@ -2,9 +2,7 @@ use crate::common::{CommonState, RoadColorer, RoadColorerBuilder}; use crate::game::{State, Transition, WizardState}; use crate::helpers::ID; use crate::ui::UI; -use ezgui::{ - Choice, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, ModalMenu, Text, WarpingItemSlider, -}; +use ezgui::{Choice, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, Text, WarpingItemSlider}; use geom::{Circle, Distance, Pt2D}; use map_model::{BusRoute, BusRouteID, BusStopID, PathConstraints, PathRequest, PathStep}; @@ -178,22 +176,16 @@ impl State for BusRouteExplorer { } } -pub struct BusRoutePicker; -impl BusRoutePicker { - pub fn new(ui: &UI, menu: &mut ModalMenu) -> Option> { - if ui.primary.current_selection.is_some() || !menu.action("explore a bus route") { - return None; - } - Some(make_bus_route_picker( - ui.primary - .map - .get_all_bus_routes() - .iter() - .map(|r| r.id) - .collect(), - None, - )) - } +pub fn pick_any_bus_route(_: &mut EventCtx, ui: &mut UI) -> Option { + Some(Transition::Push(make_bus_route_picker( + ui.primary + .map + .get_all_bus_routes() + .iter() + .map(|r| r.id) + .collect(), + None, + ))) } fn make_bus_route_picker(routes: Vec, start: Option) -> Box { diff --git a/game/src/sandbox/mod.rs b/game/src/sandbox/mod.rs index 6febf959fd..ac2063937a 100644 --- a/game/src/sandbox/mod.rs +++ b/game/src/sandbox/mod.rs @@ -16,8 +16,8 @@ use crate::pregame::main_menu; use crate::ui::{ShowEverything, UI}; use abstutil::Timer; use ezgui::{ - hotkey, layout, lctrl, Choice, Color, EventCtx, EventLoopMode, GfxCtx, Key, Line, ModalMenu, - ScreenPt, Text, + hotkey, layout, lctrl, Button, Choice, Color, EventCtx, EventLoopMode, GfxCtx, Key, Line, + ModalMenu, ScreenPt, Text, }; pub use gameplay::spawner::spawn_agents_around; pub use gameplay::GameplayMode; @@ -45,23 +45,45 @@ impl SandboxMode { agent_tools: AgentTools::new(), overlay: Overlays::Inactive, common: CommonState::new(), - tool_panel: tool_panel(ctx, Some(Box::new(Overlays::change_overlays))), + tool_panel: tool_panel( + ctx, + vec![ + ManagedWidget::svg_button( + ctx, + "assets/tools/layers.svg", + "change overlay", + hotkey(Key::L), + Box::new(Overlays::change_overlays), + ), + ManagedWidget::btn_no_cb(Button::text( + Text::from(Line("scoreboard").size(12)), + Color::grey(0.6), + Color::ORANGE, + hotkey(Key::Q), + "scoreboard", + ctx, + )), + ManagedWidget::btn( + Button::text( + Text::from(Line("explore a bus route").size(12)), + Color::grey(0.6), + Color::ORANGE, + hotkey(Key::Q), + "explore a bus route", + ctx, + ), + Box::new(bus_explorer::pick_any_bus_route), + ), + ], + ), minimap: if mode.has_minimap() { Some(Minimap::new(ctx, ui)) } else { None }, gameplay: gameplay::GameplayRunner::initialize(mode, ui, ctx), - menu: ModalMenu::new( - "Sandbox Mode", - vec![ - (lctrl(Key::E), "edit mode"), - (hotkey(Key::Q), "scoreboard"), - (None, "explore a bus route"), - ], - ctx, - ) - .disable_standalone_layout(), + menu: ModalMenu::new("Sandbox Mode", vec![(lctrl(Key::E), "edit mode")], ctx) + .disable_standalone_layout(), } } } @@ -103,19 +125,9 @@ impl State for SandboxMode { if let Some(t) = self.agent_tools.event(ctx, ui, &mut self.menu) { return t; } - if self.menu.action("scoreboard") { - return Transition::Push(Box::new(score::Scoreboard::new( - ctx, - ui, - &self.gameplay.prebaked, - ))); - } if let Some(explorer) = bus_explorer::BusRouteExplorer::new(ctx, ui) { return Transition::PushWithMode(explorer, EventLoopMode::Animation); } - if let Some(picker) = bus_explorer::BusRoutePicker::new(ui, &mut self.menu) { - return Transition::Push(picker); - } if ui.opts.dev && ctx.input.new_was_pressed(lctrl(Key::D).unwrap()) { return Transition::Push(Box::new(DebugMode::new(ctx))); @@ -250,6 +262,13 @@ impl State for SandboxMode { } }))); } + "scoreboard" => { + return Transition::Push(Box::new(score::Scoreboard::new( + ctx, + ui, + &self.gameplay.prebaked, + ))); + } _ => unreachable!(), }, None => {}