mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
draw signal diagram exactly below modal menu
This commit is contained in:
parent
1f60a718de
commit
a232d023ff
@ -2,7 +2,7 @@ use crate::objects::{Ctx, ID};
|
||||
use crate::plugins::{Plugin, PluginCtx};
|
||||
use crate::render::{draw_signal_cycle, draw_signal_diagram, DrawTurn};
|
||||
use dimensioned::si;
|
||||
use ezgui::{Color, GfxCtx, Key, Wizard, WrappedWizard, TOP_MENU_HEIGHT};
|
||||
use ezgui::{Color, GfxCtx, Key, ScreenPt, Wizard, WrappedWizard};
|
||||
use map_model::{ControlTrafficSignal, Cycle, IntersectionID, Map, TurnID, TurnPriority, TurnType};
|
||||
|
||||
// TODO Warn if there are empty cycles or if some turn is completely absent from the signal.
|
||||
@ -14,6 +14,8 @@ pub struct TrafficSignalEditor {
|
||||
cycle_duration_wizard: Option<Wizard>,
|
||||
preset_wizard: Option<Wizard>,
|
||||
icon_selected: Option<TurnID>,
|
||||
|
||||
diagram_top_left: ScreenPt,
|
||||
}
|
||||
|
||||
impl TrafficSignalEditor {
|
||||
@ -24,12 +26,15 @@ impl TrafficSignalEditor {
|
||||
.input
|
||||
.contextual_action(Key::E, &format!("edit traffic signal for {}", id))
|
||||
{
|
||||
let diagram_top_left = ctx.input.set_mode("Traffic Signal Editor", &ctx.canvas);
|
||||
|
||||
return Some(TrafficSignalEditor {
|
||||
i: id,
|
||||
current_cycle: 0,
|
||||
cycle_duration_wizard: None,
|
||||
preset_wizard: None,
|
||||
icon_selected: None,
|
||||
diagram_top_left,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -219,7 +224,7 @@ impl Plugin for TrafficSignalEditor {
|
||||
self.i,
|
||||
self.current_cycle,
|
||||
None,
|
||||
TOP_MENU_HEIGHT + 400.0,
|
||||
self.diagram_top_left.y,
|
||||
g,
|
||||
ctx,
|
||||
);
|
||||
|
@ -229,12 +229,19 @@ impl UserInput {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_mode_with_prompt(&mut self, mode: &str, prompt: String, canvas: &Canvas) {
|
||||
// Returns the bottom left of the modal menu.
|
||||
pub fn set_mode_with_prompt(
|
||||
&mut self,
|
||||
mode: &str,
|
||||
prompt: String,
|
||||
canvas: &Canvas,
|
||||
) -> ScreenPt {
|
||||
self.set_mode_called.insert(mode.to_string());
|
||||
self.current_mode = Some(mode.to_string());
|
||||
if let Some(ref mut menu) = self.modal_state.mut_active_mode(mode) {
|
||||
menu.mark_all_inactive();
|
||||
menu.change_prompt(prompt);
|
||||
menu.get_bottom_left()
|
||||
} else {
|
||||
if let Some(ref m) = self.modal_state.modes.get(mode) {
|
||||
let mut menu = Menu::new(
|
||||
@ -248,15 +255,17 @@ impl UserInput {
|
||||
canvas,
|
||||
);
|
||||
menu.mark_all_inactive();
|
||||
let corner = menu.get_bottom_left();
|
||||
self.modal_state.active.push((mode.to_string(), menu));
|
||||
corner
|
||||
} else {
|
||||
panic!("set_mode called on unknown {}", mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_mode(&mut self, mode: &str, canvas: &Canvas) {
|
||||
self.set_mode_with_prompt(mode, mode.to_string(), canvas);
|
||||
pub fn set_mode(&mut self, mode: &str, canvas: &Canvas) -> ScreenPt {
|
||||
self.set_mode_with_prompt(mode, mode.to_string(), canvas)
|
||||
}
|
||||
|
||||
pub fn modal_action(&mut self, action: &str) -> bool {
|
||||
|
@ -14,6 +14,7 @@ pub struct Menu<T: Clone> {
|
||||
row_height: f64,
|
||||
top_left: ScreenPt,
|
||||
first_choice_row: ScreenRectangle,
|
||||
total_height: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -91,6 +92,7 @@ impl<T: Clone> Menu<T> {
|
||||
y2: top_left.y + row_height,
|
||||
}
|
||||
},
|
||||
total_height,
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,4 +252,8 @@ impl<T: Clone> Menu<T> {
|
||||
assert!(self.prompt.is_some());
|
||||
self.prompt = Some(prompt);
|
||||
}
|
||||
|
||||
pub fn get_bottom_left(&self) -> ScreenPt {
|
||||
ScreenPt::new(self.top_left.x, self.top_left.y + self.total_height)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user