Skip to content

Commit

Permalink
Refactor + add title screen configs
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 3, 2023
1 parent 97148d0 commit 3d7f890
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 99 deletions.
21 changes: 19 additions & 2 deletions assets/config.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
(
window_mode: Windowed,
present_mode: AutoVsync,
fg_color: Rgba(red: 0.925, green: 0.925, blue: 0.925, alpha: 1.0),
bg_color: Rgba(red: 0.157, green: 0.157, blue: 0.157, alpha: 1.0),

title_screen: TitleScreenConfig(
text_color: Rgba(red: 0.149, green: 0.149, blue: 0.149, alpha: 1.000),
border_color: Rgba(red: 0.510, green: 0.612, blue: 0.769, alpha: 1.000),
border_width: VMin(1.0),
background_color: Rgba(red: 0.580, green: 0.682, blue: 0.839, alpha: 1.000),

title_background_color: Rgba(red: 0.549, green: 0.647, blue: 0.796, alpha: 1.000),
title_font_size: Vw(4.5),

body_font_size: Vw(2.2),

button_text_color: Rgba(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000),
button_font_size: Vw(4.5),
button_border_color: Rgba(red: 0.118, green: 0.306, blue: 0.820, alpha: 1.000),
button_normal_color: Rgba(red: 0.000, green: 0.188, blue: 0.702, alpha: 1.000),
button_hovered_color: Rgba(red: 0.039, green: 0.227, blue: 0.741, alpha: 1.000),
button_pressed_color: Rgba(red: 0.000, green: 0.176, blue: 0.690, alpha: 1.000),
),
)
21 changes: 10 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use serde::Deserialize;
use serde::Serialize;
use tap::TapFallible;

use crate::state::title_screen::TitleScreenConfig;

pub struct ConfigPlugin;

