pickup shows in toolbar

This commit is contained in:
LorrensP-2158466
2025-04-06 16:31:32 +02:00
10 changed files with 349 additions and 59 deletions

View File

@@ -12,6 +12,12 @@ pub struct Item(Option<Entity>);
#[derive(Component, Default, Debug)]
pub struct ItemIcon(Handle<Image>);
impl ItemIcon {
pub fn new(h: Handle<Image>) -> Self {
Self(h)
}
}
impl Item {
pub fn none() -> Self {
Default::default()
@@ -31,9 +37,19 @@ fn bottom_panel(
mut egui_ctx: EguiContexts,
player_item_query: Query<&Item, With<Player>>,
item_query: Query<(&Name, &ItemIcon), With<Interact>>,
models: Res<Assets<Image>>,
gltf_assets: Res<ImageAssets>,
) {
let item = single!(player_item_query);
let item = item.0.and_then(|id| item_query.get(id).ok());
let (name, icon) = item.map_or_else(
|| (Name::new(""), None),
|(name, handle)| {
(
name.clone(),
Some(egui_ctx.add_image(handle.0.clone_weak())),
)
},
);
egui::TopBottomPanel::bottom("inventory_toolbar")
.frame(egui::Frame {
fill: egui::Color32::from_rgba_premultiplied(0, 0, 0, 0),
@@ -52,7 +68,7 @@ fn bottom_panel(
// Create a frame for the slot
let slot_frame = egui::Frame {
fill: egui::Color32::from_rgba_premultiplied(50, 50, 50, 100),
fill: egui::Color32::from_rgba_premultiplied(75, 75, 75, 100),
stroke: egui::Stroke::new(2.0, egui::Color32::WHITE),
..Default::default()
};
@@ -61,20 +77,24 @@ fn bottom_panel(
ui.add_sized([50.0, 50.0], |ui: &mut egui::Ui| {
// Display the item
ui.vertical_centered(|ui| {
let item = single!(player_item_query);
let item = item.0.and_then(|id| item_query.get(id).ok());
// Placeholder for texture - in a real app, load the texture
ui.label(egui::RichText::new("🔨").size(24.0));
// let (name, icon) = item.map_or_else((Name::new(""), ), |(name, handle)|{
// });
// Item count (display only if > 1)
ui.label(
egui::RichText::new("")
.color(egui::Color32::WHITE)
.size(12.0),
);
ui.horizontal_centered(|ui| {
match icon {
Some(image) => {
ui.add(egui::widgets::Image::new(
egui::load::SizedTexture::new(image, [50.0, 30.0]),
));
}
None => {
ui.label(egui::RichText::new("").size(24.0));
ui.label(egui::RichText::new("Empty").size(12.0));
}
}
ui.label(
egui::RichText::new(name)
.color(egui::Color32::WHITE)
.size(12.0),
);
});
});
ui.allocate_response(ui.available_size(), egui::Sense::click())
});