From b606aa88e1277b087a9c3e5670ab258f0245476c Mon Sep 17 00:00:00 2001 From: Rich Churcher Date: Sun, 17 Nov 2024 17:43:15 +1300 Subject: [PATCH] Re-order systems --- examples/picking/ui_picking.rs | 56 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/examples/picking/ui_picking.rs b/examples/picking/ui_picking.rs index ea0767c5c0..d6728c9833 100644 --- a/examples/picking/ui_picking.rs +++ b/examples/picking/ui_picking.rs @@ -99,6 +99,34 @@ fn spawn_inventory_slot(mut commands: Commands, inventory: Single, + mut commands: Commands, + slots: Query>, +) { + let paths = [ + "textures/rpg/props/generic-rpg-loot01.png", + "textures/rpg/props/generic-rpg-loot02.png", + ]; + for (i, slot) in slots.iter().enumerate().take(2) { + commands.entity(slot).with_children(|parent| { + parent + .spawn(( + Draggable, + // This node serves solely to be dragged! It provides the transform, using required + // components. + Node::default(), + ImageNode::new(asset_server.load(paths[i])), + // TODO: seems clumsy, better solution? + ZIndex(99), + )) + .observe(drag_start()) + .observe(drag_end()); + }); + } +} + /// This observer detects the beginning of a drag-and-drop motion and takes care of tasks such as /// detaching the target from its parent and allowing the node to be moved. fn drag_start() -> impl Fn( @@ -206,34 +234,6 @@ fn drag_inventory_items( item_node.top = Val::Px(cursor_pos.y); } -/// Spawn two arbitrary inventory items. Here we'll just pick the first two slots. -fn add_items_to_inventory( - asset_server: Res, - mut commands: Commands, - slots: Query>, -) { - let paths = [ - "textures/rpg/props/generic-rpg-loot01.png", - "textures/rpg/props/generic-rpg-loot02.png", - ]; - for (i, slot) in slots.iter().enumerate().take(2) { - commands.entity(slot).with_children(|parent| { - parent - .spawn(( - Draggable, - // This node serves solely to be dragged! It provides the transform, using required - // components. - Node::default(), - ImageNode::new(asset_server.load(paths[i])), - // TODO: seems clumsy, better solution? - ZIndex(99), - )) - .observe(drag_start()) - .observe(drag_end()); - }); - } -} - /// Display instructions. fn spawn_text(mut commands: Commands) { commands.spawn((