mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +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
|
||||
- undo the y inversion hacks at last!
|
||||
- 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
|
||||
- move colorscheme ownership into parameterized state too
|
||||
- stop passing Canvas inside of ezgui when it's in GfxCtx just fine
|
||||
- wizard wrap
|
||||
- canvas owning text-drawing is maybe a bit weird, at least API-wise
|
||||
- hide stuff inside the ctx's? canvas and prerender shouldnt even be known outside of crate
|
||||
- generic World with quadtree should have actions on objects
|
||||
- more speculative performance ideas
|
||||
- experiment with batching and not passing colors
|
||||
|
@ -19,22 +19,18 @@ fn main() {
|
||||
.start("./profile")
|
||||
.unwrap();*/
|
||||
|
||||
let cs = colors::ColorScheme::load().unwrap();
|
||||
|
||||
if flags.sim_flags.load == "../data/raw_maps/ban_left_turn.abst" {
|
||||
ezgui::run("A/B Street", 1024.0, 768.0, |mut canvas, prerender| {
|
||||
ui::UI::new(
|
||||
tutorial::TutorialState::new(flags, &mut canvas, &cs, prerender),
|
||||
tutorial::TutorialState::new(flags, &mut canvas, prerender),
|
||||
canvas,
|
||||
cs,
|
||||
)
|
||||
});
|
||||
} else {
|
||||
ezgui::run("A/B Street", 1024.0, 768.0, |canvas, prerender| {
|
||||
ui::UI::new(
|
||||
state::DefaultUIState::new(flags, &canvas, &cs, prerender, true),
|
||||
state::DefaultUIState::new(flags, &canvas, prerender, true),
|
||||
canvas,
|
||||
cs,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ pub trait UIState {
|
||||
ctx: &mut EventCtx,
|
||||
hints: &mut RenderingHints,
|
||||
recalculate_current_selection: &mut bool,
|
||||
cs: &mut ColorScheme,
|
||||
);
|
||||
fn draw(&self, g: &mut GfxCtx, ctx: &Ctx);
|
||||
}
|
||||
@ -60,20 +59,24 @@ pub struct DefaultUIState {
|
||||
pub layers: debug::layers::ToggleableLayers,
|
||||
|
||||
pub enable_debug_controls: bool,
|
||||
|
||||
pub cs: ColorScheme,
|
||||
}
|
||||
|
||||
impl DefaultUIState {
|
||||
pub fn new(
|
||||
flags: Flags,
|
||||
canvas: &Canvas,
|
||||
cs: &ColorScheme,
|
||||
prerender: &Prerender,
|
||||
enable_debug_controls: bool,
|
||||
) -> DefaultUIState {
|
||||
let cs = ColorScheme::load().unwrap();
|
||||
|
||||
// Do this first to trigger the log console initialization, so anything logged by sim::load
|
||||
// isn't lost.
|
||||
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 {
|
||||
primary,
|
||||
primary_plugins,
|
||||
@ -85,6 +88,7 @@ impl DefaultUIState {
|
||||
sim_controls: plugins::sim::controls::SimControls::new(),
|
||||
layers: debug::layers::ToggleableLayers::new(),
|
||||
enable_debug_controls,
|
||||
cs,
|
||||
};
|
||||
state.layers.handle_zoom(-1.0, canvas.cam_zoom);
|
||||
state
|
||||
@ -136,13 +140,12 @@ impl UIState for DefaultUIState {
|
||||
event_ctx: &mut EventCtx,
|
||||
hints: &mut RenderingHints,
|
||||
recalculate_current_selection: &mut bool,
|
||||
cs: &mut ColorScheme,
|
||||
) {
|
||||
let mut ctx = PluginCtx {
|
||||
primary: &mut self.primary,
|
||||
secondary: &mut self.secondary,
|
||||
canvas: event_ctx.canvas,
|
||||
cs,
|
||||
cs: &mut self.cs,
|
||||
prerender: event_ctx.prerender,
|
||||
input: event_ctx.input,
|
||||
hints,
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::colors::ColorScheme;
|
||||
use crate::objects::{Ctx, RenderingHints};
|
||||
use crate::plugins::view::legend::Legend;
|
||||
use crate::state::{DefaultUIState, Flags, PerMapUI, UIState};
|
||||
@ -23,14 +22,9 @@ enum State {
|
||||
const SPAWN_CARS_PER_BORDER: usize = 100 * 10;
|
||||
|
||||
impl TutorialState {
|
||||
pub fn new(
|
||||
flags: Flags,
|
||||
canvas: &mut Canvas,
|
||||
cs: &ColorScheme,
|
||||
prerender: &Prerender,
|
||||
) -> TutorialState {
|
||||
pub fn new(flags: Flags, canvas: &mut Canvas, prerender: &Prerender) -> 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![
|
||||
"Welcome to the A/B Street tutorial!".to_string(),
|
||||
"".to_string(),
|
||||
@ -57,7 +51,6 @@ impl UIState for TutorialState {
|
||||
ctx: &mut EventCtx,
|
||||
hints: &mut RenderingHints,
|
||||
recalculate_current_selection: &mut bool,
|
||||
cs: &mut ColorScheme,
|
||||
) {
|
||||
match self.state {
|
||||
State::GiveInstructions(ref mut scroller) => {
|
||||
@ -77,8 +70,7 @@ impl UIState for TutorialState {
|
||||
ref mut spawned_from_north,
|
||||
ref mut spawned_from_south,
|
||||
} => {
|
||||
self.main
|
||||
.event(ctx, hints, recalculate_current_selection, cs);
|
||||
self.main.event(ctx, hints, recalculate_current_selection);
|
||||
|
||||
if let Some((tick, events)) = self
|
||||
.main
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::colors::ColorScheme;
|
||||
use abstutil;
|
||||
//use cpuprofiler;
|
||||
use crate::objects::{Ctx, RenderingHints, ID};
|
||||
@ -18,8 +17,6 @@ use std::process;
|
||||
|
||||
pub struct UI<S: UIState> {
|
||||
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> {
|
||||
@ -206,12 +203,8 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||
}
|
||||
|
||||
let mut recalculate_current_selection = false;
|
||||
self.state.event(
|
||||
&mut ctx,
|
||||
&mut hints,
|
||||
&mut recalculate_current_selection,
|
||||
&mut self.cs,
|
||||
);
|
||||
self.state
|
||||
.event(&mut ctx, &mut hints, &mut recalculate_current_selection);
|
||||
if recalculate_current_selection {
|
||||
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 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 {
|
||||
cs: &self.cs,
|
||||
cs: &self.state.get_state().cs,
|
||||
map: &self.state.get_state().primary.map,
|
||||
draw_map: &self.state.get_state().primary.draw_map,
|
||||
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) {
|
||||
self.save_editor_state(canvas);
|
||||
self.cs.save();
|
||||
self.state.get_state().cs.save();
|
||||
info!("Saved color_scheme");
|
||||
//cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
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") {
|
||||
Ok(ref loaded) if state.get_state().primary.map.get_name() == &loaded.map_name => {
|
||||
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> {
|
||||
|
Loading…
Reference in New Issue
Block a user