mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 19:27:11 +03:00
redo mouseover when plugins suddenly change the screen
This commit is contained in:
parent
9400e3d010
commit
ebebce179a
@ -59,6 +59,7 @@ impl SimController {
|
||||
match primary.sim.load_most_recent() {
|
||||
Ok(new_sim) => {
|
||||
primary.sim = new_sim;
|
||||
primary.recalculate_current_selection = true;
|
||||
self.benchmark = None;
|
||||
|
||||
if let Some(s) = secondary {
|
||||
@ -80,6 +81,7 @@ impl SimController {
|
||||
self.benchmark = Some(primary.sim.start_benchmark());
|
||||
} else if input.unimportant_key_pressed(Key::M, SIM, "run one step") {
|
||||
primary.sim.step(&primary.map, &primary.control_map);
|
||||
primary.recalculate_current_selection = true;
|
||||
if let Some(s) = secondary {
|
||||
s.sim.step(&s.map, &s.control_map);
|
||||
}
|
||||
@ -93,12 +95,13 @@ impl SimController {
|
||||
let mut the_secondary = secondary.take();
|
||||
the_secondary.as_mut().map(|s| mem::swap(primary, s));
|
||||
*secondary = the_secondary;
|
||||
// TODO Any time the screen changes, need to recalculate mouseover state
|
||||
primary.recalculate_current_selection = true;
|
||||
}
|
||||
} else {
|
||||
// Interactively spawning stuff would ruin an A/B test, don't allow it
|
||||
if input.unimportant_key_pressed(Key::S, SIM, "Seed the map with agents") {
|
||||
primary.sim.small_spawn(&primary.map);
|
||||
primary.recalculate_current_selection = true;
|
||||
}
|
||||
match primary.current_selection {
|
||||
Some(ID::Car(id)) => {
|
||||
@ -123,6 +126,7 @@ impl SimController {
|
||||
let dt_s = elapsed_seconds(tick);
|
||||
if dt_s >= TIMESTEP.value_unsafe / self.desired_speed {
|
||||
primary.sim.step(&primary.map, &primary.control_map);
|
||||
primary.recalculate_current_selection = true;
|
||||
if let Some(s) = secondary {
|
||||
s.sim.step(&s.map, &s.control_map);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ impl UIWrapper {
|
||||
plugins: vec![
|
||||
Box::new(|ctx| {
|
||||
if ctx.ui.layers.event(ctx.input) {
|
||||
ctx.ui.primary.current_selection = ctx.ui.mouseover_something();
|
||||
ctx.ui.primary.recalculate_current_selection = true;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@ -278,6 +278,7 @@ pub struct PerMapUI {
|
||||
pub sim: Sim,
|
||||
|
||||
pub current_selection: Option<ID>,
|
||||
pub recalculate_current_selection: bool,
|
||||
current_flags: SimFlags,
|
||||
|
||||
// Anything that holds onto any kind of ID has to live here!
|
||||
@ -325,6 +326,7 @@ impl PerMapUI {
|
||||
sim,
|
||||
|
||||
current_selection: None,
|
||||
recalculate_current_selection: false,
|
||||
current_flags: flags,
|
||||
|
||||
hider: Hider::new(),
|
||||
@ -464,6 +466,12 @@ impl UI {
|
||||
let result = self
|
||||
.sim_ctrl
|
||||
.event(&mut input, &mut self.primary, &mut self.secondary, osd);
|
||||
|
||||
if self.primary.recalculate_current_selection {
|
||||
self.primary.recalculate_current_selection = false;
|
||||
self.primary.current_selection = self.mouseover_something();
|
||||
}
|
||||
|
||||
input.populate_osd(osd);
|
||||
result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user