mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
rename analytics in UI to overlays, clash less with analytics from sim
This commit is contained in:
parent
ec956f5b13
commit
6c16840076
@ -1,6 +1,6 @@
|
||||
use crate::game::{msg, Transition, WizardState};
|
||||
use crate::render::AgentColorScheme;
|
||||
use crate::sandbox::{analytics, bus_explorer, spawner, SandboxMode};
|
||||
use crate::sandbox::{bus_explorer, overlays, spawner, SandboxMode};
|
||||
use crate::ui::UI;
|
||||
use abstutil::{prettyprint_usize, Timer};
|
||||
use ezgui::{hotkey, Choice, Color, EventCtx, GfxCtx, Key, Line, ModalMenu, Text, Wizard};
|
||||
@ -193,7 +193,7 @@ impl GameplayState {
|
||||
&mut self,
|
||||
ctx: &mut EventCtx,
|
||||
ui: &mut UI,
|
||||
analytics: &mut analytics::Analytics,
|
||||
overlays: &mut overlays::Overlays,
|
||||
) -> Option<Transition> {
|
||||
match self.state {
|
||||
State::Freeform => {
|
||||
@ -237,19 +237,19 @@ impl GameplayState {
|
||||
ref mut stat,
|
||||
} => {
|
||||
self.menu.event(ctx);
|
||||
if manage_analytics(
|
||||
if manage_overlays(
|
||||
&mut self.menu,
|
||||
ctx,
|
||||
"show bus route",
|
||||
"hide bus route",
|
||||
analytics,
|
||||
match analytics {
|
||||
analytics::Analytics::BusRoute(_) => true,
|
||||
overlays,
|
||||
match overlays {
|
||||
overlays::Overlays::BusRoute(_) => true,
|
||||
_ => false,
|
||||
},
|
||||
*time != ui.primary.sim.time(),
|
||||
) {
|
||||
*analytics = analytics::Analytics::BusRoute(bus_explorer::ShowBusRoute::new(
|
||||
*overlays = overlays::Overlays::BusRoute(bus_explorer::ShowBusRoute::new(
|
||||
ui.primary.map.get_br(route),
|
||||
ui,
|
||||
ctx,
|
||||
@ -496,14 +496,14 @@ fn change_scenario(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<
|
||||
))))
|
||||
}
|
||||
|
||||
// Must call menu.event first. Returns true if the caller should set the analytics to the custom
|
||||
// Must call menu.event first. Returns true if the caller should set the overlay to the custom
|
||||
// thing.
|
||||
fn manage_analytics(
|
||||
fn manage_overlays(
|
||||
menu: &mut ModalMenu,
|
||||
ctx: &mut EventCtx,
|
||||
show: &str,
|
||||
hide: &str,
|
||||
analytics: &mut analytics::Analytics,
|
||||
overlay: &mut overlays::Overlays,
|
||||
active_originally: bool,
|
||||
time_changed: bool,
|
||||
) -> bool {
|
||||
@ -517,7 +517,7 @@ fn manage_analytics(
|
||||
if !active_originally && menu.swap_action(show, hide, ctx) {
|
||||
true
|
||||
} else if active_originally && menu.swap_action(hide, show, ctx) {
|
||||
*analytics = analytics::Analytics::Inactive;
|
||||
*overlay = overlays::Overlays::Inactive;
|
||||
false
|
||||
} else {
|
||||
active_originally && time_changed
|
||||
|
@ -1,6 +1,6 @@
|
||||
mod analytics;
|
||||
mod bus_explorer;
|
||||
mod gameplay;
|
||||
mod overlays;
|
||||
mod score;
|
||||
mod spawner;
|
||||
mod trip_stats;
|
||||
@ -25,7 +25,7 @@ pub struct SandboxMode {
|
||||
general_tools: MenuUnderButton,
|
||||
save_tools: MenuUnderButton,
|
||||
agent_tools: AgentTools,
|
||||
analytics: analytics::Analytics,
|
||||
overlay: overlays::Overlays,
|
||||
gameplay: gameplay::GameplayState,
|
||||
common: CommonState,
|
||||
menu: ModalMenu,
|
||||
@ -71,7 +71,7 @@ impl SandboxMode {
|
||||
ctx,
|
||||
),
|
||||
agent_tools: AgentTools::new(),
|
||||
analytics: analytics::Analytics::Inactive,
|
||||
overlay: overlays::Overlays::Inactive,
|
||||
gameplay: gameplay::GameplayState::initialize(mode, ui, ctx),
|
||||
common: CommonState::new(ctx),
|
||||
menu: ModalMenu::new(
|
||||
@ -102,7 +102,7 @@ impl State for SandboxMode {
|
||||
}
|
||||
self.menu.set_info(ctx, txt);
|
||||
}
|
||||
if let Some(t) = self.gameplay.event(ctx, ui, &mut self.analytics) {
|
||||
if let Some(t) = self.gameplay.event(ctx, ui, &mut self.overlay) {
|
||||
return t;
|
||||
}
|
||||
// Give both menus a chance to set_info before doing this
|
||||
@ -124,7 +124,7 @@ impl State for SandboxMode {
|
||||
if let Some(t) = self.common.event(ctx, ui) {
|
||||
return t;
|
||||
}
|
||||
if let Some(t) = self.analytics.event(ctx, ui, &mut self.info_tools) {
|
||||
if let Some(t) = self.overlay.event(ctx, ui, &mut self.info_tools) {
|
||||
return t;
|
||||
}
|
||||
|
||||
@ -306,7 +306,7 @@ impl State for SandboxMode {
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
if self.analytics.draw(g, ui) {
|
||||
if self.overlay.draw(g, ui) {
|
||||
// Don't draw agent tools!
|
||||
} else {
|
||||
ui.draw(
|
||||
|
@ -13,7 +13,7 @@ use map_model::PathStep;
|
||||
use sim::ParkingSpot;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub enum Analytics {
|
||||
pub enum Overlays {
|
||||
Inactive,
|
||||
ParkingAvailability(Duration, RoadColorer),
|
||||
IntersectionDelay(Duration, ObjectColorer),
|
||||
@ -25,7 +25,7 @@ pub enum Analytics {
|
||||
BusRoute(ShowBusRoute),
|
||||
}
|
||||
|
||||
impl Analytics {
|
||||
impl Overlays {
|
||||
pub fn event(
|
||||
&mut self,
|
||||
ctx: &mut EventCtx,
|
||||
@ -50,29 +50,29 @@ impl Analytics {
|
||||
})?;
|
||||
Some(Transition::PopWithData(Box::new(move |state, ui, ctx| {
|
||||
let mut sandbox = state.downcast_mut::<SandboxMode>().unwrap();
|
||||
sandbox.analytics = Analytics::recalc(&choice, ui, ctx);
|
||||
sandbox.overlay = Overlays::recalc(&choice, ui, ctx);
|
||||
})))
|
||||
},
|
||||
))));
|
||||
}
|
||||
|
||||
let (choice, time) = match self {
|
||||
Analytics::Inactive => {
|
||||
Overlays::Inactive => {
|
||||
return None;
|
||||
}
|
||||
Analytics::ParkingAvailability(t, _) => ("parking availability", *t),
|
||||
Analytics::IntersectionDelay(t, _) => ("intersection delay", *t),
|
||||
Analytics::Throughput(t, _) => ("cumulative throughput", *t),
|
||||
Analytics::FinishedTrips(t, _) => ("finished trips", *t),
|
||||
Analytics::Chokepoints(t, _) => ("chokepoints", *t),
|
||||
Analytics::BikeNetwork(_) => ("bike network", ui.primary.sim.time()),
|
||||
Analytics::BusRoute(_) => {
|
||||
Overlays::ParkingAvailability(t, _) => ("parking availability", *t),
|
||||
Overlays::IntersectionDelay(t, _) => ("intersection delay", *t),
|
||||
Overlays::Throughput(t, _) => ("cumulative throughput", *t),
|
||||
Overlays::FinishedTrips(t, _) => ("finished trips", *t),
|
||||
Overlays::Chokepoints(t, _) => ("chokepoints", *t),
|
||||
Overlays::BikeNetwork(_) => ("bike network", ui.primary.sim.time()),
|
||||
Overlays::BusRoute(_) => {
|
||||
// The gameplay mode will update it.
|
||||
return None;
|
||||
}
|
||||
};
|
||||
if time != ui.primary.sim.time() {
|
||||
*self = Analytics::recalc(choice, ui, ctx);
|
||||
*self = Overlays::recalc(choice, ui, ctx);
|
||||
}
|
||||
None
|
||||
}
|
||||
@ -80,19 +80,18 @@ impl Analytics {
|
||||
// True if active and should block normal drawing
|
||||
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) -> bool {
|
||||
match self {
|
||||
Analytics::Inactive => false,
|
||||
Analytics::ParkingAvailability(_, ref heatmap)
|
||||
| Analytics::BikeNetwork(ref heatmap) => {
|
||||
Overlays::Inactive => false,
|
||||
Overlays::ParkingAvailability(_, ref heatmap) | Overlays::BikeNetwork(ref heatmap) => {
|
||||
heatmap.draw(g, ui);
|
||||
true
|
||||
}
|
||||
Analytics::IntersectionDelay(_, ref heatmap)
|
||||
| Analytics::Throughput(_, ref heatmap)
|
||||
| Analytics::Chokepoints(_, ref heatmap) => {
|
||||
Overlays::IntersectionDelay(_, ref heatmap)
|
||||
| Overlays::Throughput(_, ref heatmap)
|
||||
| Overlays::Chokepoints(_, ref heatmap) => {
|
||||
heatmap.draw(g, ui);
|
||||
true
|
||||
}
|
||||
Analytics::FinishedTrips(_, ref s) => {
|
||||
Overlays::FinishedTrips(_, ref s) => {
|
||||
ui.draw(
|
||||
g,
|
||||
DrawOptions::new(),
|
||||
@ -102,34 +101,34 @@ impl Analytics {
|
||||
s.draw(g);
|
||||
true
|
||||
}
|
||||
Analytics::BusRoute(ref s) => {
|
||||
Overlays::BusRoute(ref s) => {
|
||||
s.draw(g, ui);
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn recalc(choice: &str, ui: &UI, ctx: &mut EventCtx) -> Analytics {
|
||||
fn recalc(choice: &str, ui: &UI, ctx: &mut EventCtx) -> Overlays {
|
||||
let time = ui.primary.sim.time();
|
||||
match choice {
|
||||
"none" => Analytics::Inactive,
|
||||
"none" => Overlays::Inactive,
|
||||
"parking availability" => {
|
||||
Analytics::ParkingAvailability(time, calculate_parking_heatmap(ctx, ui))
|
||||
Overlays::ParkingAvailability(time, calculate_parking_heatmap(ctx, ui))
|
||||
}
|
||||
"intersection delay" => {
|
||||
Analytics::IntersectionDelay(time, calculate_intersection_delay(ctx, ui))
|
||||
Overlays::IntersectionDelay(time, calculate_intersection_delay(ctx, ui))
|
||||
}
|
||||
"cumulative throughput" => Analytics::Throughput(time, calculate_thruput(ctx, ui)),
|
||||
"cumulative throughput" => Overlays::Throughput(time, calculate_thruput(ctx, ui)),
|
||||
"finished trips" => {
|
||||
if let Some(s) = ShowTripStats::new(ui, ctx) {
|
||||
Analytics::FinishedTrips(time, s)
|
||||
Overlays::FinishedTrips(time, s)
|
||||
} else {
|
||||
println!("No data on finished trips yet");
|
||||
Analytics::Inactive
|
||||
Overlays::Inactive
|
||||
}
|
||||
}
|
||||
"chokepoints" => Analytics::Chokepoints(time, calculate_chokepoints(ctx, ui)),
|
||||
"bike network" => Analytics::BikeNetwork(calculate_bike_network(ctx, ui)),
|
||||
"chokepoints" => Overlays::Chokepoints(time, calculate_chokepoints(ctx, ui)),
|
||||
"bike network" => Overlays::BikeNetwork(calculate_bike_network(ctx, ui)),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user