-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scale factor option for configuring video resolution.
- Loading branch information
Showing
7 changed files
with
218 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
body { | ||
width: 100vw; | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ pub enum AppState { | |
GameModeMenu, | ||
LevelMenu, | ||
Game, | ||
ChangeScale, | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use bevy::prelude::*; | ||
use num_traits::FromPrimitive; | ||
|
||
use crate::{ | ||
app_state::AppState, game::transform::GameTransform, | ||
game_option_menu::transform::GameOptionMenuTransform, | ||
level_menu::transform::LevelMenuTransform, splash::transform::SplashTransform, | ||
}; | ||
|
||
pub fn setup(app: &mut App) { | ||
app.insert_resource(ScaleFactor::default()) | ||
.add_systems(OnEnter(AppState::ChangeScale), change_scale_system); | ||
} | ||
|
||
#[derive(Default, Clone, Copy, FromPrimitive, Resource)] | ||
pub enum ScaleFactor { | ||
S720 = 0, | ||
#[default] | ||
S1080, | ||
S1440, | ||
S1800, | ||
S2160, | ||
S3240, | ||
S4320, | ||
} | ||
|
||
impl ScaleFactor { | ||
pub fn mul(&self) -> f32 { | ||
let base = 1080.0; | ||
|
||
match self { | ||
ScaleFactor::S720 => 720.0 / base, | ||
ScaleFactor::S1080 => 1080.0 / base, | ||
ScaleFactor::S1440 => 1440.0 / base, | ||
ScaleFactor::S1800 => 1800.0 / base, | ||
ScaleFactor::S2160 => 2160.0 / base, | ||
ScaleFactor::S3240 => 3240.0 / base, | ||
ScaleFactor::S4320 => 4320.0 / base, | ||
} | ||
} | ||
|
||
pub fn prev(&mut self) -> Option<Self> { | ||
FromPrimitive::from_i8(*self as i8 - 1).map(|n| std::mem::replace(self, n)) | ||
} | ||
|
||
pub fn next(&mut self) -> Option<Self> { | ||
FromPrimitive::from_i8(*self as i8 + 1).map(|n| std::mem::replace(self, n)) | ||
} | ||
} | ||
|
||
fn change_scale_system( | ||
scale_factor: Res<ScaleFactor>, | ||
mut splash_transform: ResMut<SplashTransform>, | ||
mut game_option_menu_transform: ResMut<GameOptionMenuTransform>, | ||
mut level_menu_transform: ResMut<LevelMenuTransform>, | ||
mut game_transform: ResMut<GameTransform>, | ||
mut app_state: ResMut<NextState<AppState>>, | ||
) { | ||
*splash_transform = SplashTransform::new(scale_factor.mul()); | ||
*game_option_menu_transform = GameOptionMenuTransform::new(scale_factor.mul()); | ||
*level_menu_transform = LevelMenuTransform::new(scale_factor.mul()); | ||
*game_transform = GameTransform::new(scale_factor.mul()); | ||
|
||
app_state.set(AppState::GameModeMenu); | ||
} |