Skip to content

Commit

Permalink
Add color palette
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Apr 6, 2024
1 parent 5e191ed commit 68fc3c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
11 changes: 3 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use bevy::prelude::*;

use crate::palette;

// tile
pub const TILE_SIZE: f32 = 100.0;
pub const TILE_SPACING: f32 = 10.0;
Expand All @@ -16,12 +18,5 @@ pub const TILE_SOUND_T: &str = "sounds/letters/t.ogg";
pub const SPLASH_SCREEN_DURATION: f32 = 1.0;

// game/menu screen
pub const WALL_COLOR: Color = Color::rgb(1.0, 1.0, 1.0);
pub const WALL_COLOR: Color = palette::WHITE;
pub const WALL_THICKNESS: f32 = 4.0;

// buttons
pub const NORMAL_BUTTON: Color = Color::rgb(0.16, 0.17, 0.18);
pub const HOVERED_BUTTON: Color = Color::rgb(0.20, 0.21, 0.22);
pub const PRESSED_BUTTON: Color = Color::rgb(1.0, 0.56, 0.0);
pub const BUTTON_BORDER_COLOR: Color = Color::rgb(1.0, 1.0, 1.0);
pub const PRESSED_BUTTON_BORDER_COLOR: Color = Color::rgb(1.0, 1.0, 1.0);
28 changes: 17 additions & 11 deletions src/game/ui/button.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use bevy::prelude::*;

use crate::config;
use crate::palette;

pub const NORMAL_BUTTON: Color = palette::SLATE_800;
pub const HOVERED_BUTTON: Color = palette::PURPLE_400;
pub const PRESSED_BUTTON: Color = palette::PURPLE_500;
pub const BUTTON_BORDER_COLOR: Color = palette::WHITE;
pub const PRESSED_BUTTON_BORDER_COLOR: Color = palette::WHITE;

#[derive(Component)]
pub struct Shortcut(pub KeyCode);
Expand Down Expand Up @@ -39,16 +45,16 @@ fn button_system(
for (interaction, mut color, mut border_color) in &mut query {
match *interaction {
Interaction::Pressed => {
*color = config::PRESSED_BUTTON.into();
border_color.0 = config::BUTTON_BORDER_COLOR;
*color = PRESSED_BUTTON.into();
border_color.0 = BUTTON_BORDER_COLOR;
}
Interaction::Hovered => {
*color = config::HOVERED_BUTTON.into();
border_color.0 = config::BUTTON_BORDER_COLOR;
*color = HOVERED_BUTTON.into();
border_color.0 = BUTTON_BORDER_COLOR;
}
Interaction::None => {
*color = config::NORMAL_BUTTON.into();
border_color.0 = config::BUTTON_BORDER_COLOR;
*color = NORMAL_BUTTON.into();
border_color.0 = BUTTON_BORDER_COLOR;
}
}
}
Expand All @@ -60,13 +66,13 @@ fn button_shortcut_system(
) {
for (mut color, mut border_color, shortcut) in &mut query {
if keyboard_input.pressed(shortcut.0) {
*color = config::PRESSED_BUTTON.into();
border_color.0 = config::PRESSED_BUTTON_BORDER_COLOR;
*color = PRESSED_BUTTON.into();
border_color.0 = PRESSED_BUTTON_BORDER_COLOR;
}

if keyboard_input.just_released(shortcut.0) {
*color = config::NORMAL_BUTTON.into();
border_color.0 = config::BUTTON_BORDER_COLOR;
*color = NORMAL_BUTTON.into();
border_color.0 = BUTTON_BORDER_COLOR;
}
}
}
17 changes: 7 additions & 10 deletions src/game/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts};

use crate::{
config,
state::{AppState, OnGameScreen},
};
use crate::state::{AppState, OnGameScreen};

use self::button::{GameButtonBundle, Shortcut};

Expand Down Expand Up @@ -54,8 +51,8 @@ pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>, settings: R
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
border_color: button::BUTTON_BORDER_COLOR.into(),
background_color: button::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyA),
Expand Down Expand Up @@ -86,8 +83,8 @@ pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>, settings: R
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
border_color: button::BUTTON_BORDER_COLOR.into(),
background_color: button::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyS),
Expand Down Expand Up @@ -118,8 +115,8 @@ pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>, settings: R
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
border_color: button::BUTTON_BORDER_COLOR.into(),
background_color: button::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyD),
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use bevy_asset_loader::loading_state::{
use bevy_egui::EguiPlugin;
use bevy_kira_audio::AudioPlugin;
use nback::{
asset::AudioAssets, game::GamePlugin, menu::MenuPlugin, splash::SplashPlugin, state::AppState,
asset::AudioAssets, game::GamePlugin, menu::MenuPlugin, palette, splash::SplashPlugin,
state::AppState,
};

fn main() {
Expand All @@ -16,6 +17,7 @@ fn main() {
.continue_to_state(AppState::Menu)
.load_collection::<AudioAssets>(),
)
.insert_resource(ClearColor(palette::SLATE_800))
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(1280., 720.),
Expand Down

0 comments on commit 68fc3c4

Please sign in to comment.