From 2bdc541ed5dda5c7c992674c5af34249c1c13524 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Sat, 13 Jul 2024 11:08:11 -0700 Subject: [PATCH] Move text colors into constants --- src/action_panel.rs | 30 +++++++++++++++++++----------- src/game_over.rs | 11 ++++++----- src/main.rs | 14 ++++++-------- src/typing.rs | 15 +++++++-------- src/ui_color.rs | 6 ++++++ 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/action_panel.rs b/src/action_panel.rs index 04be996..730c0b4 100644 --- a/src/action_panel.rs +++ b/src/action_panel.rs @@ -1,7 +1,4 @@ -use bevy::{ - color::palettes::css::{LIME, RED, WHITE}, - prelude::*, -}; +use bevy::prelude::*; use crate::{ loading::{FontHandles, UiTextureHandles}, @@ -9,7 +6,7 @@ use crate::{ typing::{ TypingTarget, TypingTargetBundle, TypingTargetSettings, TypingTargetText, TypingTargets, }, - ui_color::TRANSPARENT_BACKGROUND, + ui_color::{self, TRANSPARENT_BACKGROUND}, Action, AfterUpdate, Currency, TaipoState, TowerSelection, }; @@ -257,7 +254,7 @@ fn spawn_action_panel_item( style: TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE_ACTION_PANEL, - color: LIME.into(), + color: ui_color::GOOD_TEXT.into(), }, }, TextSection { @@ -265,7 +262,7 @@ fn spawn_action_panel_item( style: TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE_ACTION_PANEL, - color: WHITE.into(), + color: ui_color::NORMAL_TEXT.into(), }, }, ], @@ -371,8 +368,11 @@ fn update_action_panel( for child in children.iter() { if let Ok(mut text) = price_text_query.get_mut(*child) { text.sections[0].value = format!("{}", price); - text.sections[0].style.color = - if disabled { RED.into() } else { WHITE.into() }; + text.sections[0].style.color = if disabled { + ui_color::BAD_TEXT.into() + } else { + ui_color::NORMAL_TEXT.into() + }; } } } @@ -385,8 +385,16 @@ fn update_action_panel( if let Ok((_, target_children)) = typing_target_query.get(*entity) { for target_child in target_children.iter() { if let Ok(mut text) = text_query.get_mut(*target_child) { - text.sections[0].style.color = if disabled { RED.into() } else { LIME.into() }; - text.sections[1].style.color = if disabled { RED.into() } else { WHITE.into() }; + text.sections[0].style.color = if disabled { + ui_color::BAD_TEXT.into() + } else { + ui_color::GOOD_TEXT.into() + }; + text.sections[1].style.color = if disabled { + ui_color::BAD_TEXT.into() + } else { + ui_color::NORMAL_TEXT.into() + }; } } } diff --git a/src/game_over.rs b/src/game_over.rs index 93c526f..27c20b1 100644 --- a/src/game_over.rs +++ b/src/game_over.rs @@ -1,7 +1,4 @@ -use bevy::{ - color::palettes::css::{RED, WHITE}, - prelude::*, -}; +use bevy::prelude::*; use crate::{ enemy::AnimationState, loading::FontHandles, ui_color, wave::Waves, AfterUpdate, Currency, @@ -96,7 +93,11 @@ fn spawn_game_over( TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE, - color: if lost { RED.into() } else { WHITE.into() }, + color: if lost { + ui_color::BAD_TEXT.into() + } else { + ui_color::NORMAL_TEXT.into() + }, }, ) .with_justify(JustifyText::Center), diff --git a/src/main.rs b/src/main.rs index 6a60fe3..d46911f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ use atlas_loader::{AtlasImage, AtlasImageLoader}; use bevy::{ app::MainScheduleOrder, asset::AssetMetaCheck, - color::palettes::css::{LIME, WHITE}, ecs::schedule::ScheduleLabel, prelude::*, text::{update_text2d_layout, TextLayoutInfo, TextSection}, @@ -34,7 +33,6 @@ use crate::{ AsciiModeEvent, TypingPlugin, TypingTarget, TypingTargetBundle, TypingTargetFinishedEvent, TypingTargetSettings, TypingTargetText, TypingTargets, }, - ui_color::TRANSPARENT_BACKGROUND, wave::{Wave, WavePlugin, WaveState, Waves}, }; @@ -360,7 +358,7 @@ fn startup_system( height: Val::Px(42.0), ..default() }, - background_color: TRANSPARENT_BACKGROUND.into(), + background_color: ui_color::TRANSPARENT_BACKGROUND.into(), ..default() }) .with_children(|parent| { @@ -391,7 +389,7 @@ fn startup_system( TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE, - color: Color::WHITE, + color: ui_color::NORMAL_TEXT.into(), }, ), ..default() @@ -425,7 +423,7 @@ fn startup_system( TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE, - color: Color::WHITE, + color: ui_color::NORMAL_TEXT.into(), }, ), ..default() @@ -618,7 +616,7 @@ fn spawn_map_objects( SpriteBundle { transform: label_bg_transform, sprite: Sprite { - color: TRANSPARENT_BACKGROUND.into(), + color: ui_color::TRANSPARENT_BACKGROUND.into(), custom_size: Some(Vec2::new(108.0, FONT_SIZE_LABEL)), ..default() }, @@ -643,7 +641,7 @@ fn spawn_map_objects( style: TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE_LABEL, - color: LIME.into(), + color: ui_color::GOOD_TEXT.into(), }, }, TextSection { @@ -651,7 +649,7 @@ fn spawn_map_objects( style: TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE_LABEL, - color: WHITE.into(), + color: ui_color::NORMAL_TEXT.into(), }, }, ], diff --git a/src/typing.rs b/src/typing.rs index c76b14e..cacb3b4 100644 --- a/src/typing.rs +++ b/src/typing.rs @@ -1,5 +1,4 @@ use bevy::{ - color::palettes::css::{RED, WHITE}, input::keyboard::{Key, KeyCode, KeyboardInput}, prelude::*, }; @@ -7,8 +6,8 @@ use bevy::{ use std::collections::VecDeque; use crate::{ - loading::AudioHandles, ui_color::TRANSPARENT_BACKGROUND, Action, AudioSettings, FontHandles, - TaipoState, FONT_SIZE_INPUT, + loading::AudioHandles, ui_color, Action, AudioSettings, FontHandles, TaipoState, + FONT_SIZE_INPUT, }; pub struct TypingPlugin; @@ -229,7 +228,7 @@ fn startup(mut commands: Commands, font_handles: Res) { bottom: Val::Px(0.), ..default() }, - background_color: TRANSPARENT_BACKGROUND.into(), + background_color: ui_color::TRANSPARENT_BACKGROUND.into(), ..default() }) .with_children(|parent| { @@ -247,7 +246,7 @@ fn startup(mut commands: Commands, font_handles: Res) { TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE_INPUT, - color: WHITE.into(), + color: ui_color::NORMAL_TEXT.into(), }, ), ..default() @@ -259,7 +258,7 @@ fn startup(mut commands: Commands, font_handles: Res) { TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE_INPUT, - color: WHITE.into(), + color: ui_color::NORMAL_TEXT.into(), }, ), ..default() @@ -273,7 +272,7 @@ fn startup(mut commands: Commands, font_handles: Res) { TextStyle { font: font_handles.jptext.clone(), font_size: FONT_SIZE_INPUT, - color: RED.into(), + color: ui_color::CURSOR_TEXT.into(), }, ), ..default() @@ -396,7 +395,7 @@ fn update_cursor_text( if target.sections[0].style.color != Color::NONE { target.sections[0].style.color = Color::NONE; } else { - target.sections[0].style.color = RED.into(); + target.sections[0].style.color = ui_color::CURSOR_TEXT.into(); } } } diff --git a/src/ui_color.rs b/src/ui_color.rs index e683ef9..046ac00 100644 --- a/src/ui_color.rs +++ b/src/ui_color.rs @@ -1,3 +1,4 @@ +use bevy::color::palettes::css::*; use bevy::prelude::Srgba; pub const NORMAL_BUTTON: Srgba = Srgba::rgb(0.20, 0.20, 0.20); @@ -7,3 +8,8 @@ pub const OVERLAY: Srgba = Srgba::new(0.0, 0.0, 0.0, 0.8); pub const TRANSPARENT_BACKGROUND: Srgba = Srgba::new(0.0, 0.0, 0.0, 0.7); pub const DIALOG_BACKGROUND: Srgba = Srgba::rgb(0.0, 0.0, 0.0); pub const BUTTON_TEXT: Srgba = Srgba::rgb(0.9, 0.9, 0.9); + +pub const NORMAL_TEXT: Srgba = WHITE; +pub const GOOD_TEXT: Srgba = LIME; +pub const BAD_TEXT: Srgba = RED; +pub const CURSOR_TEXT: Srgba = LIME;