diff --git a/src/components.rs b/src/components.rs index df2281c..eadb1e9 100644 --- a/src/components.rs +++ b/src/components.rs @@ -55,12 +55,14 @@ impl MenuStates { #[derive(Component, PartialEq, Copy, Clone, Debug)] pub enum ActorType { // Entity? Character? Creature? Actor? Avatar? Unit? Agent? + Human, Pig, Rat, } impl ActorType { pub fn sprite_row_and_col(&self) -> (usize, usize) { match self { + ActorType::Human => (66, 46), ActorType::Pig => (64, 0), ActorType::Rat => (64, 19), } diff --git a/src/interface/info_panel.rs b/src/interface/info_panel.rs index 53aaf02..e3a9025 100644 --- a/src/interface/info_panel.rs +++ b/src/interface/info_panel.rs @@ -21,8 +21,28 @@ pub fn show_info_panel( for text in texts.iter() { commands.entity(text).despawn(); } + commands.spawn(( + TextBundle::from_section( + &object_info.name, + TextStyle { + font: font.0.clone(), + font_size: 24.0, + ..default() + }, + ) // Set the alignment of the Text + .with_text_alignment(TextAlignment::TOP_LEFT) + .with_style(Style { + position_type: PositionType::Absolute, + position: UiRect { + top: Val::Px(15.0), + left: Val::Px(15.0), + ..default() + }, + ..default() + }), + InfoPanelText, + )); for (i, info) in object_info.info.iter().enumerate() { - println!("Info: {}", info); commands.spawn(( TextBundle::from_section( info, @@ -45,15 +65,23 @@ pub fn show_info_panel( pub fn info_system( mut commands: Commands, - mut people: Query<(Entity, &Position, &Status, &ClickedOn)>, + mut people: Query<(Entity, &Position, &Status, &ClickedOn, Option<&HasName>)>, mut info_panel: ResMut, ) { - for (entity, position, status, _clickedon) in people.iter_mut() { - commands.entity(entity).insert(ClickedOn); + if let Some((entity, position, status, _clickedon, has_name)) = people.iter_mut().last() { + if let Some(has_name) = has_name { + info_panel.name = has_name.name.clone(); + } info_panel.info = vec![]; info_panel.info.push(format!("Position: {}, {}", position.x, position.y)); info_panel.info.extend_from_slice(&status.info_panel()); } + let count = people.iter().count(); + for (index, (entity, _, _, clickedon, _)) in people.iter_mut().enumerate() { + if index < count - 1 { + commands.entity(entity).remove::(); + } + } } #[derive(Component)] diff --git a/src/resources.rs b/src/resources.rs index 563d4cb..e39a675 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -47,6 +47,7 @@ pub struct SelectedObjectInformation { #[derive(Resource, Default)] pub struct InfoPanelInformation { pub info: Vec, + pub name: String, } #[derive(Resource)] diff --git a/src/startup.rs b/src/startup.rs index 5a37acd..ad66f72 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -24,7 +24,7 @@ pub fn startup( // GENERATE UNITS for i in 1..6 { let position = Position { x: 3, y: 3*i, z: 0 }; - let sprite = TextureAtlasSprite::new(66*64+46_usize); + let sprite = TextureAtlasSprite::new(ActorType::Human.sprite_index()); // TO DO commands.spawn(SpriteSheetBundle { sprite,