From 4de552167d349bfcd8cdac78dfb532ffc0fdca35 Mon Sep 17 00:00:00 2001 From: Trevor Settles Date: Fri, 13 Oct 2023 20:11:09 -0600 Subject: [PATCH] dev: moved settings to new file --- game/src/lib.rs | 58 +-------------------------------------- game/src/settings_page.rs | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 57 deletions(-) create mode 100644 game/src/settings_page.rs diff --git a/game/src/lib.rs b/game/src/lib.rs index c94e455..73533eb 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -2,6 +2,7 @@ use bevy::prelude::*; pub mod classes; pub mod main_menu; +pub mod settings_page; pub struct BasePlugin; impl Plugin for BasePlugin { @@ -41,60 +42,3 @@ enum GameState { MainMenu, Settings, } - -pub mod settings_page { - use bevy::prelude::*; - use bevy_ui_dsl::*; - - use crate::{classes::*, *}; - - pub struct SettingsPlugin; - impl Plugin for SettingsPlugin { - fn build(&self, app: &mut App) { - app.add_systems(OnEnter(GameState::Settings), draw_settings) - .add_systems( - Update, - (button_actions, button_interaction::) - .run_if(in_state(GameState::Settings)), - ) - .add_systems(OnExit(GameState::Settings), teardown::); - } - } - - fn draw_settings(mut commands: Commands, assets: Res) { - rooti( - (c_background, c_centers), - &assets, - &mut commands, - OnSettings, - |p| { - node((), p, |p| { - buttoni(c_button, SettingsButton::Back, p, |p| { - text("Back", (), c_button_text, p); - }); - }); - }, - ); - } - - fn button_actions( - query: Query<(&Interaction, &SettingsButton), Changed>, - mut state: ResMut>, - ) { - for (interaction, button) in &query { - if interaction == &Interaction::Pressed { - match button { - SettingsButton::Back => state.set(GameState::MainMenu), - } - } - } - } - - #[derive(Component)] - enum SettingsButton { - Back, - } - - #[derive(Component)] - struct OnSettings; -} diff --git a/game/src/settings_page.rs b/game/src/settings_page.rs new file mode 100644 index 0000000..6db1a7c --- /dev/null +++ b/game/src/settings_page.rs @@ -0,0 +1,54 @@ +use bevy::prelude::*; +use bevy_ui_dsl::*; + +use crate::{classes::*, *}; + +pub struct SettingsPlugin; +impl Plugin for SettingsPlugin { + fn build(&self, app: &mut App) { + app.add_systems(OnEnter(GameState::Settings), draw_settings) + .add_systems( + Update, + (button_actions, button_interaction::) + .run_if(in_state(GameState::Settings)), + ) + .add_systems(OnExit(GameState::Settings), teardown::); + } +} + +fn draw_settings(mut commands: Commands, assets: Res) { + rooti( + (c_background, c_centers), + &assets, + &mut commands, + OnSettings, + |p| { + node((), p, |p| { + buttoni(c_button, SettingsButton::Back, p, |p| { + text("Back", (), c_button_text, p); + }); + }); + }, + ); +} + +fn button_actions( + query: Query<(&Interaction, &SettingsButton), Changed>, + mut state: ResMut>, +) { + for (interaction, button) in &query { + if interaction == &Interaction::Pressed { + match button { + SettingsButton::Back => state.set(GameState::MainMenu), + } + } + } +} + +#[derive(Component)] +enum SettingsButton { + Back, +} + +#[derive(Component)] +struct OnSettings;