impl Plugin for ConfigPlugin {
Expand Down Expand Up @@ -50,9 +52,11 @@ const WINDOW_TITLE: &str = "bevy_jam4";
pub struct Config {
pub window_mode: WindowMode,
pub present_mode: PresentMode,
// TODO: Color palette
pub fg_color: Color,
pub bg_color: Color,
//pub splash_screen: SplashScreenConfig,
pub title_screen: TitleScreenConfig,
//pub loading_screen: LoadingScreenConfig,
//pub editor_screen: EditorScreenConfig,
//pub end_screen: EndScreenConfig,
// TODO: Volume
// TODO: Mute when out of focus
// TODO: Keybindings
Expand All @@ -63,23 +67,18 @@ impl Default for Config {
Self {
window_mode: WindowMode::BorderlessFullscreen,
present_mode: PresentMode::AutoVsync,
fg_color: Color::WHITE,
bg_color: Color::BLACK,
title_screen: default(),
}
}
}

fn apply_config(
config: Res<Config>,
mut clear_color: ResMut<ClearColor>,
mut window_query: Query<&mut Window, With<PrimaryWindow>>,
) {
fn apply_config(config: Res<Config>, mut window_query: Query<&mut Window, With<PrimaryWindow>>) {
info!("Applying config");

if let Ok(mut window) = window_query.get_single_mut() {
window.mode = config.window_mode;
window.present_mode = config.present_mode;
}

clear_color.0 = config.bg_color;
// TODO: Implement the rest (not important for game jam)
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Plugin for AppPlugin {
app.add_plugins(debug::DebugPlugin {
ambiguity_detection: false,
//editor: false,
start: state::AppState::Game,
//start: state::AppState::EditorScreen,
..default()
});
}
Expand Down
14 changes: 7 additions & 7 deletions src/state/mod.rs → src/state.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod end_screen;
mod game;
mod loading_screen;
mod splash_screen;
mod title_screen;
pub mod editor_screen;
pub mod end_screen;
pub mod loading_screen;
pub mod splash_screen;
pub mod title_screen;

use bevy::prelude::*;
use strum::EnumIter;
Expand All @@ -15,7 +15,7 @@ impl Plugin for StatePlugin {
splash_screen::SplashScreenStatePlugin,
title_screen::TitleScreenStatePlugin,
loading_screen::LoadingScreenStatePlugin,
game::GameStatePlugin,
editor_screen::EditorScreenStatePlugin,
end_screen::EndScreenStatePlugin,
));
}
Expand All @@ -27,6 +27,6 @@ pub enum AppState {
SplashScreen,
TitleScreen,
LoadingScreen,
Game,
EditorScreen,
EndScreen,
}
22 changes: 11 additions & 11 deletions src/state/game.rs → src/state/editor_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ mod code_view;
mod entity_view;
mod systems_view;

pub struct GameStatePlugin;
pub struct EditorScreenStatePlugin;

impl Plugin for GameStatePlugin {
impl Plugin for EditorScreenStatePlugin {
fn build(&self, app: &mut App) {
app.register_type::<GameAssets>()
.init_collection::<GameAssets>()
.add_systems(OnEnter(Game), enter_game)
.add_systems(OnExit(Game), exit_game)
app.register_type::<EditorScreenAssets>()
.init_collection::<EditorScreenAssets>()
.add_systems(OnEnter(EditorScreen), enter_editor_screen)
.add_systems(OnExit(EditorScreen), exit_editor_screen)
.add_systems(
Update,
(
Expand All @@ -26,7 +26,7 @@ impl Plugin for GameStatePlugin {
entity_view::update_bar,
systems_view::button_color_system,
)
.run_if(in_state(Game)),
.run_if(in_state(EditorScreen)),
);
}
}
Expand All @@ -50,16 +50,16 @@ const SYSTEMS_VIEW_WIDTH: f32 = 25.0;

#[derive(AssetCollection, Resource, Reflect, Default)]
#[reflect(Resource)]
pub struct GameAssets {}
pub struct EditorScreenAssets {}

fn enter_game(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>) {
commands.insert_resource(ClearColor(config.bg_color));
fn enter_editor_screen(mut commands: Commands, root: Res<AppRoot>, _config: Res<Config>) {
commands.insert_resource(ClearColor(Color::BLACK));
code_view::init(&mut commands, &root);
entity_view::init(&mut commands, &root);
systems_view::init(&mut commands, &root);
}

fn exit_game(root: Res<AppRoot>, mut transform_query: Query<&mut Transform>) {
fn exit_editor_screen(root: Res<AppRoot>, mut transform_query: Query<&mut Transform>) {
let Ok(mut transform) = transform_query.get_mut(root.camera) else {
return;
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/state/end_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub struct EndScreenAssets {
// TODO: Music / SFX maybe
}

fn enter_end_screen(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>) {
commands.insert_resource(ClearColor(config.bg_color));
fn enter_end_screen(mut commands: Commands, root: Res<AppRoot>, _config: Res<Config>) {
commands.insert_resource(ClearColor(Color::BLACK));

let screen = commands
.spawn((
Expand Down
14 changes: 7 additions & 7 deletions src/state/loading_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_asset_loader::prelude::*;
use iyes_progress::prelude::*;

use crate::config::Config;
use crate::state::game::GameAssets;
use crate::state::editor_screen::EditorScreenAssets;
use crate::state::AppState::*;
use crate::ui::BOLD_FONT_HANDLE;
use crate::AppRoot;
Expand All @@ -15,8 +15,8 @@ impl Plugin for LoadingScreenStatePlugin {
fn build(&self, app: &mut App) {
app.register_type::<IsLoadingBarFill>()
.add_loading_state(LoadingState::new(LoadingScreen))
.add_collection_to_loading_state::<_, GameAssets>(LoadingScreen)
.add_plugins(ProgressPlugin::new(LoadingScreen).continue_to(Game))
.add_collection_to_loading_state::<_, EditorScreenAssets>(LoadingScreen)
.add_plugins(ProgressPlugin::new(LoadingScreen).continue_to(EditorScreen))
.add_systems(OnEnter(LoadingScreen), enter_loading)
.add_systems(OnExit(LoadingScreen), exit_loading)
.add_systems(
Expand All @@ -31,8 +31,8 @@ impl Plugin for LoadingScreenStatePlugin {
#[derive(Component, Reflect)]
struct IsLoadingBarFill;

fn enter_loading(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>) {
commands.insert_resource(ClearColor(config.bg_color));
fn enter_loading(mut commands: Commands, root: Res<AppRoot>, _config: Res<Config>) {
commands.insert_resource(ClearColor(Color::BLACK));

let screen = commands
.spawn((
Expand Down Expand Up @@ -78,7 +78,7 @@ fn enter_loading(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>
TextStyle {
font: BOLD_FONT_HANDLE,
font_size: 64.0,
color: config.fg_color,
color: Color::WHITE,
},
),
..default()
Expand All @@ -101,7 +101,7 @@ fn enter_loading(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>
commands.spawn((
Name::new("LoadingBarFill"),
NodeBundle {
background_color: BackgroundColor(config.fg_color),
background_color: BackgroundColor(Color::WHITE),
style: Style {
width: Val::Percent(0.0),
height: Val::Percent(100.0),
Expand Down
6 changes: 3 additions & 3 deletions src/state/splash_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ struct SplashScreenStartTime(f64);
fn enter_splash_screen(
mut commands: Commands,
root: Res<AppRoot>,
config: Res<Config>,
_config: Res<Config>,
time: Res<Time>,
) {
commands.insert_resource(ClearColor(config.bg_color));
commands.insert_resource(ClearColor(Color::BLACK));

commands.insert_resource(SplashScreenStartTime(time.elapsed_seconds_f64()));

Expand Down Expand Up @@ -93,7 +93,7 @@ fn enter_splash_screen(
image: UiImage::new(SPLASH_SCREEN_IMAGE_HANDLE),
..default()
},
SplashImageFadeInOut(config.fg_color),
SplashImageFadeInOut(Color::WHITE),
))
.set_parent(screen);
}
Expand Down
Loading

0 comments on commit 3d7f890

Please sign in to comment.