예제 #1
0
    private void buildInventorySlots()
    {
        inventory_parent = GetNode <GridContainer>(InventoryParentPath);
        PackedScene slotPs      = (PackedScene)ResourceLoader.Load(inventorySlotPath);
        int         pos         = 1;
        float       margin_left = 0;
        float       margin_top  = 0;

        for (int y = 0; y < InventoryHeight; y++)
        {
            for (int x = 0; x < InventoryWidth; x++)
            {
                Control slot = slotPs.Instance() as Control;
                slot.Name         = $"slot_{pos}";
                slot.RectPosition = new Vector2(margin_left, margin_top);
                inventory_parent.CallDeferred("add_child", slot);
                inventory_slots[pos] = slot;
                margin_left         += 25f;
                pos++;
            }
            margin_top += 25f;
            margin_left = 0;
        }
    }