From ab0b90326e13b537cd51ccb0b8f106ea2be2139c Mon Sep 17 00:00:00 2001 From: CoCo_Sol Date: Sun, 31 Mar 2024 23:47:04 +0200 Subject: [PATCH 1/3] save --- crates/border-wars/src/hover.rs | 38 +++++++++++++++++++++++++++++++++ crates/border-wars/src/lib.rs | 1 + 2 files changed, 39 insertions(+) create mode 100644 crates/border-wars/src/hover.rs diff --git a/crates/border-wars/src/hover.rs b/crates/border-wars/src/hover.rs new file mode 100644 index 0000000..11c0209 --- /dev/null +++ b/crates/border-wars/src/hover.rs @@ -0,0 +1,38 @@ +//! The file that contains the hover logic. + +use bevy::prelude::*; + +/// The plugin for the hover system. +pub struct HoverPlugin; + +impl Plugin for HoverPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Update, hovering); + } +} + +/// A component that stores the hover textures and the original texture. +#[derive(Component, Clone)] +struct HoveredTexture { + /// The original texture. + texture: Handle, + + /// The hovered texture. + hovered_texture: Handle, +} + +/// The system that applies the great texture to the hovered entity. +fn hovering( + mut interaction_query: Query< + (&Interaction, &HoveredTexture, &mut UiImage), + Changed, + >, +) { + for (interaction, textures, mut image) in interaction_query.iter_mut() { + match *interaction { + Interaction::Hovered => image.texture = textures.hovered_texture.clone(), + Interaction::None => image.texture = textures.texture.clone(), + Interaction::Pressed => (), + } + } +} diff --git a/crates/border-wars/src/lib.rs b/crates/border-wars/src/lib.rs index 6f144ae..726dfd0 100644 --- a/crates/border-wars/src/lib.rs +++ b/crates/border-wars/src/lib.rs @@ -6,6 +6,7 @@ use networking::PlayerRank; use serde::{Deserialize, Serialize}; pub mod camera; +pub mod hover; pub mod map; pub mod networking; pub mod responsive_scale; -- 2.43.4 From 61aef28296f949471bfc49438ca02bfbd7800fb8 Mon Sep 17 00:00:00 2001 From: CoCo_Sol Date: Sun, 31 Mar 2024 23:58:22 +0200 Subject: [PATCH 2/3] change doc --- crates/border-wars/src/hover.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/border-wars/src/hover.rs b/crates/border-wars/src/hover.rs index 11c0209..ca6d3bc 100644 --- a/crates/border-wars/src/hover.rs +++ b/crates/border-wars/src/hover.rs @@ -11,7 +11,7 @@ impl Plugin for HoverPlugin { } } -/// A component that stores the hover textures and the original texture. +/// A component that stores the hover texture and the original texture. #[derive(Component, Clone)] struct HoveredTexture { /// The original texture. -- 2.43.4 From c081e36933a6fcf4516c7ff1f9930d1e11b23536 Mon Sep 17 00:00:00 2001 From: CoCo_Sol Date: Sun, 31 Mar 2024 23:59:20 +0200 Subject: [PATCH 3/3] chnage doc again --- crates/border-wars/src/hover.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/border-wars/src/hover.rs b/crates/border-wars/src/hover.rs index ca6d3bc..632dc07 100644 --- a/crates/border-wars/src/hover.rs +++ b/crates/border-wars/src/hover.rs @@ -21,7 +21,7 @@ struct HoveredTexture { hovered_texture: Handle, } -/// The system that applies the great texture to the hovered entity. +/// The system that applies the hover logic by changing the texture. fn hovering( mut interaction_query: Query< (&Interaction, &HoveredTexture, &mut UiImage), -- 2.43.4