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).
// TODO Super close to deleting this.
pub fn draw_blocking_text(
pub(crate) fn draw_blocking_text(
&mut self,
txt: Text,
(horiz, vert): (HorizontalAlignment, VerticalAlignment),

View File

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

View File

@ -5,7 +5,7 @@ mod world;
use abstutil::{CmdArgs, Timer};
use ezgui::{
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 map_model::raw::{OriginalBuilding, OriginalIntersection, OriginalRoad, RestrictionType};
@ -17,7 +17,8 @@ struct UI {
model: Model,
state: State,
menu: ModalMenu,
sidebar: Text,
popup: Option<Drawable>,
info_key_held: bool,
last_id: Option<ID>,
}
@ -91,7 +92,8 @@ impl UI {
],
ctx,
),
sidebar: Text::new().with_bg(),
popup: None,
info_key_held: false,
last_id: None,
};
@ -112,19 +114,27 @@ impl UI {
ways_audited.insert(r.osm_tags[osm::OSM_WAY_ID].clone());
}
}
self.menu.set_info(
ctx,
Text::from(Line(format!(
"Parking data audited: {} / {} ways",
abstutil::prettyprint_usize(ways_audited.len()),
abstutil::prettyprint_usize(ways_audited.len() + ways_missing.len())
))),
);
let mut txt = Text::from(Line(format!(
"Parking data audited: {} / {} ways",
abstutil::prettyprint_usize(ways_audited.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 {
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();
self.menu.event(ctx);
if ctx.redo_mouseover() {
@ -559,23 +569,16 @@ impl GUI for UI {
}
}
self.sidebar = Text::new().with_bg();
// TODO Do this differently
//self.sidebar.override_width = Some(0.3 * ctx.canvas.window_width);
//self.sidebar.override_height = Some(ctx.canvas.window_height);
if let Some(id) = self.model.world.get_selection() {
self.model.populate_obj_info(id, &mut self.sidebar);
} else {
self.sidebar.add_highlighted(Line("..."), Color::BLUE);
self.popup = None;
if self.info_key_held {
if let Some(id) = self.model.world.get_selection() {
let mut txt = self.model.describe_obj(id);
txt.add(Line(""));
ctx.input.populate_osd(&mut txt);
self.popup = Some(ctx.upload(txt.render_to_batch(ctx.prerender)));
}
}
// 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();
EventLoopMode::InputOnly
@ -657,13 +660,9 @@ impl GUI for UI {
};
self.menu.draw(g);
g.draw_blocking_text(
self.sidebar.clone(),
(
ezgui::HorizontalAlignment::Left,
ezgui::VerticalAlignment::Top,
),
);
if let Some(ref popup) = self.popup {
g.redraw_at(ScreenPt::new(0.0, 0.0), popup);
}
}
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 {
ID::Building(b) => {
txt.add_highlighted(Line(b.to_string()), Color::BLUE);
@ -245,6 +246,7 @@ impl Model {
txt.add(Line(format!("to {}", to)));
}
}
txt
}
}