fix: Use UI components for inventory

This commit is contained in:
demenik
2025-11-28 14:56:28 +01:00
parent 9a1e7cb95a
commit 202f62b41c
2 changed files with 15 additions and 35 deletions

View File

@@ -9,9 +9,7 @@ pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>) {
position_type: PositionType::Absolute,
width: percent(100),
height: percent(100),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
..Node::center()
},
ZIndex(1),
BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)),
@@ -20,10 +18,8 @@ pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>) {
parent
.spawn((
Node {
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
padding: UiRect::all(px(20.0)),
..default()
..Node::vstack(px(0))
},
BackgroundColor(Color::srgb(0.2, 0.2, 0.2)),
BorderRadius::all(px(10.0)),
@@ -33,10 +29,8 @@ pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>) {
Node {
width: percent(100.0),
justify_content: JustifyContent::SpaceBetween,
align_items: AlignItems::Center,
margin: UiRect::bottom(px(20.0)),
column_gap: px(20.0),
..default()
..Node::hstack(px(20))
},
children![
(
@@ -44,34 +38,25 @@ pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>) {
TextFont::from_font_size(40.0),
TextColor(Color::WHITE),
),
(
Button,
pill_button(
ButtonType::InventoryClose,
ButtonVariant::Destructive,
Node {
width: px(40.0),
height: px(40.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
width: px(40),
height: px(40),
..default()
},
BackgroundColor(Color::srgb(0.8, 0.2, 0.2)),
BorderRadius::MAX,
children![(
Text::new("X"),
TextFont::from_font_size(24.0),
TextColor(Color::WHITE),
)]
)
"X",
24.0
),
],
));
parent
.spawn(Node {
width: percent(100),
flex_direction: FlexDirection::Column,
margin: UiRect::top(px(10.0)),
row_gap: px(10.0),
..default()
..Node::vstack(px(10))
})
.with_children(|parent| {
for itemstack in items.iter() {

View File

@@ -8,13 +8,10 @@ pub fn list_itemstack(itemstack: &ItemStack) -> impl Bundle {
(
Node {
flex_direction: FlexDirection::Row,
column_gap: px(8),
align_items: AlignItems::Center,
padding: UiRect::all(px(4)),
..default()
..Node::hstack(px(8))
},
BackgroundColor(NORMAL_BUTTON),
BackgroundColor(ButtonVariant::Secondary.normal_background()),
BorderRadius::all(px(10)),
children![
(
@@ -24,16 +21,14 @@ pub fn list_itemstack(itemstack: &ItemStack) -> impl Bundle {
aspect_ratio: Some(1.0),
..default()
},
BackgroundColor(HOVERED_BUTTON),
BackgroundColor(ButtonVariant::Secondary.hover_background()),
BorderRadius::all(px(10))
),
(
Node {
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
row_gap: px(4),
padding: UiRect::vertical(px(4)),
..default()
..Node::vstack(px(4))
},
children![
(