From 8f0c027bb08d3136c0da24acc8c36e3b7da66882 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sat, 30 Jan 2021 14:20:28 -0800 Subject: [PATCH] Fix critical bug causing a crash only in the .zip releases, where widgetry icons aren't present relative to the data/ directory. --- game/src/edit/traffic_signals/mod.rs | 14 +++++++++----- game/src/info/person.rs | 12 +++++++----- santa/src/before_level.rs | 7 ++++++- widgetry/src/style/buttons.rs | 3 +++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/game/src/edit/traffic_signals/mod.rs b/game/src/edit/traffic_signals/mod.rs index 7ffaa34d54..b0020a21da 100644 --- a/game/src/edit/traffic_signals/mod.rs +++ b/game/src/edit/traffic_signals/mod.rs @@ -10,9 +10,9 @@ use map_model::{ TurnPriority, }; use widgetry::{ - lctrl, Color, ControlState, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx, - HorizontalAlignment, Key, Line, MultiButton, Outcome, Panel, RewriteColor, State, - StyledButtons, Text, TextExt, VerticalAlignment, Widget, + include_labeled_bytes, lctrl, Color, ControlState, DrawBaselayer, Drawable, EventCtx, + GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, MultiButton, Outcome, Panel, RewriteColor, + State, StyledButtons, Text, TextExt, VerticalAlignment, Widget, }; use crate::app::{App, ShowEverything, Transition}; @@ -628,12 +628,16 @@ fn make_side_panel( let up_button = ctx .style() - .btn_solid_light_icon("../widgetry/icons/arrow_up.svg") + .btn_solid_light_icon_bytes(include_labeled_bytes!( + "../../../../widgetry/icons/arrow_up.svg" + )) .disabled(idx == 0); let down_button = ctx .style() - .btn_solid_light_icon("../widgetry/icons/arrow_down.svg") + .btn_solid_light_icon_bytes(include_labeled_bytes!( + "../../../../widgetry/icons/arrow_down.svg" + )) .disabled(idx == canonical_signal.stages.len() - 1); let stage_controls = Widget::row(vec![ diff --git a/game/src/info/person.rs b/game/src/info/person.rs index 97cc68cced..baaf23b6bb 100644 --- a/game/src/info/person.rs +++ b/game/src/info/person.rs @@ -190,11 +190,13 @@ pub fn trips( Widget::nothing() }, { - let mut icon = - GeomBatch::load_svg(ctx.prerender, "../widgetry/icons/arrow_drop_down.svg") - .autocrop() - .color(RewriteColor::ChangeAll(Color::WHITE)) - .scale(1.5); + // TODO Maybe generalize ImageSource::Bytes beyond just buttons + let mut icon = GeomBatch::from_uncached_svg_contents(include_bytes!( + "../../../widgetry/icons/arrow_drop_down.svg" + )) + .autocrop() + .color(RewriteColor::ChangeAll(Color::WHITE)) + .scale(1.5); if !open_trips.contains_key(t) { icon = icon.rotate(Angle::degrees(180.0)); diff --git a/santa/src/before_level.rs b/santa/src/before_level.rs index edc195c502..455e935078 100644 --- a/santa/src/before_level.rs +++ b/santa/src/before_level.rs @@ -75,7 +75,12 @@ impl Picker { let instructions_panel = Panel::new(Widget::col(vec![ txt.draw(ctx), Widget::row(vec![ - Widget::draw_svg(ctx, "../widgetry/icons/arrow_keys.svg"), + Widget::draw_batch( + ctx, + GeomBatch::from_uncached_svg_contents(include_bytes!( + "../../widgetry/icons/arrow_keys.svg" + )), + ), Text::from_all(vec![ Line("arrow keys").fg(ctx.style().hotkey_color), Line(" to move (or "), diff --git a/widgetry/src/style/buttons.rs b/widgetry/src/style/buttons.rs index 1099ad3d98..2e63d3f80e 100644 --- a/widgetry/src/style/buttons.rs +++ b/widgetry/src/style/buttons.rs @@ -41,6 +41,9 @@ pub trait StyledButtons<'a> { fn btn_solid_light_icon(&self, image_path: &'a str) -> ButtonBuilder<'a> { icon_button(self.btn_solid_light().image_path(image_path)) } + fn btn_solid_light_icon_bytes(&self, labeled_bytes: (&'a str, &'a [u8])) -> ButtonBuilder<'a> { + icon_button(self.btn_solid_light().image_bytes(labeled_bytes)) + } fn btn_solid_light_icon_text(&self, image_path: &'a str, text: &'a str) -> ButtonBuilder<'a> { self.btn_solid_light() .label_text(text)