mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 10:44:56 +03:00
tune minimap controls. also avoid the brief flash of a loading screen
when it's very fast [rebuild]
This commit is contained in:
parent
c07d5b7c55
commit
d54384742a
@ -172,7 +172,7 @@ pub struct LoadingScreen<'a> {
|
||||
assets: &'a Assets,
|
||||
lines: VecDeque<String>,
|
||||
max_capacity: usize,
|
||||
last_drawn: Option<Instant>,
|
||||
last_drawn: Instant,
|
||||
title: String,
|
||||
}
|
||||
|
||||
@ -193,7 +193,8 @@ impl<'a> LoadingScreen<'a> {
|
||||
assets,
|
||||
lines: VecDeque::new(),
|
||||
max_capacity: (0.8 * initial_height / assets.default_line_height) as usize,
|
||||
last_drawn: None,
|
||||
// If the loading callback takes less than 0.2s, we don't redraw at all.
|
||||
last_drawn: Instant::now(),
|
||||
title,
|
||||
canvas,
|
||||
}
|
||||
@ -201,12 +202,10 @@ impl<'a> LoadingScreen<'a> {
|
||||
|
||||
// Timer throttles updates reasonably, so don't bother throttling redraws.
|
||||
fn redraw(&mut self) {
|
||||
if let Some(t) = self.last_drawn {
|
||||
if elapsed_seconds(t) < 0.2 {
|
||||
return;
|
||||
}
|
||||
if elapsed_seconds(self.last_drawn) < 0.2 {
|
||||
return;
|
||||
}
|
||||
self.last_drawn = Some(Instant::now());
|
||||
self.last_drawn = Instant::now();
|
||||
|
||||
let mut txt = Text::prompt(&self.title);
|
||||
txt.override_width = Some(self.canvas.window_width * 0.8);
|
||||
|
@ -102,9 +102,9 @@ impl Minimap {
|
||||
let (_, acs) =
|
||||
wiz.wrap(ctx).choose("Which colorscheme for agents?", || {
|
||||
let mut choices = Vec::new();
|
||||
for (acs, name) in AgentColorScheme::all(&ui.cs) {
|
||||
for acs in AgentColorScheme::all(&ui.cs) {
|
||||
if ui.agent_cs.acs != acs.acs {
|
||||
choices.push(Choice::new(name, acs));
|
||||
choices.push(Choice::new(acs.long_name.clone(), acs));
|
||||
}
|
||||
}
|
||||
choices
|
||||
@ -336,7 +336,8 @@ fn make_minimap_panel(ctx: &mut EventCtx, acs: &AgentColorScheme, zoom_lvl: usiz
|
||||
WrappedComposite::svg_button(ctx, "assets/minimap/down.svg", "pan down", None)
|
||||
.margin(5)
|
||||
.centered_horiz(),
|
||||
]),
|
||||
])
|
||||
.centered(),
|
||||
])
|
||||
.bg(Color::grey(0.5)),
|
||||
)
|
||||
@ -388,12 +389,11 @@ fn make_viz_panel(ctx: &mut EventCtx, acs: &AgentColorScheme) -> ManagedWidget {
|
||||
hotkey(Key::L),
|
||||
)
|
||||
.margin(10),
|
||||
]),
|
||||
// TODO Too wide most of the time...
|
||||
ManagedWidget::draw_text(ctx, Text::prompt(&acs.title)).centered_horiz(),
|
||||
])
|
||||
.centered(),
|
||||
WrappedComposite::nice_text_button(
|
||||
ctx,
|
||||
Text::from(Line("change")),
|
||||
Text::from(Line(format!("{} ▼", acs.short_name))),
|
||||
hotkey(Key::Semicolon),
|
||||
"change agent colorscheme",
|
||||
)
|
||||
@ -402,13 +402,19 @@ fn make_viz_panel(ctx: &mut EventCtx, acs: &AgentColorScheme) -> ManagedWidget {
|
||||
for (label, color, enabled) in &acs.rows {
|
||||
col.push(
|
||||
ManagedWidget::row(vec![
|
||||
ManagedWidget::btn(Button::rectangle_svg(
|
||||
ManagedWidget::btn(Button::rectangle_svg_rewrite(
|
||||
"assets/tools/visibility.svg",
|
||||
&format!("show/hide {}", label),
|
||||
None,
|
||||
RewriteColor::Change(Color::WHITE, Color::ORANGE),
|
||||
if *enabled {
|
||||
RewriteColor::NoOp
|
||||
} else {
|
||||
RewriteColor::ChangeAll(Color::WHITE.alpha(0.5))
|
||||
},
|
||||
RewriteColor::ChangeAll(Color::ORANGE),
|
||||
ctx,
|
||||
)),
|
||||
))
|
||||
.margin(3),
|
||||
ManagedWidget::draw_batch(
|
||||
ctx,
|
||||
GeomBatch::from(vec![(
|
||||
@ -420,7 +426,8 @@ fn make_viz_panel(ctx: &mut EventCtx, acs: &AgentColorScheme) -> ManagedWidget {
|
||||
Circle::new(Pt2D::new(radius, radius), Distance::meters(radius))
|
||||
.to_polygon(),
|
||||
)]),
|
||||
),
|
||||
)
|
||||
.margin(3),
|
||||
ManagedWidget::draw_text(
|
||||
ctx,
|
||||
Text::from(if *enabled {
|
||||
@ -428,7 +435,8 @@ fn make_viz_panel(ctx: &mut EventCtx, acs: &AgentColorScheme) -> ManagedWidget {
|
||||
} else {
|
||||
Line(label).fg(Color::WHITE.alpha(0.5))
|
||||
}),
|
||||
),
|
||||
)
|
||||
.margin(3),
|
||||
])
|
||||
.centered_cross(),
|
||||
);
|
||||
|
@ -454,10 +454,11 @@ pub enum InnerAgentColorScheme {
|
||||
}
|
||||
|
||||
impl InnerAgentColorScheme {
|
||||
fn data(self, cs: &ColorScheme) -> (&str, Vec<(&str, Color)>) {
|
||||
fn data(self, cs: &ColorScheme) -> (&str, &str, Vec<(&str, Color)>) {
|
||||
match self {
|
||||
InnerAgentColorScheme::VehicleTypes => (
|
||||
"vehicle types",
|
||||
"types",
|
||||
"agent types",
|
||||
vec![
|
||||
("car", cs.get_def("unzoomed car", Color::RED.alpha(0.5))),
|
||||
("bike", cs.get_def("unzoomed bike", Color::GREEN.alpha(0.5))),
|
||||
@ -469,7 +470,8 @@ impl InnerAgentColorScheme {
|
||||
],
|
||||
),
|
||||
InnerAgentColorScheme::Delay => (
|
||||
"time spent delayed/blocked",
|
||||
"delay",
|
||||
"time spent delayed",
|
||||
vec![
|
||||
("<= 1 minute", Color::BLUE.alpha(0.3)),
|
||||
("<= 5 minutes", Color::ORANGE.alpha(0.5)),
|
||||
@ -477,6 +479,7 @@ impl InnerAgentColorScheme {
|
||||
],
|
||||
),
|
||||
InnerAgentColorScheme::TripTimeSoFar => (
|
||||
"trip time",
|
||||
"trip time so far",
|
||||
vec![
|
||||
("<= 1 minute", Color::BLUE.alpha(0.3)),
|
||||
@ -485,6 +488,7 @@ impl InnerAgentColorScheme {
|
||||
],
|
||||
),
|
||||
InnerAgentColorScheme::DistanceCrossedSoFar => (
|
||||
"distance crossed",
|
||||
"distance crossed to goal so far",
|
||||
vec![
|
||||
("<= 10%", rotating_color(0)),
|
||||
@ -522,7 +526,8 @@ impl InnerAgentColorScheme {
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct AgentColorScheme {
|
||||
pub acs: InnerAgentColorScheme,
|
||||
pub title: String,
|
||||
pub short_name: String,
|
||||
pub long_name: String,
|
||||
pub rows: Vec<(String, Color, bool)>,
|
||||
}
|
||||
|
||||
@ -530,10 +535,11 @@ impl Cloneable for AgentColorScheme {}
|
||||
|
||||
impl AgentColorScheme {
|
||||
pub fn new(acs: InnerAgentColorScheme, cs: &ColorScheme) -> AgentColorScheme {
|
||||
let (title, rows) = acs.data(cs);
|
||||
let (short_name, long_name, rows) = acs.data(cs);
|
||||
AgentColorScheme {
|
||||
acs,
|
||||
title: title.to_string(),
|
||||
short_name: short_name.to_string(),
|
||||
long_name: long_name.to_string(),
|
||||
rows: rows
|
||||
.into_iter()
|
||||
.map(|(name, color)| (name.to_string(), color, true))
|
||||
@ -545,7 +551,7 @@ impl AgentColorScheme {
|
||||
AgentColorScheme::new(InnerAgentColorScheme::VehicleTypes, cs)
|
||||
}
|
||||
|
||||
pub fn all(cs: &ColorScheme) -> Vec<(AgentColorScheme, String)> {
|
||||
pub fn all(cs: &ColorScheme) -> Vec<AgentColorScheme> {
|
||||
vec![
|
||||
InnerAgentColorScheme::VehicleTypes,
|
||||
InnerAgentColorScheme::Delay,
|
||||
@ -553,11 +559,7 @@ impl AgentColorScheme {
|
||||
InnerAgentColorScheme::DistanceCrossedSoFar,
|
||||
]
|
||||
.into_iter()
|
||||
.map(|acs| {
|
||||
let x = AgentColorScheme::new(acs, cs);
|
||||
let title = x.title.clone();
|
||||
(x, title)
|
||||
})
|
||||
.map(|acs| AgentColorScheme::new(acs, cs))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user