mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
Refactor calls to calculate_current_selection
This commit is contained in:
parent
acaf7eb587
commit
98d26d8979
@ -10,7 +10,7 @@ use geom::{Bounds, Circle, Distance, Duration, Pt2D, Time};
|
||||
use map_model::{IntersectionID, Map, Traversable};
|
||||
use maplit::btreemap;
|
||||
use rand::seq::SliceRandom;
|
||||
use sim::{Analytics, GetDrawAgents, Sim, SimCallback, SimFlags};
|
||||
use sim::{Analytics, DontDrawAgents, GetDrawAgents, Sim, SimCallback, SimFlags};
|
||||
use std::collections::BTreeMap;
|
||||
use widgetry::{EventCtx, GfxCtx, Prerender};
|
||||
|
||||
@ -298,10 +298,41 @@ impl App {
|
||||
);
|
||||
}
|
||||
|
||||
// Because we have to sometimes borrow part of self for GetDrawAgents, this just returns the
|
||||
// Option<ID> that the caller should assign. When this monolithic UI nonsense is dismantled,
|
||||
// this weirdness goes away.
|
||||
pub fn calculate_current_selection(
|
||||
pub fn mouseover_unzoomed_roads_and_intersections(&self, ctx: &EventCtx) -> Option<ID> {
|
||||
self.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
}
|
||||
pub fn mouseover_unzoomed_buildings(&self, ctx: &EventCtx) -> Option<ID> {
|
||||
self.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
)
|
||||
}
|
||||
pub fn mouseover_unzoomed_everything(&self, ctx: &EventCtx) -> Option<ID> {
|
||||
self.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
)
|
||||
}
|
||||
pub fn mouseover_debug_mode(&self, ctx: &EventCtx, show_objs: &dyn ShowObject) -> Option<ID> {
|
||||
self.calculate_current_selection(ctx, &self.primary.sim, show_objs, true, false, false)
|
||||
}
|
||||
|
||||
fn calculate_current_selection(
|
||||
&self,
|
||||
ctx: &EventCtx,
|
||||
source: &dyn GetDrawAgents,
|
||||
|
@ -112,8 +112,7 @@ impl State for DebugMode {
|
||||
ctx.canvas_movement();
|
||||
|
||||
if ctx.redo_mouseover() {
|
||||
app.primary.current_selection =
|
||||
app.calculate_current_selection(ctx, &app.primary.sim, self, true, false, false);
|
||||
app.primary.current_selection = app.mouseover_debug_mode(ctx, self);
|
||||
}
|
||||
|
||||
match self.panel.event(ctx) {
|
||||
@ -200,14 +199,7 @@ impl State for DebugMode {
|
||||
}
|
||||
"unhide everything" => {
|
||||
self.hidden.clear();
|
||||
app.primary.current_selection = app.calculate_current_selection(
|
||||
ctx,
|
||||
&app.primary.sim,
|
||||
self,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_debug_mode(ctx, self);
|
||||
self.reset_info(ctx);
|
||||
}
|
||||
"search OSM metadata" => {
|
||||
|
@ -1,12 +1,11 @@
|
||||
// A state to count the number of trips that will cross different roads.
|
||||
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::{ColorLegend, ColorNetwork, CommonState};
|
||||
use crate::game::{State, Transition};
|
||||
use crate::helpers::ID;
|
||||
use abstutil::Counter;
|
||||
use map_model::{IntersectionID, PathStep, RoadID, Traversable};
|
||||
use sim::DontDrawAgents;
|
||||
use widgetry::{
|
||||
Btn, Color, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, Text,
|
||||
VerticalAlignment, Widget,
|
||||
@ -88,14 +87,7 @@ impl State for PathCounter {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
ctx.canvas_movement();
|
||||
if ctx.redo_mouseover() {
|
||||
app.primary.current_selection = app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_unzoomed_roads_and_intersections(ctx);
|
||||
self.tooltip = None;
|
||||
if let Some(r) = match app.primary.current_selection {
|
||||
Some(ID::Lane(l)) => Some(app.primary.map.get_l(l).parent),
|
||||
|
@ -1,10 +1,10 @@
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::{make_heatmap, HeatmapOptions};
|
||||
use crate::game::{State, Transition};
|
||||
use crate::helpers::{amenity_type, ID};
|
||||
use abstutil::Counter;
|
||||
use map_model::BuildingID;
|
||||
use sim::{DontDrawAgents, Scenario, TripEndpoint};
|
||||
use sim::{Scenario, TripEndpoint};
|
||||
use widgetry::{
|
||||
Btn, Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
|
||||
Outcome, Panel, Text, VerticalAlignment, Widget,
|
||||
@ -111,14 +111,7 @@ impl State for PopularDestinations {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
ctx.canvas_movement();
|
||||
if ctx.redo_mouseover() {
|
||||
app.primary.current_selection = app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_unzoomed_buildings(ctx);
|
||||
if let Some(ID::Building(_)) = app.primary.current_selection {
|
||||
} else {
|
||||
app.primary.current_selection = None;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::{CityPicker, ColorLegend};
|
||||
use crate::game::{PopupMsg, State, Transition};
|
||||
use crate::helpers::{nice_map_name, open_browser, ID};
|
||||
@ -6,7 +6,6 @@ use abstutil::{prettyprint_usize, Tags, Timer};
|
||||
use geom::{Distance, FindClosest, PolyLine, Polygon};
|
||||
use map_model::{osm, RoadID};
|
||||
use osm::WayID;
|
||||
use sim::DontDrawAgents;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
@ -192,14 +191,7 @@ impl State for ParkingMapper {
|
||||
|
||||
ctx.canvas_movement();
|
||||
if ctx.redo_mouseover() {
|
||||
let mut maybe_r = match app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
) {
|
||||
let mut maybe_r = match app.mouseover_unzoomed_roads_and_intersections(ctx) {
|
||||
Some(ID::Road(r)) => Some(r),
|
||||
Some(ID::Lane(l)) => Some(map.get_l(l).parent),
|
||||
_ => None,
|
||||
|
@ -14,7 +14,7 @@ pub use self::routes::RouteEditor;
|
||||
pub use self::stop_signs::StopSignEditor;
|
||||
pub use self::traffic_signals::TrafficSignalEditor;
|
||||
pub use self::validate::{check_blackholes, check_sidewalk_connectivity, try_change_lt};
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::{tool_panel, ColorLegend, CommonState, Warping};
|
||||
use crate::debug::DebugMode;
|
||||
use crate::game::{ChooseSomething, PopupMsg, State, Transition};
|
||||
@ -26,7 +26,6 @@ use abstutil::Timer;
|
||||
use geom::Speed;
|
||||
use map_model::{EditCmd, IntersectionID, LaneID, LaneType, MapEdits};
|
||||
use maplit::btreeset;
|
||||
use sim::DontDrawAgents;
|
||||
use std::collections::BTreeSet;
|
||||
use widgetry::{
|
||||
lctrl, Btn, Choice, Color, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Menu,
|
||||
@ -127,14 +126,7 @@ impl State for EditMode {
|
||||
ctx.canvas_movement();
|
||||
// Restrict what can be selected.
|
||||
if ctx.redo_mouseover() {
|
||||
app.primary.current_selection = app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_unzoomed_roads_and_intersections(ctx);
|
||||
if let Some(ID::Lane(l)) = app.primary.current_selection {
|
||||
if !can_edit_lane(&self.mode, l, app) {
|
||||
app.primary.current_selection = None;
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::CommonState;
|
||||
use crate::helpers::{intersections_from_roads, ID};
|
||||
use map_model::{IntersectionID, RoadID};
|
||||
use sim::DontDrawAgents;
|
||||
use std::collections::BTreeSet;
|
||||
use widgetry::{Btn, Color, Drawable, EventCtx, GeomBatch, GfxCtx, Key, RewriteColor, Widget};
|
||||
|
||||
@ -105,14 +104,7 @@ impl RoadSelector {
|
||||
// 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(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_unzoomed_roads_and_intersections(ctx);
|
||||
match self.mode {
|
||||
Mode::Pan => {
|
||||
app.primary.current_selection = None;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::CommonState;
|
||||
use crate::edit::traffic_signals::fade_irrelevant;
|
||||
use crate::game::{State, Transition};
|
||||
@ -6,7 +6,7 @@ use crate::helpers::ID;
|
||||
use geom::{Distance, Duration};
|
||||
use map_model::IntersectionID;
|
||||
use maplit::btreeset;
|
||||
use sim::{DontDrawAgents, Scenario};
|
||||
use sim::Scenario;
|
||||
use std::collections::BTreeSet;
|
||||
use widgetry::{
|
||||
Btn, Color, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel,
|
||||
@ -59,14 +59,7 @@ impl State for ShowAbsolute {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
ctx.canvas_movement();
|
||||
if ctx.redo_mouseover() {
|
||||
app.primary.current_selection = app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_unzoomed_roads_and_intersections(ctx);
|
||||
}
|
||||
if let Some(ID::Intersection(i)) = app.primary.current_selection {
|
||||
if self.members.contains(&i) {
|
||||
@ -168,14 +161,7 @@ impl State for ShowRelative {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
ctx.canvas_movement();
|
||||
if ctx.redo_mouseover() {
|
||||
app.primary.current_selection = app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_unzoomed_roads_and_intersections(ctx);
|
||||
}
|
||||
if let Some(ID::Intersection(i)) = app.primary.current_selection {
|
||||
if self.members.contains(&i) && i != self.base {
|
||||
|
@ -1,11 +1,10 @@
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::CommonState;
|
||||
use crate::edit::TrafficSignalEditor;
|
||||
use crate::game::{State, Transition};
|
||||
use crate::helpers::ID;
|
||||
use crate::sandbox::gameplay::GameplayMode;
|
||||
use map_model::IntersectionID;
|
||||
use sim::DontDrawAgents;
|
||||
use std::collections::BTreeSet;
|
||||
use widgetry::{
|
||||
hotkeys, Btn, Color, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome,
|
||||
@ -48,14 +47,7 @@ impl State for SignalPicker {
|
||||
fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition {
|
||||
ctx.canvas_movement();
|
||||
if ctx.redo_mouseover() {
|
||||
app.primary.current_selection = app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_unzoomed_roads_and_intersections(ctx);
|
||||
}
|
||||
if let Some(ID::Intersection(i)) = app.primary.current_selection {
|
||||
if app.primary.map.maybe_get_traffic_signal(i).is_some() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::{ColorLegend, ColorNetwork, DivergingScale};
|
||||
use crate::helpers::ID;
|
||||
use crate::layer::{Layer, LayerOutcome};
|
||||
@ -6,7 +6,7 @@ use abstutil::{prettyprint_usize, Counter};
|
||||
use geom::{Circle, Distance, Duration, Polygon, Pt2D, Time};
|
||||
use map_model::{IntersectionID, Map, Traversable, NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS};
|
||||
use maplit::btreeset;
|
||||
use sim::{DontDrawAgents, GetDrawAgents};
|
||||
use sim::GetDrawAgents;
|
||||
use std::collections::BTreeSet;
|
||||
use widgetry::{
|
||||
Btn, Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
|
||||
@ -132,14 +132,7 @@ impl Layer for Throughput {
|
||||
if ctx.canvas.cam_zoom < app.opts.min_zoom_for_detail {
|
||||
if ctx.redo_mouseover() || recalc_tooltip {
|
||||
self.tooltip = None;
|
||||
match app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
) {
|
||||
match app.mouseover_unzoomed_roads_and_intersections(ctx) {
|
||||
Some(ID::Road(r)) => {
|
||||
let cnt = app.primary.sim.get_analytics().road_thruput.total_for(r);
|
||||
if cnt > 0 {
|
||||
|
@ -69,14 +69,8 @@ impl State for TrafficSignalDemand {
|
||||
// TODO DrawWithTooltips works great in screenspace; make a similar tool for mapspace?
|
||||
if ctx.redo_mouseover() {
|
||||
self.selected = None;
|
||||
if let Some(ID::Intersection(i)) = app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
) {
|
||||
app.recalculate_current_selection(ctx);
|
||||
if let Some(ID::Intersection(i)) = app.primary.current_selection.take() {
|
||||
if let Some(ts) = app.primary.map.maybe_get_traffic_signal(i) {
|
||||
// If we're mousing over something, the cursor is on the map.
|
||||
let pt = ctx.canvas.get_cursor_in_map_space().unwrap();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::app::App;
|
||||
use crate::common::{CityPicker, CommonState};
|
||||
use crate::edit::EditMode;
|
||||
use crate::game::{ChooseSomething, PopupMsg, PromptInput, State, Transition};
|
||||
@ -11,8 +11,8 @@ use map_model::{BuildingID, IntersectionID, Position, NORMAL_LANE_THICKNESS};
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::Rng;
|
||||
use sim::{
|
||||
DontDrawAgents, DrivingGoal, IndividTrip, PersonID, PersonSpec, Scenario, SidewalkSpot,
|
||||
SpawnTrip, TripEndpoint, TripMode, TripPurpose, TripSpec,
|
||||
DrivingGoal, IndividTrip, PersonID, PersonSpec, Scenario, SidewalkSpot, SpawnTrip,
|
||||
TripEndpoint, TripMode, TripPurpose, TripSpec,
|
||||
};
|
||||
use widgetry::{
|
||||
lctrl, Btn, Choice, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel,
|
||||
@ -357,14 +357,7 @@ impl State for AgentSpawner {
|
||||
}
|
||||
|
||||
if ctx.redo_mouseover() {
|
||||
app.primary.current_selection = app.calculate_current_selection(
|
||||
ctx,
|
||||
&DontDrawAgents {},
|
||||
&ShowEverything::new(),
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
app.primary.current_selection = app.mouseover_unzoomed_everything(ctx);
|
||||
if let Some(ID::Intersection(i)) = app.primary.current_selection {
|
||||
if !app.primary.map.get_i(i).is_border() {
|
||||
app.primary.current_selection = None;
|
||||
|
Loading…
Reference in New Issue
Block a user