Example #1
0
 private void _cleanGridContainer(GridContainer gridContainer)
 {
     if (gridContainer.GetChildCount() != 0)
     {
         foreach (Node node in gridContainer.GetChildren())
         {
             node.QueueFree();
         }
     }
 }
Example #2
0
        private async void UpdateInventoryUI()
        {
            if (_chestInstance == null)
            {
                GD.PushError("Chest instance not found");
                return;
            }

            var movableInventory = new List <string>(_playerInstance.Inventory);

            movableInventory.Remove(_playerInstance.EquippedWeapon);
            movableInventory.Remove(_playerInstance.EquippedArmor);

            foreach (Node child in _inventoryContents.GetChildren())
            {
                child.QueueFree();
            }

            var childCount = _inventoryContents.GetChildCount();

            if (childCount > 0)
            {
                await ToSignal(_inventoryContents.GetChild(childCount - 1),
                               "tree_exited");
            }

            foreach (var itemName in movableInventory)
            {
                var inventoryItem = (ChestItems)ChestItemResource.Instance();
                inventoryItem.ItemName = itemName;
                _inventoryContents.AddChild(inventoryItem);
            }

            for (var i = 0; i < 8; i++)
            {
                var inventoryItem = (ChestItems)ChestItemResource.Instance();
                _inventoryContents.AddChild(inventoryItem);
            }

            foreach (ChestItems inventoryItems in _inventoryContents.GetChildren())
            {
                inventoryItems.Connect(nameof(ChestItems.LeftClicked), this,
                                       nameof(OnInventoryItem_LeftClicked));
            }
        }