From 4fe09e3040d7e750d585bd2c24df17d710146956 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 26 Apr 2019 10:46:41 -0700 Subject: [PATCH] moving color picker to debug mode --- .../{plugins/edit => debug}/color_picker.rs | 59 ++++++++----------- editor/src/debug/mod.rs | 28 ++++++++- editor/src/plugins/edit/mod.rs | 1 - editor/src/state.rs | 2 - editor/src/ui.rs | 10 ++-- 5 files changed, 55 insertions(+), 45 deletions(-) rename editor/src/{plugins/edit => debug}/color_picker.rs (66%) diff --git a/editor/src/plugins/edit/color_picker.rs b/editor/src/debug/color_picker.rs similarity index 66% rename from editor/src/plugins/edit/color_picker.rs rename to editor/src/debug/color_picker.rs index 5fe79d35a3..49f471eccd 100644 --- a/editor/src/plugins/edit/color_picker.rs +++ b/editor/src/debug/color_picker.rs @@ -1,7 +1,5 @@ -use crate::objects::DrawCtx; -use crate::plugins::{BlockingPlugin, PluginCtx}; -use ezgui::ScreenPt; -use ezgui::{Canvas, Color, GfxCtx, InputResult, ScrollingMenu}; +use crate::ui::UI; +use ezgui::{Canvas, Color, EventCtx, GfxCtx, InputResult, ScreenPt, ScrollingMenu}; use geom::Polygon; // TODO assumes minimum screen size @@ -17,32 +15,19 @@ pub enum ColorPicker { } impl ColorPicker { - pub fn new(ctx: &mut PluginCtx) -> Option { - if ctx.input.action_chosen("configure colors") { - return Some(ColorPicker::Choosing(ScrollingMenu::new( - "Pick a color to change", - ctx.cs.color_names(), - ))); - } - None - } -} - -impl BlockingPlugin for ColorPicker { - fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool { + // True when done + pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) -> bool { match self { - ColorPicker::Choosing(ref mut menu) => { - match menu.event(&mut ctx.input) { - InputResult::Canceled => { - return false; - } - InputResult::StillActive => {} - InputResult::Done(name, _) => { - *self = - ColorPicker::ChangingColor(name.clone(), ctx.cs.get_modified(&name)); - } - }; - } + ColorPicker::Choosing(ref mut menu) => match menu.event(&mut ctx.input) { + InputResult::Canceled => { + return true; + } + InputResult::StillActive => {} + InputResult::Done(name, _) => { + *self = + ColorPicker::ChangingColor(name.clone(), ui.state.cs.get_modified(&name)); + } + }, ColorPicker::ChangingColor(name, orig) => { ctx.input.set_mode_with_prompt( "Color Picker", @@ -50,11 +35,11 @@ impl BlockingPlugin for ColorPicker { &ctx.canvas, ); if ctx.input.modal_action("revert") { - ctx.cs.reset_modified(name, *orig); - return false; + ui.state.cs.reset_modified(name, *orig); + return true; } else if ctx.input.modal_action("finalize") { println!("Setting color for {}", name); - return false; + return true; } if let Some(pt) = ctx.input.get_moved_mouse() { @@ -63,15 +48,17 @@ impl BlockingPlugin for ColorPicker { let x = (pt.x - start_x) / TILE_DIMS / 255.0; let y = (pt.y - start_y) / TILE_DIMS / 255.0; if x >= 0.0 && x <= 1.0 && y >= 0.0 && y <= 1.0 { - ctx.cs.override_color(name, get_color(x as f32, y as f32)); + ui.state + .cs + .override_color(name, get_color(x as f32, y as f32)); } } } - }; - true + } + false } - fn draw(&self, g: &mut GfxCtx, _ctx: &DrawCtx) { + pub fn draw(&self, g: &mut GfxCtx) { match self { ColorPicker::Choosing(menu) => { menu.draw(g); diff --git a/editor/src/debug/mod.rs b/editor/src/debug/mod.rs index 9924450f3b..eaa3d440ae 100644 --- a/editor/src/debug/mod.rs +++ b/editor/src/debug/mod.rs @@ -1,4 +1,5 @@ mod chokepoints; +mod color_picker; mod connected_roads; mod objects; mod polygons; @@ -6,7 +7,9 @@ mod polygons; use crate::game::{GameState, Mode}; use crate::objects::ID; use crate::ui::{ShowLayers, ShowObject}; -use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, InputResult, Key, Text, TextBox, Wizard}; +use ezgui::{ + Color, EventCtx, EventLoopMode, GfxCtx, InputResult, Key, ScrollingMenu, Text, TextBox, Wizard, +}; use map_model::RoadID; use std::collections::{HashMap, HashSet}; @@ -25,6 +28,7 @@ enum State { Exploring, Polygons(polygons::PolygonDebugger), SearchOSM(TextBox), + Colors(color_picker::ColorPicker), } impl DebugMode { @@ -175,6 +179,13 @@ impl DebugMode { } } else if ctx.input.modal_action("search OSM metadata") { mode.state = State::SearchOSM(TextBox::new("Search for what?", None)); + } else if ctx.input.modal_action("configure colors") { + mode.state = State::Colors(color_picker::ColorPicker::Choosing( + ScrollingMenu::new( + "Pick a color to change", + state.ui.state.cs.color_names(), + ), + )); } EventLoopMode::InputOnly @@ -219,6 +230,12 @@ impl DebugMode { } EventLoopMode::InputOnly } + State::Colors(ref mut picker) => { + if picker.event(ctx, &mut state.ui) { + mode.state = State::Exploring; + } + EventLoopMode::InputOnly + } } } _ => unreachable!(), @@ -296,8 +313,17 @@ impl DebugMode { debugger.draw(g, &state.ui); } State::SearchOSM(ref tb) => { + state + .ui + .new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim, mode); tb.draw(g); } + State::Colors(ref picker) => { + state + .ui + .new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim, mode); + picker.draw(g); + } }, _ => unreachable!(), } diff --git a/editor/src/plugins/edit/mod.rs b/editor/src/plugins/edit/mod.rs index 13a7b3e7ad..a6852c22a6 100644 --- a/editor/src/plugins/edit/mod.rs +++ b/editor/src/plugins/edit/mod.rs @@ -1,4 +1,3 @@ pub mod a_b_tests; -pub mod color_picker; pub mod draw_neighborhoods; pub mod scenarios; diff --git a/editor/src/state.rs b/editor/src/state.rs index 8711dabb2d..0c73651b87 100644 --- a/editor/src/state.rs +++ b/editor/src/state.rs @@ -127,8 +127,6 @@ impl UIState { } else if ctx.secondary.is_none() { if let Some(p) = edit::a_b_tests::ABTestManager::new(&mut ctx) { self.exclusive_blocking_plugin = Some(Box::new(p)); - } else if let Some(p) = edit::color_picker::ColorPicker::new(&mut ctx) { - self.exclusive_blocking_plugin = Some(Box::new(p)); } else if let Some(p) = edit::draw_neighborhoods::DrawNeighborhoodState::new(&mut ctx) { diff --git a/editor/src/ui.rs b/editor/src/ui.rs index 45429c9fe0..f573edbbbf 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -35,7 +35,6 @@ impl GUI for UI { "Edit", vec![ (Some(Key::B), "manage A/B tests"), - (None, "configure colors"), (Some(Key::N), "manage neighborhoods"), (Some(Key::W), "manage scenarios"), ], @@ -64,10 +63,6 @@ impl GUI for UI { (Key::Enter, "quit"), ], ), - ModalMenu::new( - "Color Picker", - vec![(Key::Backspace, "revert"), (Key::Enter, "finalize")], - ), ModalMenu::new("A/B Test Editor", vec![(Key::R, "run A/B test")]), ModalMenu::new( "Neighborhood Editor", @@ -156,6 +151,7 @@ impl GUI for UI { (Key::F1, "screenshot everything"), (Key::Slash, "search OSM metadata"), (Key::M, "clear OSM search results"), + (Key::S, "configure colors"), ], ), ModalMenu::new( @@ -168,6 +164,10 @@ impl GUI for UI { (Key::L, "last item"), ], ), + ModalMenu::new( + "Color Picker", + vec![(Key::Backspace, "revert"), (Key::Enter, "finalize")], + ), ] }