mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 06:55:40 +03:00
show a score card in the tutorial too [rebuild]
This commit is contained in:
parent
5c79efcc60
commit
2316a725b1
@ -2,7 +2,7 @@ use crate::common::Overlays;
|
||||
use crate::game::Transition;
|
||||
use crate::managed::{WrappedComposite, WrappedOutcome};
|
||||
use crate::sandbox::gameplay::{challenge_controller, FinalScore, GameplayMode, GameplayState};
|
||||
use crate::sandbox::SandboxControls;
|
||||
use crate::sandbox::{SandboxControls, ScoreCard};
|
||||
use crate::ui::UI;
|
||||
use ezgui::{EventCtx, GfxCtx};
|
||||
use geom::{Duration, Statistic, Time};
|
||||
@ -72,8 +72,11 @@ impl GameplayState for FixTrafficSignals {
|
||||
self.top_center.draw(g);
|
||||
}
|
||||
|
||||
fn get_agent_meter_params(&self) -> Option<bool> {
|
||||
Some(true)
|
||||
fn get_agent_meter_params(&self) -> Option<Option<ScoreCard>> {
|
||||
Some(Some(ScoreCard {
|
||||
stat: Statistic::Mean,
|
||||
goal: GOAL,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ use crate::game::{msg, State, Transition};
|
||||
use crate::managed::WrappedComposite;
|
||||
use crate::pregame::main_menu;
|
||||
use crate::render::{AgentColorScheme, InnerAgentColorScheme};
|
||||
use crate::sandbox::{SandboxControls, SandboxMode};
|
||||
use crate::sandbox::{SandboxControls, SandboxMode, ScoreCard};
|
||||
use crate::ui::UI;
|
||||
use abstutil::Timer;
|
||||
use ezgui::{
|
||||
@ -71,8 +71,8 @@ pub trait GameplayState: downcast_rs::Downcast {
|
||||
fn has_speed(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn get_agent_meter_params(&self) -> Option<bool> {
|
||||
Some(false)
|
||||
fn get_agent_meter_params(&self) -> Option<Option<ScoreCard>> {
|
||||
Some(None)
|
||||
}
|
||||
fn has_minimap(&self) -> bool {
|
||||
true
|
||||
|
@ -5,8 +5,10 @@ use crate::game::{msg, State, Transition};
|
||||
use crate::helpers::ID;
|
||||
use crate::managed::WrappedComposite;
|
||||
use crate::sandbox::gameplay::{GameplayMode, GameplayState};
|
||||
use crate::sandbox::{spawn_agents_around, AgentMeter, SpeedControls, TimePanel};
|
||||
use crate::sandbox::{SandboxControls, SandboxMode};
|
||||
use crate::sandbox::{
|
||||
spawn_agents_around, AgentMeter, SandboxControls, SandboxMode, ScoreCard, SpeedControls,
|
||||
TimePanel,
|
||||
};
|
||||
use crate::ui::UI;
|
||||
use abstutil::Timer;
|
||||
use ezgui::{
|
||||
@ -521,9 +523,16 @@ impl GameplayState for Tutorial {
|
||||
fn has_speed(&self) -> bool {
|
||||
self.last_finished_task >= Task::InspectObjects
|
||||
}
|
||||
fn get_agent_meter_params(&self) -> Option<bool> {
|
||||
fn get_agent_meter_params(&self) -> Option<Option<ScoreCard>> {
|
||||
if self.last_finished_task >= Task::PauseResume {
|
||||
Some(false)
|
||||
if self.last_finished_task == Task::WatchBikes {
|
||||
Some(Some(ScoreCard {
|
||||
stat: Statistic::Max,
|
||||
goal: Duration::seconds(45.0),
|
||||
}))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -979,7 +988,7 @@ impl TutorialState {
|
||||
let tool_panel = tool_panel(ctx);
|
||||
let time = TimePanel::new(ctx, ui);
|
||||
let speed = SpeedControls::new(ctx);
|
||||
let agent_meter = AgentMeter::new(ctx, ui, false);
|
||||
let agent_meter = AgentMeter::new(ctx, ui, None);
|
||||
// The minimap is hidden at low zoom levels
|
||||
let orig_zoom = ctx.canvas.cam_zoom;
|
||||
ctx.canvas.cam_zoom = 100.0;
|
||||
|
@ -360,15 +360,20 @@ fn exit_sandbox(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Tra
|
||||
Some(Transition::Clear(vec![main_menu(ctx, ui)]))
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct ScoreCard {
|
||||
pub stat: Statistic,
|
||||
pub goal: Duration,
|
||||
}
|
||||
|
||||
pub struct AgentMeter {
|
||||
time: Time,
|
||||
pub composite: Composite,
|
||||
// TODO Way more options than this...
|
||||
pub show_score: bool,
|
||||
pub show_score: Option<ScoreCard>,
|
||||
}
|
||||
|
||||
impl AgentMeter {
|
||||
pub fn new(ctx: &mut EventCtx, ui: &UI, show_score: bool) -> AgentMeter {
|
||||
pub fn new(ctx: &mut EventCtx, ui: &UI, show_score: Option<ScoreCard>) -> AgentMeter {
|
||||
let (finished, unfinished, by_mode) = ui.primary.sim.num_trips();
|
||||
|
||||
let mut rows = vec![
|
||||
@ -392,26 +397,28 @@ impl AgentMeter {
|
||||
// TODO The SVG button uses clip and doesn't seem to work
|
||||
WrappedComposite::text_button(ctx, "finished trip data", hotkey(Key::Q)),
|
||||
];
|
||||
if show_score {
|
||||
let (now, _, _) = ui
|
||||
.primary
|
||||
.sim
|
||||
.get_analytics()
|
||||
.all_finished_trips(ui.primary.sim.time());
|
||||
let (baseline, _, _) = ui.prebaked().all_finished_trips(ui.primary.sim.time());
|
||||
let mut txt = Text::from(Line("Average trip time: ").size(20));
|
||||
if now.count() > 0 && baseline.count() > 0 {
|
||||
txt.append_all(cmp_duration_shorter(
|
||||
now.select(Statistic::Mean),
|
||||
baseline.select(Statistic::Mean),
|
||||
));
|
||||
} else {
|
||||
txt.append(Line("same as baseline"));
|
||||
// TODO Slight hack. If we're jumping right into a tutorial and don't have the prebaked
|
||||
// stuff loaded yet, just skip a tick.
|
||||
if ui.has_prebaked().is_some() {
|
||||
if let Some(ScoreCard { stat, goal }) = show_score {
|
||||
let (now, _, _) = ui
|
||||
.primary
|
||||
.sim
|
||||
.get_analytics()
|
||||
.all_finished_trips(ui.primary.sim.time());
|
||||
let (baseline, _, _) = ui.prebaked().all_finished_trips(ui.primary.sim.time());
|
||||
let mut txt = Text::from(Line(format!("{} trip time: ", stat)).size(20));
|
||||
if now.count() > 0 && baseline.count() > 0 {
|
||||
txt.append_all(cmp_duration_shorter(
|
||||
now.select(stat),
|
||||
baseline.select(stat),
|
||||
));
|
||||
} else {
|
||||
txt.append(Line("same as baseline"));
|
||||
}
|
||||
txt.add(Line(format!("Goal: {} faster", goal)).size(20));
|
||||
rows.push(ManagedWidget::draw_text(ctx, txt));
|
||||
}
|
||||
// TODO Definitely parameterized more ;)
|
||||
const GOAL: Duration = Duration::const_seconds(30.0);
|
||||
txt.add(Line(format!("Goal: {} faster", GOAL)).size(20));
|
||||
rows.push(ManagedWidget::draw_text(ctx, txt));
|
||||
}
|
||||
|
||||
let composite = Composite::new(ManagedWidget::col(rows).bg(colors::PANEL_BG).padding(20))
|
||||
|
Loading…
Reference in New Issue
Block a user