Skip to content

Commit

Permalink
feat: Tint the sprite color of the aspect icons when deselected
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxTube committed Jul 29, 2024
1 parent f70ba6c commit fa7341f
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/aspect/icon.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{
color::palettes::css::{GRAY, WHITE},
prelude::*,
};
use bevy_tweening::{lens::TransformPositionLens, Animator, EaseFunction, Tween};

use crate::{world::camera::YSortChild, GameAssets};
Expand Down Expand Up @@ -34,18 +37,21 @@ pub fn icon_texture(assets: &Res<GameAssets>, aspect: &Aspect) -> Handle<Image>
}
}

fn set_icon_pos(
fn set_icon_properties(
commands: &mut Commands,
q_icons: &Query<(Entity, &Transform), With<AspectIcon>>,
q_icons: &mut Query<(Entity, &Transform, &mut Sprite), With<AspectIcon>>,
children: &Children,
pos: Vec2,
tint: Color,
) {
for child in children.iter() {
let (entity, transform) = match q_icons.get(*child) {
let (entity, transform, mut sprite) = match q_icons.get_mut(*child) {
Ok(r) => r,
Err(_) => continue,
};

sprite.color = tint;

let tween = Tween::new(
EaseFunction::CubicOut,
std::time::Duration::from_secs_f32(REPOSITION_TIME),
Expand All @@ -58,30 +64,30 @@ fn set_icon_pos(
}
}

fn set_icons_pos(
fn set_icons_properties(
mut commands: Commands,
combiner: Res<Combiner>,
q_sockets: Query<(&Children, &Socket)>,
q_icons: Query<(Entity, &Transform), With<AspectIcon>>,
mut q_icons: Query<(Entity, &Transform, &mut Sprite), With<AspectIcon>>,
) {
for (children, socket) in &q_sockets {
let pos = if combiner.all_sockets_full
let (pos, tint) = if combiner.all_sockets_full
|| socket.on_top
&& combiner.left_aspect.is_some()
&& combiner.left_aspect != Some(socket.aspect)
|| !socket.on_top
&& combiner.right_aspect.is_some()
&& combiner.right_aspect != Some(socket.aspect)
{
DEHIGHLIGHTED_ICON_POSITION
(DEHIGHLIGHTED_ICON_POSITION, GRAY)
} else if socket.on_top && combiner.left_aspect == Some(socket.aspect)
|| !socket.on_top && combiner.right_aspect == Some(socket.aspect)
{
HIGHLIGHTED_ICON_POSITION
(HIGHLIGHTED_ICON_POSITION, WHITE)
} else {
DEFAULT_ICON_POSITION
(DEFAULT_ICON_POSITION, WHITE)
};
set_icon_pos(&mut commands, &q_icons, children, pos);
set_icon_properties(&mut commands, &mut q_icons, children, pos, tint.into());
}
}

Expand All @@ -95,6 +101,6 @@ pub struct AspectIconPlugin;

impl Plugin for AspectIconPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, (set_icons_pos, update_icon_ysorts));
app.add_systems(Update, (set_icons_properties, update_icon_ysorts));
}
}

0 comments on commit fa7341f

Please sign in to comment.