private void dragDrop_OnItemDropped(object sender, MyDragAndDropEventArgs eventArgs)
        {
            if (m_selectedAssembler != null && eventArgs.DropTo != null)
            {
                var queueItem = (MyProductionBlock.QueueItem)eventArgs.Item.UserData;

                m_selectedAssembler.MoveQueueItemRequest(queueItem.ItemId, eventArgs.DropTo.ItemIndex);
            }

            m_dragAndDropInfo = null;
        }
        private void dragDrop_OnItemDropped(object sender, MyDragAndDropEventArgs eventArgs)
        {
            if (eventArgs.DropTo != null)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudItem);

                MyPhysicalInventoryItem inventoryItem = (MyPhysicalInventoryItem)eventArgs.Item.UserData;

                var srcGrid = eventArgs.DragFrom.Grid;
                var dstGrid = eventArgs.DropTo.Grid;

                var srcControl = (MyGuiControlInventoryOwner)srcGrid.Owner;
                var dstControl = dstGrid.Owner as MyGuiControlInventoryOwner;
                Debug.Assert(dstControl != null);
                if (dstControl == null)
                    return;
                var srcInventory = (MyInventory)srcGrid.UserData;
                var dstInventory = (MyInventory)dstGrid.UserData;

                if (srcGrid == dstGrid)
                {
                    //GR: Why alter ItemIndex? This caused invalid swapping of items
                    //if (eventArgs.DragFrom.ItemIndex < eventArgs.DropTo.ItemIndex)
                    //    eventArgs.DropTo.ItemIndex++;
                    if (eventArgs.DragButton == MySharedButtonsEnum.Secondary)
                    {
                        ShowAmountTransferDialog(inventoryItem, delegate(float amount)
                        {
                            if (amount == 0)
                                return;
                            if (!srcInventory.IsItemAt(eventArgs.DragFrom.ItemIndex))
                                return;
                            inventoryItem.Amount = (MyFixedPoint)amount;
                            CorrectItemAmount(ref inventoryItem);
                            MyInventory.TransferByUser(srcInventory, srcInventory, inventoryItem.ItemId, eventArgs.DropTo.ItemIndex, inventoryItem.Amount);
                            if (dstGrid.IsValidIndex(eventArgs.DropTo.ItemIndex))
                                dstGrid.SelectedIndex = eventArgs.DropTo.ItemIndex;
                            else
                                dstGrid.SelectLastItem();
                            RefreshSelectedInventoryItem();
                        });
                    }
                    else
                    {
                        MyInventory.TransferByUser(srcInventory, srcInventory, inventoryItem.ItemId, eventArgs.DropTo.ItemIndex);
                        if (dstGrid.IsValidIndex(eventArgs.DropTo.ItemIndex))
                            dstGrid.SelectedIndex = eventArgs.DropTo.ItemIndex;
                        else
                            dstGrid.SelectLastItem();
                        RefreshSelectedInventoryItem();
                    }
                }
                else if (eventArgs.DragButton == MySharedButtonsEnum.Secondary)
                {
                    ShowAmountTransferDialog(inventoryItem, delegate(float amount)
                    {
                        if (amount == 0)
                            return;
                        if (!srcInventory.IsItemAt(eventArgs.DragFrom.ItemIndex))
                            return;
                        inventoryItem.Amount = (MyFixedPoint)amount;
                        CorrectItemAmount(ref inventoryItem);
                        MyInventory.TransferByUser(srcInventory, dstInventory, inventoryItem.ItemId, eventArgs.DropTo.ItemIndex, inventoryItem.Amount);
                        RefreshSelectedInventoryItem();
                    });
                }
                else
                {
                    MyInventory.TransferByUser(srcInventory, dstInventory, inventoryItem.ItemId, eventArgs.DropTo.ItemIndex);
                    RefreshSelectedInventoryItem();
                }
            }

            ClearDisabledControls();

            m_dragAndDropInfo = null;
        }
Exemplo n.º 3
0
 public void HandleDragAndDrop(object sender, MyDragAndDropEventArgs eventArgs)
 {
     MyToolbarItem toolbarItem = eventArgs.Item.UserData as MyToolbarItem;
     if (toolbarItem != null)
     {
         var itemIndex = MyToolbarComponent.CurrentToolbar.GetItemIndex(toolbarItem);
         if (eventArgs.DropTo != null && IsToolbarGrid(eventArgs.DropTo.Grid))
         {
             var dropToItem = MyToolbarComponent.CurrentToolbar.GetItemAtSlot(eventArgs.DropTo.ItemIndex);
             var itemSlot = MyToolbarComponent.CurrentToolbar.IndexToSlot(itemIndex);
             var dropSlot = eventArgs.DropTo.ItemIndex;
             MyToolbarComponent.CurrentToolbar.SetItemAtSlot(dropSlot, toolbarItem);
             MyToolbarComponent.CurrentToolbar.SetItemAtSlot(itemSlot, dropToItem);
         }
         else
         {
             MyToolbarComponent.CurrentToolbar.SetItemAtIndex(itemIndex, null);
         }
     }
 }