Move grey_out_map out of State, in preparation for generalizing state/transition. #253

This commit is contained in:
Dustin Carlino 2020-10-22 16:53:15 -07:00
parent 4a3ea8b5c7
commit 89977b3b31
12 changed files with 43 additions and 43 deletions

View File

@ -6,7 +6,7 @@ use widgetry::{
use crate::app::App; use crate::app::App;
use crate::game::{DrawBaselayer, State, Transition}; 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::load::MapLoader;
use crate::render::DrawArea; use crate::render::DrawArea;
@ -168,7 +168,7 @@ impl State for CityPicker {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
if let Some(idx) = self.selected { if let Some(idx) = self.selected {

View File

@ -9,7 +9,7 @@ use widgetry::{
use crate::app::App; use crate::app::App;
use crate::common::Warping; use crate::common::Warping;
use crate::game::{State, Transition}; 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 // TODO Canonicalize names, handling abbreviations like east/e and street/st
pub struct Navigator { pub struct Navigator {
@ -72,7 +72,7 @@ impl State for Navigator {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }
@ -189,7 +189,7 @@ impl State for CrossStreet {
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
g.redraw(&self.draw); g.redraw(&self.draw);
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }
@ -285,7 +285,7 @@ impl State for SearchBuildings {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }

View File

@ -8,7 +8,7 @@ use widgetry::{Btn, EventCtx, GfxCtx, Key, Line, Outcome, Panel, Text, TextExt,
use crate::app::{App, PerMap}; use crate::app::{App, PerMap};
use crate::common::Tab; use crate::common::Tab;
use crate::game::{PopupMsg, State, Transition}; use crate::game::{PopupMsg, State, Transition};
use crate::helpers::ID; use crate::helpers::{grey_out_map, ID};
use crate::info::OpenTrip; use crate::info::OpenTrip;
use crate::sandbox::SandboxMode; use crate::sandbox::SandboxMode;
@ -150,7 +150,7 @@ impl State for DebugWarp {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }

View File

@ -5,6 +5,7 @@ use widgetry::{
use crate::app::App; use crate::app::App;
use crate::game::{DrawBaselayer, State, Transition}; use crate::game::{DrawBaselayer, State, Transition};
use crate::helpers::grey_out_map;
pub struct CutsceneBuilder { pub struct CutsceneBuilder {
name: String, name: String,
@ -318,7 +319,7 @@ impl State for FYI {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }

View File

@ -20,7 +20,7 @@ use crate::app::App;
use crate::common::{tool_panel, ColorLegend, CommonState, Warping}; use crate::common::{tool_panel, ColorLegend, CommonState, Warping};
use crate::debug::DebugMode; use crate::debug::DebugMode;
use crate::game::{ChooseSomething, PopupMsg, State, Transition}; use crate::game::{ChooseSomething, PopupMsg, State, Transition};
use crate::helpers::ID; use crate::helpers::{grey_out_map, ID};
use crate::options::OptionsPanel; use crate::options::OptionsPanel;
use crate::render::DrawMap; use crate::render::DrawMap;
use crate::sandbox::{GameplayMode, SandboxMode, TimeWarpScreen}; use crate::sandbox::{GameplayMode, SandboxMode, TimeWarpScreen};
@ -508,7 +508,7 @@ impl State for SaveEdits {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }
@ -628,7 +628,7 @@ impl State for LoadEdits {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }

View File

@ -1,4 +1,3 @@
use geom::Polygon;
use map_model::PermanentMapEdits; use map_model::PermanentMapEdits;
use widgetry::{ use widgetry::{
hotkeys, Btn, Canvas, Choice, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, hotkeys, Btn, Canvas, Choice, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key,
@ -6,6 +5,7 @@ use widgetry::{
}; };
use crate::app::{App, Flags, ShowEverything}; use crate::app::{App, Flags, ShowEverything};
use crate::helpers::grey_out_map;
use crate::options::Options; use crate::options::Options;
use crate::pregame::TitleScreen; use crate::pregame::TitleScreen;
use crate::render::DrawOptions; 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. // 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); downcast_rs::impl_downcast!(State);
pub enum Transition { pub enum Transition {
@ -344,7 +331,7 @@ impl<T: 'static> State for ChooseSomething<T> {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }
@ -402,7 +389,7 @@ impl State for PromptInput {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }
@ -469,7 +456,7 @@ impl State for PopupMsg {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
if g.canvas.cam_zoom < app.opts.min_zoom_for_detail { if g.canvas.cam_zoom < app.opts.min_zoom_for_detail {
g.redraw(&self.unzoomed); g.redraw(&self.unzoomed);

View File

@ -1,9 +1,9 @@
use std::collections::BTreeSet; 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 map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParkingLotID, RoadID};
use sim::{AgentID, AgentType, CarID, PedestrianID, TripMode, TripPhaseType}; 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}; 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"), 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();
}

View File

@ -3,7 +3,7 @@ use widgetry::{Btn, EventCtx, GfxCtx, Key, Line, Outcome, Panel, TextExt, Widget
use crate::app::App; use crate::app::App;
use crate::common::HeatmapOptions; use crate::common::HeatmapOptions;
use crate::game::{DrawBaselayer, State, Transition}; use crate::game::{DrawBaselayer, State, Transition};
use crate::helpers::hotkey_btn; use crate::helpers::{grey_out_map, hotkey_btn};
use crate::sandbox::dashboards; use crate::sandbox::dashboards;
mod elevation; mod elevation;
@ -251,7 +251,7 @@ impl State for PickLayer {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }

View File

@ -7,6 +7,7 @@ use widgetry::{
use crate::app::App; use crate::app::App;
use crate::colors::{ColorScheme, ColorSchemeChoice}; use crate::colors::{ColorScheme, ColorSchemeChoice};
use crate::game::{State, Transition}; use crate::game::{State, Transition};
use crate::helpers::grey_out_map;
use crate::render::{DrawBuilding, DrawMap}; use crate::render::{DrawBuilding, DrawMap};
/// Options controlling the UI. /// Options controlling the UI.
@ -342,7 +343,7 @@ impl State for OptionsPanel {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }

View File

@ -12,7 +12,7 @@ use crate::app::App;
use crate::common::CityPicker; use crate::common::CityPicker;
use crate::edit::EditMode; use crate::edit::EditMode;
use crate::game::{ChooseSomething, PopupMsg, State, Transition}; 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::freeform::make_change_traffic;
use crate::sandbox::gameplay::{GameplayMode, GameplayState}; use crate::sandbox::gameplay::{GameplayMode, GameplayState};
use crate::sandbox::{Actions, SandboxControls, SandboxMode}; use crate::sandbox::{Actions, SandboxControls, SandboxMode};
@ -307,7 +307,7 @@ impl State for EditScenarioModifiers {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }
@ -431,7 +431,7 @@ impl State for ChangeMode {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }

View File

@ -19,7 +19,7 @@ use crate::common::{tool_panel, Minimap, Warping};
use crate::cutscene::CutsceneBuilder; use crate::cutscene::CutsceneBuilder;
use crate::edit::EditMode; use crate::edit::EditMode;
use crate::game::{PopupMsg, State, Transition}; 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::gameplay::{GameplayMode, GameplayState};
use crate::sandbox::{ use crate::sandbox::{
maybe_exit_sandbox, spawn_agents_around, Actions, AgentMeter, SandboxControls, SandboxMode, 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(); let tut = app.session.tutorial.as_ref().unwrap();
if self.msg_panel.is_some() { if self.msg_panel.is_some() {
State::grey_out_map(g, app); grey_out_map(g, app);
} }
self.top_center.draw(g); self.top_center.draw(g);

View File

@ -10,7 +10,7 @@ use widgetry::{
use crate::app::{App, FindDelayedIntersections, ShowEverything}; use crate::app::{App, FindDelayedIntersections, ShowEverything};
use crate::common::Warping; use crate::common::Warping;
use crate::game::{DrawBaselayer, PopupMsg, State, Transition}; use crate::game::{DrawBaselayer, PopupMsg, State, Transition};
use crate::helpers::ID; use crate::helpers::{grey_out_map, ID};
use crate::render::DrawOptions; use crate::render::DrawOptions;
use crate::sandbox::{GameplayMode, SandboxMode}; use crate::sandbox::{GameplayMode, SandboxMode};
@ -141,7 +141,7 @@ impl State for JumpToTime {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }
@ -236,7 +236,7 @@ impl State for JumpToDelay {
} }
fn draw(&self, g: &mut GfxCtx, app: &App) { fn draw(&self, g: &mut GfxCtx, app: &App) {
State::grey_out_map(g, app); grey_out_map(g, app);
self.panel.draw(g); self.panel.draw(g);
} }
} }
@ -406,7 +406,7 @@ impl State for TimeWarpScreen {
g.clear(app.cs.section_bg); g.clear(app.cs.section_bg);
} else { } else {
app.draw(g, DrawOptions::new(), &ShowEverything::new()); app.draw(g, DrawOptions::new(), &ShowEverything::new());
State::grey_out_map(g, app); grey_out_map(g, app);
} }
self.panel.draw(g); self.panel.draw(g);