mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-29 04:35:51 +03:00
share agent following and route tools also
This commit is contained in:
parent
b9c9a77f40
commit
36b3558db5
@ -1,7 +1,7 @@
|
|||||||
mod score;
|
mod score;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
|
|
||||||
use crate::common::{time_controls, CommonState, SpeedControls};
|
use crate::common::{time_controls, AgentTools, CommonState, RouteExplorer, SpeedControls};
|
||||||
use crate::game::{State, Transition};
|
use crate::game::{State, Transition};
|
||||||
use crate::render::MIN_ZOOM_FOR_DETAIL;
|
use crate::render::MIN_ZOOM_FOR_DETAIL;
|
||||||
use crate::ui::{PerMapUI, UI};
|
use crate::ui::{PerMapUI, UI};
|
||||||
@ -14,9 +14,10 @@ use sim::{Sim, TripID};
|
|||||||
pub struct ABTestMode {
|
pub struct ABTestMode {
|
||||||
menu: ModalMenu,
|
menu: ModalMenu,
|
||||||
speed: SpeedControls,
|
speed: SpeedControls,
|
||||||
|
primary_agent_tools: AgentTools,
|
||||||
|
secondary_agent_tools: AgentTools,
|
||||||
diff_trip: Option<DiffOneTrip>,
|
diff_trip: Option<DiffOneTrip>,
|
||||||
diff_all: Option<DiffAllTrips>,
|
diff_all: Option<DiffAllTrips>,
|
||||||
// TODO Not present in Setup state.
|
|
||||||
common: CommonState,
|
common: CommonState,
|
||||||
test_name: String,
|
test_name: String,
|
||||||
}
|
}
|
||||||
@ -40,6 +41,8 @@ impl ABTestMode {
|
|||||||
(hotkey(Key::S), "swap"),
|
(hotkey(Key::S), "swap"),
|
||||||
(hotkey(Key::D), "diff all trips"),
|
(hotkey(Key::D), "diff all trips"),
|
||||||
(hotkey(Key::A), "stop diffing trips"),
|
(hotkey(Key::A), "stop diffing trips"),
|
||||||
|
(hotkey(Key::F), "stop following agent"),
|
||||||
|
(hotkey(Key::R), "stop showing agent's route"),
|
||||||
(hotkey(Key::Q), "scoreboard"),
|
(hotkey(Key::Q), "scoreboard"),
|
||||||
(hotkey(Key::O), "save state"),
|
(hotkey(Key::O), "save state"),
|
||||||
],
|
],
|
||||||
@ -49,6 +52,8 @@ impl ABTestMode {
|
|||||||
ctx,
|
ctx,
|
||||||
),
|
),
|
||||||
speed: SpeedControls::new(ctx, None),
|
speed: SpeedControls::new(ctx, None),
|
||||||
|
primary_agent_tools: AgentTools::new(),
|
||||||
|
secondary_agent_tools: AgentTools::new(),
|
||||||
diff_trip: None,
|
diff_trip: None,
|
||||||
diff_all: None,
|
diff_all: None,
|
||||||
common: CommonState::new(),
|
common: CommonState::new(),
|
||||||
@ -70,6 +75,7 @@ impl State for ABTestMode {
|
|||||||
diff.lines.len()
|
diff.lines.len()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
self.primary_agent_tools.update_menu_info(&mut txt);
|
||||||
txt.add_line(ui.primary.sim.summary());
|
txt.add_line(ui.primary.sim.summary());
|
||||||
self.menu.handle_event(ctx, Some(txt));
|
self.menu.handle_event(ctx, Some(txt));
|
||||||
|
|
||||||
@ -90,6 +96,11 @@ impl State for ABTestMode {
|
|||||||
let primary = std::mem::replace(&mut ui.primary, secondary);
|
let primary = std::mem::replace(&mut ui.primary, secondary);
|
||||||
ui.secondary = Some(primary);
|
ui.secondary = Some(primary);
|
||||||
self.recalculate_stuff(ui, ctx);
|
self.recalculate_stuff(ui, ctx);
|
||||||
|
|
||||||
|
std::mem::swap(
|
||||||
|
&mut self.primary_agent_tools,
|
||||||
|
&mut self.secondary_agent_tools,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.menu.action("scoreboard") {
|
if self.menu.action("scoreboard") {
|
||||||
@ -100,6 +111,12 @@ impl State for ABTestMode {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(explorer) = RouteExplorer::new(ctx, ui) {
|
||||||
|
return Transition::Push(Box::new(explorer));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.primary_agent_tools.event(ctx, ui, &mut self.menu);
|
||||||
|
|
||||||
if self.menu.action("save state") {
|
if self.menu.action("save state") {
|
||||||
self.savestate(ui);
|
self.savestate(ui);
|
||||||
}
|
}
|
||||||
@ -165,6 +182,7 @@ impl State for ABTestMode {
|
|||||||
}
|
}
|
||||||
self.menu.draw(g);
|
self.menu.draw(g);
|
||||||
self.speed.draw(g);
|
self.speed.draw(g);
|
||||||
|
self.primary_agent_tools.draw(g, ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_suspend(&mut self, _: &mut UI) {
|
fn on_suspend(&mut self, _: &mut UI) {
|
||||||
|
69
editor/src/common/agent.rs
Normal file
69
editor/src/common/agent.rs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
use crate::common::route_viewer::RouteViewer;
|
||||||
|
use crate::ui::UI;
|
||||||
|
use ezgui::{EventCtx, GfxCtx, Key, ModalMenu, Text};
|
||||||
|
use sim::TripID;
|
||||||
|
|
||||||
|
pub struct AgentTools {
|
||||||
|
following: Option<TripID>,
|
||||||
|
route_viewer: RouteViewer,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AgentTools {
|
||||||
|
pub fn new() -> AgentTools {
|
||||||
|
AgentTools {
|
||||||
|
following: None,
|
||||||
|
route_viewer: RouteViewer::Inactive,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_menu_info(&self, txt: &mut Text) {
|
||||||
|
if let Some(trip) = self.following {
|
||||||
|
txt.add_line(format!("Following {}", trip));
|
||||||
|
}
|
||||||
|
match self.route_viewer {
|
||||||
|
RouteViewer::Active(_, trip, _) => {
|
||||||
|
txt.add_line(format!("Showing {}'s route", trip));
|
||||||
|
}
|
||||||
|
RouteViewer::DebugAllRoutes(_, _) => {
|
||||||
|
txt.add_line("Showing all routes".to_string());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI, menu: &mut ModalMenu) {
|
||||||
|
if self.following.is_none() {
|
||||||
|
if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||||
|
if let Some(trip) = ui.primary.sim.agent_to_trip(agent) {
|
||||||
|
if ctx
|
||||||
|
.input
|
||||||
|
.contextual_action(Key::F, &format!("follow {}", agent))
|
||||||
|
{
|
||||||
|
self.following = Some(trip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(trip) = self.following {
|
||||||
|
if let Some(pt) = ui
|
||||||
|
.primary
|
||||||
|
.sim
|
||||||
|
.get_canonical_pt_per_trip(trip, &ui.primary.map)
|
||||||
|
{
|
||||||
|
ctx.canvas.center_on_map_pt(pt);
|
||||||
|
} else {
|
||||||
|
// TODO ideally they wouldnt vanish for so long according to
|
||||||
|
// get_canonical_point_for_trip
|
||||||
|
println!("{} is gone... temporarily or not?", trip);
|
||||||
|
}
|
||||||
|
if menu.action("stop following agent") {
|
||||||
|
self.following = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.route_viewer.event(ctx, ui, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||||
|
self.route_viewer.draw(g, ui);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,15 @@
|
|||||||
|
mod agent;
|
||||||
mod associated;
|
mod associated;
|
||||||
mod navigate;
|
mod navigate;
|
||||||
|
mod route_explorer;
|
||||||
|
mod route_viewer;
|
||||||
mod speed;
|
mod speed;
|
||||||
mod time;
|
mod time;
|
||||||
mod turn_cycler;
|
mod turn_cycler;
|
||||||
mod warp;
|
mod warp;
|
||||||
|
|
||||||
|
pub use self::agent::AgentTools;
|
||||||
|
pub use self::route_explorer::RouteExplorer;
|
||||||
pub use self::speed::SpeedControls;
|
pub use self::speed::SpeedControls;
|
||||||
pub use self::time::time_controls;
|
pub use self::time::time_controls;
|
||||||
use crate::game::Transition;
|
use crate::game::Transition;
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
mod route_explorer;
|
|
||||||
mod route_viewer;
|
|
||||||
mod score;
|
mod score;
|
||||||
mod show_activity;
|
mod show_activity;
|
||||||
mod spawner;
|
mod spawner;
|
||||||
mod time_travel;
|
mod time_travel;
|
||||||
|
|
||||||
use crate::common::{time_controls, CommonState, SpeedControls};
|
use crate::common::{time_controls, AgentTools, CommonState, RouteExplorer, SpeedControls};
|
||||||
use crate::debug::DebugMode;
|
use crate::debug::DebugMode;
|
||||||
use crate::edit::EditMode;
|
use crate::edit::EditMode;
|
||||||
use crate::game::{State, Transition};
|
use crate::game::{State, Transition};
|
||||||
use crate::ui::{ShowEverything, UI};
|
use crate::ui::{ShowEverything, UI};
|
||||||
use ezgui::{hotkey, lctrl, EventCtx, EventLoopMode, GfxCtx, Key, ModalMenu, Text};
|
use ezgui::{hotkey, lctrl, EventCtx, EventLoopMode, GfxCtx, Key, ModalMenu, Text};
|
||||||
use geom::Duration;
|
use geom::Duration;
|
||||||
use sim::{Sim, TripID};
|
use sim::Sim;
|
||||||
|
|
||||||
pub struct SandboxMode {
|
pub struct SandboxMode {
|
||||||
speed: SpeedControls,
|
speed: SpeedControls,
|
||||||
following: Option<TripID>,
|
agent_tools: AgentTools,
|
||||||
route_viewer: route_viewer::RouteViewer,
|
|
||||||
show_activity: show_activity::ShowActivity,
|
show_activity: show_activity::ShowActivity,
|
||||||
pub time_travel: time_travel::InactiveTimeTravel,
|
pub time_travel: time_travel::InactiveTimeTravel,
|
||||||
common: CommonState,
|
common: CommonState,
|
||||||
@ -28,8 +25,7 @@ impl SandboxMode {
|
|||||||
pub fn new(ctx: &mut EventCtx) -> SandboxMode {
|
pub fn new(ctx: &mut EventCtx) -> SandboxMode {
|
||||||
SandboxMode {
|
SandboxMode {
|
||||||
speed: SpeedControls::new(ctx, None),
|
speed: SpeedControls::new(ctx, None),
|
||||||
following: None,
|
agent_tools: AgentTools::new(),
|
||||||
route_viewer: route_viewer::RouteViewer::Inactive,
|
|
||||||
show_activity: show_activity::ShowActivity::Inactive,
|
show_activity: show_activity::ShowActivity::Inactive,
|
||||||
time_travel: time_travel::InactiveTimeTravel::new(),
|
time_travel: time_travel::InactiveTimeTravel::new(),
|
||||||
common: CommonState::new(),
|
common: CommonState::new(),
|
||||||
@ -75,18 +71,7 @@ impl State for SandboxMode {
|
|||||||
|
|
||||||
let mut txt = Text::prompt("Sandbox Mode");
|
let mut txt = Text::prompt("Sandbox Mode");
|
||||||
txt.add_line(ui.primary.sim.summary());
|
txt.add_line(ui.primary.sim.summary());
|
||||||
if let Some(trip) = self.following {
|
self.agent_tools.update_menu_info(&mut txt);
|
||||||
txt.add_line(format!("Following {}", trip));
|
|
||||||
}
|
|
||||||
match self.route_viewer {
|
|
||||||
route_viewer::RouteViewer::Active(_, trip, _) => {
|
|
||||||
txt.add_line(format!("Showing {}'s route", trip));
|
|
||||||
}
|
|
||||||
route_viewer::RouteViewer::DebugAllRoutes(_, _) => {
|
|
||||||
txt.add_line("Showing all routes".to_string());
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
match self.show_activity {
|
match self.show_activity {
|
||||||
show_activity::ShowActivity::Inactive => {}
|
show_activity::ShowActivity::Inactive => {}
|
||||||
_ => {
|
_ => {
|
||||||
@ -106,39 +91,11 @@ impl State for SandboxMode {
|
|||||||
if let Some(spawner) = spawner::AgentSpawner::new(ctx, ui, &mut self.menu) {
|
if let Some(spawner) = spawner::AgentSpawner::new(ctx, ui, &mut self.menu) {
|
||||||
return Transition::Push(Box::new(spawner));
|
return Transition::Push(Box::new(spawner));
|
||||||
}
|
}
|
||||||
if let Some(explorer) = route_explorer::RouteExplorer::new(ctx, ui) {
|
if let Some(explorer) = RouteExplorer::new(ctx, ui) {
|
||||||
return Transition::Push(Box::new(explorer));
|
return Transition::Push(Box::new(explorer));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.following.is_none() {
|
self.agent_tools.event(ctx, ui, &mut self.menu);
|
||||||
if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) {
|
|
||||||
if let Some(trip) = ui.primary.sim.agent_to_trip(agent) {
|
|
||||||
if ctx
|
|
||||||
.input
|
|
||||||
.contextual_action(Key::F, &format!("follow {}", agent))
|
|
||||||
{
|
|
||||||
self.following = Some(trip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(trip) = self.following {
|
|
||||||
if let Some(pt) = ui
|
|
||||||
.primary
|
|
||||||
.sim
|
|
||||||
.get_canonical_pt_per_trip(trip, &ui.primary.map)
|
|
||||||
{
|
|
||||||
ctx.canvas.center_on_map_pt(pt);
|
|
||||||
} else {
|
|
||||||
// TODO ideally they wouldnt vanish for so long according to
|
|
||||||
// get_canonical_point_for_trip
|
|
||||||
println!("{} is gone... temporarily or not?", trip);
|
|
||||||
}
|
|
||||||
if self.menu.action("stop following agent") {
|
|
||||||
self.following = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.route_viewer.event(ctx, ui, &mut self.menu);
|
|
||||||
self.show_activity.event(ctx, ui, &mut self.menu);
|
self.show_activity.event(ctx, ui, &mut self.menu);
|
||||||
if self.menu.action("start time traveling") {
|
if self.menu.action("start time traveling") {
|
||||||
return self.time_travel.start(ctx, ui);
|
return self.time_travel.start(ctx, ui);
|
||||||
@ -227,7 +184,7 @@ impl State for SandboxMode {
|
|||||||
&ShowEverything::new(),
|
&ShowEverything::new(),
|
||||||
);
|
);
|
||||||
self.common.draw(g, ui);
|
self.common.draw(g, ui);
|
||||||
self.route_viewer.draw(g, ui);
|
self.agent_tools.draw(g, ui);
|
||||||
self.show_activity.draw(g, ui);
|
self.show_activity.draw(g, ui);
|
||||||
self.menu.draw(g);
|
self.menu.draw(g);
|
||||||
self.speed.draw(g);
|
self.speed.draw(g);
|
||||||
|
Loading…
Reference in New Issue
Block a user