From 41f4cfff6d0d03975b680931c355f782b2ffb435 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 3 Aug 2020 13:42:59 -0700 Subject: [PATCH] tool-assisted refactor of ezgui Outcome --- ezgui/examples/demo.rs | 8 ++++---- ezgui/src/managed.rs | 10 +++++----- ezgui/src/tools/wizard.rs | 14 +++++++------- ezgui/src/widgets/button.rs | 4 ++-- ezgui/src/widgets/checkbox.rs | 7 ++++--- ezgui/src/widgets/containers.rs | 4 ++-- ezgui/src/widgets/dropdown.rs | 7 ++++--- ezgui/src/widgets/menu.rs | 6 +++--- ezgui/src/widgets/mod.rs | 10 ++++++++-- ezgui/src/widgets/persistent_split.rs | 4 ++-- ezgui/src/widgets/spinner.rs | 10 ++++++---- game/src/common/city_picker.rs | 4 ++-- game/src/common/isochrone.rs | 4 ++-- game/src/common/minimap.rs | 4 ++-- game/src/common/navigate.rs | 12 ++++++------ game/src/common/warp.rs | 4 ++-- game/src/cutscene.rs | 8 ++++---- game/src/debug/floodfill.rs | 4 ++-- game/src/debug/mod.rs | 4 ++-- game/src/debug/polygons.rs | 4 ++-- game/src/devtools/destinations.rs | 4 ++-- game/src/devtools/kml.rs | 4 ++-- game/src/devtools/mapping.rs | 4 ++-- game/src/devtools/mod.rs | 4 ++-- game/src/devtools/polygon.rs | 4 ++-- game/src/devtools/scenario.rs | 4 ++-- game/src/devtools/story.rs | 8 ++++---- game/src/edit/bulk.rs | 8 ++++---- game/src/edit/cluster_traffic_signals.rs | 4 ++-- game/src/edit/lanes.rs | 4 ++-- game/src/edit/mod.rs | 16 ++++++++-------- game/src/edit/select.rs | 2 +- game/src/edit/stop_signs.rs | 4 ++-- game/src/edit/traffic_signals.rs | 12 ++++++------ game/src/edit/zones.rs | 4 ++-- game/src/info/mod.rs | 4 ++-- game/src/layer/mod.rs | 8 ++++---- game/src/layer/pandemic.rs | 4 ++-- game/src/layer/parking.rs | 4 ++-- game/src/layer/population.rs | 4 ++-- game/src/layer/traffic.rs | 8 ++++---- game/src/layer/transit.rs | 4 ++-- game/src/managed.rs | 3 ++- game/src/options.rs | 4 ++-- game/src/pregame.rs | 16 ++++++++-------- game/src/sandbox/dashboards/commuter.rs | 4 ++-- game/src/sandbox/dashboards/misc.rs | 8 ++++---- game/src/sandbox/dashboards/parking_overhead.rs | 4 ++-- game/src/sandbox/dashboards/summaries.rs | 4 ++-- game/src/sandbox/dashboards/trip_table.rs | 4 ++-- game/src/sandbox/gameplay/commute.rs | 8 ++++---- game/src/sandbox/gameplay/fix_traffic_signals.rs | 8 ++++---- game/src/sandbox/gameplay/freeform.rs | 8 ++++---- game/src/sandbox/gameplay/mod.rs | 4 ++-- game/src/sandbox/gameplay/play_scenario.rs | 12 ++++++------ game/src/sandbox/gameplay/tutorial.rs | 8 ++++---- game/src/sandbox/misc_tools.rs | 8 ++++---- game/src/sandbox/mod.rs | 4 ++-- game/src/sandbox/speed.rs | 12 ++++++------ game/src/sandbox/uber_turns.rs | 8 ++++---- map_editor/src/main.rs | 4 ++-- 61 files changed, 198 insertions(+), 187 deletions(-) diff --git a/ezgui/examples/demo.rs b/ezgui/examples/demo.rs index bba9e994a2..3359bbdbde 100644 --- a/ezgui/examples/demo.rs +++ b/ezgui/examples/demo.rs @@ -121,7 +121,7 @@ impl GUI for App { // This dispatches event handling to all of the widgets inside. match self.controls.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { // These outcomes should probably be a custom enum per Composite, to be more // typesafe. "reset the stopwatch" => { @@ -140,7 +140,7 @@ impl GUI for App { } _ => unreachable!(), }, - None => {} + _ => {} } // An update event means that no keyboard/mouse input happened, but time has passed. @@ -176,8 +176,8 @@ impl GUI for App { if let Some((_, ref mut p)) = self.timeseries_panel { match p.event(ctx) { // No buttons in there - Some(Outcome::Clicked(_)) => unreachable!(), - None => {} + Outcome::Clicked(_) => unreachable!(), + _ => {} } } diff --git a/ezgui/src/managed.rs b/ezgui/src/managed.rs index 906576941d..4a42374252 100644 --- a/ezgui/src/managed.rs +++ b/ezgui/src/managed.rs @@ -742,7 +742,7 @@ impl Composite { } } - pub fn event(&mut self, ctx: &mut EventCtx) -> Option { + pub fn event(&mut self, ctx: &mut EventCtx) -> Outcome { if (self.scrollable_x || self.scrollable_y) && ctx .canvas @@ -834,7 +834,7 @@ impl Composite { self.top_level.restore(ctx, &prev); // Since we just moved things around, let all widgets respond to the mouse being somewhere - ctx.no_op_event(true, |ctx| assert!(self.event(ctx).is_none())); + ctx.no_op_event(true, |ctx| assert_eq!(self.event(ctx), Outcome::Nothing)); } pub fn scroll_to_member(&mut self, ctx: &EventCtx, name: String) { @@ -934,14 +934,14 @@ impl Composite { self.recompute_layout(ctx, false); // Since we just moved things around, let all widgets respond to the mouse being somewhere - ctx.no_op_event(true, |ctx| assert!(self.event(ctx).is_none())); + ctx.no_op_event(true, |ctx| assert_eq!(self.event(ctx), Outcome::Nothing)); } pub fn align_below(&mut self, ctx: &mut EventCtx, other: &Composite, pad: f64) { self.vert = VerticalAlignment::Below(other.top_level.rect.y2 + pad); self.recompute_layout(ctx, false); // Since we just moved things around, let all widgets respond to the mouse being somewhere - ctx.no_op_event(true, |ctx| assert!(self.event(ctx).is_none())); + ctx.no_op_event(true, |ctx| assert_eq!(self.event(ctx), Outcome::Nothing)); } // All margins/padding/etc from the previous widget are retained. @@ -1045,7 +1045,7 @@ impl CompositeBuilder { // Just trigger error if a button is double-defined c.get_all_click_actions(); // Let all widgets initially respond to the mouse being somewhere - ctx.no_op_event(true, |ctx| assert!(c.event(ctx).is_none())); + ctx.no_op_event(true, |ctx| assert_eq!(c.event(ctx), Outcome::Nothing)); c } diff --git a/ezgui/src/tools/wizard.rs b/ezgui/src/tools/wizard.rs index 16dbb2a2f6..5ebe54334f 100644 --- a/ezgui/src/tools/wizard.rs +++ b/ezgui/src/tools/wizard.rs @@ -104,7 +104,7 @@ impl Wizard { } match self.tb_comp.as_mut().unwrap().event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "quit" => { self.alive = false; self.tb_comp = None; @@ -129,7 +129,7 @@ impl Wizard { } _ => unreachable!(), }, - None => None, + _ => None, } } } @@ -220,14 +220,14 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { // wizard if self.wizard.ack.is_some() { match self.wizard.ack.as_mut().unwrap().event(self.ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "OK" => { self.wizard.ack = None; self.wizard.alive = false; } _ => unreachable!(), }, - None => { + _ => { return None; } } @@ -280,7 +280,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { } match self.wizard.menu_comp.as_mut().unwrap().event(self.ctx) { - Some(Outcome::Clicked(x)) if x == "quit" => { + Outcome::Clicked(x) if x == "quit" => { self.wizard.alive = false; self.wizard.menu_comp = None; return None; @@ -367,7 +367,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { self.setup_ack(txt); } match self.wizard.ack.as_mut().unwrap().event(self.ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "OK" => { self.wizard.confirmed_state.push(Box::new(())); self.wizard.ack = None; @@ -375,7 +375,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { } _ => unreachable!(), }, - None => None, + _ => None, } } diff --git a/ezgui/src/widgets/button.rs b/ezgui/src/widgets/button.rs index cb816c1bc3..3bc1873063 100644 --- a/ezgui/src/widgets/button.rs +++ b/ezgui/src/widgets/button.rs @@ -81,14 +81,14 @@ impl WidgetImpl for Button { } if self.hovering && ctx.normal_left_click() { self.hovering = false; - output.outcome = Some(Outcome::Clicked(self.action.clone())); + output.outcome = Outcome::Clicked(self.action.clone()); return; } if let Some(ref hotkey) = self.hotkey { if ctx.input.new_was_pressed(hotkey) { self.hovering = false; - output.outcome = Some(Outcome::Clicked(self.action.clone())); + output.outcome = Outcome::Clicked(self.action.clone()); return; } } diff --git a/ezgui/src/widgets/checkbox.rs b/ezgui/src/widgets/checkbox.rs index 03e64b3ae6..452557c045 100644 --- a/ezgui/src/widgets/checkbox.rs +++ b/ezgui/src/widgets/checkbox.rs @@ -1,6 +1,6 @@ use crate::{ - Btn, Button, Color, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, RewriteColor, ScreenDims, - ScreenPt, Text, TextExt, TextSpan, Widget, WidgetImpl, WidgetOutput, + Btn, Button, Color, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, Outcome, RewriteColor, + ScreenDims, ScreenPt, Text, TextExt, TextSpan, Widget, WidgetImpl, WidgetOutput, }; pub struct Checkbox { @@ -196,7 +196,8 @@ impl WidgetImpl for Checkbox { fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput) { self.btn.event(ctx, output); - if output.outcome.take().is_some() { + if let Outcome::Clicked(_) = output.outcome { + output.outcome = Outcome::Nothing; std::mem::swap(&mut self.btn, &mut self.other_btn); self.btn.set_pos(self.other_btn.top_left); self.enabled = !self.enabled; diff --git a/ezgui/src/widgets/containers.rs b/ezgui/src/widgets/containers.rs index 2c5f2a7224..d4ba5968ed 100644 --- a/ezgui/src/widgets/containers.rs +++ b/ezgui/src/widgets/containers.rs @@ -1,4 +1,4 @@ -use crate::{EventCtx, GfxCtx, ScreenDims, ScreenPt, Widget, WidgetImpl, WidgetOutput}; +use crate::{EventCtx, GfxCtx, Outcome, ScreenDims, ScreenPt, Widget, WidgetImpl, WidgetOutput}; pub struct Nothing {} @@ -49,7 +49,7 @@ impl WidgetImpl for Container { fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput) { for w in &mut self.members { w.widget.event(ctx, output); - if output.outcome.is_some() { + if output.outcome != Outcome::Nothing { return; } } diff --git a/ezgui/src/widgets/dropdown.rs b/ezgui/src/widgets/dropdown.rs index 42a8cc98de..a03f507002 100644 --- a/ezgui/src/widgets/dropdown.rs +++ b/ezgui/src/widgets/dropdown.rs @@ -1,6 +1,6 @@ use crate::{ - Btn, Button, Choice, Color, EventCtx, GeomBatch, GfxCtx, InputResult, Menu, ScreenDims, - ScreenPt, ScreenRectangle, WidgetImpl, WidgetOutput, + Btn, Button, Choice, Color, EventCtx, GeomBatch, GfxCtx, InputResult, Menu, Outcome, + ScreenDims, ScreenPt, ScreenRectangle, WidgetImpl, WidgetOutput, }; use geom::{Distance, Polygon, Pt2D}; @@ -113,7 +113,8 @@ impl WidgetImpl for Dropdown { } } else { self.btn.event(ctx, output); - if output.outcome.take().is_some() { + if let Outcome::Clicked(_) = output.outcome { + output.outcome = Outcome::Nothing; self.open_menu(ctx); } } diff --git a/ezgui/src/widgets/menu.rs b/ezgui/src/widgets/menu.rs index d08c361928..2d636526fe 100644 --- a/ezgui/src/widgets/menu.rs +++ b/ezgui/src/widgets/menu.rs @@ -124,7 +124,7 @@ impl WidgetImpl for Menu { if rect.contains(pt) && choice.active { // TODO Two ways of communicating results, based on use in wizards or a // larger composite. - output.outcome = Some(Outcome::Clicked(choice.label.clone())); + output.outcome = Outcome::Clicked(choice.label.clone()); self.state = InputResult::Done(choice.label.clone(), choice.data.clone()); return; } @@ -146,7 +146,7 @@ impl WidgetImpl for Menu { if let Some(ref hotkey) = choice.hotkey { if ctx.input.new_was_pressed(hotkey) { self.state = InputResult::Done(choice.label.clone(), choice.data.clone()); - output.outcome = Some(Outcome::Clicked(choice.label.clone())); + output.outcome = Outcome::Clicked(choice.label.clone()); return; } } @@ -157,7 +157,7 @@ impl WidgetImpl for Menu { let choice = &self.choices[self.current_idx]; if choice.active { self.state = InputResult::Done(choice.label.clone(), choice.data.clone()); - output.outcome = Some(Outcome::Clicked(choice.label.clone())); + output.outcome = Outcome::Clicked(choice.label.clone()); return; } else { return; diff --git a/ezgui/src/widgets/mod.rs b/ezgui/src/widgets/mod.rs index 7915bd9f33..efe8dc0f1a 100644 --- a/ezgui/src/widgets/mod.rs +++ b/ezgui/src/widgets/mod.rs @@ -42,8 +42,14 @@ pub trait WidgetImpl: downcast_rs::Downcast { } } +#[derive(Debug, PartialEq)] pub enum Outcome { + /// An action was done Clicked(String), + /// A dropdown or checkbox changed values + Changed(String), + /// Nothing happened + Nothing, } pub struct WidgetOutput { @@ -51,14 +57,14 @@ pub struct WidgetOutput { pub redo_layout: bool, /// This widget produced an Outcome, and event handling should immediately stop. Most widgets /// shouldn't set this. - pub outcome: Option, + pub outcome: Outcome, } impl WidgetOutput { pub fn new() -> WidgetOutput { WidgetOutput { redo_layout: false, - outcome: None, + outcome: Outcome::Nothing, } } } diff --git a/ezgui/src/widgets/persistent_split.rs b/ezgui/src/widgets/persistent_split.rs index 45aa4ff4d3..a6fa3bd193 100644 --- a/ezgui/src/widgets/persistent_split.rs +++ b/ezgui/src/widgets/persistent_split.rs @@ -1,5 +1,5 @@ use crate::{ - Btn, Button, Choice, Color, Dropdown, EventCtx, GeomBatch, GfxCtx, JustDraw, MultiKey, + Btn, Button, Choice, Color, Dropdown, EventCtx, GeomBatch, GfxCtx, JustDraw, MultiKey, Outcome, ScreenDims, ScreenPt, Widget, WidgetImpl, WidgetOutput, }; use geom::Polygon; @@ -71,7 +71,7 @@ impl WidgetImpl for PersistentSplit { fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput) { self.btn.event(ctx, output); - if output.outcome.is_some() { + if let Outcome::Clicked(_) = output.outcome { return; } diff --git a/ezgui/src/widgets/spinner.rs b/ezgui/src/widgets/spinner.rs index 19957ea510..f948f03638 100644 --- a/ezgui/src/widgets/spinner.rs +++ b/ezgui/src/widgets/spinner.rs @@ -1,6 +1,6 @@ use crate::{ - text, Btn, Button, EventCtx, GeomBatch, GfxCtx, Line, ScreenDims, ScreenPt, ScreenRectangle, - Text, Widget, WidgetImpl, WidgetOutput, + text, Btn, Button, EventCtx, GeomBatch, GfxCtx, Line, Outcome, ScreenDims, ScreenPt, + ScreenRectangle, Text, Widget, WidgetImpl, WidgetOutput, }; use geom::{Polygon, Pt2D}; @@ -69,7 +69,8 @@ impl WidgetImpl for Spinner { fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput) { self.up.event(ctx, output); - if output.outcome.take().is_some() { + if let Outcome::Clicked(_) = output.outcome { + output.outcome = Outcome::Nothing; if self.current != self.high { self.current += 1; } @@ -78,7 +79,8 @@ impl WidgetImpl for Spinner { } self.down.event(ctx, output); - if output.outcome.take().is_some() { + if let Outcome::Clicked(_) = output.outcome { + output.outcome = Outcome::Nothing; if self.current != self.low { self.current -= 1; } diff --git a/game/src/common/city_picker.rs b/game/src/common/city_picker.rs index 4876118788..86adf7341f 100644 --- a/game/src/common/city_picker.rs +++ b/game/src/common/city_picker.rs @@ -109,7 +109,7 @@ impl CityPicker { impl State for CityPicker { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -120,7 +120,7 @@ impl State for CityPicker { }); } }, - None => {} + _ => {} } if ctx.redo_mouseover() { diff --git a/game/src/common/isochrone.rs b/game/src/common/isochrone.rs index 26d9dd706a..ed24e9390f 100644 --- a/game/src/common/isochrone.rs +++ b/game/src/common/isochrone.rs @@ -39,13 +39,13 @@ impl State for IsochroneViewer { ctx.canvas_movement(); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep diff --git a/game/src/common/minimap.rs b/game/src/common/minimap.rs index 31ce173a19..a8e290a05b 100644 --- a/game/src/common/minimap.rs +++ b/game/src/common/minimap.rs @@ -121,7 +121,7 @@ impl Minimap { let pan_speed = 100.0; match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x { + Outcome::Clicked(x) => match x { x if x == "pan up" => { self.offset_y -= pan_speed * self.zoom; return Some(Transition::KeepWithMouseover); @@ -188,7 +188,7 @@ impl Minimap { } _ => unreachable!(), }, - None => {} + _ => {} } if self.composite.has_widget("zorder") { app.primary.show_zorder = self.composite.spinner("zorder"); diff --git a/game/src/common/navigate.rs b/game/src/common/navigate.rs index 4b54c28d99..44a5106de7 100644 --- a/game/src/common/navigate.rs +++ b/game/src/common/navigate.rs @@ -44,7 +44,7 @@ impl Navigator { impl State for Navigator { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -53,7 +53,7 @@ impl State for Navigator { } _ => unreachable!(), }, - None => {} + _ => {} } if let Some(roads) = self.composite.autocomplete_done("street") { if roads.is_empty() { @@ -137,7 +137,7 @@ impl State for CrossStreet { let map = &app.primary.map; match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { // Just warp to somewhere on the first road let road = map.get_r(self.first[0]); @@ -151,7 +151,7 @@ impl State for CrossStreet { } _ => unreachable!(), }, - None => {} + _ => {} } if let Some(roads) = self.composite.autocomplete_done("street") { // Find the best match @@ -240,7 +240,7 @@ impl SearchBuildings { impl State for SearchBuildings { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -249,7 +249,7 @@ impl State for SearchBuildings { } _ => unreachable!(), }, - None => {} + _ => {} } if let Some(bldgs) = self.composite.autocomplete_done("bldg") { if bldgs.is_empty() { diff --git a/game/src/common/warp.rs b/game/src/common/warp.rs index e652283134..ab72fdff1f 100644 --- a/game/src/common/warp.rs +++ b/game/src/common/warp.rs @@ -124,7 +124,7 @@ impl DebugWarp { impl State for DebugWarp { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -141,7 +141,7 @@ impl State for DebugWarp { } _ => unreachable!(), }, - None => Transition::Keep, + _ => Transition::Keep, } } diff --git a/game/src/cutscene.rs b/game/src/cutscene.rs index 8082ab3234..bd717a6d59 100644 --- a/game/src/cutscene.rs +++ b/game/src/cutscene.rs @@ -85,7 +85,7 @@ struct CutscenePlayer { impl State for CutscenePlayer { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "quit" => { // TODO Should SandboxMode use on_destroy for this? app.primary.clear_sim(); @@ -130,7 +130,7 @@ impl State for CutscenePlayer { } _ => unreachable!(), }, - None => {} + _ => {} } // TODO Should the Composite for text widgets with wrapping do this instead? if ctx.input.is_window_resized() { @@ -317,11 +317,11 @@ impl FYI { impl State for FYI { fn event(&mut self, ctx: &mut EventCtx, _: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Okay" => Transition::Pop, _ => unreachable!(), }, - None => Transition::Keep, + _ => Transition::Keep, } } diff --git a/game/src/debug/floodfill.rs b/game/src/debug/floodfill.rs index 51dcb021ad..f8e9d0061b 100644 --- a/game/src/debug/floodfill.rs +++ b/game/src/debug/floodfill.rs @@ -88,13 +88,13 @@ impl State for Floodfiller { ctx.canvas_movement(); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } _ => unreachable!(), }, - None => {} + _ => {} } let constraints = self.composite.dropdown_value("constraints"); diff --git a/game/src/debug/mod.rs b/game/src/debug/mod.rs index a77e5a82d1..0092fb420f 100644 --- a/game/src/debug/mod.rs +++ b/game/src/debug/mod.rs @@ -112,7 +112,7 @@ impl State for DebugMode { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -213,7 +213,7 @@ impl State for DebugMode { } _ => unreachable!(), }, - None => {} + _ => {} } // TODO We should really recalculate current_selection when these change. Meh. self.layers.show_buildings = self.composite.is_checked("show buildings"); diff --git a/game/src/debug/polygons.rs b/game/src/debug/polygons.rs index 7d15efb153..e4930c7e8a 100644 --- a/game/src/debug/polygons.rs +++ b/game/src/debug/polygons.rs @@ -59,7 +59,7 @@ impl State for PolygonDebugger { ctx.canvas_movement(); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -83,7 +83,7 @@ impl State for PolygonDebugger { } _ => unreachable!(), }, - None => {} + _ => {} } // TODO Could be more efficient here let idx = (self.composite.slider("slider").get_percent() * (self.items.len() - 1) as f64) diff --git a/game/src/devtools/destinations.rs b/game/src/devtools/destinations.rs index 7a599febde..76cd968448 100644 --- a/game/src/devtools/destinations.rs +++ b/game/src/devtools/destinations.rs @@ -128,13 +128,13 @@ impl State for PopularDestinations { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } _ => unreachable!(), }, - None => {} + _ => {} } let opts = if self.composite.is_checked("Show heatmap") { diff --git a/game/src/devtools/kml.rs b/game/src/devtools/kml.rs index e7d2bf7549..4f27543b1e 100644 --- a/game/src/devtools/kml.rs +++ b/game/src/devtools/kml.rs @@ -151,13 +151,13 @@ impl State for ViewKML { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } _ => unreachable!(), }, - None => {} + _ => {} } let query: String = self.composite.dropdown_value("query"); diff --git a/game/src/devtools/mapping.rs b/game/src/devtools/mapping.rs index abc564f9cb..f93c7e0a1b 100644 --- a/game/src/devtools/mapping.rs +++ b/game/src/devtools/mapping.rs @@ -384,7 +384,7 @@ impl State for ParkingMapper { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { app.opts.min_zoom_for_detail = crate::options::Options::default().min_zoom_for_detail; @@ -428,7 +428,7 @@ impl State for ParkingMapper { } _ => unreachable!(), }, - None => {} + _ => {} } let show = self.composite.dropdown_value("Show"); if show != self.show { diff --git a/game/src/devtools/mod.rs b/game/src/devtools/mod.rs index 629fdd5472..b7da062f5b 100644 --- a/game/src/devtools/mod.rs +++ b/game/src/devtools/mod.rs @@ -56,7 +56,7 @@ impl DevToolsMode { impl State for DevToolsMode { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -90,7 +90,7 @@ impl State for DevToolsMode { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep diff --git a/game/src/devtools/polygon.rs b/game/src/devtools/polygon.rs index 42f7eebfab..66eb01029d 100644 --- a/game/src/devtools/polygon.rs +++ b/game/src/devtools/polygon.rs @@ -65,7 +65,7 @@ impl State for PolygonEditor { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -76,7 +76,7 @@ impl State for PolygonEditor { } _ => unreachable!(), }, - None => {} + _ => {} } if let Some(cursor) = ctx.canvas.get_cursor_in_map_space() { diff --git a/game/src/devtools/scenario.rs b/game/src/devtools/scenario.rs index fb7309ba42..626882ad8e 100644 --- a/game/src/devtools/scenario.rs +++ b/game/src/devtools/scenario.rs @@ -87,7 +87,7 @@ impl ScenarioManager { impl State for ScenarioManager { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -96,7 +96,7 @@ impl State for ScenarioManager { } _ => unreachable!(), }, - None => {} + _ => {} } ctx.canvas_movement(); diff --git a/game/src/devtools/story.rs b/game/src/devtools/story.rs index 608b3ebc1e..a8bad8ff4a 100644 --- a/game/src/devtools/story.rs +++ b/game/src/devtools/story.rs @@ -128,7 +128,7 @@ impl State for StoryMapEditor { Mode::Editing(idx, ref mut composite) => { ctx.canvas_movement(); match composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { self.mode = Mode::View; self.redo_panel(ctx); @@ -152,7 +152,7 @@ impl State for StoryMapEditor { } _ => unreachable!(), }, - None => {} + _ => {} } } Mode::Freehand(None) => { @@ -176,7 +176,7 @@ impl State for StoryMapEditor { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { // TODO autosave return Transition::Pop; @@ -264,7 +264,7 @@ impl State for StoryMapEditor { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep diff --git a/game/src/edit/bulk.rs b/game/src/edit/bulk.rs index 499029437d..a6ee8d44bf 100644 --- a/game/src/edit/bulk.rs +++ b/game/src/edit/bulk.rs @@ -60,7 +60,7 @@ fn make_select_composite(ctx: &mut EventCtx, app: &App, selector: &RoadSelector) impl State for BulkSelect { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Cancel" => { return Transition::Pop; } @@ -83,7 +83,7 @@ impl State for BulkSelect { } } }, - None => { + _ => { if self.selector.event(ctx, app, None) { self.composite = make_select_composite(ctx, app, &self.selector); } @@ -164,7 +164,7 @@ impl State for BulkEdit { ctx.canvas_movement(); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Quit" => { return Transition::Pop; } @@ -192,7 +192,7 @@ impl State for BulkEdit { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep diff --git a/game/src/edit/cluster_traffic_signals.rs b/game/src/edit/cluster_traffic_signals.rs index cee64d41e7..831cdaeb56 100644 --- a/game/src/edit/cluster_traffic_signals.rs +++ b/game/src/edit/cluster_traffic_signals.rs @@ -36,13 +36,13 @@ impl ClusterTrafficSignalEditor { impl State for ClusterTrafficSignalEditor { fn event(&mut self, ctx: &mut EventCtx, _: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Finish" => { return Transition::Pop; } _ => unreachable!(), }, - None => {} + _ => {} } ctx.canvas_movement(); diff --git a/game/src/edit/lanes.rs b/game/src/edit/lanes.rs index 220297b672..c154b8388d 100644 --- a/game/src/edit/lanes.rs +++ b/game/src/edit/lanes.rs @@ -140,7 +140,7 @@ impl State for LaneEditor { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Change access restrictions" => { return Transition::Push(ZoneEditor::new( ctx, @@ -197,7 +197,7 @@ impl State for LaneEditor { } } }, - None => { + _ => { let parent = app.primary.map.get_parent(self.l); let new = self.composite.dropdown_value("speed limit"); let old = parent.speed_limit; diff --git a/game/src/edit/mod.rs b/game/src/edit/mod.rs index 33999aeb0a..98c128b6f3 100644 --- a/game/src/edit/mod.rs +++ b/game/src/edit/mod.rs @@ -159,7 +159,7 @@ impl State for EditMode { } match self.top_center.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "bulk edit" => { return Transition::Push(bulk::BulkSelect::new(ctx, app)); } @@ -168,10 +168,10 @@ impl State for EditMode { } _ => unreachable!(), }, - None => {} + _ => {} } match self.changelist.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "load edits" => { if app.primary.map.unsaved_edits() { return Transition::PushTwice( @@ -224,7 +224,7 @@ impl State for EditMode { )); } }, - None => {} + _ => {} } // Just kind of constantly scrape this app.opts.resume_after_edit = self.top_center.persistent_split_value("finish editing"); @@ -347,7 +347,7 @@ impl SaveEdits { impl State for SaveEdits { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Save" | "Overwrite existing edits" => { let mut edits = app.primary.map.get_edits().clone(); edits.edits_name = self.current_name.clone(); @@ -369,7 +369,7 @@ impl State for SaveEdits { } _ => unreachable!(), }, - None => {} + _ => {} } let name = self.composite.text_box("filename"); if name != self.current_name { @@ -442,7 +442,7 @@ impl LoadEdits { impl State for LoadEdits { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => Transition::Pop, "Start over with blank edits" => { apply_map_edits(ctx, app, MapEdits::new()); @@ -489,7 +489,7 @@ impl State for LoadEdits { } } }, - None => Transition::Keep, + _ => Transition::Keep, } } diff --git a/game/src/edit/select.rs b/game/src/edit/select.rs index 8ee1ec8283..cafe43c071 100644 --- a/game/src/edit/select.rs +++ b/game/src/edit/select.rs @@ -106,7 +106,7 @@ impl RoadSelector { self.preview = Some(ctx.upload(batch)); } - // Pass it Outcome::Clicked. Returns true if anything changed. + // Pass None. Returns true if anything changed. pub fn event(&mut self, ctx: &mut EventCtx, app: &mut App, clicked: Option<&str>) -> bool { if ctx.redo_mouseover() { app.primary.current_selection = app.calculate_current_selection( diff --git a/game/src/edit/stop_signs.rs b/game/src/edit/stop_signs.rs index 0fc4059209..3ba809bfb0 100644 --- a/game/src/edit/stop_signs.rs +++ b/game/src/edit/stop_signs.rs @@ -116,7 +116,7 @@ impl State for StopSignEditor { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Finish" => { return Transition::Pop; } @@ -178,7 +178,7 @@ impl State for StopSignEditor { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep } diff --git a/game/src/edit/traffic_signals.rs b/game/src/edit/traffic_signals.rs index 808fb66551..823d836687 100644 --- a/game/src/edit/traffic_signals.rs +++ b/game/src/edit/traffic_signals.rs @@ -105,7 +105,7 @@ impl State for TrafficSignalEditor { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Edit entire signal" => { return Transition::Push(edit_entire_signal( app, @@ -178,7 +178,7 @@ impl State for TrafficSignalEditor { unreachable!() } }, - None => {} + _ => {} } if ctx.redo_mouseover() { @@ -237,7 +237,7 @@ impl State for TrafficSignalEditor { } match self.top_panel.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Finish" => { if let Some(orig) = self.command_stack.get(0) { return check_for_missing_groups(ctx, app, &mut self.composite, orig); @@ -281,7 +281,7 @@ impl State for TrafficSignalEditor { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep @@ -814,14 +814,14 @@ impl State for PreviewTrafficSignal { ctx.canvas_movement(); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "back to editing" => { app.primary.clear_sim(); return Transition::Pop; } _ => unreachable!(), }, - None => {} + _ => {} } self.time_panel.event(ctx, app); diff --git a/game/src/edit/zones.rs b/game/src/edit/zones.rs index 339b697086..cfdb528307 100644 --- a/game/src/edit/zones.rs +++ b/game/src/edit/zones.rs @@ -74,7 +74,7 @@ impl ZoneEditor { impl State for ZoneEditor { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Apply" => { let mut edits = app.primary.map.get_edits().clone(); for r in self.orig_members.difference(&self.selector.roads) { @@ -123,7 +123,7 @@ impl State for ZoneEditor { } } }, - None => { + _ => { if self.selector.event(ctx, app, None) { let new_controls = self.selector.make_controls(ctx).named("selector"); self.composite.replace(ctx, "selector", new_controls); diff --git a/game/src/info/mod.rs b/game/src/info/mod.rs index 7fdd00da51..4c3ecdb969 100644 --- a/game/src/info/mod.rs +++ b/game/src/info/mod.rs @@ -461,7 +461,7 @@ impl InfoPanel { let maybe_id = self.tab.to_id(app); match self.composite.event(ctx) { - Some(Outcome::Clicked(action)) => { + Outcome::Clicked(action) => { if let Some(new_tab) = self.hyperlinks.get(&action).cloned() { let mut new = InfoPanel::new(ctx, app, new_tab, ctx_actions); // TODO Most cases use changed_settings, but one doesn't. Detect that @@ -560,7 +560,7 @@ impl InfoPanel { (close_panel, Some(t)) } } - None => { + _ => { // Maybe a non-click action should change the tab. Aka, checkboxes/dropdowns/etc on // a tab. if let Some(new_tab) = self.tab.changed_settings(&self.composite) { diff --git a/game/src/layer/mod.rs b/game/src/layer/mod.rs index a54caf8e18..76019de586 100644 --- a/game/src/layer/mod.rs +++ b/game/src/layer/mod.rs @@ -37,11 +37,11 @@ impl dyn Layer { ) -> Option { composite.align_above(ctx, minimap); match composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => Some(LayerOutcome::Close), _ => unreachable!(), }, - None => None, + _ => None, } } } @@ -145,7 +145,7 @@ impl PickLayer { impl State for PickLayer { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => {} "None" => { app.layer = None; @@ -211,7 +211,7 @@ impl State for PickLayer { } _ => unreachable!(), }, - None => { + _ => { if self.composite.clicked_outside(ctx) { return Transition::Pop; } diff --git a/game/src/layer/pandemic.rs b/game/src/layer/pandemic.rs index 9eb93e6180..c46f718cf2 100644 --- a/game/src/layer/pandemic.rs +++ b/game/src/layer/pandemic.rs @@ -37,13 +37,13 @@ impl Layer for Pandemic { self.composite.align_above(ctx, minimap); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Some(LayerOutcome::Close); } _ => unreachable!(), }, - None => { + _ => { let new_opts = self.options(); if self.opts != new_opts { *self = Pandemic::new(ctx, app, new_opts); diff --git a/game/src/layer/parking.rs b/game/src/layer/parking.rs index 638298e0d7..4c15c6d8b8 100644 --- a/game/src/layer/parking.rs +++ b/game/src/layer/parking.rs @@ -45,13 +45,13 @@ impl Layer for Occupancy { self.composite.align_above(ctx, minimap); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Some(LayerOutcome::Close); } _ => unreachable!(), }, - None => { + _ => { let new_onstreet = self.composite.is_checked("On-street spots"); let new_garages = self.composite.is_checked("Public garages"); let new_lots = self.composite.is_checked("Parking lots"); diff --git a/game/src/layer/population.rs b/game/src/layer/population.rs index ba1617252f..99c2d5c905 100644 --- a/game/src/layer/population.rs +++ b/game/src/layer/population.rs @@ -37,13 +37,13 @@ impl Layer for PopulationMap { self.composite.align_above(ctx, minimap); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Some(LayerOutcome::Close); } _ => unreachable!(), }, - None => { + _ => { let new_opts = self.options(); if self.opts != new_opts { *self = PopulationMap::new(ctx, app, new_opts); diff --git a/game/src/layer/traffic.rs b/game/src/layer/traffic.rs index 5c8fd875e6..2cc9372e30 100644 --- a/game/src/layer/traffic.rs +++ b/game/src/layer/traffic.rs @@ -126,13 +126,13 @@ impl Layer for Throughput { self.composite.align_above(ctx, minimap); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Some(LayerOutcome::Close); } _ => unreachable!(), }, - None => { + _ => { let new_compare = self .composite .maybe_is_checked("Compare before edits") @@ -307,13 +307,13 @@ impl Layer for Delay { self.composite.align_above(ctx, minimap); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Some(LayerOutcome::Close); } _ => unreachable!(), }, - None => { + _ => { let new_compare = self .composite .maybe_is_checked("Compare before edits") diff --git a/game/src/layer/transit.rs b/game/src/layer/transit.rs index 15929cd024..598620419a 100644 --- a/game/src/layer/transit.rs +++ b/game/src/layer/transit.rs @@ -28,13 +28,13 @@ impl Layer for TransitNetwork { ) -> Option { self.composite.align_above(ctx, minimap); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Some(LayerOutcome::Close); } _ => unreachable!(), }, - None => { + _ => { let new_show_all_routes = self.composite.is_checked("show all routes"); let new_show_buses = self.composite.is_checked("show buses"); let new_show_trains = self.composite.is_checked("show trains"); diff --git a/game/src/managed.rs b/game/src/managed.rs index ec5c2a77dc..928c60552a 100644 --- a/game/src/managed.rs +++ b/game/src/managed.rs @@ -36,7 +36,7 @@ impl WrappedComposite { } pub fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Option { - match self.inner.event(ctx)? { + match self.inner.event(ctx) { Outcome::Clicked(x) => { if let Some(ref cb) = self.callbacks.get(&x) { let t = (cb)(ctx, app)?; @@ -45,6 +45,7 @@ impl WrappedComposite { Some(WrappedOutcome::Clicked(x)) } } + _ => None, } } diff --git a/game/src/options.rs b/game/src/options.rs index 3cbc5feae3..5b24efb7ae 100644 --- a/game/src/options.rs +++ b/game/src/options.rs @@ -214,7 +214,7 @@ impl OptionsPanel { impl State for OptionsPanel { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -266,7 +266,7 @@ impl State for OptionsPanel { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep diff --git a/game/src/pregame.rs b/game/src/pregame.rs index cde97a7c37..3486bde9c0 100644 --- a/game/src/pregame.rs +++ b/game/src/pregame.rs @@ -59,13 +59,13 @@ impl TitleScreen { impl State for TitleScreen { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "start game" => { return Transition::Replace(MainMenu::new(ctx, app)); } _ => unreachable!(), }, - None => {} + _ => {} } self.screensaver.update(&mut self.rng, ctx, app); @@ -169,7 +169,7 @@ impl MainMenu { impl State for MainMenu { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "quit" => { // TODO before_quit? std::process::exit(0); @@ -226,7 +226,7 @@ impl State for MainMenu { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep @@ -297,7 +297,7 @@ impl About { impl State for About { fn event(&mut self, ctx: &mut EventCtx, _: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "back" => { return Transition::Pop; } @@ -310,7 +310,7 @@ impl State for About { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep @@ -409,7 +409,7 @@ impl Proposals { impl State for Proposals { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "back" => { return Transition::Pop; } @@ -462,7 +462,7 @@ impl State for Proposals { return Transition::Replace(Proposals::new(ctx, app, Some(x.to_string()))); } }, - None => {} + _ => {} } Transition::Keep diff --git a/game/src/sandbox/dashboards/commuter.rs b/game/src/sandbox/dashboards/commuter.rs index bf892506e4..cfc4c110f2 100644 --- a/game/src/sandbox/dashboards/commuter.rs +++ b/game/src/sandbox/dashboards/commuter.rs @@ -341,13 +341,13 @@ impl State for CommuterPatterns { ctx.canvas_movement(); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } _ => unreachable!(), }, - None => {} + _ => {} } let block_selection = if let Some(Some(b)) = ctx diff --git a/game/src/sandbox/dashboards/misc.rs b/game/src/sandbox/dashboards/misc.rs index 8263851f0c..a62415ad53 100644 --- a/game/src/sandbox/dashboards/misc.rs +++ b/game/src/sandbox/dashboards/misc.rs @@ -49,8 +49,8 @@ impl ActiveTraffic { impl State for ActiveTraffic { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => DashTab::TripSummaries.transition(ctx, app, &x), - None => Transition::Keep, + Outcome::Clicked(x) => DashTab::TripSummaries.transition(ctx, app, &x), + _ => Transition::Keep, } } @@ -155,14 +155,14 @@ impl TransitRoutes { impl State for TransitRoutes { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { let route = match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => { + Outcome::Clicked(x) => { if let Some(x) = x.strip_prefix("BusRoute #") { BusRouteID(x.parse::().unwrap()) } else { return DashTab::TransitRoutes.transition(ctx, app, &x); } } - None => { + _ => { if let Some(routes) = self.composite.autocomplete_done("search") { if !routes.is_empty() { routes[0] diff --git a/game/src/sandbox/dashboards/parking_overhead.rs b/game/src/sandbox/dashboards/parking_overhead.rs index dce877d036..e37d1df451 100644 --- a/game/src/sandbox/dashboards/parking_overhead.rs +++ b/game/src/sandbox/dashboards/parking_overhead.rs @@ -77,7 +77,7 @@ impl ParkingOverhead { impl State for ParkingOverhead { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Total duration" => { self.opts.change(SortBy::TotalDuration); self.recalc(ctx, app); @@ -124,7 +124,7 @@ impl State for ParkingOverhead { return DashTab::ParkingOverhead.transition(ctx, app, x); } }, - None => { + _ => { let off_map_starts = self.composite.is_checked("starting off-map"); let off_map_ends = self.composite.is_checked("ending off-map"); if self.opts.off_map_starts != off_map_starts diff --git a/game/src/sandbox/dashboards/summaries.rs b/game/src/sandbox/dashboards/summaries.rs index e40f553a47..5dc462c175 100644 --- a/game/src/sandbox/dashboards/summaries.rs +++ b/game/src/sandbox/dashboards/summaries.rs @@ -54,8 +54,8 @@ impl TripSummaries { impl State for TripSummaries { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => DashTab::TripSummaries.transition(ctx, app, &x), - None => { + Outcome::Clicked(x) => DashTab::TripSummaries.transition(ctx, app, &x), + _ => { let mut filter = Filter { changes_pct: self.composite.dropdown_value("filter"), modes: BTreeSet::new(), diff --git a/game/src/sandbox/dashboards/trip_table.rs b/game/src/sandbox/dashboards/trip_table.rs index a540c42b66..b8a4dcdf1f 100644 --- a/game/src/sandbox/dashboards/trip_table.rs +++ b/game/src/sandbox/dashboards/trip_table.rs @@ -84,7 +84,7 @@ impl TripTable { impl State for TripTable { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Departure" => { self.opts.change(SortBy::Departure); self.recalc(ctx, app); @@ -135,7 +135,7 @@ impl State for TripTable { return DashTab::TripTable.transition(ctx, app, x); } }, - None => { + _ => { let mut modes = BTreeSet::new(); for m in TripMode::all() { if self.composite.is_checked(m.ongoing_verb()) { diff --git a/game/src/sandbox/gameplay/commute.rs b/game/src/sandbox/gameplay/commute.rs index 5281dbf5da..368ff7bbfd 100644 --- a/game/src/sandbox/gameplay/commute.rs +++ b/game/src/sandbox/gameplay/commute.rs @@ -167,7 +167,7 @@ impl GameplayState for OptimizeCommute { } match self.top_center.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "edit map" => { return Some(Transition::Push(Box::new(EditMode::new( ctx, @@ -191,10 +191,10 @@ impl GameplayState for OptimizeCommute { } _ => unreachable!(), }, - None => {} + _ => {} } match self.meter.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "locate VIP" => { controls.common.as_mut().unwrap().launch_info_panel( ctx, @@ -207,7 +207,7 @@ impl GameplayState for OptimizeCommute { } _ => unreachable!(), }, - None => {} + _ => {} } None diff --git a/game/src/sandbox/gameplay/fix_traffic_signals.rs b/game/src/sandbox/gameplay/fix_traffic_signals.rs index 5b325ff636..5f1b7c10fc 100644 --- a/game/src/sandbox/gameplay/fix_traffic_signals.rs +++ b/game/src/sandbox/gameplay/fix_traffic_signals.rs @@ -191,7 +191,7 @@ impl GameplayState for FixTrafficSignals { } match self.top_center.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "edit map" => { return Some(Transition::Push(Box::new(EditMode::new( ctx, @@ -228,10 +228,10 @@ impl GameplayState for FixTrafficSignals { } _ => unreachable!(), }, - None => {} + _ => {} } match self.meter.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "go to slowest intersection" => { let i = app .primary @@ -268,7 +268,7 @@ impl GameplayState for FixTrafficSignals { } _ => unreachable!(), }, - None => {} + _ => {} } None diff --git a/game/src/sandbox/gameplay/freeform.rs b/game/src/sandbox/gameplay/freeform.rs index 3353789ad0..d51ff9949b 100644 --- a/game/src/sandbox/gameplay/freeform.rs +++ b/game/src/sandbox/gameplay/freeform.rs @@ -43,7 +43,7 @@ impl GameplayState for Freeform { _: &mut SandboxControls, ) -> Option { match self.top_center.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "change map" => { Some(Transition::Push(CityPicker::new( ctx, @@ -71,7 +71,7 @@ impl GameplayState for Freeform { "Start a new trip" => Some(Transition::Push(AgentSpawner::new(ctx, None))), _ => unreachable!(), }, - None => None, + _ => None, } } @@ -242,7 +242,7 @@ impl State for AgentSpawner { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { let old_mode: TripMode = self.composite.dropdown_value("mode"); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -278,7 +278,7 @@ impl State for AgentSpawner { } _ => unreachable!(), }, - None => {} + _ => {} } // We need to recalculate the path to see if this is sane. Otherwise we could trick a // pedestrian into wandering on/off a highway border. diff --git a/game/src/sandbox/gameplay/mod.rs b/game/src/sandbox/gameplay/mod.rs index ce8e1e379d..596216979b 100644 --- a/game/src/sandbox/gameplay/mod.rs +++ b/game/src/sandbox/gameplay/mod.rs @@ -355,7 +355,7 @@ impl FinalScore { impl State for FinalScore { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Keep simulating" => { return Transition::Pop; } @@ -392,7 +392,7 @@ impl State for FinalScore { } _ => unreachable!(), }, - None => {} + _ => {} } if self.chose_next || self.chose_back_to_challenges { diff --git a/game/src/sandbox/gameplay/play_scenario.rs b/game/src/sandbox/gameplay/play_scenario.rs index 8531079607..0ee9710b78 100644 --- a/game/src/sandbox/gameplay/play_scenario.rs +++ b/game/src/sandbox/gameplay/play_scenario.rs @@ -48,7 +48,7 @@ impl GameplayState for PlayScenario { app.primary.has_modified_trips = !self.modifiers.is_empty(); match self.top_center.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "change map" => { let scenario = self.scenario_name.clone(); Some(Transition::Push(CityPicker::new( @@ -90,7 +90,7 @@ impl GameplayState for PlayScenario { ))), _ => unreachable!(), }, - None => None, + _ => None, } } @@ -214,7 +214,7 @@ impl EditScenarioModifiers { impl State for EditScenarioModifiers { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Discard changes" => { return Transition::Pop; } @@ -256,7 +256,7 @@ impl State for EditScenarioModifiers { } } }, - None => {} + _ => {} } Transition::Keep @@ -357,7 +357,7 @@ impl ChangeMode { impl State for ChangeMode { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Discard changes" => Transition::Pop, "Apply" => { let to_mode = self.composite.dropdown_value::("to_mode"); @@ -404,7 +404,7 @@ impl State for ChangeMode { } _ => unreachable!(), }, - None => Transition::Keep, + _ => Transition::Keep, } } diff --git a/game/src/sandbox/gameplay/tutorial.rs b/game/src/sandbox/gameplay/tutorial.rs index eba23486e1..3e3edb986e 100644 --- a/game/src/sandbox/gameplay/tutorial.rs +++ b/game/src/sandbox/gameplay/tutorial.rs @@ -103,7 +103,7 @@ impl Tutorial { } match self.top_center.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "Quit" => { return Some(maybe_exit_sandbox()); } @@ -128,12 +128,12 @@ impl Tutorial { } _ => unreachable!(), }, - None => {} + _ => {} } if let Some(ref mut msg) = self.msg_panel { match msg.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "previous message" => { tut.prev(); return Some(transition(ctx, app, tut)); @@ -144,7 +144,7 @@ impl Tutorial { } _ => unreachable!(), }, - None => { + _ => { // Don't allow other interactions return Some(Transition::Keep); } diff --git a/game/src/sandbox/misc_tools.rs b/game/src/sandbox/misc_tools.rs index 59d5549b5d..f6e98272d9 100644 --- a/game/src/sandbox/misc_tools.rs +++ b/game/src/sandbox/misc_tools.rs @@ -104,7 +104,7 @@ impl State for ShowTrafficSignal { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -112,7 +112,7 @@ impl State for ShowTrafficSignal { self.change_phase(x["phase ".len()..].parse::().unwrap() - 1, ctx, app); } }, - None => {} + _ => {} } Transition::Keep @@ -164,7 +164,7 @@ impl State for TurnExplorer { ctx.canvas_movement(); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -178,7 +178,7 @@ impl State for TurnExplorer { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep diff --git a/game/src/sandbox/mod.rs b/game/src/sandbox/mod.rs index a46eeb575d..a42a580617 100644 --- a/game/src/sandbox/mod.rs +++ b/game/src/sandbox/mod.rs @@ -373,13 +373,13 @@ impl AgentMeter { return self.event(ctx, app); } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "more data" => { return Some(Transition::Push(dashboards::TripTable::new(ctx, app))); } _ => unreachable!(), }, - None => {} + _ => {} } None diff --git a/game/src/sandbox/speed.rs b/game/src/sandbox/speed.rs index ce52575885..c93e250b34 100644 --- a/game/src/sandbox/speed.rs +++ b/game/src/sandbox/speed.rs @@ -144,7 +144,7 @@ impl SpeedControls { maybe_mode: Option<&GameplayMode>, ) -> Option { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "real-time speed" => { self.setting = SpeedSetting::Realtime; self.composite = SpeedControls::make_panel(ctx, app, self.paused, self.setting); @@ -212,7 +212,7 @@ impl SpeedControls { } _ => unreachable!(), }, - None => {} + _ => {} } // Just kind of constantly scrape this app.opts.time_increment = self.composite.persistent_split_value("step forwards"); @@ -420,7 +420,7 @@ impl JumpToTime { impl State for JumpToTime { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -450,7 +450,7 @@ impl State for JumpToTime { } _ => unreachable!(), }, - None => {} + _ => {} } app.opts.dont_draw_time_warp = self.composite.is_checked("don't draw"); let target = app @@ -612,13 +612,13 @@ impl State for TimeWarpScreen { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "stop now" => { return Transition::Pop; } _ => unreachable!(), }, - None => {} + _ => {} } if self.composite.clicked_outside(ctx) { return Transition::Pop; diff --git a/game/src/sandbox/uber_turns.rs b/game/src/sandbox/uber_turns.rs index 4e26b53b52..317338ecf7 100644 --- a/game/src/sandbox/uber_turns.rs +++ b/game/src/sandbox/uber_turns.rs @@ -65,7 +65,7 @@ impl State for UberTurnPicker { } match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -105,7 +105,7 @@ impl State for UberTurnPicker { } _ => unreachable!(), }, - None => {} + _ => {} } Transition::Keep @@ -214,7 +214,7 @@ impl State for UberTurnViewer { ctx.canvas_movement(); match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "close" => { return Transition::Pop; } @@ -238,7 +238,7 @@ impl State for UberTurnViewer { } _ => unreachable!(), }, - None => { + _ => { if self.composite.is_checked("legal / illegal movements") != self.legal_turns { return Transition::Replace(UberTurnViewer::new( ctx, diff --git a/map_editor/src/main.rs b/map_editor/src/main.rs index 07a015d794..36ee626f8b 100644 --- a/map_editor/src/main.rs +++ b/map_editor/src/main.rs @@ -250,7 +250,7 @@ impl GUI for UI { } None => { match self.composite.event(ctx) { - Some(Outcome::Clicked(x)) => match x.as_ref() { + Outcome::Clicked(x) => match x.as_ref() { "quit" => { self.before_quit(ctx.canvas); std::process::exit(0); @@ -285,7 +285,7 @@ impl GUI for UI { } _ => unreachable!(), }, - None => { + _ => { if ctx.input.key_pressed(Key::I, "create intersection") { if let Some(pt) = cursor { self.model.create_i(pt, ctx.prerender);