moving color picker to debug mode

This commit is contained in:
Dustin Carlino 2019-04-26 10:46:41 -07:00
parent 5450739231
commit 4fe09e3040
5 changed files with 55 additions and 45 deletions

View File

@ -1,7 +1,5 @@
use crate::objects::DrawCtx; use crate::ui::UI;
use crate::plugins::{BlockingPlugin, PluginCtx}; use ezgui::{Canvas, Color, EventCtx, GfxCtx, InputResult, ScreenPt, ScrollingMenu};
use ezgui::ScreenPt;
use ezgui::{Canvas, Color, GfxCtx, InputResult, ScrollingMenu};
use geom::Polygon; use geom::Polygon;
// TODO assumes minimum screen size // TODO assumes minimum screen size
@ -17,32 +15,19 @@ pub enum ColorPicker {
} }
impl ColorPicker { impl ColorPicker {
pub fn new(ctx: &mut PluginCtx) -> Option<ColorPicker> { // True when done
if ctx.input.action_chosen("configure colors") { pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) -> bool {
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 {
match self { match self {
ColorPicker::Choosing(ref mut menu) => { ColorPicker::Choosing(ref mut menu) => match menu.event(&mut ctx.input) {
match menu.event(&mut ctx.input) { InputResult::Canceled => {
InputResult::Canceled => { return true;
return false; }
} InputResult::StillActive => {}
InputResult::StillActive => {} InputResult::Done(name, _) => {
InputResult::Done(name, _) => { *self =
*self = ColorPicker::ChangingColor(name.clone(), ui.state.cs.get_modified(&name));
ColorPicker::ChangingColor(name.clone(), ctx.cs.get_modified(&name)); }
} },
};
}
ColorPicker::ChangingColor(name, orig) => { ColorPicker::ChangingColor(name, orig) => {
ctx.input.set_mode_with_prompt( ctx.input.set_mode_with_prompt(
"Color Picker", "Color Picker",
@ -50,11 +35,11 @@ impl BlockingPlugin for ColorPicker {
&ctx.canvas, &ctx.canvas,
); );
if ctx.input.modal_action("revert") { if ctx.input.modal_action("revert") {
ctx.cs.reset_modified(name, *orig); ui.state.cs.reset_modified(name, *orig);
return false; return true;
} else if ctx.input.modal_action("finalize") { } else if ctx.input.modal_action("finalize") {
println!("Setting color for {}", name); println!("Setting color for {}", name);
return false; return true;
} }
if let Some(pt) = ctx.input.get_moved_mouse() { 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 x = (pt.x - start_x) / TILE_DIMS / 255.0;
let y = (pt.y - start_y) / 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 { 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 { match self {
ColorPicker::Choosing(menu) => { ColorPicker::Choosing(menu) => {
menu.draw(g); menu.draw(g);

View File

@ -1,4 +1,5 @@
mod chokepoints; mod chokepoints;
mod color_picker;
mod connected_roads; mod connected_roads;
mod objects; mod objects;
mod polygons; mod polygons;
@ -6,7 +7,9 @@ mod polygons;
use crate::game::{GameState, Mode}; use crate::game::{GameState, Mode};
use crate::objects::ID; use crate::objects::ID;
use crate::ui::{ShowLayers, ShowObject}; 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 map_model::RoadID;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
@ -25,6 +28,7 @@ enum State {
Exploring, Exploring,
Polygons(polygons::PolygonDebugger), Polygons(polygons::PolygonDebugger),
SearchOSM(TextBox), SearchOSM(TextBox),
Colors(color_picker::ColorPicker),
} }
impl DebugMode { impl DebugMode {
@ -175,6 +179,13 @@ impl DebugMode {
} }
} else if ctx.input.modal_action("search OSM metadata") { } else if ctx.input.modal_action("search OSM metadata") {
mode.state = State::SearchOSM(TextBox::new("Search for what?", None)); 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 EventLoopMode::InputOnly
@ -219,6 +230,12 @@ impl DebugMode {
} }
EventLoopMode::InputOnly EventLoopMode::InputOnly
} }
State::Colors(ref mut picker) => {
if picker.event(ctx, &mut state.ui) {
mode.state = State::Exploring;
}
EventLoopMode::InputOnly
}
} }
} }
_ => unreachable!(), _ => unreachable!(),
@ -296,8 +313,17 @@ impl DebugMode {
debugger.draw(g, &state.ui); debugger.draw(g, &state.ui);
} }
State::SearchOSM(ref tb) => { State::SearchOSM(ref tb) => {
state
.ui
.new_draw(g, None, HashMap::new(), &state.ui.state.primary.sim, mode);
tb.draw(g); 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!(), _ => unreachable!(),
} }

View File

@ -1,4 +1,3 @@
pub mod a_b_tests; pub mod a_b_tests;
pub mod color_picker;
pub mod draw_neighborhoods; pub mod draw_neighborhoods;
pub mod scenarios; pub mod scenarios;

View File

@ -127,8 +127,6 @@ impl UIState {
} else if ctx.secondary.is_none() { } else if ctx.secondary.is_none() {
if let Some(p) = edit::a_b_tests::ABTestManager::new(&mut ctx) { if let Some(p) = edit::a_b_tests::ABTestManager::new(&mut ctx) {
self.exclusive_blocking_plugin = Some(Box::new(p)); 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) = } else if let Some(p) =
edit::draw_neighborhoods::DrawNeighborhoodState::new(&mut ctx) edit::draw_neighborhoods::DrawNeighborhoodState::new(&mut ctx)
{ {

View File

@ -35,7 +35,6 @@ impl GUI for UI {
"Edit", "Edit",
vec![ vec![
(Some(Key::B), "manage A/B tests"), (Some(Key::B), "manage A/B tests"),
(None, "configure colors"),
(Some(Key::N), "manage neighborhoods"), (Some(Key::N), "manage neighborhoods"),
(Some(Key::W), "manage scenarios"), (Some(Key::W), "manage scenarios"),
], ],
@ -64,10 +63,6 @@ impl GUI for UI {
(Key::Enter, "quit"), (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("A/B Test Editor", vec![(Key::R, "run A/B test")]),
ModalMenu::new( ModalMenu::new(
"Neighborhood Editor", "Neighborhood Editor",
@ -156,6 +151,7 @@ impl GUI for UI {
(Key::F1, "screenshot everything"), (Key::F1, "screenshot everything"),
(Key::Slash, "search OSM metadata"), (Key::Slash, "search OSM metadata"),
(Key::M, "clear OSM search results"), (Key::M, "clear OSM search results"),
(Key::S, "configure colors"),
], ],
), ),
ModalMenu::new( ModalMenu::new(
@ -168,6 +164,10 @@ impl GUI for UI {
(Key::L, "last item"), (Key::L, "last item"),
], ],
), ),
ModalMenu::new(
"Color Picker",
vec![(Key::Backspace, "revert"), (Key::Enter, "finalize")],
),
] ]
} }