Files
XericUIActionVessel/Runtime/XTable/Core/XTableBlock.cs
T

91 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
namespace XericUI.XTable.Core
{
/// <summary>
/// 单个数据块——保存 BlockSizeX × BlockSizeY 个单元格数据。
/// 数据使用线性数组存储,索引 = localRow * BlockSizeX + localCol。
/// </summary>
public class XTableBlock
{
/// <summary>块在全局块坐标系中的行号</summary>
public int BlockRow;
/// <summary>块在全局块坐标系中的列号</summary>
public int BlockCol;
/// <summary>块内单元格列数</summary>
public int BlockSizeX;
/// <summary>块内单元格行数</summary>
public int BlockSizeY;
/// <summary>
/// 数据存储——线性数组。
/// 索引 = localRow * BlockSizeX + localCol。
/// </summary>
public XTableCellData[] Cells;
/// <summary>合并单元格描述列表</summary>
public List<XTableMergeDescriptor> MergeDescriptors;
/// <summary>
/// 创建指定尺寸的块
/// </summary>
public XTableBlock(int blockSizeX, int blockSizeY)
{
BlockSizeX = blockSizeX;
BlockSizeY = blockSizeY;
Cells = new XTableCellData[blockSizeX * blockSizeY];
MergeDescriptors = new List<XTableMergeDescriptor>();
}
/// <summary>
/// 创建指定尺寸和位置的块
/// </summary>
public XTableBlock(int blockSizeX, int blockSizeY, int blockRow, int blockCol)
: this(blockSizeX, blockSizeY)
{
BlockRow = blockRow;
BlockCol = blockCol;
}
/// <summary>
/// 通过块内局部坐标获取单元格数据
/// </summary>
public XTableCellData GetCell(int localRow, int localCol)
{
int index = localRow * BlockSizeX + localCol;
if (index < 0 || index >= Cells.Length) return null;
return Cells[index];
}
/// <summary>
/// 通过块内局部坐标设置单元格数据
/// </summary>
public void SetCell(int localRow, int localCol, XTableCellData data)
{
int index = localRow * BlockSizeX + localCol;
if (index < 0 || index >= Cells.Length) return;
Cells[index] = data;
}
/// <summary>
/// 检查是否有合并描述重定向此单元格
/// </summary>
/// <returns>合并描述,若无重定向则返回 null</returns>
public XTableMergeDescriptor GetMergeRedirect(int localRow, int localCol)
{
if (MergeDescriptors == null || MergeDescriptors.Count == 0)
return null;
for (int i = 0; i < MergeDescriptors.Count; i++)
{
if (MergeDescriptors[i].Contains(localRow, localCol))
return MergeDescriptors[i];
}
return null;
}
}
}