Ejemplo n.º 1
0
        private void DropItem(MyGuiControlListbox listbox, MyGuiControlListboxItem item, int rowIndex, int itemIndex)
        {
            // in god editor and other side listbox, we don't want put this item to this listbox, so we remove it
            if (m_inventoryScreenType == MyGuiScreenInventoryType.GodEditor && listbox == m_otherSideInventoryListBox)
            {
                m_itemsRepository.RemoveItem(item.Key);
            }
            else
            {
                if (listbox.GetItem(rowIndex, itemIndex) != null || listbox.GetRowsCount() <= rowIndex)
                {
                    listbox.AddItem(item);
                }
                else
                {
                    listbox.AddItem(item, rowIndex, itemIndex);
                }

                // if there are no empty row, we try add new row
                if (listbox.GetEmptyRowsCount() == 0)
                {
                    AddFreeRowsIfCan(listbox, 1);
                }                
            }
            StopDragging();
        }
Ejemplo n.º 2
0
        private void MoveItemBetweenListboxes(MyGuiControlListbox listboxFrom, MyGuiControlListbox listboxTo, bool copyItem, bool deleteItem)
        {
            bool moved = false;
            MyGuiControlListboxItem selectedItem = listboxFrom.GetSelectedItem();
            if (selectedItem != null)
            {
                System.Diagnostics.Debug.Assert(m_itemsRepository.Contains(selectedItem.Key));

                if (!IsListboxFull(listboxTo) && m_itemsRepository.Contains(selectedItem.Key))
                {
                    MyInventoryItem item = m_itemsRepository.GetItem(selectedItem.Key);
                    if (!CanDropItem(item, listboxFrom, listboxTo)) 
                    {
                        return;
                    }
                    
                    if (m_tradeForMoney)
                    {
                        selectedItem.ToolTip = GetListboxItemTooltip(listboxTo, selectedItem.Key);
                        bool tradeForMoneyResult = HandleTradeForMoney(listboxFrom, listboxTo, item);
                        if (!tradeForMoneyResult) 
                        {
                            return;
                        }
                    }

                    if (NeedHandleSmallShipDrop(item))
                    {
                        HandleSmallShipDrop(listboxFrom, listboxTo, item);                        
                    }

                    // we make copy of moved item
                    if (copyItem)
                    {
                        listboxTo.AddItem(CreateCopyOfListboxItem(selectedItem));
                    }
                    else
                    {
                        listboxFrom.RemoveItem(selectedItem.Key, false);
                        // if we don't want delete moved item
                        if (!deleteItem)
                        {
                            listboxTo.AddItem(selectedItem);
                        }
                    }
                    moved = true;
                    m_wasAnythingTrasfered = true;

                    if (m_tradeForMoney) 
                    {
                        UpdateOtherSideInventoryListboxForTrading();
                    }
                }
                else
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.HudInventoryFullWarning);
                }
            }

            if (moved && listboxTo.GetEmptyRowsCount() == 0)
            {
                AddFreeRowsIfCan(listboxTo, 1);                
            }
        }