Ejemplo n.º 1
0
    private void _populateWeaponSlots()
    {
        for (int weaponOrderIndex = 0; weaponOrderIndex <= (int)Weapon.WeaponOrder.Left; weaponOrderIndex++)
        {
            Weapon.WeaponOrder weaponOrder = (Weapon.WeaponOrder)weaponOrderIndex;

            Agent agent = _inventory.GetAgent();
            if (agent != null && IsInstanceValid(agent))
            {
                Godot.Collections.Array <Weapon> weapons = agent.GetWeapons(weaponOrder);
                for (int weaponIndex = 0; weaponIndex < weapons.Count; weaponIndex++)
                {
                    String name = "WeaponSlotPanel_" + weaponOrder + "_" + weaponIndex;

                    WeaponSlotPanel currentWeaponSlotPanel = null;

                    // If panel does not exist, created it
                    if (!_gridContainerWeaponSlots.HasNode(name))
                    {
                        currentWeaponSlotPanel      = (WeaponSlotPanel)GetNode("WeaponSlotPanel").Duplicate();
                        currentWeaponSlotPanel.Name = name;
                        _gridContainerWeaponSlots.AddChild(currentWeaponSlotPanel);

                        currentWeaponSlotPanel.Connect(nameof(WeaponSlotPanel.WeaponSlotPanelClickSignal), this, nameof(_populateWeaponChoices));
                    }
                    else
                    {
                        currentWeaponSlotPanel = (WeaponSlotPanel)_gridContainerWeaponSlots.GetNode(name);
                    }

                    ItemResource itemResource = null;

                    if (weapons[weaponIndex] != null)
                    {
                        itemResource = _inventoryManager.GetPurchasableItemByID(weapons[weaponIndex].ItemResourceID);
                    }

                    // Initialize with current weapon
                    currentWeaponSlotPanel.Initialize(itemResource, weaponOrder, weaponIndex);
                    currentWeaponSlotPanel.Show();
                }
            }
        }
    }