|
|
|
@ -11,6 +11,10 @@ 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
|
|
|
|
|
|
|
|
.run_if(any_component_changed::<Window>)
|
|
|
|
|
|
|
|
.run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
|
|
|
|
scale_ui.run_if(on_event::<AssetEvent<tweak::Tweaks>>()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -61,3 +65,38 @@ fn interactive_button(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn scale_ui(
|
|
|
|
|
|
|
|
mut windows: Query<&mut Window, Changed<Window>>,
|
|
|
|
|
|
|
|
mut ui_scale: ResMut<UiScale>,
|
|
|
|
|
|
|
|
mut resolution_set: Local<bool>,
|
|
|
|
|
|
|
|
tweakfile: Res<tweak::GameTweaks>,
|
|
|
|
|
|
|
|
tweaks: Res<Assets<tweak::Tweaks>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// There is only 1 window
|
|
|
|
|
|
|
|
assert_eq!(windows.iter().count(), 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !tweaks.contains(tweakfile.handle.clone()) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let tweak = tweaks.get(tweakfile.handle.clone()).unwrap();
|
|
|
|
|
|
|
|
let width = tweak.get::<f32>("resolution_x").unwrap();
|
|
|
|
|
|
|
|
let height = tweak.get::<f32>("resolution_y").unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
windows.iter_mut().for_each(|mut w| {
|
|
|
|
|
|
|
|
// Setting window resolution at startup
|
|
|
|
|
|
|
|
if !*resolution_set {
|
|
|
|
|
|
|
|
w.resolution.set(width, height);
|
|
|
|
|
|
|
|
*resolution_set = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setting UI Scale based on ratio of expected to current ratio
|
|
|
|
|
|
|
|
let width_ratio = w.resolution.width() / width;
|
|
|
|
|
|
|
|
let height_ratio = w.resolution.height() / height;
|
|
|
|
|
|
|
|
let new_scale = (width_ratio).min(height_ratio) as f64;
|
|
|
|
|
|
|
|
if ui_scale.0 != new_scale {
|
|
|
|
|
|
|
|
ui_scale.0 = new_scale;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|