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(); } } } }
private void _updateWeaponChange(Weapon.WeaponOrder weaponOrder, int weaponIndex) { String name = "WeaponSlotPanel_" + weaponOrder + "_" + weaponIndex; WeaponSlotPanel currentWeaponSlotPanel = (WeaponSlotPanel)_gridContainerWeaponSlots.GetNode(name); Agent agent = _inventory.GetAgent(); Weapon weapon = agent.GetWeapons(weaponOrder)[weaponIndex]; ItemResource itemResource = null; if (weapon != null) { itemResource = _inventoryManager.GetPurchasableItemByID(weapon.ItemResourceID); } currentWeaponSlotPanel.Initialize(itemResource, weaponOrder, weaponIndex); _populateWeaponChoices(weaponOrder, weaponIndex); }