mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
Start some initial UI for tuning offset of multiple intersections
This commit is contained in:
parent
3f86af0dc0
commit
5bede4aca2
@ -20,7 +20,7 @@ use map_model::{
|
||||
ControlTrafficSignal, EditCmd, EditIntersection, IntersectionID, Phase, PhaseType, TurnGroup,
|
||||
TurnGroupID, TurnPriority,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
|
||||
// Welcome to one of the most overwhelmingly complicated parts of the UI...
|
||||
|
||||
@ -250,6 +250,25 @@ impl State for TrafficSignalEditor {
|
||||
});
|
||||
return Transition::Keep;
|
||||
}
|
||||
if x == "Apply offsets" {
|
||||
let offsets: HashMap<IntersectionID, Duration> = self
|
||||
.members
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, i)| {
|
||||
(
|
||||
*i,
|
||||
Duration::seconds(
|
||||
self.side_panel.spinner(&format!("offset {}", idx)) as f64,
|
||||
),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
self.add_new_edit(ctx, app, self.current_phase, |ts| {
|
||||
ts.offset = offsets[&ts.id];
|
||||
});
|
||||
return Transition::Keep;
|
||||
}
|
||||
if let Some(x) = x.strip_prefix("change duration of phase ") {
|
||||
let idx = x.parse::<usize>().unwrap() - 1;
|
||||
return Transition::Push(edits::ChangeDuration::new(
|
||||
@ -644,6 +663,30 @@ fn make_side_panel(
|
||||
col.push(Widget::horiz_separator(ctx, 0.2));
|
||||
col.push(Btn::text_fg("Add new phase").build_def(ctx, None));
|
||||
|
||||
// TODO This doesn't even have a way of knowing which spinner corresponds to which
|
||||
// intersection!
|
||||
if members.len() > 1 {
|
||||
col.push("Tune offset (s)".draw_text(ctx));
|
||||
col.push(
|
||||
Widget::row(
|
||||
members
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, i)| {
|
||||
Spinner::new(
|
||||
ctx,
|
||||
(0, 90),
|
||||
map.get_traffic_signal(*i).offset.inner_seconds() as isize,
|
||||
)
|
||||
.named(format!("offset {}", idx))
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.evenly_spaced(),
|
||||
);
|
||||
col.push(Btn::text_bg2("Apply").build(ctx, "Apply offsets", None));
|
||||
}
|
||||
|
||||
Composite::new(Widget::col(col))
|
||||
.aligned(HorizontalAlignment::Left, VerticalAlignment::Top)
|
||||
.exact_size_percent(30, 85)
|
||||
|
@ -84,7 +84,9 @@ impl IntersectionSimState {
|
||||
// What phase are we starting with?
|
||||
let mut offset = signal.offset;
|
||||
loop {
|
||||
let dt = signal.phases[state.current_phase].phase_type.simple_duration();
|
||||
let dt = signal.phases[state.current_phase]
|
||||
.phase_type
|
||||
.simple_duration();
|
||||
if offset >= dt {
|
||||
offset -= dt;
|
||||
state.current_phase += 1;
|
||||
|
Loading…
Reference in New Issue
Block a user