386 战斗系统buff详情界面 实现根据buff描述文字宽度自适应cell的宽度
1个文件已修改
51 ■■■■■ 已修改文件
Main/System/OtherPlayerDetail/BuffInfoCell.cs 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/OtherPlayerDetail/BuffInfoCell.cs
@@ -2,11 +2,24 @@
public class BuffInfoCell : CellView
{
    private const float BaseCellWidth = 607f;
    private const float BaseDescWidth = 564.48f;
    [SerializeField] TextEx buffNameText;
    [SerializeField] TextEx roundText;
    [SerializeField] ImageEx buffImage;
    [SerializeField] TextEx buffCountText;
    [SerializeField] RichText descText;
    RectTransform cellRectTransform;
    RectTransform descRectTransform;
    private void Awake()
    {
        ResetWidth();
        SetDescAutoNewLine();
    }
    public void Display(int index, BattleClickBuffData data)
    {
        if (data.datas?.Count <= index) return;
@@ -19,6 +32,8 @@
        buffCountText.text = info.Layer == 0 ? "" : info.Layer.ToString();
        buffNameText.text = UIHelper.AppendColor(config.IsDebuff() ? TextColType.Red : TextColType.LightGreen, config.SkillName);
        ResetWidth();
        SetDescAutoNewLine();
        descText.text = config.Description;
        roundText.text = info.LastTime <= 0 ? "" : Language.Get("BuffInfo01", info.LastTime);
@@ -27,7 +42,41 @@
    public float GetTextHeight(string content)
    {
        ResetWidth();
        SetDescAutoNewLine();
        descText.text = content;
        return string.IsNullOrEmpty(content) ? 0 : descText.preferredHeight + 80;
    }
}
    private void ResetWidth()
    {
        if (cellRectTransform == null)
        {
            cellRectTransform = transform as RectTransform;
        }
        if (descRectTransform == null && descText != null)
        {
            descRectTransform = descText.rectTransform;
        }
        SetWidth(cellRectTransform, BaseCellWidth);
        SetWidth(descRectTransform, BaseDescWidth);
    }
    private void SetDescAutoNewLine()
    {
        if (descText != null && !descText.AutoNewLine)
        {
            descText.AutoNewLine = true;
        }
    }
    private void SetWidth(RectTransform rectTransform, float width)
    {
        if (rectTransform != null)
        {
            rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
        }
    }
}