Skip to content

Commit

Permalink
fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Nov 14, 2024
1 parent 4c4b52e commit c8bdbdf
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct GameConfig {
pub se_volume: f32,
pub player_name: String,
pub language: Languages,
pub fullscreen: bool,
}

impl Default for GameConfig {
Expand All @@ -20,6 +21,7 @@ impl Default for GameConfig {
se_volume: 0.8,
player_name: "".to_string(),
language: Languages::Ja,
fullscreen: false,
}
}
}
Expand Down
71 changes: 71 additions & 0 deletions src/ui/pause_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::world::NextLevel;
use crate::{asset::GameAssets, states::GameState};
use bevy::ecs::system::SystemId;
use bevy::prelude::*;
use bevy::window::WindowMode;
use bevy_rapier2d::plugin::{PhysicsSet, RapierConfiguration};
use bevy_simple_websocket::ClientMessage;

Expand All @@ -25,6 +26,8 @@ struct ButtonShots {
se_volume_down: SystemId,
ja: SystemId,
en: SystemId,
fullscreen_on: SystemId,
fullscreen_off: SystemId,
wait: i32,
}

Expand All @@ -48,6 +51,8 @@ impl FromWorld for ButtonShots {
se_volume_down: world.register_system(se_volume_down),
ja: world.register_system(ja),
en: world.register_system(en),
fullscreen_on: world.register_system(fullscreen_on),
fullscreen_off: world.register_system(fullscreen_off),
wait: 0,
}
}
Expand Down Expand Up @@ -104,6 +109,28 @@ fn en(mut config: ResMut<GameConfig>, mut writer: EventWriter<GameCommand>) {
writer.send(GameCommand::SEKettei(None));
}

fn fullscreen_on(
mut config: ResMut<GameConfig>,
mut writer: EventWriter<GameCommand>,
mut window_query: Query<&mut Window>,
) {
let mut window = window_query.single_mut();
window.mode = WindowMode::SizedFullscreen;
writer.send(GameCommand::SEKettei(None));
config.fullscreen = true;
}

fn fullscreen_off(
mut config: ResMut<GameConfig>,
mut writer: EventWriter<GameCommand>,
mut window_query: Query<&mut Window>,
) {
let mut window = window_query.single_mut();
window.mode = WindowMode::Windowed;
writer.send(GameCommand::SEKettei(None));
config.fullscreen = false;
}

fn setup_game_menu(
mut commands: Commands,
assets: Res<GameAssets>,
Expand Down Expand Up @@ -198,6 +225,50 @@ fn setup_game_menu(
);
});

#[cfg(not(target_arch = "wasm32"))]
parent
.spawn(NodeBundle {
style: Style {
column_gap: Val::Px(4.0),
align_items: AlignItems::Center,
..default()
},
..default()
})
.with_children(|parent| {
spawn_label(
parent,
&assets,
Dict {
ja: "フルスクリーン",
en: "Full Screen",
},
);

menu_button(
parent,
&assets,
shots.fullscreen_on,
80.0,
40.0,
Dict {
ja: "オン",
en: "On",
},
);
menu_button(
parent,
&assets,
shots.fullscreen_off,
80.0,
40.0,
Dict {
ja: "オフ",
en: "Off",
},
);
});

spawn_range(
parent,
&assets,
Expand Down

0 comments on commit c8bdbdf

Please sign in to comment.