skip to end of commute challenge as soon as last trip is done. show

sentiment of matching goal so far or not
This commit is contained in:
Dustin Carlino 2020-04-16 12:49:36 -07:00
parent ec409742e7
commit 371d98ba03
5 changed files with 59 additions and 29 deletions

View File

@ -166,6 +166,8 @@ fe358c0fdf48b65117f7c4970fa35d91 data/system/assets/tools/settings.svg
1e0135f13d0aea11650460d6a61b5463 data/system/assets/tools/edit.svg
cddd0aa7a98d4d511138befe8f56a6b7 data/system/assets/tools/delete.svg
13c640d3aef2067470c81cc324e91a30 data/system/assets/tools/shortcuts.svg
be78b20de5ec9311773237f58126a26d data/system/assets/tools/sad.svg
c072219792a6392007d9f345e636c34d data/system/assets/tools/happy.svg
4221e3cc98b20265d9bbbe551a018fa6 data/system/assets/tools/redo.svg
21b36a364bee7066abfb4b9045277600 data/system/assets/tools/save.svg
512477d8556de48901712165e905782f data/system/assets/tools/pin.svg

View File

@ -0,0 +1,3 @@
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.99 0C4.47 0 0 4.48 0 10C0 15.52 4.47 20 9.99 20C15.52 20 20 15.52 20 10C20 4.48 15.52 0 9.99 0ZM10 18C5.58 18 2 14.42 2 10C2 5.58 5.58 2 10 2C14.42 2 18 5.58 18 10C18 14.42 14.42 18 10 18ZM13.5 9C14.33 9 15 8.33 15 7.5C15 6.67 14.33 6 13.5 6C12.67 6 12 6.67 12 7.5C12 8.33 12.67 9 13.5 9ZM6.5 9C7.33 9 8 8.33 8 7.5C8 6.67 7.33 6 6.5 6C5.67 6 5 6.67 5 7.5C5 8.33 5.67 9 6.5 9ZM10 15.5C12.33 15.5 14.31 14.04 15.11 12H4.89C5.69 14.04 7.67 15.5 10 15.5Z" fill="green"/>
</svg>

After

Width:  |  Height:  |  Size: 582 B

View File

@ -0,0 +1,3 @@
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.99 0C4.47 0 0 4.48 0 10C0 15.52 4.47 20 9.99 20C15.52 20 20 15.52 20 10C20 4.48 15.52 0 9.99 0ZM10 18C5.58 18 2 14.42 2 10C2 5.58 5.58 2 10 2C14.42 2 18 5.58 18 10C18 14.42 14.42 18 10 18ZM13.5 9C14.33 9 15 8.33 15 7.5C15 6.67 14.33 6 13.5 6C12.67 6 12 6.67 12 7.5C12 8.33 12.67 9 13.5 9ZM6.5 9C7.33 9 8 8.33 8 7.5C8 6.67 7.33 6 6.5 6C5.67 6 5 6.67 5 7.5C5 8.33 5.67 9 6.5 9ZM10 11.5C7.67 11.5 5.69 12.96 4.89 15H15.11C14.31 12.96 12.33 11.5 10 11.5Z" fill="red"/>
</svg>

After

Width:  |  Height:  |  Size: 580 B

View File

@ -48,3 +48,4 @@ Other binary data bundled in:
- Overpass font (https://fonts.google.com/specimen/Overpass, Open Font License)
- Bungee fonts (https://fonts.google.com/specimen/Bungee, Open Font License)
- Material Design icons (https://material.io/resources/icons, Apache license)

View File

@ -35,7 +35,7 @@ impl OptimizeCommute {
pub fn new(ctx: &mut EventCtx, app: &App, person: PersonID) -> Box<dyn GameplayState> {
let trips = app.primary.sim.get_person(person).trips.clone();
Box::new(OptimizeCommute {
top_center: make_top_center(ctx, app, &trips),
top_center: make_top_center(ctx, app, Duration::ZERO, Duration::ZERO, 0, trips.len()),
person,
time: Time::START_OF_DAY,
trips,
@ -108,8 +108,26 @@ impl GameplayState for OptimizeCommute {
}
if self.time != app.primary.sim.time() {
self.top_center = make_top_center(ctx, app, &self.trips);
self.time = app.primary.sim.time();
let (before, after, done) = get_score(app, &self.trips);
self.top_center = make_top_center(ctx, app, before, after, done, self.trips.len());
if done == self.trips.len() {
let (verdict, _success) = final_score(app, &self.trips);
// TODO Plumb through a next stage here
let next = None;
return (
Some(Transition::Push(FinalScore::new(
ctx,
app,
verdict,
GameplayMode::OptimizeCommute(self.person),
next,
))),
false,
);
}
}
match self.top_center.event(ctx) {
@ -145,23 +163,6 @@ impl GameplayState for OptimizeCommute {
None => {}
}
// TODO After all of the person's trips are done, we can actually end then
if app.primary.sim.is_done() {
let (verdict, _success) = final_score(app, &self.trips);
// TODO Plumb through a next stage here
let next = None;
return (
Some(Transition::Push(FinalScore::new(
ctx,
app,
verdict,
GameplayMode::OptimizeCommute(self.person),
next,
))),
false,
);
}
(None, false)
}
@ -170,21 +171,37 @@ impl GameplayState for OptimizeCommute {
}
}
fn make_top_center(ctx: &mut EventCtx, app: &App, trips: &Vec<TripID>) -> Composite {
// Returns (before, after, number of trips done)
fn get_score(app: &App, trips: &Vec<TripID>) -> (Duration, Duration, usize) {
let mut done = 0;
let mut before_time = Duration::ZERO;
let mut after_time = Duration::ZERO;
let mut before = Duration::ZERO;
let mut after = Duration::ZERO;
for t in trips {
if let Some((total, _)) = app.primary.sim.finished_trip_time(*t) {
done += 1;
after_time += total;
before_time += app.prebaked().finished_trip_time(*t).unwrap();
after += total;
before += app.prebaked().finished_trip_time(*t).unwrap();
}
}
(before, after, done)
}
let mut txt = Text::from(Line(format!("Total trip time: {} (", after_time)));
txt.append_all(cmp_duration_shorter(after_time, before_time));
fn make_top_center(
ctx: &mut EventCtx,
app: &App,
before: Duration,
after: Duration,
done: usize,
trips: usize,
) -> Composite {
let mut txt = Text::from(Line(format!("Total trip time: {} (", after)));
txt.append_all(cmp_duration_shorter(after, before));
txt.append(Line(")"));
let sentiment = if before - after >= GOAL {
"../data/system/assets/tools/happy.svg"
} else {
"../data/system/assets/tools/sad.svg"
};
Composite::new(
Widget::col(vec![
@ -193,14 +210,18 @@ fn make_top_center(ctx: &mut EventCtx, app: &App, trips: &Vec<TripID>) -> Compos
Btn::svg_def("../data/system/assets/tools/location.svg")
.build(ctx, "locate VIP", None)
.margin_right(10),
format!("{}/{} trips done", done, trips.len())
format!("{}/{} trips done", done, trips)
.draw_text(ctx)
.margin_right(20),
txt.draw(ctx).margin_right(20),
format!("Goal: {} faster", GOAL).draw_text(ctx),
format!("Goal: {} faster", GOAL)
.draw_text(ctx)
.margin_right(5),
Widget::draw_svg(ctx, sentiment).centered_vert(),
]),
])
.bg(app.cs.panel_bg),
.bg(app.cs.panel_bg)
.padding(5),
)
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx)