コード例 #1
0
 /// <summary>
 /// Starts dragging item
 /// </summary>
 /// <param name="dropHandleType">On which action released drop event</param>
 /// <param name="draggingItem">Item which is dragging</param>
 /// <param name="draggingFrom">Information about item's origin</param>
 public void StartDragging(MyDropHandleType dropHandleType, MyGuiControlListboxItem draggingItem, MyDragAndDropInfo draggingFrom)
 {
     m_currentDropHandleType = dropHandleType;
     m_draggingListboxItem   = draggingItem;
     m_draggingFrom          = draggingFrom;
     m_toolTip = draggingItem.ToolTip;
 }
コード例 #2
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();
        }
コード例 #3
0
 private MyGuiControlListboxItem CreateCopyOfListboxItem(MyGuiControlListboxItem templateItem)
 {
     MyInventoryItem templateInventoryItem = m_itemsRepository.GetItem(templateItem.Key);
     int newItemKey = CreateInventoryItemAddToRepository(templateInventoryItem.GetInventoryItemObjectBuilder(true), templateInventoryItem.Amount, (MyMwcObjectBuilder_Inventory)templateInventoryItem.Owner);
     MyGuiControlListboxItem itemsCopy = new MyGuiControlListboxItem(newItemKey, templateItem.ColoredText, templateItem.Icon, templateItem.ToolTip);
     itemsCopy.IconTexts = templateItem.IconTexts;
     return itemsCopy;
 }
コード例 #4
0
        private void FillListBoxFromID(MyGuiControlListbox listbox, int id, bool canBeMoved = true)
        {
            MyInventoryItem inventoryItem = m_itemsRepository.GetItem(id);
            StringBuilder description = null;
            if (inventoryItem.Icon == null)
            {
                description = inventoryItem.MultiLineDescription;
            }

            MyGuiControlListboxItem listboxItem = new MyGuiControlListboxItem(id, description, inventoryItem.Icon, GetListboxItemTooltip(listbox, id), MyGuiConstants.LABEL_TEXT_SCALE);
            listboxItem.IconTexts = new MyIconTexts();

            // add amount icon's text
            if (inventoryItem.Amount != 0f || inventoryItem.Amount != inventoryItem.MaxAmount)            
            {
                StringBuilder amount = new StringBuilder();
                if (inventoryItem.Amount > (int)inventoryItem.Amount)
                {
                    float fixedAmount = Math.Max(0.01f, inventoryItem.Amount);  // prevent items with zero amount, for visualization 0.01 is the minimum value
                    amount.AppendDecimal(fixedAmount, 2);
                }
                else 
                {
                    amount.AppendInt32((int)inventoryItem.Amount);                    
                }
                //amount.Append(inventoryItem.Amount.ToString());
                MyGuiDrawAlignEnum align;
                Vector2 offset;

                //All amounts alignet to right bottom position from now
                /*
                if (inventoryItem.AmountTextAlign == MyInventoryAmountTextAlign.MiddleRight)
                {
                    align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
                    offset = new Vector2(-0.004f, 0.0038f);
                }
                 
                else if (inventoryItem.AmountTextAlign == MyInventoryAmountTextAlign.BottomRight)
                {
                 * */
                align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                offset = new Vector2(-0.013f, -0.01f);

                /*}
                    else
                    {
                        throw new MyMwcExceptionApplicationShouldNotGetHere();
                    }
                 * */

                listboxItem.IconTexts[align] = new MyColoredText(amount, Color.White, Color.White, MyGuiManager.GetFontMinerWarsBlue(), 0.6f, offset);
            }
            bool enabled = inventoryItem.CanBeMoved && canBeMoved;
            if (m_tradeForMoney)
            {
                enabled &= inventoryItem.CanBeTraded;                
            }
            listboxItem.Enabled = enabled;
            //if (!inventoryItem.CanBeMoved) 
            //{
            //    listboxItem.Enabled = false;
            //}
            listbox.AddItem(listboxItem);
        }
コード例 #5
0
 string GetCheckpointNameFromItem(MyGuiControlListboxItem item)
 {
     return item.Value.ToString();
 }
コード例 #6
0
 /// <summary>
 /// Stops dragging item
 /// </summary>
 public void Stop()
 {
     m_draggingFrom = null;
     m_draggingListboxItem = null;
     m_currentDropHandleType = null;
 }
コード例 #7
0
 /// <summary>
 /// Starts dragging item
 /// </summary>
 /// <param name="dropHandleType">On which action released drop event</param>
 /// <param name="draggingItem">Item which is dragging</param>
 /// <param name="draggingFrom">Information about item's origin</param>
 public void StartDragging(MyDropHandleType dropHandleType, MyGuiControlListboxItem draggingItem, MyDragAndDropInfo draggingFrom)
 {
     m_currentDropHandleType = dropHandleType;
     m_draggingListboxItem = draggingItem;
     m_draggingFrom = draggingFrom;
     m_toolTip = draggingItem.ToolTip;
 }
コード例 #8
0
        /// <summary>
        /// Adds new item to specific row and item's index
        /// </summary>
        /// <param name="item">item</param>
        /// <param name="rowIndex">row's index</param>
        /// <param name="itemIndex">item's index</param>
        public void AddItem(MyGuiControlListboxItem item, int rowIndex, int itemIndex)
        {
            MyGuiControlListboxRow row = m_rows[rowIndex];
            row.Items[itemIndex] = item;

            if (item != null)
            {
                m_itemsCount++;
            }
        }
コード例 #9
0
        /// <summary>
        /// Adds new item to first free row
        /// </summary>
        /// <param name="item">item</param>
        public void AddItem(MyGuiControlListboxItem item)
        {
            // if there are no rows, then add new one and add item there
            if (m_rows.Count == 0)
            {
                AddRow();
                AddItem(item, 0, 0);
            }
            else
            {
                int? emptyRowIndex = null;
                int? emptyItemIndex = null;

                // try find first empty row
                for (int rowIndex = 0; rowIndex < m_rows.Count; rowIndex++)
                {
                    emptyItemIndex = m_rows[rowIndex].GetFirstEmptyItemSlot();
                    if (emptyItemIndex != null)
                    {
                        emptyRowIndex = rowIndex;
                        break;
                    }
                }

                // if not founded, then add new row
                if (emptyRowIndex == null || emptyItemIndex == null)
                {
                    emptyRowIndex = this.AddRow();
                    emptyItemIndex = 0;
                }

                // add item at first empty position
                AddItem(item, emptyRowIndex.Value, emptyItemIndex.Value);
            }
        }
コード例 #10
0
 private MyGuiControlListboxItem CreateListboxItem(int key, StringBuilder value, MyTexture2D icon)
 {
     MyColoredText coloredText = null;
     MyToolTips toolTips = null;
     if (value != null)
     {
         coloredText = new MyColoredText(value, new Color(MyGuiConstants.LISTBOX_TEXT_COLOR),
                                         new Color(MyGuiConstants.LISTBOX_TEXT_COLOR * MyGuiConstants.CONTROL_MOUSE_OVER_BACKGROUND_COLOR_MULTIPLIER),
                                         MyGuiManager.GetFontMinerWarsBlue(), m_textScale, Vector2.Zero);
         toolTips = new MyToolTips(value);
     }
     MyGuiControlListboxItem newItem = new MyGuiControlListboxItem(key, coloredText, icon, toolTips);
     return newItem;
 }
コード例 #11
0
 /// <summary>
 /// Stops dragging item
 /// </summary>
 public void Stop()
 {
     m_draggingFrom          = null;
     m_draggingListboxItem   = null;
     m_currentDropHandleType = null;
 }
コード例 #12
0
 private void MoveItemToListbox(MyGuiControlListbox moveTo, MyGuiControlListboxItem item, int? rowIndex = null, int? itemIndex = null) 
 {
     if (moveTo == m_allItemsInventoryListbox)
     {
         RemoveCopy(item.Key);                
     }
     else 
     {
         if (rowIndex != null && itemIndex != null)
         {
             moveTo.AddItem(item, rowIndex.Value, itemIndex.Value);
         }
         else
         {
             moveTo.AddItem(item);
         }
     }
 }
コード例 #13
0
 private MyGuiControlListboxItem CreateCopy(MyGuiControlListboxItem original) 
 {
     MyInventoryItem templateInventoryItem = m_inventoryItemsRepository.GetItem(original.Key);
     MyInventoryItem newInventoryItem = MyInventory.CreateInventoryItemFromObjectBuilder(templateInventoryItem.GetInventoryItemObjectBuilder(true));
     newInventoryItem.Amount = templateInventoryItem.Amount;
     MyGuiControlListboxItem newItem =  CreateListboxItemAndAddToRepository(newInventoryItem);
     newItem.IconTexts = original.IconTexts;
     m_itemsAdded.Add(newInventoryItem);
     return newItem;
 }
コード例 #14
0
        private MyGuiControlListboxItem CreateListboxItemAndAddToRepository(MyInventoryItem inventoryItem) 
        {
            int inventoryItemKey = m_inventoryItemsRepository.AddItem(inventoryItem);            

            StringBuilder description = null;
            if (inventoryItem.Icon == null)
            {
                description = inventoryItem.MultiLineDescription;
            }

            MyToolTips toolTips = new MyToolTips();
            toolTips.AddToolTip(inventoryItem.MultiLineDescription, Color.White, 0.7f);            

            MyGuiControlListboxItem listboxItem = new MyGuiControlListboxItem(inventoryItemKey, description, inventoryItem.Icon, toolTips, MyGuiConstants.LABEL_TEXT_SCALE);
            listboxItem.IconTexts = new MyIconTexts();

            // add amount icon's text
            if (inventoryItem.Amount != 1f || inventoryItem.Amount != inventoryItem.MaxAmount)
            {
                StringBuilder amount = new StringBuilder();
                amount.Append(inventoryItem.Amount.ToString());
                MyGuiDrawAlignEnum align;
                Vector2 offset;
                if (inventoryItem.AmountTextAlign == MyInventoryAmountTextAlign.MiddleRight)
                {
                    align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
                    offset = new Vector2(-0.004f, 0.0038f);
                }
                else if (inventoryItem.AmountTextAlign == MyInventoryAmountTextAlign.BottomRight)
                {
                    align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                    offset = new Vector2(-0.004f, -0.0025f);
                }
                else
                {
                    throw new MyMwcExceptionApplicationShouldNotGetHere();
                }
                listboxItem.IconTexts[align] = new MyColoredText(amount, Color.White, Color.White, MyGuiManager.GetFontMinerWarsWhite(), 0.5f, offset);
            }

            return listboxItem;
        }