Esempio n. 1
0
    public void Populate()
    {
        RealmInventory = DarkestDungeonManager.Campaign.RealmInventory;
        InventoryRows  = new List <InventoryRow>();

        int trinketCount   = RealmInventory.Trinkets.Count;
        int rowCount       = Mathf.Max(3, trinketCount / 7 + 1);
        int trinketsLoaded = 0;

        CurrentCapacity = trinketCount;
        MaxCapacity     = rowCount * 7;

        for (int i = 0; i < rowCount; i++)
        {
            InventoryRow newRow = Instantiate(rowTemplate);
            newRow.Initialize(this);
            newRow.onRowEmptied += RealmInventoryWindow_onRowEmptied;
            newRow.RectTransform.SetParent(trinketBox, false);
            InventoryRows.Add(newRow);
            InventorySlots.AddRange(newRow.InventorySlots);

            for (int j = 0; j < 7; j++)
            {
                if (trinketsLoaded != trinketCount)
                {
                    Trinket trinket = RealmInventory.Trinkets[trinketsLoaded];
                    newRow.InventorySlots[j].CreateItem(trinket);
                    newRow.ItemAdded();
                    trinketsLoaded++;
                }
                else
                {
                    break;
                }
            }
        }

        for (int i = 0; i < InventoryRows.Count; i++)
        {
            InventoryRows[i].RowNumber     = i + 1;
            InventoryRows[i].onRowEmptied += RealmInventoryWindow_onRowEmptied;
            for (int j = 0; j < InventoryRows[i].SlotCount; j++)
            {
                InventoryRows[i].InventorySlots[j].onDropIn  += RealmInventoryWindow_onDropIn;
                InventoryRows[i].InventorySlots[j].onDropOut += RealmInventoryWindow_onDropOut;
            }
        }
        UpdateWindow();
    }
    private InventoryRow AddRow()
    {
        InventoryRow newRow = Instantiate(rowTemplate);

        newRow.Initialize(this);
        newRow.RectTransform.SetParent(trinketBox, false);
        InventoryRows.Add(newRow);
        InventorySlots.AddRange(newRow.InventorySlots);

        newRow.RowNumber        = InventoryRows.Count;
        MaxCapacity            += newRow.SlotCount;
        newRow.EventRowEmptied += RealmInventoryRowEmptied;

        for (int j = 0; j < newRow.SlotCount; j++)
        {
            newRow.InventorySlots[j].EventDropIn  += RealmInventorySlotDropIn;
            newRow.InventorySlots[j].EventDropOut += RealmInventorySlotDropOut;
        }
        return(newRow);
    }