generated from tipragot/rust
Add a generic hover system (#93)
All checks were successful
Rust Checks / checks (push) Successful in 2m6s
All checks were successful
Rust Checks / checks (push) Successful in 2m6s
Reviewed-on: fish-canard/border-wars#93 Reviewed-by: Raphaël <r.lauray@outlook.fr> Co-authored-by: CoCo_Sol <solois.corentin@gmail.com> Co-committed-by: CoCo_Sol <solois.corentin@gmail.com>
This commit is contained in:
parent
949356449c
commit
d431bd3734
38
crates/border-wars/src/hover.rs
Normal file
38
crates/border-wars/src/hover.rs
Normal file
|
@ -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 texture and the original texture.
|
||||
#[derive(Component, Clone)]
|
||||
struct HoveredTexture {
|
||||
/// The original texture.
|
||||
texture: Handle<Image>,
|
||||
|
||||
/// The hovered texture.
|
||||
hovered_texture: Handle<Image>,
|
||||
}
|
||||
|
||||
/// The system that applies the hover logic by changing the texture.
|
||||
fn hovering(
|
||||
mut interaction_query: Query<
|
||||
(&Interaction, &HoveredTexture, &mut UiImage),
|
||||
Changed<Interaction>,
|
||||
>,
|
||||
) {
|
||||
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 => (),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue