mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-29 04:35:51 +03:00
rearrange colorscheme ownership
This commit is contained in:
parent
64573ea0ea
commit
c4d09b6e4f
@ -87,13 +87,9 @@
|
|||||||
- probably use f32, not f64 everywhere... but after Pt2D becomes fixed size
|
- probably use f32, not f64 everywhere... but after Pt2D becomes fixed size
|
||||||
- undo the y inversion hacks at last!
|
- undo the y inversion hacks at last!
|
||||||
- ezgui passes EventCtx and DrawCtx with appropriate things exposed.
|
- ezgui passes EventCtx and DrawCtx with appropriate things exposed.
|
||||||
- canvas owning text-drawing is maybe a bit weird, at least API-wise
|
|
||||||
- draw ctx should include OSD
|
|
||||||
- hide stuff inside the ctx's? canvas and prerender shouldnt even be known outside of crate
|
|
||||||
- maybe move glyph ownership out of canvas entirely
|
- maybe move glyph ownership out of canvas entirely
|
||||||
- move colorscheme ownership into parameterized state too
|
- canvas owning text-drawing is maybe a bit weird, at least API-wise
|
||||||
- stop passing Canvas inside of ezgui when it's in GfxCtx just fine
|
- hide stuff inside the ctx's? canvas and prerender shouldnt even be known outside of crate
|
||||||
- wizard wrap
|
|
||||||
- generic World with quadtree should have actions on objects
|
- generic World with quadtree should have actions on objects
|
||||||
- more speculative performance ideas
|
- more speculative performance ideas
|
||||||
- experiment with batching and not passing colors
|
- experiment with batching and not passing colors
|
||||||
|
@ -19,22 +19,18 @@ fn main() {
|
|||||||
.start("./profile")
|
.start("./profile")
|
||||||
.unwrap();*/
|
.unwrap();*/
|
||||||
|
|
||||||
let cs = colors::ColorScheme::load().unwrap();
|
|
||||||
|
|
||||||
if flags.sim_flags.load == "../data/raw_maps/ban_left_turn.abst" {
|
if flags.sim_flags.load == "../data/raw_maps/ban_left_turn.abst" {
|
||||||
ezgui::run("A/B Street", 1024.0, 768.0, |mut canvas, prerender| {
|
ezgui::run("A/B Street", 1024.0, 768.0, |mut canvas, prerender| {
|
||||||
ui::UI::new(
|
ui::UI::new(
|
||||||
tutorial::TutorialState::new(flags, &mut canvas, &cs, prerender),
|
tutorial::TutorialState::new(flags, &mut canvas, prerender),
|
||||||
canvas,
|
canvas,
|
||||||
cs,
|
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ezgui::run("A/B Street", 1024.0, 768.0, |canvas, prerender| {
|
ezgui::run("A/B Street", 1024.0, 768.0, |canvas, prerender| {
|
||||||
ui::UI::new(
|
ui::UI::new(
|
||||||
state::DefaultUIState::new(flags, &canvas, &cs, prerender, true),
|
state::DefaultUIState::new(flags, &canvas, prerender, true),
|
||||||
canvas,
|
canvas,
|
||||||
cs,
|
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ pub trait UIState {
|
|||||||
ctx: &mut EventCtx,
|
ctx: &mut EventCtx,
|
||||||
hints: &mut RenderingHints,
|
hints: &mut RenderingHints,
|
||||||
recalculate_current_selection: &mut bool,
|
recalculate_current_selection: &mut bool,
|
||||||
cs: &mut ColorScheme,
|
|
||||||
);
|
);
|
||||||
fn draw(&self, g: &mut GfxCtx, ctx: &Ctx);
|
fn draw(&self, g: &mut GfxCtx, ctx: &Ctx);
|
||||||
}
|
}
|
||||||
@ -60,20 +59,24 @@ pub struct DefaultUIState {
|
|||||||
pub layers: debug::layers::ToggleableLayers,
|
pub layers: debug::layers::ToggleableLayers,
|
||||||
|
|
||||||
pub enable_debug_controls: bool,
|
pub enable_debug_controls: bool,
|
||||||
|
|
||||||
|
pub cs: ColorScheme,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DefaultUIState {
|
impl DefaultUIState {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
canvas: &Canvas,
|
canvas: &Canvas,
|
||||||
cs: &ColorScheme,
|
|
||||||
prerender: &Prerender,
|
prerender: &Prerender,
|
||||||
enable_debug_controls: bool,
|
enable_debug_controls: bool,
|
||||||
) -> DefaultUIState {
|
) -> DefaultUIState {
|
||||||
|
let cs = ColorScheme::load().unwrap();
|
||||||
|
|
||||||
// Do this first to trigger the log console initialization, so anything logged by sim::load
|
// Do this first to trigger the log console initialization, so anything logged by sim::load
|
||||||
// isn't lost.
|
// isn't lost.
|
||||||
view::logs::DisplayLogs::initialize();
|
view::logs::DisplayLogs::initialize();
|
||||||
let (primary, primary_plugins) = PerMapUI::new(flags, cs, prerender, enable_debug_controls);
|
let (primary, primary_plugins) =
|
||||||
|
PerMapUI::new(flags, &cs, prerender, enable_debug_controls);
|
||||||
let mut state = DefaultUIState {
|
let mut state = DefaultUIState {
|
||||||
primary,
|
primary,
|
||||||
primary_plugins,
|
primary_plugins,
|
||||||
@ -85,6 +88,7 @@ impl DefaultUIState {
|
|||||||
sim_controls: plugins::sim::controls::SimControls::new(),
|
sim_controls: plugins::sim::controls::SimControls::new(),
|
||||||
layers: debug::layers::ToggleableLayers::new(),
|
layers: debug::layers::ToggleableLayers::new(),
|
||||||
enable_debug_controls,
|
enable_debug_controls,
|
||||||
|
cs,
|
||||||
};
|
};
|
||||||
state.layers.handle_zoom(-1.0, canvas.cam_zoom);
|
state.layers.handle_zoom(-1.0, canvas.cam_zoom);
|
||||||
state
|
state
|
||||||
@ -136,13 +140,12 @@ impl UIState for DefaultUIState {
|
|||||||
event_ctx: &mut EventCtx,
|
event_ctx: &mut EventCtx,
|
||||||
hints: &mut RenderingHints,
|
hints: &mut RenderingHints,
|
||||||
recalculate_current_selection: &mut bool,
|
recalculate_current_selection: &mut bool,
|
||||||
cs: &mut ColorScheme,
|
|
||||||
) {
|
) {
|
||||||
let mut ctx = PluginCtx {
|
let mut ctx = PluginCtx {
|
||||||
primary: &mut self.primary,
|
primary: &mut self.primary,
|
||||||
secondary: &mut self.secondary,
|
secondary: &mut self.secondary,
|
||||||
canvas: event_ctx.canvas,
|
canvas: event_ctx.canvas,
|
||||||
cs,
|
cs: &mut self.cs,
|
||||||
prerender: event_ctx.prerender,
|
prerender: event_ctx.prerender,
|
||||||
input: event_ctx.input,
|
input: event_ctx.input,
|
||||||
hints,
|
hints,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use crate::colors::ColorScheme;
|
|
||||||
use crate::objects::{Ctx, RenderingHints};
|
use crate::objects::{Ctx, RenderingHints};
|
||||||
use crate::plugins::view::legend::Legend;
|
use crate::plugins::view::legend::Legend;
|
||||||
use crate::state::{DefaultUIState, Flags, PerMapUI, UIState};
|
use crate::state::{DefaultUIState, Flags, PerMapUI, UIState};
|
||||||
@ -23,14 +22,9 @@ enum State {
|
|||||||
const SPAWN_CARS_PER_BORDER: usize = 100 * 10;
|
const SPAWN_CARS_PER_BORDER: usize = 100 * 10;
|
||||||
|
|
||||||
impl TutorialState {
|
impl TutorialState {
|
||||||
pub fn new(
|
pub fn new(flags: Flags, canvas: &mut Canvas, prerender: &Prerender) -> TutorialState {
|
||||||
flags: Flags,
|
|
||||||
canvas: &mut Canvas,
|
|
||||||
cs: &ColorScheme,
|
|
||||||
prerender: &Prerender,
|
|
||||||
) -> TutorialState {
|
|
||||||
TutorialState {
|
TutorialState {
|
||||||
main: DefaultUIState::new(flags, canvas, cs, prerender, false),
|
main: DefaultUIState::new(flags, canvas, prerender, false),
|
||||||
state: State::GiveInstructions(LogScroller::new_from_lines(vec![
|
state: State::GiveInstructions(LogScroller::new_from_lines(vec![
|
||||||
"Welcome to the A/B Street tutorial!".to_string(),
|
"Welcome to the A/B Street tutorial!".to_string(),
|
||||||
"".to_string(),
|
"".to_string(),
|
||||||
@ -57,7 +51,6 @@ impl UIState for TutorialState {
|
|||||||
ctx: &mut EventCtx,
|
ctx: &mut EventCtx,
|
||||||
hints: &mut RenderingHints,
|
hints: &mut RenderingHints,
|
||||||
recalculate_current_selection: &mut bool,
|
recalculate_current_selection: &mut bool,
|
||||||
cs: &mut ColorScheme,
|
|
||||||
) {
|
) {
|
||||||
match self.state {
|
match self.state {
|
||||||
State::GiveInstructions(ref mut scroller) => {
|
State::GiveInstructions(ref mut scroller) => {
|
||||||
@ -77,8 +70,7 @@ impl UIState for TutorialState {
|
|||||||
ref mut spawned_from_north,
|
ref mut spawned_from_north,
|
||||||
ref mut spawned_from_south,
|
ref mut spawned_from_south,
|
||||||
} => {
|
} => {
|
||||||
self.main
|
self.main.event(ctx, hints, recalculate_current_selection);
|
||||||
.event(ctx, hints, recalculate_current_selection, cs);
|
|
||||||
|
|
||||||
if let Some((tick, events)) = self
|
if let Some((tick, events)) = self
|
||||||
.main
|
.main
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use crate::colors::ColorScheme;
|
|
||||||
use abstutil;
|
use abstutil;
|
||||||
//use cpuprofiler;
|
//use cpuprofiler;
|
||||||
use crate::objects::{Ctx, RenderingHints, ID};
|
use crate::objects::{Ctx, RenderingHints, ID};
|
||||||
@ -18,8 +17,6 @@ use std::process;
|
|||||||
|
|
||||||
pub struct UI<S: UIState> {
|
pub struct UI<S: UIState> {
|
||||||
state: S,
|
state: S,
|
||||||
// TODO Not sure why this needs to live here and not in state
|
|
||||||
cs: ColorScheme,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||||
@ -206,12 +203,8 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut recalculate_current_selection = false;
|
let mut recalculate_current_selection = false;
|
||||||
self.state.event(
|
self.state
|
||||||
&mut ctx,
|
.event(&mut ctx, &mut hints, &mut recalculate_current_selection);
|
||||||
&mut hints,
|
|
||||||
&mut recalculate_current_selection,
|
|
||||||
&mut self.cs,
|
|
||||||
);
|
|
||||||
if recalculate_current_selection {
|
if recalculate_current_selection {
|
||||||
self.state.mut_state().primary.current_selection = self.mouseover_something(&ctx);
|
self.state.mut_state().primary.current_selection = self.mouseover_something(&ctx);
|
||||||
}
|
}
|
||||||
@ -244,10 +237,15 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
|||||||
fn draw(&self, _: &mut GfxCtx, _: &RenderingHints) {}
|
fn draw(&self, _: &mut GfxCtx, _: &RenderingHints) {}
|
||||||
|
|
||||||
fn new_draw(&self, g: &mut GfxCtx, hints: &RenderingHints, screencap: bool) -> Option<String> {
|
fn new_draw(&self, g: &mut GfxCtx, hints: &RenderingHints, screencap: bool) -> Option<String> {
|
||||||
g.clear(self.cs.get_def("map background", Color::rgb(242, 239, 233)));
|
g.clear(
|
||||||
|
self.state
|
||||||
|
.get_state()
|
||||||
|
.cs
|
||||||
|
.get_def("map background", Color::rgb(242, 239, 233)),
|
||||||
|
);
|
||||||
|
|
||||||
let ctx = Ctx {
|
let ctx = Ctx {
|
||||||
cs: &self.cs,
|
cs: &self.state.get_state().cs,
|
||||||
map: &self.state.get_state().primary.map,
|
map: &self.state.get_state().primary.map,
|
||||||
draw_map: &self.state.get_state().primary.draw_map,
|
draw_map: &self.state.get_state().primary.draw_map,
|
||||||
sim: &self.state.get_state().primary.sim,
|
sim: &self.state.get_state().primary.sim,
|
||||||
@ -305,14 +303,14 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
|||||||
|
|
||||||
fn before_quit(&self, canvas: &Canvas) {
|
fn before_quit(&self, canvas: &Canvas) {
|
||||||
self.save_editor_state(canvas);
|
self.save_editor_state(canvas);
|
||||||
self.cs.save();
|
self.state.get_state().cs.save();
|
||||||
info!("Saved color_scheme");
|
info!("Saved color_scheme");
|
||||||
//cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
|
//cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: UIState> UI<S> {
|
impl<S: UIState> UI<S> {
|
||||||
pub fn new(state: S, canvas: &mut Canvas, cs: ColorScheme) -> UI<S> {
|
pub fn new(state: S, canvas: &mut Canvas) -> UI<S> {
|
||||||
match abstutil::read_json::<EditorState>("../editor_state") {
|
match abstutil::read_json::<EditorState>("../editor_state") {
|
||||||
Ok(ref loaded) if state.get_state().primary.map.get_name() == &loaded.map_name => {
|
Ok(ref loaded) if state.get_state().primary.map.get_name() == &loaded.map_name => {
|
||||||
info!("Loaded previous editor_state");
|
info!("Loaded previous editor_state");
|
||||||
@ -340,7 +338,7 @@ impl<S: UIState> UI<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UI { state, cs }
|
UI { state }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mouseover_something(&self, ctx: &EventCtx) -> Option<ID> {
|
fn mouseover_something(&self, ctx: &EventCtx) -> Option<ID> {
|
||||||
|
Loading…
Reference in New Issue
Block a user