From 985799e5093193e69b1b4c86156b1d3a45f982a6 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Mon, 29 Jul 2024 16:36:16 -0500 Subject: [PATCH] Toggle fullscreen --- src/main.rs | 26 +++++++++++++++++++++++++- src/main_menu.rs | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index c3b436c..37dec24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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>, + mut window: Query<&mut Window, With>, + mut app_exit_events: ResMut>, +) { + 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) { + if window.mode == WindowMode::Windowed { + window.mode = WindowMode::BorderlessFullscreen + } else { + window.mode = WindowMode::Windowed + } +} diff --git a/src/main_menu.rs b/src/main_menu.rs index ca8fa15..9135061 100644 --- a/src/main_menu.rs +++ b/src/main_menu.rs @@ -23,7 +23,7 @@ pub fn startup(mut commands: Commands, assets: Res) { // text parent.spawn(( TextBundle::from_section( - "Text Example", + "Text Example\nPress ENTER to play", TextStyle { font: assets.fonts.iosevkalytemin.clone(), font_size: 30.0,