Fix bug with minimizing crashing the game

main
Elijah C. Voigt 2 years ago
parent 2946c89f36
commit 974e878763

@ -1,3 +1,6 @@
###
# Credits text, rendered as-is from the "Credits" menu button
###
[credits] [credits]
text = """ text = """
# Martian Chess # Martian Chess
@ -29,6 +32,9 @@ Space Blanket Folds - https://www.textures.com/download/PBR0152/133187
Background 2D art by NASA: LINK HERE Background 2D art by NASA: LINK HERE
""" """
###
# Intro text, typed out during normal gameplay
###
[intro] [intro]
# Higher rate is slower typing speed. Integers only! # Higher rate is slower typing speed. Integers only!
rate = 5 rate = 5
@ -43,6 +49,9 @@ But Can you adapt?
Will you be a part of the universal rhyme, and if so, which side are you on? Will you be a part of the universal rhyme, and if so, which side are you on?
""" """
###
# Tutorial text, revealed interactively based on context
###
[tutorial] [tutorial]
intro = [ intro = [
""" """

@ -11,10 +11,11 @@ impl Plugin for UiPlugin {
( (
manage_cursor.run_if(any_component_changed::<Interaction>), manage_cursor.run_if(any_component_changed::<Interaction>),
interactive_button.run_if(any_component_changed::<Interaction>), interactive_button.run_if(any_component_changed::<Interaction>),
scale_ui scale_ui.run_if(
.run_if(any_component_changed::<Window>) on_event::<AssetEvent<tweak::Tweaks>>()
.run_if(resource_exists::<tweak::GameTweaks>()), .or_else(any_component_changed::<Window>)
scale_ui.run_if(on_event::<AssetEvent<tweak::Tweaks>>()), .and_then(resource_exists::<tweak::GameTweaks>()),
),
), ),
); );
} }
@ -90,12 +91,15 @@ fn scale_ui(
*resolution_set = true; *resolution_set = true;
} }
// Setting UI Scale based on ratio of expected to current ratio // Check if window is minimized
let width_ratio = w.resolution.width() / width; if w.resolution.height() > 0.0 && w.resolution.height() > 0.0 {
let height_ratio = w.resolution.height() / height; // Setting UI Scale based on ratio of expected to current ratio
let new_scale = (width_ratio).min(height_ratio) as f64; let width_ratio = w.resolution.width() / width;
if ui_scale.0 != new_scale { let height_ratio = w.resolution.height() / height;
ui_scale.0 = new_scale; let new_scale = (width_ratio).min(height_ratio) as f64;
if ui_scale.0 != new_scale {
ui_scale.0 = new_scale;
}
} }
}); });
} }

Loading…
Cancel
Save