mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-03 12:03:30 +03:00
moving the map diffs viewer into a top-level Edit mode
This commit is contained in:
parent
c0947fcb35
commit
d771927576
82
editor/src/edit.rs
Normal file
82
editor/src/edit.rs
Normal file
@ -0,0 +1,82 @@
|
||||
use crate::game::{GameState, Mode};
|
||||
use crate::objects::DrawCtx;
|
||||
use crate::render::{RenderOptions, Renderable, MIN_ZOOM_FOR_DETAIL};
|
||||
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Wizard, GUI};
|
||||
|
||||
pub enum EditMode {
|
||||
ViewingDiffs,
|
||||
// loading others, saving, road editor, intersection editors, etc
|
||||
}
|
||||
|
||||
impl EditMode {
|
||||
pub fn event(state: &mut GameState, ctx: EventCtx) -> EventLoopMode {
|
||||
// TODO modal with some info
|
||||
|
||||
match state.mode {
|
||||
Mode::Edit(EditMode::ViewingDiffs) => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let (event_mode, pause) = state.ui.new_event(ctx);
|
||||
if pause {
|
||||
state.mode = Mode::SplashScreen(Wizard::new());
|
||||
}
|
||||
event_mode
|
||||
}
|
||||
|
||||
pub fn draw(state: &GameState, g: &mut GfxCtx) {
|
||||
state.ui.draw(g);
|
||||
let ctx = DrawCtx {
|
||||
cs: &state.ui.state.cs,
|
||||
map: &state.ui.state.primary.map,
|
||||
draw_map: &state.ui.state.primary.draw_map,
|
||||
sim: &state.ui.state.primary.sim,
|
||||
hints: &state.ui.hints,
|
||||
};
|
||||
|
||||
match state.mode {
|
||||
Mode::Edit(EditMode::ViewingDiffs) => {
|
||||
// TODO Similar to drawing areas with traffic or not -- would be convenient to just
|
||||
// supply a set of things to highlight and have something else take care of drawing
|
||||
// with detail or not.
|
||||
let zoomed = g.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL;
|
||||
|
||||
// More generally we might want to show the diff between two edits, but for now,
|
||||
// just show diff relative to basemap.
|
||||
let edits = ctx.map.get_edits();
|
||||
for l in edits.lane_overrides.keys() {
|
||||
if zoomed {
|
||||
ctx.draw_map.get_l(*l).draw(
|
||||
g,
|
||||
RenderOptions {
|
||||
color: Some(ctx.cs.get_def("map diffs", Color::RED)),
|
||||
debug_mode: false,
|
||||
},
|
||||
&ctx,
|
||||
);
|
||||
} else {
|
||||
g.draw_polygon(
|
||||
ctx.cs.get("map diffs"),
|
||||
&ctx.map.get_parent(*l).get_thick_polygon().unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
for i in edits
|
||||
.stop_sign_overrides
|
||||
.keys()
|
||||
.chain(edits.traffic_signal_overrides.keys())
|
||||
{
|
||||
ctx.draw_map.get_i(*i).draw(
|
||||
g,
|
||||
RenderOptions {
|
||||
color: Some(ctx.cs.get("map diffs")),
|
||||
debug_mode: false,
|
||||
},
|
||||
&ctx,
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
use crate::edit::EditMode;
|
||||
use crate::state::{Flags, UIState};
|
||||
use crate::tutorial::TutorialMode;
|
||||
use crate::ui::UI;
|
||||
@ -26,6 +27,7 @@ pub struct GameState {
|
||||
pub enum Mode {
|
||||
SplashScreen(Wizard),
|
||||
Playing,
|
||||
Edit(EditMode),
|
||||
Tutorial(TutorialMode),
|
||||
}
|
||||
|
||||
@ -89,6 +91,7 @@ impl GUI for GameState {
|
||||
}
|
||||
event_mode
|
||||
}
|
||||
Mode::Edit(_) => EditMode::event(self, ctx),
|
||||
Mode::Tutorial(_) => TutorialMode::event(self, ctx),
|
||||
}
|
||||
}
|
||||
@ -100,6 +103,7 @@ impl GUI for GameState {
|
||||
wizard.draw(g);
|
||||
}
|
||||
Mode::Playing => self.ui.draw(g),
|
||||
Mode::Edit(_) => EditMode::draw(self, g),
|
||||
Mode::Tutorial(_) => TutorialMode::draw(self, g),
|
||||
}
|
||||
}
|
||||
@ -166,6 +170,7 @@ fn splash_screen(raw_wizard: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Op
|
||||
let mut wizard = raw_wizard.wrap(&mut ctx.input, ctx.canvas);
|
||||
let play = "Play";
|
||||
let load_map = "Load another map";
|
||||
let edit = "Edit map";
|
||||
let tutorial = "Tutorial";
|
||||
let about = "About";
|
||||
let quit = "Quit";
|
||||
@ -175,7 +180,7 @@ fn splash_screen(raw_wizard: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Op
|
||||
match wizard
|
||||
.choose_string(
|
||||
"Welcome to A/B Street!",
|
||||
vec![play, load_map, tutorial, about, quit],
|
||||
vec![play, load_map, edit, tutorial, about, quit],
|
||||
)?
|
||||
.as_str()
|
||||
{
|
||||
@ -202,6 +207,7 @@ fn splash_screen(raw_wizard: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Op
|
||||
break None;
|
||||
}
|
||||
}
|
||||
x if x == edit => break Some(Mode::Edit(EditMode::ViewingDiffs)),
|
||||
x if x == tutorial => {
|
||||
break Some(Mode::Tutorial(TutorialMode::Part1(
|
||||
ctx.canvas.center_to_map_pt(),
|
||||
|
@ -1,4 +1,5 @@
|
||||
mod colors;
|
||||
mod edit;
|
||||
mod game;
|
||||
mod objects;
|
||||
mod plugins;
|
||||
|
@ -4,6 +4,5 @@ pub mod draw_neighborhoods;
|
||||
pub mod map_edits;
|
||||
pub mod road_editor;
|
||||
pub mod scenarios;
|
||||
pub mod show_map_diffs;
|
||||
pub mod stop_sign_editor;
|
||||
pub mod traffic_signal_editor;
|
||||
|
@ -1,75 +0,0 @@
|
||||
use crate::objects::DrawCtx;
|
||||
use crate::plugins::{AmbientPlugin, PluginCtx};
|
||||
use crate::render::{RenderOptions, Renderable, MIN_ZOOM_FOR_DETAIL};
|
||||
use ezgui::{Color, GfxCtx};
|
||||
|
||||
pub struct ShowMapDiffs {
|
||||
active: bool,
|
||||
}
|
||||
|
||||
impl ShowMapDiffs {
|
||||
pub fn new() -> ShowMapDiffs {
|
||||
ShowMapDiffs { active: false }
|
||||
}
|
||||
}
|
||||
|
||||
impl AmbientPlugin for ShowMapDiffs {
|
||||
fn ambient_event(&mut self, ctx: &mut PluginCtx) {
|
||||
if self.active {
|
||||
ctx.input.set_mode("Map Edits Differ", &ctx.canvas);
|
||||
if ctx.input.modal_action("quit") {
|
||||
self.active = false;
|
||||
}
|
||||
} else {
|
||||
if ctx.input.action_chosen("show map diffs") {
|
||||
self.active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, ctx: &DrawCtx) {
|
||||
if !self.active {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Similar to drawing areas with traffic or not -- would be convenient to just supply
|
||||
// a set of things to highlight and have something else take care of drawing with detail or
|
||||
// not.
|
||||
let zoomed = g.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL;
|
||||
|
||||
// More generally we might want to show the diff between two edits, but for now, just show
|
||||
// diff relative to basemap.
|
||||
let edits = ctx.map.get_edits();
|
||||
for l in edits.lane_overrides.keys() {
|
||||
if zoomed {
|
||||
ctx.draw_map.get_l(*l).draw(
|
||||
g,
|
||||
RenderOptions {
|
||||
color: Some(ctx.cs.get_def("map diffs", Color::RED)),
|
||||
debug_mode: false,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
} else {
|
||||
g.draw_polygon(
|
||||
ctx.cs.get("map diffs"),
|
||||
&ctx.map.get_parent(*l).get_thick_polygon().unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
for i in edits
|
||||
.stop_sign_overrides
|
||||
.keys()
|
||||
.chain(edits.traffic_signal_overrides.keys())
|
||||
{
|
||||
ctx.draw_map.get_i(*i).draw(
|
||||
g,
|
||||
RenderOptions {
|
||||
color: Some(ctx.cs.get("map diffs")),
|
||||
debug_mode: false,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -490,7 +490,6 @@ impl PluginsPerMap {
|
||||
Box::new(view::show_associated::ShowAssociatedState::new()),
|
||||
Box::new(view::show_route::ShowRouteState::new()),
|
||||
Box::new(view::turn_cycler::TurnCyclerState::new()),
|
||||
Box::new(edit::show_map_diffs::ShowMapDiffs::new()),
|
||||
],
|
||||
time_travel: plugins::sim::time_travel::TimeTravel::new(),
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ use std::collections::HashSet;
|
||||
|
||||
// TODO Collapse stuff!
|
||||
pub struct UI {
|
||||
hints: RenderingHints,
|
||||
pub hints: RenderingHints,
|
||||
pub state: UIState,
|
||||
}
|
||||
|
||||
@ -58,7 +58,6 @@ impl GUI for UI {
|
||||
(Some(Key::Q), "manage map edits"),
|
||||
(Some(Key::E), "edit roads"),
|
||||
(Some(Key::W), "manage scenarios"),
|
||||
(None, "show map diffs"),
|
||||
],
|
||||
),
|
||||
Folder::new(
|
||||
|
Loading…
Reference in New Issue
Block a user