From eedbb2b967dffc5ef1abdb92a139b5b39e134c49 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 3 Apr 2020 16:46:11 -0700 Subject: [PATCH] rearrange minimap controls. nearly matching the new design. --- data/MANIFEST.txt | 4 +- data/system/assets/minimap/zoom_in_fully.svg | 4 +- data/system/assets/minimap/zoom_out_fully.svg | 4 +- game/src/common/minimap.rs | 279 ++++++++++-------- 4 files changed, 158 insertions(+), 133 deletions(-) diff --git a/data/MANIFEST.txt b/data/MANIFEST.txt index 898b9250d6..45d744d940 100644 --- a/data/MANIFEST.txt +++ b/data/MANIFEST.txt @@ -197,9 +197,9 @@ f71b2ce735102531e11934781fe748b1 data/system/assets/edit/parking.svg 2f15de4a863cc755984726da0c29c0a4 data/system/assets/edit/driving.svg cad08c84562d640c5a4d4e45cd3731b2 data/system/assets/minimap/right.svg 39eb3adcf91244c50092f0aad6628e1a data/system/assets/minimap/left.svg -65c3dfeadeb35e91f45038292226ab36 data/system/assets/minimap/zoom_in_fully.svg +c063a7b561f00f4b2ccad16390d3c5f0 data/system/assets/minimap/zoom_in_fully.svg 55598346b4b038899f8972d7468a20a6 data/system/assets/minimap/down.svg -e761e1d1f6c9b8befe53296e0411cef2 data/system/assets/minimap/zoom_out_fully.svg +add7f832f0a7b501a59c505b63a0c5b5 data/system/assets/minimap/zoom_out_fully.svg 9caf97939884d4859accca34265f45fb data/system/assets/minimap/up.svg a5e849fa8883569519976ebfef3ae269 data/system/night_colors.json 1909af5ebfefe7ad4102335c9e789d24 data/system/override_colors.json diff --git a/data/system/assets/minimap/zoom_in_fully.svg b/data/system/assets/minimap/zoom_in_fully.svg index 08fee6cae4..e328baf690 100644 --- a/data/system/assets/minimap/zoom_in_fully.svg +++ b/data/system/assets/minimap/zoom_in_fully.svg @@ -1,3 +1,3 @@ - - + + diff --git a/data/system/assets/minimap/zoom_out_fully.svg b/data/system/assets/minimap/zoom_out_fully.svg index fda9fb68f3..c966061903 100644 --- a/data/system/assets/minimap/zoom_out_fully.svg +++ b/data/system/assets/minimap/zoom_out_fully.svg @@ -1,3 +1,3 @@ - - + + diff --git a/game/src/common/minimap.rs b/game/src/common/minimap.rs index 5ad48e0936..acb66d0e5a 100644 --- a/game/src/common/minimap.rs +++ b/game/src/common/minimap.rs @@ -242,66 +242,84 @@ impl Minimap { fn make_minimap_panel(ctx: &mut EventCtx, app: &App, zoom_lvl: usize) -> Composite { if ctx.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL { - return Composite::new(make_viz_panel(ctx, app)) - .aligned( - HorizontalAlignment::Right, - VerticalAlignment::BottomAboveOSD, - ) - .build(ctx); + return Composite::new( + Widget::col(vec![ + make_tool_panel(ctx, app).align_right().margin_below(5), + make_viz_panel(ctx, app).bg(colors::PANEL_BG), + ]) + .padding(7), + ) + .aligned( + HorizontalAlignment::Right, + VerticalAlignment::BottomAboveOSD, + ) + .build(ctx); } + let zoom_col = { + let mut col = vec![Btn::svg_def("../data/system/assets/speed/speed_up.svg") + .build(ctx, "zoom in", None) + .margin(12)]; + for i in (0..=3).rev() { + let color = if zoom_lvl < i { + Color::WHITE.alpha(0.2) + } else { + Color::WHITE + }; + let rect = Polygon::rectangle(20.0, 8.0); + col.push( + Btn::custom( + GeomBatch::from(vec![(color, rect.clone())]), + GeomBatch::from(vec![(colors::HOVERING, rect.clone())]), + rect, + ) + .build(ctx, format!("zoom to level {}", i + 1), None) + .margin(12), + ); + } + col.push( + Btn::svg_def("../data/system/assets/speed/slow_down.svg") + .build(ctx, "zoom out", None) + .margin(12), + ); + // The zoom column should start below the "pan up" arrow. But if we put it on the row with + // <, minimap, and > then it messes up the horizontal alignment of the pan up arrow. + // Also, double column to avoid the background color stretching to the bottom of the row. + Widget::col(vec![Widget::col(col).bg(colors::INNER_PANEL)]).margin_above(26) + }; + let square_len = 0.15 * ctx.canvas.window_width; - let mut zoom_col = - vec![Btn::svg_def("../data/system/assets/speed/speed_up.svg").build(ctx, "zoom in", None)]; - for i in (0..=3).rev() { - let color = if zoom_lvl < i { - Color::grey(0.2) - } else { - Color::WHITE - }; - let rect = Polygon::rectangle(20.0, 8.0); - zoom_col.push( - Btn::custom( - GeomBatch::from(vec![(color, rect.clone())]), - GeomBatch::from(vec![(colors::HOVERING, rect.clone())]), - rect, - ) - .build(ctx, format!("zoom to level {}", i + 1), None), - ); - } - zoom_col.push( - Btn::svg_def("../data/system/assets/speed/slow_down.svg").build(ctx, "zoom out", None), - ); - - Composite::new( + let minimap_controls = Widget::col(vec![ + Btn::svg_def("../data/system/assets/minimap/up.svg") + .build(ctx, "pan up", None) + .margin(5) + .centered_horiz(), Widget::row(vec![ - Widget::col(zoom_col).margin(5).centered(), - Widget::col(vec![ - Btn::svg_def("../data/system/assets/minimap/up.svg") - .build(ctx, "pan up", None) - .margin(5) - .centered_horiz(), - Widget::row(vec![ - Btn::svg_def("../data/system/assets/minimap/left.svg") - .build(ctx, "pan left", None) - .margin(5) - .centered_vert(), - Filler::new(ScreenDims::new(square_len, square_len)).named("minimap"), - Btn::svg_def("../data/system/assets/minimap/right.svg") - .build(ctx, "pan right", None) - .margin(5) - .centered_vert(), - ]), - Btn::svg_def("../data/system/assets/minimap/down.svg") - .build(ctx, "pan down", None) - .margin(5) - .centered_horiz(), - ]) - .centered(), - make_viz_panel(ctx, app).centered_vert(), + Btn::svg_def("../data/system/assets/minimap/left.svg") + .build(ctx, "pan left", None) + .margin(5) + .centered_vert(), + Filler::new(ScreenDims::new(square_len, square_len)).named("minimap"), + Btn::svg_def("../data/system/assets/minimap/right.svg") + .build(ctx, "pan right", None) + .margin(5) + .centered_vert(), + ]), + Btn::svg_def("../data/system/assets/minimap/down.svg") + .build(ctx, "pan down", None) + .margin(5) + .centered_horiz(), + ]); + + Composite::new(Widget::row(vec![ + make_tool_panel(ctx, app).margin_right(16), + Widget::col(vec![ + Widget::row(vec![minimap_controls, zoom_col]), + make_viz_panel(ctx, app), ]) + .padding(7) .bg(colors::PANEL_BG), - ) + ])) .aligned( HorizontalAlignment::Right, VerticalAlignment::BottomAboveOSD, @@ -309,24 +327,25 @@ fn make_minimap_panel(ctx: &mut EventCtx, app: &App, zoom_lvl: usize) -> Composi .build(ctx) } -fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> Widget { - let radius = 10.0; - let mut col = vec![Widget::row(vec![ - Btn::svg_def("../data/system/assets/tools/search.svg") - .build(ctx, "search", hotkey(Key::K)) - .margin(10), - Btn::svg_def("../data/system/assets/tools/shortcuts.svg") - .build(ctx, "shortcuts", hotkey(Key::SingleQuote)) - .margin(10), - if ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL { - Btn::svg_def("../data/system/assets/minimap/zoom_out_fully.svg") - .build(ctx, "zoom out fully", None) - .margin(10) +fn make_tool_panel(ctx: &mut EventCtx, app: &App) -> Widget { + // TODO Apply something to everything in the column + Widget::col(vec![ + (if ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL { + Btn::svg_def("../data/system/assets/minimap/zoom_out_fully.svg").build( + ctx, + "zoom out fully", + None, + ) } else { - Btn::svg_def("../data/system/assets/minimap/zoom_in_fully.svg") - .build(ctx, "zoom in fully", None) - .margin(10) - }, + Btn::svg_def("../data/system/assets/minimap/zoom_in_fully.svg").build( + ctx, + "zoom in fully", + None, + ) + }) + .bg(colors::INNER_PANEL) + .padding(9) + .margin_below(16), Btn::svg_def("../data/system/assets/tools/layers.svg") .normal_color(if app.overlay.is_empty() { RewriteColor::NoOp @@ -334,68 +353,74 @@ fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> Widget { RewriteColor::ChangeAll(Color::BLUE) }) .build(ctx, "change overlay", hotkey(Key::L)) - .margin(10), + .bg(colors::INNER_PANEL) + .padding(9) + .margin_below(16), + Btn::svg_def("../data/system/assets/tools/search.svg") + .build(ctx, "search", hotkey(Key::K)) + .bg(colors::INNER_PANEL) + .padding(9) + .margin_below(16), + Btn::svg_def("../data/system/assets/tools/shortcuts.svg") + .build(ctx, "shortcuts", hotkey(Key::SingleQuote)) + .bg(colors::INNER_PANEL) + .padding(9), ]) - .centered()]; - for (label, color, enabled) in &app.agent_cs.rows { - col.push( - Widget::row(vec![ - // TODO Make sure the dims of these two fit - if *enabled { - Btn::svg_def("../data/system/assets/tools/visible.svg") - .build(ctx, format!("hide {}", label), None) - .margin(3) - } else { - Btn::svg_def("../data/system/assets/tools/invisible.svg") - .build(ctx, format!("show {}", label), None) - .margin(3) - }, - Widget::draw_batch( - ctx, - GeomBatch::from(vec![( - Color::WHITE.alpha(0.5), - Polygon::rectangle(2.0, 1.5 * radius), - )]), - ) - .margin(3), - Widget::draw_batch( - ctx, - GeomBatch::from(vec![( - color.alpha(if *enabled { 1.0 } else { 0.5 }), - Circle::new(Pt2D::new(radius, radius), Distance::meters(radius)) - .to_polygon(), - )]), - ) - .margin(3), - Text::from(if *enabled { - Line(label).small() - } else { - Line(label).small().fg(Color::WHITE.alpha(0.5)) - }) - .draw(ctx) - .margin(3), - ]) - .centered_cross(), - ); - } +} +fn make_viz_panel(ctx: &mut EventCtx, app: &App) -> Widget { + let mut col = Vec::new(); + + // TODO Really rethink this if ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_DETAIL { if let Some(name) = app.overlay.zoomed_name() { // TODO Should the full legend have this icon too? - col.insert( - 0, - Widget::row(vec![ - Widget::draw_svg_transform( - ctx, - "../data/system/assets/tools/layers.svg", - RewriteColor::ChangeAll(Color::BLUE), - ) - .margin(5), - Line(name).small().draw(ctx), - ]), - ); + col.push(Widget::row(vec![ + Widget::draw_svg_transform( + ctx, + "../data/system/assets/tools/layers.svg", + RewriteColor::ChangeAll(Color::BLUE), + ) + .margin(5), + Line(name).small().draw(ctx), + ])); } } - Widget::col(col).bg(colors::PANEL_BG).padding(5) + let mut row = Vec::new(); + let radius = 10.0; + for (label, color, enabled) in &app.agent_cs.rows { + // TODO Make sure the dims of these two fit + row.push(if *enabled { + Btn::svg_def("../data/system/assets/tools/visible.svg") + .build(ctx, format!("hide {}", label), None) + .margin(3) + } else { + Btn::svg_def("../data/system/assets/tools/invisible.svg") + .build(ctx, format!("show {}", label), None) + .margin(3) + }); + row.push( + Widget::draw_batch( + ctx, + GeomBatch::from(vec![( + color.alpha(if *enabled { 1.0 } else { 0.5 }), + Circle::new(Pt2D::new(radius, radius), Distance::meters(radius)).to_polygon(), + )]), + ) + .margin(3), + ); + row.push( + Text::from(if *enabled { + Line(label).small() + } else { + Line(label).small().fg(Color::WHITE.alpha(0.5)) + }) + .draw(ctx) + .margin(3), + ); + } + col.push(Widget::row(row)); + + Widget::col(col) }