Skip to content

Commit

Permalink
Finish Implementing Input Settings Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Jul 16, 2022
1 parent 810196c commit a523a54
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 45 deletions.
4 changes: 3 additions & 1 deletion assets/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ main-menu = Main Menu
# Settings Menu
controls = Controls
sound = Sound
reset = Reset
# Controls
action = Action
Expand All @@ -28,4 +29,5 @@ move-left = Move Left
move-right = Move Right
flop-attack = Flop Attack
shoot = Shoot
throw = Throw
throw = Throw
bind-input = Make an input to bind or press Escape to cancel.
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use enemy::*;
use input::MenuAction;
use iyes_loopless::prelude::*;
use leafwing_input_manager::prelude::*;
use platform::Storage;
use player::*;
use rand::{seq::SliceRandom, Rng};

Expand Down Expand Up @@ -61,6 +62,7 @@ use crate::{
attack::{attack_cleanup, attack_tick},
config::EngineConfig,
input::PlayerAction,
metadata::Settings,
};

#[cfg_attr(feature = "debug", derive(bevy_inspector_egui::Inspectable))]
Expand Down Expand Up @@ -199,6 +201,7 @@ fn main() {
.add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
.add_plugin(InputManagerPlugin::<PlayerAction>::default())
.add_plugin(InputManagerPlugin::<MenuAction>::default())
.insert_resource(ToggleActions::<MenuAction>::default())
.add_plugin(AttackPlugin)
.add_plugin(AnimationPlugin)
.add_plugin(StatePlugin)
Expand Down Expand Up @@ -325,6 +328,7 @@ fn load_level(
asset_server: Res<AssetServer>,
game: Res<GameMeta>,
windows: Res<Windows>,
mut storage: ResMut<Storage>,
) {
if let Some(level) = assets.get(level_handle.clone_weak()) {
debug!("Loaded level");
Expand All @@ -340,7 +344,12 @@ fn load_level(

// Spawn the players
for (i, player) in level.players.iter().enumerate() {
commands.spawn_bundle(PlayerBundle::new(player, i, &game));
commands.spawn_bundle(PlayerBundle::new(
player,
i,
&game,
storage.get(Settings::STORAGE_KEY).as_ref(),
));
}

// Spawn the enemies
Expand Down
13 changes: 9 additions & 4 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
animation::Facing,
consts,
input::PlayerAction,
metadata::{FighterMeta, FighterSpawnMeta, GameMeta},
metadata::{FighterMeta, FighterSpawnMeta, GameMeta, Settings},
};

#[derive(Component)]
Expand All @@ -23,7 +23,12 @@ pub struct PlayerBundle {
}

impl PlayerBundle {
pub fn new(player_meta: &FighterSpawnMeta, player_i: usize, game_meta: &GameMeta) -> Self {
pub fn new(
player_meta: &FighterSpawnMeta,
player_i: usize,
game_meta: &GameMeta,
settings: Option<&Settings>,
) -> Self {
let ground_offset = Vec3::new(0.0, consts::GROUND_Y, 0.0);
let player_pos = player_meta.location + ground_offset;

Expand All @@ -33,8 +38,8 @@ impl PlayerBundle {
let fighter_handle = player_meta.fighter_handle.clone();

let input_manager_bundle = InputManagerBundle {
input_map: game_meta
.default_settings
input_map: settings
.unwrap_or(&game_meta.default_settings)
.player_controls
.get_input_map(player_i),
..default()
Expand Down
7 changes: 6 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{prelude::*, utils::HashMap, window::WindowId};
use bevy_egui::{egui, EguiContext, EguiInput, EguiPlugin, EguiSettings};
use iyes_loopless::prelude::*;
use leafwing_input_manager::prelude::ActionState;
use leafwing_input_manager::{plugin::ToggleActions, prelude::ActionState};

use crate::{assets::EguiFont, input::MenuAction, metadata::GameMeta, GameState};

Expand Down Expand Up @@ -116,13 +116,18 @@ impl<'a> WidgetAdjacencyEntry<'a> {
fn handle_menu_input(
mut windows: ResMut<Windows>,
input: Query<&ActionState<MenuAction>>,
input_toggle: Res<ToggleActions<MenuAction>>,
mut egui_inputs: ResMut<HashMap<WindowId, EguiInput>>,
adjacencies: Res<WidgetAdjacencies>,
mut egui_ctx: ResMut<EguiContext>,
) {
use bevy::window::WindowMode;
let input = input.single();

if !input_toggle.enabled {
return;
}

// Handle fullscreen toggling
if input.just_pressed(MenuAction::ToggleFullscreen) {
if let Some(window) = windows.get_primary_mut() {
Expand Down
Loading

0 comments on commit a523a54

Please sign in to comment.