mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
moving color picker to debug mode
This commit is contained in:
parent
5450739231
commit
4fe09e3040
@ -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<ColorPicker> {
|
||||
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);
|
@ -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!(),
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
pub mod a_b_tests;
|
||||
pub mod color_picker;
|
||||
pub mod draw_neighborhoods;
|
||||
pub mod scenarios;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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")],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user