加入武器 tag 的羁绊效果
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public partial class ItemDetailTooltipForm
|
||||
{
|
||||
[SerializeField] private float _fixedWidth = 420f;
|
||||
[SerializeField] private float _tagCardPadding = 30f;
|
||||
[SerializeField] private float _damageCardPadding = 30f;
|
||||
[SerializeField] private float _cardSpacing = 16f;
|
||||
|
||||
public RectTransform RectTransform => View.contentRectTransform;
|
||||
|
||||
public void RefreshUI(ItemDetailTooltipContext context)
|
||||
{
|
||||
if (context == null || !context.HasAnyContent)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
gameObject.SetActive(true);
|
||||
|
||||
// 1. Tag 属性卡片
|
||||
View.tagSynergyRoot.gameObject.SetActive(context.HasTagSynergy);
|
||||
if (context.HasTagSynergy)
|
||||
{
|
||||
bool hasTitle = !string.IsNullOrEmpty(context.TagTitle);
|
||||
View.tagTitleText.gameObject.SetActive(hasTitle);
|
||||
if (hasTitle)
|
||||
{
|
||||
View.tagTitleText.text = context.TagTitle;
|
||||
}
|
||||
View.tagTiersText.text = context.TagTiersContent;
|
||||
}
|
||||
|
||||
// 2. 上一轮造成伤害卡片
|
||||
View.lastWaveDamageRoot.gameObject.SetActive(context.HasLastWaveDamage);
|
||||
if (context.HasLastWaveDamage)
|
||||
{
|
||||
View.lastWaveDamageText.text = $"这个武器在上一波敌袭中造成了 <color=#38E038>{context.LastWaveDamage}</color> 伤害";
|
||||
}
|
||||
|
||||
// 3. 强制重算尺寸
|
||||
ResizeToFitContent();
|
||||
}
|
||||
|
||||
public void ResizeToFitContent()
|
||||
{
|
||||
float totalHeight = 0f;
|
||||
int visibleCards = 0;
|
||||
|
||||
if (View.tagSynergyRoot.gameObject.activeSelf)
|
||||
{
|
||||
float titleHeight = 0f;
|
||||
if (View.tagTitleText.gameObject.activeSelf)
|
||||
{
|
||||
View.tagTitleText.ForceMeshUpdate();
|
||||
titleHeight = View.tagTitleText.preferredHeight + 8f;
|
||||
}
|
||||
|
||||
View.tagTiersText.ForceMeshUpdate();
|
||||
float tagTiersHeight = View.tagTiersText.preferredHeight;
|
||||
float tagCardHeight = titleHeight + tagTiersHeight + _tagCardPadding;
|
||||
totalHeight += tagCardHeight;
|
||||
visibleCards++;
|
||||
}
|
||||
|
||||
if (View.lastWaveDamageRoot.gameObject.activeSelf)
|
||||
{
|
||||
View.lastWaveDamageText.ForceMeshUpdate();
|
||||
float damageTextHeight = View.lastWaveDamageText.preferredHeight;
|
||||
float damageCardHeight = damageTextHeight + _damageCardPadding;
|
||||
if (visibleCards > 0)
|
||||
{
|
||||
totalHeight += _cardSpacing;
|
||||
}
|
||||
totalHeight += damageCardHeight;
|
||||
visibleCards++;
|
||||
}
|
||||
|
||||
View.contentRectTransform.sizeDelta = new Vector2(_fixedWidth, Mathf.Max(80f, totalHeight));
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(View.contentRectTransform);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user