mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
Small style cleanups after #346 (Import grouping, simplify Spinner logic)
This commit is contained in:
parent
0921a4aae5
commit
4916b10190
@ -1,3 +1,8 @@
|
||||
use crate::app::App;
|
||||
use crate::edit::traffic_signals::{BundleEdits, TrafficSignalEditor};
|
||||
use crate::edit::{apply_map_edits, check_sidewalk_connectivity, StopSignEditor};
|
||||
use crate::game::{ChooseSomething, DrawBaselayer, State, Transition};
|
||||
use crate::sandbox::GameplayMode;
|
||||
use abstutil::Timer;
|
||||
use geom::Duration;
|
||||
use map_model::{
|
||||
@ -7,12 +12,6 @@ use widgetry::{
|
||||
Btn, Checkbox, Choice, EventCtx, GfxCtx, Key, Line, Outcome, Panel, Spinner, TextExt, Widget,
|
||||
};
|
||||
|
||||
use crate::app::App;
|
||||
use crate::edit::traffic_signals::{BundleEdits, TrafficSignalEditor};
|
||||
use crate::edit::{apply_map_edits, check_sidewalk_connectivity, StopSignEditor};
|
||||
use crate::game::{ChooseSomething, DrawBaselayer, State, Transition};
|
||||
use crate::sandbox::GameplayMode;
|
||||
|
||||
pub struct ChangeDuration {
|
||||
panel: Panel,
|
||||
idx: usize,
|
||||
|
@ -1,15 +1,7 @@
|
||||
use std::collections::{BTreeSet, VecDeque};
|
||||
|
||||
use abstutil::Timer;
|
||||
use geom::{Distance, Duration, Line, Polygon, Pt2D};
|
||||
use map_model::{
|
||||
ControlTrafficSignal, EditCmd, EditIntersection, IntersectionID, MovementID, PhaseType, Stage,
|
||||
TurnPriority,
|
||||
};
|
||||
use widgetry::{
|
||||
lctrl, Btn, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
|
||||
MultiButton, Outcome, Panel, RewriteColor, Text, TextExt, VerticalAlignment, Widget,
|
||||
};
|
||||
mod edits;
|
||||
mod offsets;
|
||||
mod picker;
|
||||
mod preview;
|
||||
|
||||
use crate::app::{App, ShowEverything};
|
||||
use crate::common::{CommonState, Warping};
|
||||
@ -18,11 +10,17 @@ use crate::game::{DrawBaselayer, PopupMsg, State, Transition};
|
||||
use crate::options::TrafficSignalStyle;
|
||||
use crate::render::{traffic_signal, DrawMovement, DrawOptions};
|
||||
use crate::sandbox::GameplayMode;
|
||||
|
||||
mod edits;
|
||||
mod offsets;
|
||||
mod picker;
|
||||
mod preview;
|
||||
use abstutil::Timer;
|
||||
use geom::{Distance, Duration, Line, Polygon, Pt2D};
|
||||
use map_model::{
|
||||
ControlTrafficSignal, EditCmd, EditIntersection, IntersectionID, MovementID, PhaseType, Stage,
|
||||
TurnPriority,
|
||||
};
|
||||
use std::collections::{BTreeSet, VecDeque};
|
||||
use widgetry::{
|
||||
lctrl, Btn, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
|
||||
MultiButton, Outcome, Panel, RewriteColor, Text, TextExt, VerticalAlignment, Widget,
|
||||
};
|
||||
|
||||
// Welcome to one of the most overwhelmingly complicated parts of the UI...
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use abstutil::Timer;
|
||||
use geom::Duration;
|
||||
|
||||
use crate::{
|
||||
ControlTrafficSignal, IntersectionCluster, IntersectionID, Map, Movement, MovementID,
|
||||
PhaseType, RoadID, Stage, TurnPriority, TurnType,
|
||||
};
|
||||
use abstutil::Timer;
|
||||
use geom::Duration;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub fn get_possible_policies(
|
||||
map: &Map,
|
||||
@ -63,7 +61,6 @@ pub fn get_possible_policies(
|
||||
all_walk_all_yield(map, id),
|
||||
));
|
||||
|
||||
// TODO Automatically fix things like minimum crosswalk time
|
||||
// Make sure all possible policies have a minimum crosswalk time enforced
|
||||
for (_, signal) in &mut results {
|
||||
for stage in &mut signal.stages {
|
||||
@ -78,6 +75,7 @@ pub fn get_possible_policies(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results.retain(|pair| pair.1.validate().is_ok());
|
||||
results
|
||||
}
|
||||
|
@ -1,11 +1,3 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use abstutil::{deserialize_btreemap, retain_btreeset, serialize_btreemap, Timer};
|
||||
use geom::{Distance, Duration, Speed};
|
||||
|
||||
use crate::make::traffic_signals::{brute_force, get_possible_policies};
|
||||
use crate::objects::traffic_signals::PhaseType::{Adaptive, Fixed};
|
||||
use crate::raw::OriginalRoad;
|
||||
@ -13,6 +5,11 @@ use crate::{
|
||||
osm, CompressedMovementID, DirectedRoadID, Direction, IntersectionID, Map, Movement,
|
||||
MovementID, TurnID, TurnPriority, TurnType,
|
||||
};
|
||||
use abstutil::{deserialize_btreemap, retain_btreeset, serialize_btreemap, Timer};
|
||||
use geom::{Distance, Duration, Speed};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
// The pace to use for crosswalk pace in m/s
|
||||
// https://en.wikipedia.org/wiki/Preferred_walking_speed
|
||||
@ -78,6 +75,7 @@ impl ControlTrafficSignal {
|
||||
pub fn brute_force(map: &Map, id: IntersectionID) {
|
||||
brute_force(map, id)
|
||||
}
|
||||
|
||||
pub fn get_min_crossing_time(&self, idx: usize) -> Duration {
|
||||
let mut max_distance = Distance::meters(0.0);
|
||||
for movement in &self.stages[idx].protected_movements {
|
||||
@ -136,15 +134,6 @@ impl ControlTrafficSignal {
|
||||
// Is there enough time in each stage to walk across the crosswalk
|
||||
let min_crossing_time = self.get_min_crossing_time(stage_index);
|
||||
if stage.phase_type.simple_duration() < min_crossing_time {
|
||||
// Warn/Error does not seem to be imported?
|
||||
println!(
|
||||
"Traffic signal does not allow enough time in stage to complete the \
|
||||
crosswalk\nStage Index{}\nStage : {:?}\nTime Required: {}\nTime Given: {}",
|
||||
stage_index,
|
||||
stage,
|
||||
min_crossing_time,
|
||||
stage.phase_type.simple_duration()
|
||||
);
|
||||
return Err(format!(
|
||||
"Traffic signal does not allow enough time in stage to complete the \
|
||||
crosswalk\nStage Index{}\nStage : {:?}\nTime Required: {}\nTime Given: {}",
|
||||
@ -301,7 +290,7 @@ impl Stage {
|
||||
}
|
||||
}
|
||||
pub fn enforce_minimum_crosswalk_time(&mut self, movement: &Movement) {
|
||||
//Round up to an int, because it is exported as a usize
|
||||
// Round up to an int, because it is exported as a usize
|
||||
let time = Duration::seconds(
|
||||
(movement.geom.length() / CROSSWALK_PACE)
|
||||
.inner_seconds()
|
||||
|
@ -1,9 +1,8 @@
|
||||
use geom::{Polygon, Pt2D};
|
||||
|
||||
use crate::{
|
||||
text, Btn, Button, EventCtx, GeomBatch, GfxCtx, Line, Outcome, ScreenDims, ScreenPt,
|
||||
ScreenRectangle, Text, Widget, WidgetImpl, WidgetOutput,
|
||||
};
|
||||
use geom::{Polygon, Pt2D};
|
||||
|
||||
// TODO MAX_CHAR_WIDTH is a hardcoded nonsense value
|
||||
const TEXT_WIDTH: f64 = 2.0 * text::MAX_CHAR_WIDTH;
|
||||
@ -84,14 +83,7 @@ impl WidgetImpl for Spinner {
|
||||
self.up.event(ctx, output);
|
||||
if let Outcome::Clicked(_) = output.outcome {
|
||||
output.outcome = Outcome::Changed;
|
||||
if self.current < self.high {
|
||||
self.current += 1;
|
||||
} else if self.high < self.current {
|
||||
self.current = self.high;
|
||||
}
|
||||
if self.high < self.current {
|
||||
self.current = self.high;
|
||||
}
|
||||
self.current = (self.current + 1).min(self.high);
|
||||
ctx.no_op_event(true, |ctx| self.up.event(ctx, output));
|
||||
return;
|
||||
}
|
||||
@ -99,12 +91,7 @@ impl WidgetImpl for Spinner {
|
||||
self.down.event(ctx, output);
|
||||
if let Outcome::Clicked(_) = output.outcome {
|
||||
output.outcome = Outcome::Changed;
|
||||
if self.current != self.low {
|
||||
self.current -= 1;
|
||||
}
|
||||
if self.current < self.low {
|
||||
self.current = self.low;
|
||||
}
|
||||
self.current = (self.current - 1).max(self.low);
|
||||
ctx.no_op_event(true, |ctx| self.down.event(ctx, output));
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user