lift the special case search plugin out of simmode.

This commit is contained in:
Dustin Carlino 2018-12-24 17:34:40 -08:00
parent d06f80e918
commit fc15b28826
4 changed files with 70 additions and 30 deletions

View File

@ -578,6 +578,7 @@ Plugin styles are blocking or ambient. And some can conflict...
- layers... shouldnt be per-map state. should modify stuff itself.
- view mode... whew, one thing at a time.
- warp... exclusive blocking. apparently we used to still let ambient plugins draw and color stuff while it's active, but meh, doesnt seem important.
- search... argh, this is the one that's SOMETIMES exclusive blocking and sometimes stackable modal.
@ -588,3 +589,4 @@ Plugin styles are blocking or ambient. And some can conflict...
- can we somehow fold PluginsPerMap into PerMapUI? :D different API that doesnt blindly pass in all of primary field
- Layers could be stackable modal too, but do that later. low-pri.
- probably dont need all those methods in UIState. just a way to get the main state.
- bulk-disable debug mode stuff in tutorial land. should be easy now!

View File

@ -17,14 +17,12 @@ use ezgui::{Color, GfxCtx};
use map_model::Map;
pub struct ViewMode {
search: Option<search::SearchState>,
ambient_plugins: Vec<Box<Plugin>>,
}
impl ViewMode {
pub fn new(map: &Map, draw_map: &DrawMap, timer: &mut Timer) -> ViewMode {
ViewMode {
search: None,
ambient_plugins: vec![
Box::new(debug_objects::DebugObjectsState::new()),
Box::new(follow::FollowState::new()),
@ -44,20 +42,6 @@ impl ViewMode {
impl Plugin for ViewMode {
fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool {
if self.search.is_some() {
if self.search.as_mut().unwrap().blocking_event(ctx) {
if self.search.as_ref().unwrap().is_blocking() {
return true;
}
} else {
self.search = None;
return false;
}
} else if let Some(p) = search::SearchState::new(ctx) {
self.search = Some(p);
return true;
}
for p in self.ambient_plugins.iter_mut() {
p.ambient_event(ctx);
}
@ -69,19 +53,9 @@ impl Plugin for ViewMode {
for p in &self.ambient_plugins {
p.draw(g, ctx);
}
if let Some(ref p) = self.search {
p.draw(g, ctx);
}
}
fn color_for(&self, obj: ID, ctx: &Ctx) -> Option<Color> {
if let Some(ref p) = self.search {
if let Some(c) = p.color_for(obj, ctx) {
return Some(c);
}
}
// First one arbitrarily wins.
for p in &self.ambient_plugins {
if let Some(c) = p.color_for(obj, ctx) {

View File

@ -18,6 +18,7 @@ impl SearchState {
None
}
// If not, act like stackable modal.
pub fn is_blocking(&self) -> bool {
match self {
SearchState::EnteringSearch(_) => true,

View File

@ -49,7 +49,7 @@ pub struct DefaultUIState {
// These are stackable modal plugins. They can all coexist, and they don't block other modal
// plugins or ambient plugins.
show_score: Option<Box<Plugin>>,
show_score: Option<plugins::sim::show_score::ShowScoreState>,
// Ambient plugins always exist, and they never block anything.
pub sim_controls: plugins::sim::controls::SimControls,
@ -144,7 +144,7 @@ impl UIState for DefaultUIState {
{
let mut ctx = PluginCtx {
primary: &mut self.primary,
primary_plugins: Some(&mut self.primary_plugins),
primary_plugins: None,
secondary: &mut self.secondary,
canvas,
cs,
@ -153,6 +153,27 @@ impl UIState for DefaultUIState {
recalculate_current_selection,
};
// Special case!
if self
.primary_plugins
.search
.as_ref()
.map(|p| p.is_blocking())
.unwrap_or(false)
{
if !self
.primary_plugins
.search
.as_mut()
.unwrap()
.blocking_event(&mut ctx)
{
self.primary_plugins.search = None;
}
return;
}
ctx.primary_plugins = Some(&mut self.primary_plugins);
if self.exclusive_blocking_plugin.is_some() {
if !self
.exclusive_blocking_plugin
@ -167,6 +188,8 @@ impl UIState for DefaultUIState {
if let Some(p) = view::logs::DisplayLogs::new(&mut ctx) {
self.exclusive_blocking_plugin = Some(Box::new(p));
} else if let Some(p) = view::search::SearchState::new(&mut ctx) {
self.primary_plugins.search = Some(p);
} else if let Some(p) = debug::chokepoints::ChokepointsFinder::new(&mut ctx) {
self.exclusive_blocking_plugin = Some(Box::new(p));
} else if let Some(p) = debug::classification::OsmClassifier::new(&mut ctx) {
@ -200,7 +223,14 @@ impl UIState for DefaultUIState {
self.exclusive_blocking_plugin = Some(Box::new(p));
}
}
if self.exclusive_blocking_plugin.is_some() {
if self
.primary_plugins
.search
.as_ref()
.map(|p| p.is_blocking())
.unwrap_or(false)
|| self.exclusive_blocking_plugin.is_some()
{
return;
}
}
@ -260,7 +290,25 @@ impl UIState for DefaultUIState {
self.show_score = None;
}
} else if let Some(p) = plugins::sim::show_score::ShowScoreState::new(&mut ctx) {
self.show_score = Some(Box::new(p));
self.show_score = Some(p);
}
if self
.primary_plugins
.search
.as_ref()
.map(|p| !p.is_blocking())
.unwrap_or(false)
{
if !self
.primary_plugins
.search
.as_mut()
.unwrap()
.blocking_event(&mut ctx)
{
self.primary_plugins.search = None;
}
return;
}
if self.primary_plugins.hider.is_some() {
@ -325,6 +373,12 @@ impl UIState for DefaultUIState {
}
fn draw(&self, g: &mut GfxCtx, ctx: &Ctx) {
if let Some(ref plugin) = self.primary_plugins.search {
plugin.draw(g, ctx);
if plugin.is_blocking() {
return;
}
}
if let Some(ref plugin) = self.exclusive_blocking_plugin {
plugin.draw(g, ctx);
return;
@ -373,6 +427,11 @@ impl UIState for DefaultUIState {
}
};
if let Some(ref plugin) = self.primary_plugins.search {
if let Some(c) = plugin.color_for(id, ctx) {
return Some(c);
}
}
if let Some(ref plugin) = self.exclusive_blocking_plugin {
return plugin.color_for(id, ctx);
}
@ -484,6 +543,9 @@ pub struct PluginsPerMap {
// plugins or ambient plugins.
hider: Option<debug::hider::Hider>,
// When present, this either acts like exclusive blocking or like stackable modal. :\
search: Option<view::search::SearchState>,
// TODO legacy
view_mode: ViewMode,
time_travel: TimeTravel,
@ -493,6 +555,7 @@ impl PluginsPerMap {
pub fn new(state: &PerMapUI, timer: &mut Timer) -> PluginsPerMap {
PluginsPerMap {
hider: None,
search: None,
view_mode: ViewMode::new(&state.map, &state.draw_map, timer),
time_travel: TimeTravel::new(),
}