From fa7341fa234c2c4aedbd9a79c1870af74155de94 Mon Sep 17 00:00:00 2001 From: Rancic Date: Mon, 29 Jul 2024 15:10:21 +0200 Subject: [PATCH] feat: Tint the sprite color of the aspect icons when deselected --- src/aspect/icon.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/aspect/icon.rs b/src/aspect/icon.rs index 2795737..107458c 100644 --- a/src/aspect/icon.rs +++ b/src/aspect/icon.rs @@ -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}; @@ -34,18 +37,21 @@ pub fn icon_texture(assets: &Res, aspect: &Aspect) -> Handle } } -fn set_icon_pos( +fn set_icon_properties( commands: &mut Commands, - q_icons: &Query<(Entity, &Transform), With>, + q_icons: &mut Query<(Entity, &Transform, &mut Sprite), With>, 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), @@ -58,14 +64,14 @@ fn set_icon_pos( } } -fn set_icons_pos( +fn set_icons_properties( mut commands: Commands, combiner: Res, q_sockets: Query<(&Children, &Socket)>, - q_icons: Query<(Entity, &Transform), With>, + mut q_icons: Query<(Entity, &Transform, &mut Sprite), With>, ) { 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) @@ -73,15 +79,15 @@ fn set_icons_pos( && 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()); } } @@ -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)); } }