Skip to content

Commit

Permalink
Improve info panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankopf committed Aug 4, 2023
1 parent 3c12973 commit 73853b4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
36 changes: 32 additions & 4 deletions src/interface/info_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<InfoPanelInformation>,
) {
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::<ClickedOn>();
}
}
}

#[derive(Component)]
Expand Down
1 change: 1 addition & 0 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct SelectedObjectInformation {
#[derive(Resource, Default)]
pub struct InfoPanelInformation {
pub info: Vec<String>,
pub name: String,
}

#[derive(Resource)]
Expand Down
2 changes: 1 addition & 1 deletion src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 73853b4

Please sign in to comment.