generated from 2ndbeam/bevy-template
ui: Multiple inventories support
- Added scrollable container for inventories - Fixed slots being visibly hovered when dragging items
This commit is contained in:
parent
0c8259583a
commit
337986d2b9
5 changed files with 113 additions and 43 deletions
|
|
@ -18,9 +18,12 @@ fn player_bundle(asset_server: &Res<AssetServer>) -> impl Bundle {
|
|||
Sprite::from_image(image),
|
||||
Transform::from_xyz(0f32, 0f32, 1f32),
|
||||
Action::default_input_map(),
|
||||
Inventory::new(UVec2::new(4, 4)),
|
||||
ActiveInventory,
|
||||
Name::new("Player"),
|
||||
children![
|
||||
(Inventory::new(UVec2::new(6, 2)), ActiveInventory),
|
||||
(Inventory::new(UVec2::new(5, 3)), ActiveInventory),
|
||||
(Inventory::new(UVec2::new(4, 4)), ActiveInventory),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +38,7 @@ pub fn try_insert_item(
|
|||
) {
|
||||
let mut item = Item::new(UVec2::new(1, 1));
|
||||
let name = Name::new(format!("Item {}x{}", item.size.x, item.size.y));
|
||||
for (entity, inventory, children) in inventory_query {
|
||||
for (entity, inventory, children) in inventory_query.iter().sort::<Entity>() {
|
||||
let children = match children {
|
||||
Some(children) => &children[..],
|
||||
None => &[],
|
||||
|
|
@ -48,13 +51,10 @@ pub fn try_insert_item(
|
|||
item.position = Some(position);
|
||||
info!("Spawning item {item:?}");
|
||||
commands.entity(entity).with_child((item, name));
|
||||
break;
|
||||
},
|
||||
None => {
|
||||
warn!("Inventory does not have space for {}", item.size);
|
||||
},
|
||||
None => (),
|
||||
}
|
||||
// only first inventory
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue