Toggle fullscreen
This commit is contained in:
parent
8c26fa7eb8
commit
985799e509
2 changed files with 26 additions and 2 deletions
26
src/main.rs
26
src/main.rs
|
@ -1,5 +1,6 @@
|
||||||
use bevy::audio::{AudioPlugin, SpatialScale};
|
use bevy::audio::{AudioPlugin, SpatialScale};
|
||||||
use bevy::prelude::{default, *};
|
use bevy::prelude::{default, *};
|
||||||
|
use bevy::window::{PrimaryWindow, WindowMode};
|
||||||
|
|
||||||
mod assets;
|
mod assets;
|
||||||
mod camera;
|
mod camera;
|
||||||
|
@ -62,6 +63,7 @@ fn main() {
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
|
global_hotkeys,
|
||||||
(
|
(
|
||||||
player::sprite_select,
|
player::sprite_select,
|
||||||
player::controls,
|
player::controls,
|
||||||
|
@ -79,7 +81,7 @@ fn main() {
|
||||||
.run_if(in_state(View::MainMenu)),
|
.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 {
|
.insert_resource(AmbientLight {
|
||||||
color: Color::rgb(1., 1., 1.),
|
color: Color::rgb(1., 1., 1.),
|
||||||
brightness: 1.,
|
brightness: 1.,
|
||||||
|
@ -87,3 +89,25 @@ fn main() {
|
||||||
|
|
||||||
app.run()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub fn startup(mut commands: Commands, assets: Res<AssetLoader>) {
|
||||||
// text
|
// text
|
||||||
parent.spawn((
|
parent.spawn((
|
||||||
TextBundle::from_section(
|
TextBundle::from_section(
|
||||||
"Text Example",
|
"Text Example\nPress ENTER to play",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
font: assets.fonts.iosevkalytemin.clone(),
|
font: assets.fonts.iosevkalytemin.clone(),
|
||||||
font_size: 30.0,
|
font_size: 30.0,
|
||||||
|
|
Loading…
Reference in a new issue