move PluginCtx

This commit is contained in:
Dustin Carlino 2018-12-12 12:29:33 -08:00
parent dd859ba76d
commit e29ff690f8
3 changed files with 20 additions and 17 deletions

View File

@ -489,3 +489,5 @@ Ideas:
First simplify UI in smaller ways.
- get_objects_onscreen should return one list of things
- and between drawing and mousing over, dont recalculate all of the DrawCar/Ped stuff!
- stop doing the generic plugin stuff in UI. be direct, since we have very few "plugins".

View File

@ -6,15 +6,16 @@ pub mod time_travel;
pub mod tutorial;
pub mod view;
use crate::objects::{Ctx, ID};
use crate::ui::PluginCtx;
use crate::colors::ColorScheme;
use crate::objects::{Ctx, RenderingHints, ID};
use crate::ui::{PerMapUI, PluginsPerMap};
use ::sim::{ABTest, Neighborhood, NeighborhoodBuilder, OriginDestination, Scenario, Tick};
use abstutil;
use abstutil::WeightedUsizeChoice;
use downcast::{
downcast, downcast_methods, downcast_methods_core, downcast_methods_std, impl_downcast, Any,
};
use ezgui::{Color, GfxCtx, WrappedWizard};
use ezgui::{Canvas, Color, GfxCtx, UserInput, WrappedWizard};
use map_model::{IntersectionID, Map};
pub trait Plugin: Any {
@ -35,6 +36,19 @@ pub trait Plugin: Any {
downcast!(Plugin);
// This mirrors many, but not all, of the fields in UI.
pub struct PluginCtx<'a> {
pub primary: &'a mut PerMapUI,
// Only filled out for PluginsPerUI, not for PluginsPerMap.
pub primary_plugins: Option<&'a mut PluginsPerMap>,
pub secondary: &'a mut Option<(PerMapUI, PluginsPerMap)>,
pub canvas: &'a mut Canvas,
pub cs: &'a mut ColorScheme,
pub input: &'a mut UserInput,
pub hints: &'a mut RenderingHints,
pub kml: &'a Option<String>,
}
// TODO Further refactoring should be done, but at least group these here to start.
// General principles are to avoid actually deserializing the objects unless needed.

View File

@ -7,7 +7,7 @@ use crate::plugins::debug::layers::ToggleableLayers;
use crate::plugins::debug::DebugMode;
use crate::plugins::edit::EditMode;
use crate::plugins::time_travel::TimeTravel;
use crate::plugins::Plugin;
use crate::plugins::{Plugin, PluginCtx};
use crate::render::{DrawMap, RenderOptions};
use ezgui::{Canvas, Color, EventLoopMode, GfxCtx, Text, UserInput, BOTTOM_LEFT, GUI};
use kml;
@ -466,16 +466,3 @@ impl ShowTurnIcons for UI {
}
}
}
// This mirrors many, but not all, of the fields in UI.
pub struct PluginCtx<'a> {
pub primary: &'a mut PerMapUI,
// Only filled out for PluginsPerUI, not for PluginsPerMap.
pub primary_plugins: Option<&'a mut PluginsPerMap>,
pub secondary: &'a mut Option<(PerMapUI, PluginsPerMap)>,
pub canvas: &'a mut Canvas,
pub cs: &'a mut ColorScheme,
pub input: &'a mut UserInput,
pub hints: &'a mut RenderingHints,
pub kml: &'a Option<String>,
}