コード例 #1
0
 private void SlotClicked(InventorySlotUi sender)
 {
     if (sender.ContainingEntity != null)
     {
         _userInterfaceManager.DragInfo.StartDrag(sender.ContainingEntity);
     }
 }
コード例 #2
0
        public void RebuildInventoryView(int maxSlots, List <IEntity> entities)
        {
            int currX = 0;
            int currY = 0;

            const int spacing = 50;
            const int xOffset = 12;
            const int yOffset = 5;

            _inventoryContainer.components.Clear();

            foreach (IEntity entity in entities)
            {
                var slot = new InventorySlotUi(entity, _resourceManager)
                {
                    Position = new Vector2i(currX * spacing + xOffset, currY * spacing + yOffset)
                };

                slot.Clicked += SlotClicked;

                _inventoryContainer.components.Add(slot);

                currX++;

                if (currX < 5)
                {
                    continue;
                }

                currX = 0;
                currY++;
            }

            for (int i = 0; i < (maxSlots - entities.Count); i++)
            {
                var slot = new InventorySlotUi(null, _resourceManager)
                {
                    Position = new Vector2i(currX * spacing + xOffset, currY * spacing + yOffset)
                };

                slot.Clicked += SlotClicked;

                _inventoryContainer.components.Add(slot);

                currX++;

                if (currX < 5)
                {
                    continue;
                }

                currX = 0;
                currY++;
            }

            _inventoryContainer.ResetScrollbars();
        }