stop embedding TimePanel inside SpeedPanel (even though they always go together)

This commit is contained in:
Dustin Carlino 2019-12-29 10:55:34 -06:00
parent 4329f55e97
commit 7cd7eec5cd
3 changed files with 15 additions and 14 deletions

View File

@ -5,7 +5,7 @@ use crate::managed::Outcome;
use crate::render::{
draw_signal_phase, DrawOptions, DrawTurnGroup, TrafficSignalDiagram, BIG_ARROW_THICKNESS,
};
use crate::sandbox::{spawn_agents_around, SpeedControls};
use crate::sandbox::{spawn_agents_around, SpeedControls, TimePanel};
use crate::ui::{ShowEverything, UI};
use abstutil::Timer;
use ezgui::{
@ -504,6 +504,7 @@ fn make_previewer(i: IntersectionID, phase: usize, suspended_sim: Sim) -> Box<dy
struct PreviewTrafficSignal {
menu: ModalMenu,
speed: SpeedControls,
time_panel: TimePanel,
orig_sim: Sim,
}
@ -516,6 +517,7 @@ impl PreviewTrafficSignal {
ctx,
),
speed: SpeedControls::new(ctx, ui),
time_panel: TimePanel::new(ctx, ui),
orig_sim: ui.primary.sim.clone(),
}
}
@ -529,6 +531,7 @@ impl State for PreviewTrafficSignal {
ui.primary.clear_sim();
return Transition::Pop;
}
self.time_panel.event(ctx, ui);
match self.speed.event(ctx, ui) {
Some(Outcome::Transition(t)) => {
return t;
@ -552,5 +555,6 @@ impl State for PreviewTrafficSignal {
fn draw(&self, g: &mut GfxCtx, _: &UI) {
self.menu.draw(g);
self.speed.draw(g);
self.time_panel.draw(g);
}
}

View File

@ -23,10 +23,11 @@ pub use gameplay::GameplayMode;
use geom::Time;
use map_model::MapEdits;
use sim::TripMode;
pub use speed::SpeedControls;
pub use speed::{SpeedControls, TimePanel};
pub struct SandboxMode {
speed: SpeedControls,
time_panel: TimePanel,
agent_meter: AgentMeter,
agent_tools: AgentTools,
overlay: Overlays,
@ -59,6 +60,7 @@ impl SandboxMode {
SandboxMode {
speed: SpeedControls::new(ctx, ui),
time_panel: TimePanel::new(ctx, ui),
agent_meter: AgentMeter::new(ctx, ui),
agent_tools: AgentTools::new(),
overlay: Overlays::Inactive,
@ -135,6 +137,8 @@ impl State for SandboxMode {
}
}
self.time_panel.event(ctx, ui);
match self.speed.event(ctx, ui) {
Some(Outcome::Transition(t)) => {
return t;
@ -262,6 +266,7 @@ impl State for SandboxMode {
self.common.draw(g, ui);
self.tool_panel.draw(g);
self.speed.draw(g);
self.time_panel.draw(g);
self.gameplay.draw(g, ui);
self.agent_meter.draw(g);
if let Some(ref m) = self.minimap {
@ -274,7 +279,6 @@ impl State for SandboxMode {
}
}
// TODO This and TimePanel could get refactored
struct AgentMeter {
time: Time,
composite: Composite,

View File

@ -11,8 +11,6 @@ use std::time::Instant;
const ADJUST_SPEED_PERCENT: f64 = 0.01;
pub struct SpeedControls {
time_panel: TimePanel,
composite: Composite,
state: SpeedState,
@ -161,8 +159,6 @@ impl SpeedControls {
let composite = SpeedControls::make_panel(ctx, false, "...", slider);
SpeedControls {
time_panel: TimePanel::new(ctx, ui),
composite,
state: SpeedState::Running {
@ -176,8 +172,6 @@ impl SpeedControls {
}
pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) -> Option<Outcome> {
self.time_panel.event(ctx, ui);
let desired_speed = self.desired_speed();
match self.composite.event(ctx, ui) {
Some(Outcome::Transition(t)) => {
@ -267,7 +261,6 @@ impl SpeedControls {
}
pub fn draw(&self, g: &mut GfxCtx) {
self.time_panel.draw(g);
self.composite.draw(g);
}
@ -362,13 +355,13 @@ impl State for TimeWarpScreen {
}
}
struct TimePanel {
pub struct TimePanel {
time: Time,
composite: ezgui::Composite,
}
impl TimePanel {
fn new(ctx: &EventCtx, ui: &UI) -> TimePanel {
pub fn new(ctx: &EventCtx, ui: &UI) -> TimePanel {
TimePanel {
time: ui.primary.sim.time(),
composite: ezgui::Composite::aligned(
@ -416,14 +409,14 @@ impl TimePanel {
}
}
fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) {
pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) {
if self.time != ui.primary.sim.time() {
*self = TimePanel::new(ctx, ui);
}
self.composite.event(ctx);
}
fn draw(&self, g: &mut GfxCtx) {
pub fn draw(&self, g: &mut GfxCtx) {
self.composite.draw(g);
}
}