Toggle fullscreen

This commit is contained in:
Daniel Flanagan 2024-07-29 16:36:16 -05:00
parent 8c26fa7eb8
commit 985799e509
2 changed files with 26 additions and 2 deletions

View file

@ -1,5 +1,6 @@
use bevy::audio::{AudioPlugin, SpatialScale};
use bevy::prelude::{default, *};
use bevy::window::{PrimaryWindow, WindowMode};
mod assets;
mod camera;
@ -62,6 +63,7 @@ fn main() {
.add_systems(
Update,
(
global_hotkeys,
(
player::sprite_select,
player::controls,
@ -79,7 +81,7 @@ fn main() {
.run_if(in_state(View::MainMenu)),
),
)
.insert_resource(ClearColor(Color::rgb(0.1, 0.1, 0.1)))
.insert_resource(ClearColor(Color::rgb(0.3, 0.1, 0.5)))
.insert_resource(AmbientLight {
color: Color::rgb(1., 1., 1.),
brightness: 1.,
@ -87,3 +89,25 @@ fn main() {
app.run()
}
fn global_hotkeys(
keyboard: Res<ButtonInput<KeyCode>>,
mut window: Query<&mut Window, With<PrimaryWindow>>,
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
) {
if keyboard.just_pressed(KeyCode::Enter)
&& (keyboard.pressed(KeyCode::AltLeft) || keyboard.pressed(KeyCode::AltRight))
{
if let Ok(window) = window.get_single_mut() {
toggle_fullscreen(window)
}
}
}
fn toggle_fullscreen(mut window: Mut<Window>) {
if window.mode == WindowMode::Windowed {
window.mode = WindowMode::BorderlessFullscreen
} else {
window.mode = WindowMode::Windowed
}
}

View file

@ -23,7 +23,7 @@ pub fn startup(mut commands: Commands, assets: Res<AssetLoader>) {
// text
parent.spawn((
TextBundle::from_section(
"Text Example",
"Text Example\nPress ENTER to play",
TextStyle {
font: assets.fonts.iosevkalytemin.clone(),
font_size: 30.0,