pickup item
This commit is contained in:
@@ -94,6 +94,7 @@ fn display_interaction_prompt(
|
|||||||
fn handle_pick_up(
|
fn handle_pick_up(
|
||||||
// current action
|
// current action
|
||||||
mut action: Query<(&PlayerAction, &mut Item), With<Player>>,
|
mut action: Query<(&PlayerAction, &mut Item), With<Player>>,
|
||||||
|
mut item_query: Query<&mut Visibility, With<Interact>>,
|
||||||
// current interactable
|
// current interactable
|
||||||
interaction_opportunity: Res<InteractionOpportunity>,
|
interaction_opportunity: Res<InteractionOpportunity>,
|
||||||
) {
|
) {
|
||||||
@@ -102,6 +103,14 @@ fn handle_pick_up(
|
|||||||
};
|
};
|
||||||
let (action, mut item) = single_mut!(action);
|
let (action, mut item) = single_mut!(action);
|
||||||
if *action == PlayerAction::Interact {
|
if *action == PlayerAction::Interact {
|
||||||
let _replaced = item.set_item(target);
|
let replaced = item.set_item(target);
|
||||||
|
if let Ok(mut vis) = item_query.get_mut(target) {
|
||||||
|
*vis = Visibility::Hidden;
|
||||||
|
}
|
||||||
|
if let Some(dropped) = replaced {
|
||||||
|
if let Ok(mut vis) = item_query.get_mut(dropped) {
|
||||||
|
*vis = Visibility::Visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,11 +157,13 @@ fn spawn_objects(
|
|||||||
Interact,
|
Interact,
|
||||||
RigidBody::Dynamic,
|
RigidBody::Dynamic,
|
||||||
Name::new("Id Card"),
|
Name::new("Id Card"),
|
||||||
|
Visibility::Visible,
|
||||||
ItemIcon::new(image_assets.id_card.clone()),
|
ItemIcon::new(image_assets.id_card.clone()),
|
||||||
SceneRoot(asset.clone()),
|
SceneRoot(asset.clone()),
|
||||||
))
|
))
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
parent.spawn((
|
parent.spawn((
|
||||||
|
Visibility::Inherited,
|
||||||
ColliderMassProperties::Mass(10.0),
|
ColliderMassProperties::Mass(10.0),
|
||||||
Collider::cuboid(0.05, 0.05, 0.01),
|
Collider::cuboid(0.05, 0.05, 0.01),
|
||||||
Transform::from_rotation(Quat::from_euler(
|
Transform::from_rotation(Quat::from_euler(
|
||||||
@@ -172,6 +174,7 @@ fn spawn_objects(
|
|||||||
)),
|
)),
|
||||||
));
|
));
|
||||||
parent.spawn((
|
parent.spawn((
|
||||||
|
Visibility::Inherited,
|
||||||
ActiveEvents::COLLISION_EVENTS,
|
ActiveEvents::COLLISION_EVENTS,
|
||||||
Transform::default(),
|
Transform::default(),
|
||||||
Collider::ball(0.5), // Interaction radius
|
Collider::ball(0.5), // Interaction radius
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use bevy::prelude::*;
|
|||||||
use bevy_egui::{EguiContexts, egui};
|
use bevy_egui::{EguiContexts, egui};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
use crate::{GameState, asset_loading::ImageAssets, interaction::Interact, util::single};
|
use crate::{GameState, interaction::Interact, util::single};
|
||||||
|
|
||||||
use super::Player;
|
use super::Player;
|
||||||
|
|
||||||
@@ -40,15 +40,12 @@ fn bottom_panel(
|
|||||||
) {
|
) {
|
||||||
let item = single!(player_item_query);
|
let item = single!(player_item_query);
|
||||||
let item = item.0.and_then(|id| item_query.get(id).ok());
|
let item = item.0.and_then(|id| item_query.get(id).ok());
|
||||||
let (name, icon) = item.map_or_else(
|
let (name, icon) = item.map_or((Name::new(""), None), |(name, handle)| {
|
||||||
|| (Name::new(""), None),
|
(
|
||||||
|(name, handle)| {
|
name.clone(),
|
||||||
(
|
Some(egui_ctx.add_image(handle.0.clone_weak())),
|
||||||
name.clone(),
|
)
|
||||||
Some(egui_ctx.add_image(handle.0.clone_weak())),
|
});
|
||||||
)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
egui::TopBottomPanel::bottom("inventory_toolbar")
|
egui::TopBottomPanel::bottom("inventory_toolbar")
|
||||||
.frame(egui::Frame {
|
.frame(egui::Frame {
|
||||||
|
|||||||
Reference in New Issue
Block a user