Skip to content

Commit

Permalink
Move text colors into constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett committed Jul 13, 2024
1 parent 767d076 commit 2bdc541
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
30 changes: 19 additions & 11 deletions src/action_panel.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use bevy::{
color::palettes::css::{LIME, RED, WHITE},
prelude::*,
};
use bevy::prelude::*;

use crate::{
loading::{FontHandles, UiTextureHandles},
tower::{TowerKind, TowerState, TowerStats, TOWER_PRICE},
typing::{
TypingTarget, TypingTargetBundle, TypingTargetSettings, TypingTargetText, TypingTargets,
},
ui_color::TRANSPARENT_BACKGROUND,
ui_color::{self, TRANSPARENT_BACKGROUND},
Action, AfterUpdate, Currency, TaipoState, TowerSelection,
};

Expand Down Expand Up @@ -257,15 +254,15 @@ 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 {
value: item.target.displayed_chunks.join(""),
style: TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_ACTION_PANEL,
color: WHITE.into(),
color: ui_color::NORMAL_TEXT.into(),
},
},
],
Expand Down Expand Up @@ -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()
};
}
}
}
Expand All @@ -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()
};
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/game_over.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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),
Expand Down
14 changes: 6 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -34,7 +33,6 @@ use crate::{
AsciiModeEvent, TypingPlugin, TypingTarget, TypingTargetBundle, TypingTargetFinishedEvent,
TypingTargetSettings, TypingTargetText, TypingTargets,
},
ui_color::TRANSPARENT_BACKGROUND,
wave::{Wave, WavePlugin, WaveState, Waves},
};

Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
},
Expand All @@ -643,15 +641,15 @@ 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 {
value: target.displayed_chunks.join(""),
style: TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_LABEL,
color: WHITE.into(),
color: ui_color::NORMAL_TEXT.into(),
},
},
],
Expand Down
15 changes: 7 additions & 8 deletions src/typing.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use bevy::{
color::palettes::css::{RED, WHITE},
input::keyboard::{Key, KeyCode, KeyboardInput},
prelude::*,
};

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;
Expand Down Expand Up @@ -229,7 +228,7 @@ fn startup(mut commands: Commands, font_handles: Res<FontHandles>) {
bottom: Val::Px(0.),
..default()
},
background_color: TRANSPARENT_BACKGROUND.into(),
background_color: ui_color::TRANSPARENT_BACKGROUND.into(),
..default()
})
.with_children(|parent| {
Expand All @@ -247,7 +246,7 @@ fn startup(mut commands: Commands, font_handles: Res<FontHandles>) {
TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_INPUT,
color: WHITE.into(),
color: ui_color::NORMAL_TEXT.into(),
},
),
..default()
Expand All @@ -259,7 +258,7 @@ fn startup(mut commands: Commands, font_handles: Res<FontHandles>) {
TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_INPUT,
color: WHITE.into(),
color: ui_color::NORMAL_TEXT.into(),
},
),
..default()
Expand All @@ -273,7 +272,7 @@ fn startup(mut commands: Commands, font_handles: Res<FontHandles>) {
TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_INPUT,
color: RED.into(),
color: ui_color::CURSOR_TEXT.into(),
},
),
..default()
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/ui_color.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;

0 comments on commit 2bdc541

Please sign in to comment.