From 89977b3b318dbe51dd16f92ecb8d128a76d6466e Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 22 Oct 2020 16:53:15 -0700 Subject: [PATCH] Move grey_out_map out of State, in preparation for generalizing state/transition. #253 --- game/src/common/city_picker.rs | 4 ++-- game/src/common/navigate.rs | 8 ++++---- game/src/common/warp.rs | 4 ++-- game/src/cutscene.rs | 3 ++- game/src/edit/mod.rs | 6 +++--- game/src/game.rs | 21 ++++----------------- game/src/helpers.rs | 15 +++++++++++++-- game/src/layer/mod.rs | 4 ++-- game/src/options.rs | 3 ++- game/src/sandbox/gameplay/play_scenario.rs | 6 +++--- game/src/sandbox/gameplay/tutorial.rs | 4 ++-- game/src/sandbox/time_warp.rs | 8 ++++---- 12 files changed, 43 insertions(+), 43 deletions(-) diff --git a/game/src/common/city_picker.rs b/game/src/common/city_picker.rs index d005f064b7..7bc67250e8 100644 --- a/game/src/common/city_picker.rs +++ b/game/src/common/city_picker.rs @@ -6,7 +6,7 @@ use widgetry::{ use crate::app::App; use crate::game::{DrawBaselayer, State, Transition}; -use crate::helpers::nice_map_name; +use crate::helpers::{grey_out_map, nice_map_name}; use crate::load::MapLoader; use crate::render::DrawArea; @@ -168,7 +168,7 @@ impl State for CityPicker { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); if let Some(idx) = self.selected { diff --git a/game/src/common/navigate.rs b/game/src/common/navigate.rs index 3aa2dda581..3d47338646 100644 --- a/game/src/common/navigate.rs +++ b/game/src/common/navigate.rs @@ -9,7 +9,7 @@ use widgetry::{ use crate::app::App; use crate::common::Warping; use crate::game::{State, Transition}; -use crate::helpers::ID; +use crate::helpers::{grey_out_map, ID}; // TODO Canonicalize names, handling abbreviations like east/e and street/st pub struct Navigator { @@ -72,7 +72,7 @@ impl State for Navigator { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } @@ -189,7 +189,7 @@ impl State for CrossStreet { fn draw(&self, g: &mut GfxCtx, app: &App) { g.redraw(&self.draw); - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } @@ -285,7 +285,7 @@ impl State for SearchBuildings { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } diff --git a/game/src/common/warp.rs b/game/src/common/warp.rs index d403b62ddf..f7dcd4066f 100644 --- a/game/src/common/warp.rs +++ b/game/src/common/warp.rs @@ -8,7 +8,7 @@ use widgetry::{Btn, EventCtx, GfxCtx, Key, Line, Outcome, Panel, Text, TextExt, use crate::app::{App, PerMap}; use crate::common::Tab; use crate::game::{PopupMsg, State, Transition}; -use crate::helpers::ID; +use crate::helpers::{grey_out_map, ID}; use crate::info::OpenTrip; use crate::sandbox::SandboxMode; @@ -150,7 +150,7 @@ impl State for DebugWarp { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } diff --git a/game/src/cutscene.rs b/game/src/cutscene.rs index 5d8f9a8db5..1312e7a474 100644 --- a/game/src/cutscene.rs +++ b/game/src/cutscene.rs @@ -5,6 +5,7 @@ use widgetry::{ use crate::app::App; use crate::game::{DrawBaselayer, State, Transition}; +use crate::helpers::grey_out_map; pub struct CutsceneBuilder { name: String, @@ -318,7 +319,7 @@ impl State for FYI { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } diff --git a/game/src/edit/mod.rs b/game/src/edit/mod.rs index 5ebd6eea9b..af48a106f6 100644 --- a/game/src/edit/mod.rs +++ b/game/src/edit/mod.rs @@ -20,7 +20,7 @@ use crate::app::App; use crate::common::{tool_panel, ColorLegend, CommonState, Warping}; use crate::debug::DebugMode; use crate::game::{ChooseSomething, PopupMsg, State, Transition}; -use crate::helpers::ID; +use crate::helpers::{grey_out_map, ID}; use crate::options::OptionsPanel; use crate::render::DrawMap; use crate::sandbox::{GameplayMode, SandboxMode, TimeWarpScreen}; @@ -508,7 +508,7 @@ impl State for SaveEdits { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } @@ -628,7 +628,7 @@ impl State for LoadEdits { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } diff --git a/game/src/game.rs b/game/src/game.rs index 6b6d3e225a..fedf8f0b4d 100644 --- a/game/src/game.rs +++ b/game/src/game.rs @@ -1,4 +1,3 @@ -use geom::Polygon; use map_model::PermanentMapEdits; use widgetry::{ hotkeys, Btn, Canvas, Choice, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, @@ -6,6 +5,7 @@ use widgetry::{ }; use crate::app::{App, Flags, ShowEverything}; +use crate::helpers::grey_out_map; use crate::options::Options; use crate::pregame::TitleScreen; use crate::render::DrawOptions; @@ -239,19 +239,6 @@ pub trait State: downcast_rs::Downcast { // We don't need an on_enter -- the constructor for the state can just do it. } -impl dyn State { - pub fn grey_out_map(g: &mut GfxCtx, app: &App) { - // Make it clear the map can't be interacted with right now. - g.fork_screenspace(); - // TODO - OSD height - g.draw_polygon( - app.cs.fade_map_dark, - Polygon::rectangle(g.canvas.window_width, g.canvas.window_height), - ); - g.unfork(); - } -} - downcast_rs::impl_downcast!(State); pub enum Transition { @@ -344,7 +331,7 @@ impl State for ChooseSomething { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } @@ -402,7 +389,7 @@ impl State for PromptInput { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } @@ -469,7 +456,7 @@ impl State for PopupMsg { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); if g.canvas.cam_zoom < app.opts.min_zoom_for_detail { g.redraw(&self.unzoomed); diff --git a/game/src/helpers.rs b/game/src/helpers.rs index 7b093f753c..118d79db58 100644 --- a/game/src/helpers.rs +++ b/game/src/helpers.rs @@ -1,9 +1,9 @@ use std::collections::BTreeSet; -use geom::{Duration, Pt2D}; +use geom::{Duration, Polygon, Pt2D}; use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParkingLotID, RoadID}; use sim::{AgentID, AgentType, CarID, PedestrianID, TripMode, TripPhaseType}; -use widgetry::{Btn, Checkbox, Color, EventCtx, Key, Line, Text, TextSpan, Widget}; +use widgetry::{Btn, Checkbox, Color, EventCtx, GfxCtx, Key, Line, Text, TextSpan, Widget}; use crate::app::{App, PerMap}; @@ -302,3 +302,14 @@ pub fn loading_tips() -> Text { Line("- An API to control A/B Street from any language"), ]) } + +/// Make it clear the map can't be interacted with right now. +pub fn grey_out_map(g: &mut GfxCtx, app: &App) { + g.fork_screenspace(); + // TODO - OSD height + g.draw_polygon( + app.cs.fade_map_dark, + Polygon::rectangle(g.canvas.window_width, g.canvas.window_height), + ); + g.unfork(); +} diff --git a/game/src/layer/mod.rs b/game/src/layer/mod.rs index 8176ebfb1d..5ed72a502d 100644 --- a/game/src/layer/mod.rs +++ b/game/src/layer/mod.rs @@ -3,7 +3,7 @@ use widgetry::{Btn, EventCtx, GfxCtx, Key, Line, Outcome, Panel, TextExt, Widget use crate::app::App; use crate::common::HeatmapOptions; use crate::game::{DrawBaselayer, State, Transition}; -use crate::helpers::hotkey_btn; +use crate::helpers::{grey_out_map, hotkey_btn}; use crate::sandbox::dashboards; mod elevation; @@ -251,7 +251,7 @@ impl State for PickLayer { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } diff --git a/game/src/options.rs b/game/src/options.rs index 6806583923..54162faa08 100644 --- a/game/src/options.rs +++ b/game/src/options.rs @@ -7,6 +7,7 @@ use widgetry::{ use crate::app::App; use crate::colors::{ColorScheme, ColorSchemeChoice}; use crate::game::{State, Transition}; +use crate::helpers::grey_out_map; use crate::render::{DrawBuilding, DrawMap}; /// Options controlling the UI. @@ -342,7 +343,7 @@ impl State for OptionsPanel { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } diff --git a/game/src/sandbox/gameplay/play_scenario.rs b/game/src/sandbox/gameplay/play_scenario.rs index 5514a0c453..040025a8b5 100644 --- a/game/src/sandbox/gameplay/play_scenario.rs +++ b/game/src/sandbox/gameplay/play_scenario.rs @@ -12,7 +12,7 @@ use crate::app::App; use crate::common::CityPicker; use crate::edit::EditMode; use crate::game::{ChooseSomething, PopupMsg, State, Transition}; -use crate::helpers::{checkbox_per_mode, nice_map_name}; +use crate::helpers::{checkbox_per_mode, grey_out_map, nice_map_name}; use crate::sandbox::gameplay::freeform::make_change_traffic; use crate::sandbox::gameplay::{GameplayMode, GameplayState}; use crate::sandbox::{Actions, SandboxControls, SandboxMode}; @@ -307,7 +307,7 @@ impl State for EditScenarioModifiers { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } @@ -431,7 +431,7 @@ impl State for ChangeMode { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } diff --git a/game/src/sandbox/gameplay/tutorial.rs b/game/src/sandbox/gameplay/tutorial.rs index c49bdfc21c..b26500b383 100644 --- a/game/src/sandbox/gameplay/tutorial.rs +++ b/game/src/sandbox/gameplay/tutorial.rs @@ -19,7 +19,7 @@ use crate::common::{tool_panel, Minimap, Warping}; use crate::cutscene::CutsceneBuilder; use crate::edit::EditMode; use crate::game::{PopupMsg, State, Transition}; -use crate::helpers::ID; +use crate::helpers::{grey_out_map, ID}; use crate::sandbox::gameplay::{GameplayMode, GameplayState}; use crate::sandbox::{ maybe_exit_sandbox, spawn_agents_around, Actions, AgentMeter, SandboxControls, SandboxMode, @@ -358,7 +358,7 @@ impl GameplayState for Tutorial { let tut = app.session.tutorial.as_ref().unwrap(); if self.msg_panel.is_some() { - State::grey_out_map(g, app); + grey_out_map(g, app); } self.top_center.draw(g); diff --git a/game/src/sandbox/time_warp.rs b/game/src/sandbox/time_warp.rs index 401741e3e2..a73dad5708 100644 --- a/game/src/sandbox/time_warp.rs +++ b/game/src/sandbox/time_warp.rs @@ -10,7 +10,7 @@ use widgetry::{ use crate::app::{App, FindDelayedIntersections, ShowEverything}; use crate::common::Warping; use crate::game::{DrawBaselayer, PopupMsg, State, Transition}; -use crate::helpers::ID; +use crate::helpers::{grey_out_map, ID}; use crate::render::DrawOptions; use crate::sandbox::{GameplayMode, SandboxMode}; @@ -141,7 +141,7 @@ impl State for JumpToTime { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } @@ -236,7 +236,7 @@ impl State for JumpToDelay { } fn draw(&self, g: &mut GfxCtx, app: &App) { - State::grey_out_map(g, app); + grey_out_map(g, app); self.panel.draw(g); } } @@ -406,7 +406,7 @@ impl State for TimeWarpScreen { g.clear(app.cs.section_bg); } else { app.draw(g, DrawOptions::new(), &ShowEverything::new()); - State::grey_out_map(g, app); + grey_out_map(g, app); } self.panel.draw(g);