Merge branch 'main' into text-info
Some checks failed
Rust Checks / checks (push) Failing after 18s

This commit is contained in:
CoCo_Sol 2024-03-11 06:13:48 +01:00
commit a0e98de6bb
3 changed files with 41 additions and 2 deletions

View file

@ -4,6 +4,7 @@ use bevy::prelude::*;
pub mod camera;
pub mod map;
pub mod responsive_scale;
pub mod scenes;
pub mod ui;

View file

@ -0,0 +1,37 @@
//! The file that contains the responsive scaling logic.
use bevy::prelude::*;
/// The plugin for the responsive scaling.
pub struct ResponsiveScalingPlugin;
impl Plugin for ResponsiveScalingPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, init_window_size);
app.add_systems(Update, change_scaling);
}
}
/// The default ui layout size.
#[derive(Resource)]
pub struct UILayoutSize(pub Vec2);
/// Initializes [UILayoutSize].
pub fn init_window_size(mut command: Commands) {
command.insert_resource(UILayoutSize(Vec2::new(1280., 720.)));
}
/// Calculates the ui_scale.0 depending on the [UILayoutSize]
/// in order to make the ui layout responsive.
pub fn change_scaling(
mut ui_scale: ResMut<UiScale>,
windows: Query<&Window>,
size: Res<UILayoutSize>,
) {
let window = windows.get_single().expect("Main window not found");
let (a, b) = (
window.resolution.width() / size.0.x,
window.resolution.height() / size.0.y,
);
ui_scale.0 = if a < b { a } else { b } as f64
}

View file

@ -3,7 +3,7 @@
use bevy::prelude::*;
use bevy_egui::EguiPlugin;
use crate::CurrentScene;
use crate::{responsive_scale, CurrentScene};
pub mod lobby;
pub mod menu;
@ -16,6 +16,7 @@ impl Plugin for ScenesPlugin {
app.add_plugins(EguiPlugin)
.add_state::<CurrentScene>()
.add_plugins(menu::MenuPlugin)
.add_plugins(lobby::LobbyPlugin);
.add_plugins(lobby::LobbyPlugin)
.add_plugins(responsive_scale::ResponsiveScalingPlugin);
}
}