private void OnDrop(object sender, MyDragAndDropEventArgs eventArgs) { if (eventArgs.DropTo != null) { MyInventoryItem inventoryItem = m_itemsRepository.GetItem(eventArgs.ListboxItem.Key); MyGuiControlListboxItem itemAtDroppingPosition = eventArgs.DropTo.Listbox.GetItem(eventArgs.DropTo.RowIndex, eventArgs.DropTo.ItemIndex); // test drop condition Predicate<MyInventoryItem> dropCondition = m_listboxDropConditions[eventArgs.DropTo.Listbox]; // drop condition false (check if we able to drop this item to this listbox) if (!dropCondition(inventoryItem) || !CanDropItem(inventoryItem, eventArgs.DragFrom.Listbox, eventArgs.DropTo.Listbox)) { DropBack(eventArgs); } // check if listbox is full and we try drop item, if true drop item back else if (IsListboxFull(eventArgs.DropTo.Listbox)) { // if we try drop item at ship or other side inventory, then play warning if (eventArgs.DropTo.Listbox == m_shipInventoryListBox || eventArgs.DropTo.Listbox == m_otherSideInventoryListBox) { MyAudio.AddCue2D(MySoundCuesEnum.HudInventoryFullWarning); } DropBack(eventArgs); } // drop condition true else { if (m_tradeForMoney) { bool tradeForMoneyResult = HandleTradeForMoney(eventArgs.DragFrom.Listbox, eventArgs.DropTo.Listbox, inventoryItem); if (!tradeForMoneyResult) { DropBack(eventArgs); return; } eventArgs.ListboxItem.ToolTip = GetListboxItemTooltip(eventArgs.DropTo.Listbox, eventArgs.ListboxItem.Key); } if (NeedHandleSmallShipDrop(inventoryItem)) { HandleSmallShipDrop(eventArgs.DragFrom.Listbox, eventArgs.DropTo.Listbox, inventoryItem); } DropItem(eventArgs.DropTo.Listbox, eventArgs.ListboxItem, eventArgs.DropTo.RowIndex, eventArgs.DropTo.ItemIndex); m_wasAnythingTrasfered = true; if (m_tradeForMoney) { UpdateOtherSideInventoryListboxForTrading(); } //StopDragging(); } } else { // if item was dropped over inventory screen, then put them to original slot if (IsMouseOver() || eventArgs.DragFrom.Listbox == m_otherSideInventoryListBox) { DropBack(eventArgs); } // if item was dropped out of inventory screen, then remove from game else { m_removedInventoryItemIDs.Add(eventArgs.ListboxItem.Key); m_wasAnythingTrasfered = true; StopDragging(); } } }
private void DropBack(MyDragAndDropEventArgs eventArgs) { DropItem(eventArgs.DragFrom.Listbox, eventArgs.ListboxItem, eventArgs.DragFrom.RowIndex, eventArgs.DragFrom.ItemIndex); //StopDragging(); }
private void DragAndDropListboxItemDropped(object sender, MyDragAndDropEventArgs eventArgs) { if (eventArgs.DropTo == null) { MoveItemToListbox(eventArgs.DragFrom.Listbox, eventArgs.ListboxItem, eventArgs.DragFrom.RowIndex, eventArgs.DragFrom.ItemIndex); } else { MoveItemToListbox(eventArgs.DropTo.Listbox, eventArgs.ListboxItem); } m_dragAndDrop.Stop(); }