Пример #1
0
 private void HandleSmallShipDrop(MyGuiControlListbox listboxFrom, MyGuiControlListbox listboxTo, MyInventoryItem item) 
 {
     if (listboxFrom != listboxTo) 
     {
         if (listboxTo == m_otherSideInventoryListBox)
         {
             MySmallShipBuilderWithName builderWithName = new MySmallShipBuilderWithName(item.GetInventoryItemObjectBuilder(false) as MyMwcObjectBuilder_SmallShip_Player);
             m_smallShipsBuilders.Add(builderWithName);
             m_smallShipsInventoryItemIDs.Add(GetInventoryItemIDsFromObjectBuilder(builderWithName.Builder));
             if (m_shipsCombobox != null)
             {
                 m_shipsCombobox.AddItem(m_shipsCombobox.GetItemsCount(), builderWithName.Name);
             }
             item.IsTemporaryItem = true;
         }
         else if (listboxTo == m_shipInventoryListBox)
         {
             MySmallShipBuilderWithName builderWithName = m_smallShipsBuilders.Find(x => x.Builder == item.GetInventoryItemObjectBuilder(false));
             Debug.Assert(builderWithName != null);
             int index = m_smallShipsBuilders.IndexOf(builderWithName);
             Debug.Assert(index > -1);                                        
             SaveIntentoryItemsToObjectBuilder(index);                    
             item.ObjectBuilder = m_smallShipsBuilders[index].Builder;
             DealocateInventoryItemsFromInventoryIDs(index);
             m_smallShipsInventoryItemIDs.RemoveAt(index);
             m_smallShipsBuilders.RemoveAt(index);
             if (m_shipsCombobox != null)
             {
                 m_shipsCombobox.RemoveItemByIndex(index);
             }
             if (m_currentShipBuilderIndex > index) 
             {
                 m_currentShipBuilderIndex--;
             }
             Debug.Assert(m_currentShipBuilderIndex >= 0 && m_currentShipBuilderIndex <= m_smallShipsBuilders.Count - 1);
             item.IsTemporaryItem = false;
             //bool reloadShipInventory = m_currentShipBuilderIndex > index;
             //m_currentShipBuilderIndex = Math.Min(m_currentShipBuilderIndex, m_smallShipsBuilders.Count - 1);
             //if (reloadShipInventory)
             //{
             //    LoadShipInventory(m_currentShipBuilderIndex);
             //}
         }
         else 
         {
             throw new MyMwcExceptionApplicationShouldNotGetHere();
         }
     }            
 }
Пример #2
0
 private bool CanDropItem(MyInventoryItem item, MyGuiControlListbox dropFrom, MyGuiControlListbox dropTo) 
 {
     if (dropTo != dropFrom && NeedHandleSmallShipDrop(item) && dropTo == m_shipInventoryListBox)
     {
         MySmallShipBuilderWithName builderWithName = m_smallShipsBuilders.Find(x => x.Builder == item.GetInventoryItemObjectBuilder(false));
         Debug.Assert(builderWithName != null);
         int index = m_smallShipsBuilders.IndexOf(builderWithName);
         Debug.Assert(index > -1);
         // we can't drop same ship to current ship's inventory
         return index != m_currentShipBuilderIndex;
     }
     else 
     {
         return true;
     }
 }