From 0775704b8e05c0f4e9c2c2d9f61b1b080fcd6fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sun, 3 Mar 2024 02:01:11 +0100 Subject: [PATCH 01/10] Add a responsive scaling that calculates the ui_scale.depending on the size of the main node --- crates/border-wars/src/lib.rs | 10 ++++++++++ crates/border-wars/src/scenes/mod.rs | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/border-wars/src/lib.rs b/crates/border-wars/src/lib.rs index a4acdb8..b462412 100644 --- a/crates/border-wars/src/lib.rs +++ b/crates/border-wars/src/lib.rs @@ -19,3 +19,13 @@ pub enum CurrentScene { /// When we play this wonderful game. Game, } + +/// Calculates the ui_scale.0 depending on the size of the main node +pub fn change_scaling(mut ui_scale: ResMut, window: Query<&Window>) { + let window = window.single(); + let (a, b) = ( + window.resolution.width() / 1280., + window.resolution.height() / 720., + ); + ui_scale.0 = if a < b { a } else { b } as f64 +} diff --git a/crates/border-wars/src/scenes/mod.rs b/crates/border-wars/src/scenes/mod.rs index 2a788fd..dce2e1e 100644 --- a/crates/border-wars/src/scenes/mod.rs +++ b/crates/border-wars/src/scenes/mod.rs @@ -3,7 +3,7 @@ use bevy::prelude::*; use bevy_egui::EguiPlugin; -use crate::CurrentScene; +use crate::{change_scaling, CurrentScene}; pub mod lobby; pub mod menu; @@ -16,6 +16,7 @@ impl Plugin for ScenesPlugin { app.add_plugins(EguiPlugin) .add_state::() .add_plugins(menu::MenuPlugin) - .add_plugins(lobby::LobbyPlugin); + .add_plugins(lobby::LobbyPlugin) + .add_systems(Update, change_scaling); } } -- 2.43.4 From f0671e12e21bd27d3eda5cb3599cb352451d35af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sun, 3 Mar 2024 09:57:24 +0000 Subject: [PATCH 02/10] Adding more precision to the function docstring --- crates/border-wars/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/border-wars/src/lib.rs b/crates/border-wars/src/lib.rs index b462412..f6e9173 100644 --- a/crates/border-wars/src/lib.rs +++ b/crates/border-wars/src/lib.rs @@ -21,6 +21,7 @@ pub enum CurrentScene { } /// Calculates the ui_scale.0 depending on the size of the main node +/// in order to make the screen responsive pub fn change_scaling(mut ui_scale: ResMut, window: Query<&Window>) { let window = window.single(); let (a, b) = ( -- 2.43.4 From f0af5f4cfdfa5b126e616d905249f85fb31d37ac Mon Sep 17 00:00:00 2001 From: raphael Date: Fri, 8 Mar 2024 08:20:34 +0100 Subject: [PATCH 03/10] pull request --- crates/border-wars/src/lib.rs | 11 ----------- crates/border-wars/src/responsive_scale.rs | 13 +++++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 crates/border-wars/src/responsive_scale.rs diff --git a/crates/border-wars/src/lib.rs b/crates/border-wars/src/lib.rs index f6e9173..a4acdb8 100644 --- a/crates/border-wars/src/lib.rs +++ b/crates/border-wars/src/lib.rs @@ -19,14 +19,3 @@ pub enum CurrentScene { /// When we play this wonderful game. Game, } - -/// Calculates the ui_scale.0 depending on the size of the main node -/// in order to make the screen responsive -pub fn change_scaling(mut ui_scale: ResMut, window: Query<&Window>) { - let window = window.single(); - let (a, b) = ( - window.resolution.width() / 1280., - window.resolution.height() / 720., - ); - ui_scale.0 = if a < b { a } else { b } as f64 -} diff --git a/crates/border-wars/src/responsive_scale.rs b/crates/border-wars/src/responsive_scale.rs new file mode 100644 index 0000000..89681e5 --- /dev/null +++ b/crates/border-wars/src/responsive_scale.rs @@ -0,0 +1,13 @@ +const DEFAULT_WIDTH = 1280. +const DEFAULT_HEIGHT = 720. + +/// Calculates the ui_scale.0 depending on the size of the main node +/// in order to make the screen responsive +pub fn change_scaling(mut ui_scale: ResMut, window: Query<&Window>) { + let window = window.single(); + let (a, b) = ( + window.resolution.width() / DEFAULT_WIDTH, + window.resolution.height() / DEFAULT_HEIGHT, + ); + ui_scale.0 = if a < b { a } else { b } as f64 +} \ No newline at end of file -- 2.43.4 From f0a475626082e80cb82495e5e948d58102931ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 9 Mar 2024 14:37:29 +0100 Subject: [PATCH 04/10] reparation du programme --- crates/border-wars/src/responsive_scale.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/border-wars/src/responsive_scale.rs b/crates/border-wars/src/responsive_scale.rs index 89681e5..2a501ff 100644 --- a/crates/border-wars/src/responsive_scale.rs +++ b/crates/border-wars/src/responsive_scale.rs @@ -1,5 +1,5 @@ -const DEFAULT_WIDTH = 1280. -const DEFAULT_HEIGHT = 720. +const DEFAULT_WIDTH: f32 = 1280.; +const DEFAULT_HEIGHT: f32 = 720.; /// Calculates the ui_scale.0 depending on the size of the main node /// in order to make the screen responsive @@ -10,4 +10,4 @@ pub fn change_scaling(mut ui_scale: ResMut, window: Query<&Window>) { window.resolution.height() / DEFAULT_HEIGHT, ); ui_scale.0 = if a < b { a } else { b } as f64 -} \ No newline at end of file +} -- 2.43.4 From 4b3da44d65700806f3795baf8928e3050350909c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 9 Mar 2024 14:50:55 +0100 Subject: [PATCH 05/10] Adding doc et repair the program --- crates/border-wars/src/lib.rs | 1 + crates/border-wars/src/responsive_scale.rs | 7 +++++++ crates/border-wars/src/scenes/mod.rs | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/border-wars/src/lib.rs b/crates/border-wars/src/lib.rs index a4acdb8..0911f41 100644 --- a/crates/border-wars/src/lib.rs +++ b/crates/border-wars/src/lib.rs @@ -5,6 +5,7 @@ use bevy::prelude::*; pub mod camera; pub mod map; pub mod scenes; +pub mod responsive_scale; /// The current scene of the game. #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)] diff --git a/crates/border-wars/src/responsive_scale.rs b/crates/border-wars/src/responsive_scale.rs index 2a501ff..8a322bf 100644 --- a/crates/border-wars/src/responsive_scale.rs +++ b/crates/border-wars/src/responsive_scale.rs @@ -1,4 +1,11 @@ +//! The file that contains the responsive scaling logic. + +use bevy::prelude::*; + +/// The default width of the main node const DEFAULT_WIDTH: f32 = 1280.; + +/// The default height of the main node const DEFAULT_HEIGHT: f32 = 720.; /// Calculates the ui_scale.0 depending on the size of the main node diff --git a/crates/border-wars/src/scenes/mod.rs b/crates/border-wars/src/scenes/mod.rs index dce2e1e..1c6a2b4 100644 --- a/crates/border-wars/src/scenes/mod.rs +++ b/crates/border-wars/src/scenes/mod.rs @@ -3,7 +3,8 @@ use bevy::prelude::*; use bevy_egui::EguiPlugin; -use crate::{change_scaling, CurrentScene}; +use crate::responsive_scale::change_scaling; +use crate::CurrentScene; pub mod lobby; pub mod menu; -- 2.43.4 From 11e4aef80d90b8b6f68f0f5f600cc2a6e458cece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 9 Mar 2024 14:56:51 +0100 Subject: [PATCH 06/10] clarification du main node --- crates/border-wars/src/responsive_scale.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/border-wars/src/responsive_scale.rs b/crates/border-wars/src/responsive_scale.rs index 8a322bf..8f925f3 100644 --- a/crates/border-wars/src/responsive_scale.rs +++ b/crates/border-wars/src/responsive_scale.rs @@ -2,13 +2,13 @@ use bevy::prelude::*; -/// The default width of the main node +/// The default width of the screen const DEFAULT_WIDTH: f32 = 1280.; -/// The default height of the main node +/// The default height of the screen const DEFAULT_HEIGHT: f32 = 720.; -/// Calculates the ui_scale.0 depending on the size of the main node +/// Calculates the ui_scale.0 depending on the default screen size /// in order to make the screen responsive pub fn change_scaling(mut ui_scale: ResMut, window: Query<&Window>) { let window = window.single(); -- 2.43.4 From 31bebd65426fcc843bd59ee99fabc0dd336757e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 9 Mar 2024 15:01:13 +0100 Subject: [PATCH 07/10] adding an expect to the get_single() method --- crates/border-wars/src/responsive_scale.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/border-wars/src/responsive_scale.rs b/crates/border-wars/src/responsive_scale.rs index 8f925f3..1295893 100644 --- a/crates/border-wars/src/responsive_scale.rs +++ b/crates/border-wars/src/responsive_scale.rs @@ -10,8 +10,8 @@ const DEFAULT_HEIGHT: f32 = 720.; /// Calculates the ui_scale.0 depending on the default screen size /// in order to make the screen responsive -pub fn change_scaling(mut ui_scale: ResMut, window: Query<&Window>) { - let window = window.single(); +pub fn change_scaling(mut ui_scale: ResMut, windows: Query<&Window>) { + let window = windows.get_single().expect("Main window not found"); let (a, b) = ( window.resolution.width() / DEFAULT_WIDTH, window.resolution.height() / DEFAULT_HEIGHT, -- 2.43.4 From 66b0cab4fff1668082d978c7cc2ec53dce9678b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 9 Mar 2024 15:28:01 +0100 Subject: [PATCH 08/10] fmt --- crates/border-wars/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/border-wars/src/lib.rs b/crates/border-wars/src/lib.rs index 0911f41..257aefb 100644 --- a/crates/border-wars/src/lib.rs +++ b/crates/border-wars/src/lib.rs @@ -4,8 +4,8 @@ use bevy::prelude::*; pub mod camera; pub mod map; -pub mod scenes; pub mod responsive_scale; +pub mod scenes; /// The current scene of the game. #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)] -- 2.43.4 From ab08b03660e6b83ab582b5f8f27539a2328a65a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 9 Mar 2024 17:37:11 +0100 Subject: [PATCH 09/10] Adding default size in ressource and create a plugin for the responsive scale --- crates/border-wars/src/responsive_scale.rs | 31 +++++++++++++++++----- crates/border-wars/src/scenes/mod.rs | 5 ++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/border-wars/src/responsive_scale.rs b/crates/border-wars/src/responsive_scale.rs index 1295893..be7b882 100644 --- a/crates/border-wars/src/responsive_scale.rs +++ b/crates/border-wars/src/responsive_scale.rs @@ -2,19 +2,36 @@ use bevy::prelude::*; -/// The default width of the screen -const DEFAULT_WIDTH: f32 = 1280.; +/// The plugin for the responsive scaling. +pub struct ResponsiveScalingPlugin; -/// The default height of the screen -const DEFAULT_HEIGHT: f32 = 720.; +impl Plugin for ResponsiveScalingPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, init_window_size); + app.add_systems(Update, change_scaling); + } +} + +#[derive(Resource)] +/// The default window size +pub struct WindowSize(pub Vec2); + +/// Initializes the window size +pub fn init_window_size(mut command: Commands) { + command.insert_resource(WindowSize(Vec2::new(1280., 720.))); +} /// Calculates the ui_scale.0 depending on the default screen size /// in order to make the screen responsive -pub fn change_scaling(mut ui_scale: ResMut, windows: Query<&Window>) { +pub fn change_scaling( + mut ui_scale: ResMut, + windows: Query<&Window>, + size: Res, +) { let window = windows.get_single().expect("Main window not found"); let (a, b) = ( - window.resolution.width() / DEFAULT_WIDTH, - window.resolution.height() / DEFAULT_HEIGHT, + window.resolution.width() / size.0.x, + window.resolution.height() / size.0.y, ); ui_scale.0 = if a < b { a } else { b } as f64 } diff --git a/crates/border-wars/src/scenes/mod.rs b/crates/border-wars/src/scenes/mod.rs index 1c6a2b4..da18601 100644 --- a/crates/border-wars/src/scenes/mod.rs +++ b/crates/border-wars/src/scenes/mod.rs @@ -3,8 +3,7 @@ use bevy::prelude::*; use bevy_egui::EguiPlugin; -use crate::responsive_scale::change_scaling; -use crate::CurrentScene; +use crate::{responsive_scale, CurrentScene}; pub mod lobby; pub mod menu; @@ -18,6 +17,6 @@ impl Plugin for ScenesPlugin { .add_state::() .add_plugins(menu::MenuPlugin) .add_plugins(lobby::LobbyPlugin) - .add_systems(Update, change_scaling); + .add_plugins(responsive_scale::ResponsiveScalingPlugin); } } -- 2.43.4 From 5ea30d3501e3630af7372c8df5c51ce861ba0a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 9 Mar 2024 17:42:14 +0100 Subject: [PATCH 10/10] ajout de points a la fin des phrases --- crates/border-wars/src/responsive_scale.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/border-wars/src/responsive_scale.rs b/crates/border-wars/src/responsive_scale.rs index be7b882..612f016 100644 --- a/crates/border-wars/src/responsive_scale.rs +++ b/crates/border-wars/src/responsive_scale.rs @@ -12,17 +12,17 @@ impl Plugin for ResponsiveScalingPlugin { } } +/// The default window size. #[derive(Resource)] -/// The default window size pub struct WindowSize(pub Vec2); -/// Initializes the window size +/// Initializes the window size. pub fn init_window_size(mut command: Commands) { command.insert_resource(WindowSize(Vec2::new(1280., 720.))); } /// Calculates the ui_scale.0 depending on the default screen size -/// in order to make the screen responsive +/// in order to make the screen responsive. pub fn change_scaling( mut ui_scale: ResMut, windows: Query<&Window>, -- 2.43.4