popup info in map editor only when a key is held. lock down old

blocking_text methods a little more
This commit is contained in:
Dustin Carlino 2020-03-18 11:13:40 -07:00
parent 01b5617840
commit d63c79d87c
4 changed files with 41 additions and 39 deletions

View File

@ -175,7 +175,7 @@ impl<'a> GfxCtx<'a> {
// The text box covers up what's beneath and eats the cursor (for get_cursor_in_map_space). // The text box covers up what's beneath and eats the cursor (for get_cursor_in_map_space).
// TODO Super close to deleting this. // TODO Super close to deleting this.
pub fn draw_blocking_text( pub(crate) fn draw_blocking_text(
&mut self, &mut self,
txt: Text, txt: Text,
(horiz, vert): (HorizontalAlignment, VerticalAlignment), (horiz, vert): (HorizontalAlignment, VerticalAlignment),

View File

@ -83,7 +83,7 @@ impl TextBox {
} }
pub fn draw(&self, g: &mut GfxCtx) { pub fn draw(&self, g: &mut GfxCtx) {
let bg = g.upload(GeomBatch::from(vec![( let mut batch = GeomBatch::from(vec![(
if self.has_focus || self.autofocus { if self.has_focus || self.autofocus {
Color::ORANGE Color::ORANGE
} else if self.hovering { } else if self.hovering {
@ -92,9 +92,10 @@ impl TextBox {
text::BG_COLOR text::BG_COLOR
}, },
Polygon::rectangle(self.dims.width, self.dims.height), Polygon::rectangle(self.dims.width, self.dims.height),
)])); )]);
g.redraw_at(self.top_left, &bg); batch.append(self.calculate_text().render_to_batch(g.prerender));
g.draw_blocking_text_at_screenspace_topleft(self.calculate_text(), self.top_left); let draw = g.upload(batch);
g.redraw_at(self.top_left, &draw);
} }
pub fn get_entry(&self) -> String { pub fn get_entry(&self) -> String {

View File

@ -5,7 +5,7 @@ mod world;
use abstutil::{CmdArgs, Timer}; use abstutil::{CmdArgs, Timer};
use ezgui::{ use ezgui::{
hotkey, Canvas, Choice, Color, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx, Key, Line, hotkey, Canvas, Choice, Color, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx, Key, Line,
ModalMenu, Text, Wizard, GUI, ModalMenu, ScreenPt, Text, Wizard, GUI,
}; };
use geom::{Angle, Distance, Line, Polygon, Pt2D}; use geom::{Angle, Distance, Line, Polygon, Pt2D};
use map_model::raw::{OriginalBuilding, OriginalIntersection, OriginalRoad, RestrictionType}; use map_model::raw::{OriginalBuilding, OriginalIntersection, OriginalRoad, RestrictionType};
@ -17,7 +17,8 @@ struct UI {
model: Model, model: Model,
state: State, state: State,
menu: ModalMenu, menu: ModalMenu,
sidebar: Text, popup: Option<Drawable>,
info_key_held: bool,
last_id: Option<ID>, last_id: Option<ID>,
} }
@ -91,7 +92,8 @@ impl UI {
], ],
ctx, ctx,
), ),
sidebar: Text::new().with_bg(), popup: None,
info_key_held: false,
last_id: None, last_id: None,
}; };
@ -112,19 +114,27 @@ impl UI {
ways_audited.insert(r.osm_tags[osm::OSM_WAY_ID].clone()); ways_audited.insert(r.osm_tags[osm::OSM_WAY_ID].clone());
} }
} }
self.menu.set_info(
ctx, let mut txt = Text::from(Line(format!(
Text::from(Line(format!( "Parking data audited: {} / {} ways",
"Parking data audited: {} / {} ways", abstutil::prettyprint_usize(ways_audited.len()),
abstutil::prettyprint_usize(ways_audited.len()), abstutil::prettyprint_usize(ways_audited.len() + ways_missing.len())
abstutil::prettyprint_usize(ways_audited.len() + ways_missing.len()) )));
))), txt.add(Line("Hold right Control to show info about objects"));
); self.menu.set_info(ctx, txt);
} }
} }
impl GUI for UI { impl GUI for UI {
fn event(&mut self, ctx: &mut EventCtx) -> EventLoopMode { fn event(&mut self, ctx: &mut EventCtx) -> EventLoopMode {
if self.info_key_held {
self.info_key_held = !ctx.input.key_released(Key::RightControl);
} else {
self.info_key_held = ctx
.input
.unimportant_key_pressed(Key::RightControl, "hold to show info");
}
ctx.canvas_movement(); ctx.canvas_movement();
self.menu.event(ctx); self.menu.event(ctx);
if ctx.redo_mouseover() { if ctx.redo_mouseover() {
@ -559,23 +569,16 @@ impl GUI for UI {
} }
} }
self.sidebar = Text::new().with_bg(); self.popup = None;
// TODO Do this differently if self.info_key_held {
//self.sidebar.override_width = Some(0.3 * ctx.canvas.window_width); if let Some(id) = self.model.world.get_selection() {
//self.sidebar.override_height = Some(ctx.canvas.window_height); let mut txt = self.model.describe_obj(id);
if let Some(id) = self.model.world.get_selection() { txt.add(Line(""));
self.model.populate_obj_info(id, &mut self.sidebar); ctx.input.populate_osd(&mut txt);
} else { self.popup = Some(ctx.upload(txt.render_to_batch(ctx.prerender)));
self.sidebar.add_highlighted(Line("..."), Color::BLUE); }
} }
// I don't think a clickable menu of buttons makes sense here. These controls need to
// operate on the thing where the mouse is currently. Sometimes that's not even an object
// (like selecting an area or placing a new building).
self.sidebar.add(Line(""));
self.sidebar.add_highlighted(Line("Controls"), Color::BLUE);
ctx.input.populate_osd(&mut self.sidebar);
self.last_id = self.model.world.get_selection(); self.last_id = self.model.world.get_selection();
EventLoopMode::InputOnly EventLoopMode::InputOnly
@ -657,13 +660,9 @@ impl GUI for UI {
}; };
self.menu.draw(g); self.menu.draw(g);
g.draw_blocking_text( if let Some(ref popup) = self.popup {
self.sidebar.clone(), g.redraw_at(ScreenPt::new(0.0, 0.0), popup);
( }
ezgui::HorizontalAlignment::Left,
ezgui::VerticalAlignment::Top,
),
);
} }
fn dump_before_abort(&self, canvas: &Canvas) { fn dump_before_abort(&self, canvas: &Canvas) {

View File

@ -181,7 +181,8 @@ impl Model {
} }
} }
pub fn populate_obj_info(&self, id: ID, txt: &mut Text) { pub fn describe_obj(&self, id: ID) -> Text {
let mut txt = Text::new().with_bg();
match id { match id {
ID::Building(b) => { ID::Building(b) => {
txt.add_highlighted(Line(b.to_string()), Color::BLUE); txt.add_highlighted(Line(b.to_string()), Color::BLUE);
@ -245,6 +246,7 @@ impl Model {
txt.add(Line(format!("to {}", to))); txt.add(Line(format!("to {}", to)));
} }
} }
txt
} }
} }