加入武器 tag 的羁绊效果
This commit is contained in:
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class ItemTooltipContext : UIContext
|
||||
public class ItemBasicTooltipContext
|
||||
{
|
||||
public int Index;
|
||||
public string IconAssetName;
|
||||
@@ -14,10 +14,9 @@ namespace SepCore.UI
|
||||
public Rarity Rarity;
|
||||
public string Description;
|
||||
public int Price;
|
||||
public Vector3 TargetPos;
|
||||
public bool ShowRecycleButton;
|
||||
|
||||
public ItemTooltipContext()
|
||||
public ItemBasicTooltipContext()
|
||||
{
|
||||
Index = -1;
|
||||
IconAssetName = string.Empty;
|
||||
@@ -27,20 +26,23 @@ namespace SepCore.UI
|
||||
Rarity = Rarity.White;
|
||||
Description = string.Empty;
|
||||
Price = 0;
|
||||
TargetPos = Vector3.zero;
|
||||
ShowRecycleButton = false;
|
||||
}
|
||||
|
||||
public ItemTooltipContext(ItemTooltipRawData rawData) : this()
|
||||
public ItemBasicTooltipContext(ItemTooltipRawData rawData) : this()
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Index = rawData.Index;
|
||||
ItemType = rawData.ItemType;
|
||||
Rarity = rawData.Rarity;
|
||||
Price = rawData.Price;
|
||||
TargetPos = rawData.TargetPos;
|
||||
ShowRecycleButton = rawData.OnRecycle != null;
|
||||
|
||||
if (ItemType == ItemType.Weapon)
|
||||
if (ItemType == ItemType.Weapon && rawData.WeaponData != null)
|
||||
{
|
||||
var data = rawData.WeaponData;
|
||||
IconAssetName = data.Sprite;
|
||||
@@ -48,7 +50,7 @@ namespace SepCore.UI
|
||||
TypeName = ItemDescUtility.FormatWeaponTags(data);
|
||||
Description = ItemDescUtility.CreateWeaponDescription(data);
|
||||
}
|
||||
else if (ItemType == ItemType.Prop)
|
||||
else if (ItemType == ItemType.Prop && rawData.PropData != null)
|
||||
{
|
||||
var data = rawData.PropData;
|
||||
IconAssetName = data.IconAssetName;
|
||||
@@ -58,4 +60,69 @@ namespace SepCore.UI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemDetailTooltipContext
|
||||
{
|
||||
public bool HasTagSynergy;
|
||||
public string TagTitle;
|
||||
public string TagTiersContent;
|
||||
|
||||
public bool HasLastWaveDamage;
|
||||
public int LastWaveDamage;
|
||||
|
||||
public bool HasAnyContent => HasTagSynergy || HasLastWaveDamage;
|
||||
|
||||
public ItemDetailTooltipContext()
|
||||
{
|
||||
HasTagSynergy = false;
|
||||
TagTitle = string.Empty;
|
||||
TagTiersContent = string.Empty;
|
||||
HasLastWaveDamage = false;
|
||||
LastWaveDamage = 0;
|
||||
}
|
||||
|
||||
public ItemDetailTooltipContext(ItemTooltipRawData rawData) : this()
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HasLastWaveDamage = rawData.LastWaveDamage > 0;
|
||||
LastWaveDamage = rawData.LastWaveDamage;
|
||||
|
||||
if (rawData.ItemType == ItemType.Weapon && rawData.WeaponData != null && rawData.WeaponData.Tags != null && rawData.WeaponData.Tags.Count > 0)
|
||||
{
|
||||
ItemDescUtility.BuildTagSynergyInfo(rawData.WeaponData, rawData.CurrentTagCounts,
|
||||
out TagTitle, out TagTiersContent);
|
||||
HasTagSynergy = !string.IsNullOrEmpty(TagTiersContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemTooltipContext : UIContext
|
||||
{
|
||||
public ItemBasicTooltipContext BasicContext { get; private set; }
|
||||
public ItemDetailTooltipContext DetailContext { get; private set; }
|
||||
public Vector3 TargetPos { get; set; }
|
||||
|
||||
public ItemTooltipContext()
|
||||
{
|
||||
TargetPos = Vector3.zero;
|
||||
BasicContext = new ItemBasicTooltipContext();
|
||||
DetailContext = new ItemDetailTooltipContext();
|
||||
}
|
||||
|
||||
public ItemTooltipContext(ItemTooltipRawData rawData) : this()
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TargetPos = rawData.TargetPos;
|
||||
BasicContext = new ItemBasicTooltipContext(rawData);
|
||||
DetailContext = new ItemDetailTooltipContext(rawData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace SepCore.UI
|
||||
|
||||
protected override void RefreshUI(ItemTooltipForm form, ItemTooltipContext context)
|
||||
{
|
||||
form.RefreshUI(context).Forget();
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void CloseLoadedFormDirect(ItemTooltipForm form)
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.AsyncTask;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
@@ -9,53 +5,31 @@ namespace SepCore.UI
|
||||
{
|
||||
public partial class ItemTooltipForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private bool _autoResizeHeight = true;
|
||||
|
||||
[SerializeField] private float _fixedTopHeight = 150f;
|
||||
|
||||
[SerializeField] private float _fixedBottomHeight = 250;
|
||||
|
||||
[SerializeField] private float _fixedWidth = 600f;
|
||||
|
||||
[SerializeField] private float _screenEdgePadding = 64f;
|
||||
[SerializeField] private float _panelSpacing = 16f;
|
||||
[SerializeField] private float _screenEdgePadding = 32f;
|
||||
[SerializeField] private float _verticalGap = 10f;
|
||||
|
||||
private ItemTooltipContext _context;
|
||||
|
||||
private Vector3 _targetPos;
|
||||
|
||||
private bool _listenersBound;
|
||||
|
||||
public async UniTaskVoid RefreshUI(ItemTooltipContext context)
|
||||
public void RefreshUI(ItemTooltipContext context)
|
||||
{
|
||||
EnsureListeners();
|
||||
|
||||
_context = context;
|
||||
|
||||
_targetPos = ConvertWorldToAnchored(_context.TargetPos);
|
||||
|
||||
View.contentRectTransform.anchoredPosition3D = _targetPos;
|
||||
// 1. 刷新基础信息面板(同步执行,立即完成文本排版与尺寸自适应)
|
||||
View.basicForm.RefreshUI(_context.BasicContext);
|
||||
|
||||
View.titleText.text = _context.Title;
|
||||
View.typeText.text = _context.TypeName;
|
||||
View.infoText.text = _context.Description;
|
||||
View.textFormatText.Set(_context.Price);
|
||||
|
||||
View.recycleButton.gameObject.SetActive(_context.ShowRecycleButton);
|
||||
|
||||
if (!string.IsNullOrEmpty(_context.IconAssetName))
|
||||
// 2. 刷新扩展详情面板(Tag 羁绊 + 上一轮伤害)
|
||||
bool showDetail = _context.DetailContext != null && _context.DetailContext.HasAnyContent;
|
||||
View.detailForm.gameObject.SetActive(showDetail);
|
||||
if (showDetail)
|
||||
{
|
||||
string iconAssetName = _context.IconAssetName;
|
||||
var sprite = await SpriteLoader.LoadSpriteByKeyAsync(iconAssetName);
|
||||
if (_context != null && _context.IconAssetName == iconAssetName)
|
||||
{
|
||||
View.iconArea.OnInit(sprite, context.Rarity);
|
||||
ResizeToFitContent();
|
||||
ApplyClampedTargetPos();
|
||||
}
|
||||
View.detailForm.RefreshUI(_context.DetailContext);
|
||||
}
|
||||
|
||||
ResizeToFitContent();
|
||||
ApplyClampedTargetPos();
|
||||
// 3. 执行自适应排版定位
|
||||
ApplyAdaptiveSidePositioning();
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
@@ -68,7 +42,7 @@ namespace SepCore.UI
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshUI(context).Forget();
|
||||
RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
@@ -77,85 +51,146 @@ namespace SepCore.UI
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
public void OnRecycleButtonClick()
|
||||
public void ApplyAdaptiveSidePositioning()
|
||||
{
|
||||
GameEntry.Event.Fire(this, ItemTooltipRecycleEventArgs.Create(_context.Index, _context.Price));
|
||||
}
|
||||
|
||||
public void OnCancelButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, ItemTooltipHideEventArgs.Create());
|
||||
}
|
||||
|
||||
private void EnsureListeners()
|
||||
{
|
||||
if (_listenersBound)
|
||||
RectTransform container = View.contentRectTransform;
|
||||
if (container == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_listenersBound = true;
|
||||
RectTransform basicRect = View.basicForm.RectTransform;
|
||||
RectTransform detailRect = View.detailForm.RectTransform;
|
||||
|
||||
View.recycleButton.onClick.AddListener(OnRecycleButtonClick);
|
||||
View.cancelButton.onClick.AddListener(OnCancelButtonClick);
|
||||
}
|
||||
|
||||
private void ResizeToFitContent()
|
||||
{
|
||||
if (!_autoResizeHeight)
|
||||
Vector2 basicSize = basicRect.sizeDelta;
|
||||
if (basicSize.x <= 0f || basicSize.y <= 0f)
|
||||
{
|
||||
basicSize = basicRect.rect.size;
|
||||
}
|
||||
|
||||
float basicWidth = basicSize.x > 0f ? basicSize.x : 600f;
|
||||
float basicHeight = basicSize.y > 0f ? basicSize.y : 500f;
|
||||
|
||||
float halfWidth = container.rect.width * 0.5f;
|
||||
float halfHeight = container.rect.height * 0.5f;
|
||||
if (halfWidth <= 0f || halfHeight <= 0f)
|
||||
{
|
||||
if (container.parent is RectTransform parentRt)
|
||||
{
|
||||
halfWidth = parentRt.rect.width * 0.5f;
|
||||
halfHeight = parentRt.rect.height * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
// --- 纵向布局(基本面板以 pivot=(0.5, 0) 放置于目标顶部上方)---
|
||||
// _targetPos 是触发悬浮的物品按钮上边缘(世界转局部坐标),
|
||||
// 基本面板底部对齐其上方 _verticalGap 像素,永远不覆盖物品按钮本体,杜绝 PointerExit 闪烁循环。
|
||||
float basicY = _targetPos.y + _verticalGap;
|
||||
float maxBasicY = (halfHeight - _screenEdgePadding) - basicHeight;
|
||||
if (basicY > maxBasicY)
|
||||
{
|
||||
basicY = Mathf.Max(maxBasicY, _targetPos.y + _verticalGap);
|
||||
}
|
||||
|
||||
bool showDetail = View.detailForm.gameObject.activeSelf;
|
||||
if (!showDetail)
|
||||
{
|
||||
// 无副面板:直接以目标水平中心为准,限制在屏幕边界内
|
||||
float minX = -halfWidth + _screenEdgePadding + basicWidth * 0.5f;
|
||||
float maxX = halfWidth - _screenEdgePadding - basicWidth * 0.5f;
|
||||
float basicX = minX <= maxX ? Mathf.Clamp(_targetPos.x, minX, maxX) : 0f;
|
||||
basicRect.anchoredPosition = new Vector2(basicX, basicY);
|
||||
return;
|
||||
}
|
||||
|
||||
View.infoText.ForceMeshUpdate();
|
||||
var descriptionSize = View.infoText.rectTransform.sizeDelta;
|
||||
descriptionSize.y = View.infoText.preferredHeight;
|
||||
View.infoText.rectTransform.sizeDelta = descriptionSize;
|
||||
float descriptionHeight = Mathf.Max(0f, View.infoText.preferredHeight);
|
||||
float targetHeight = _fixedTopHeight + descriptionHeight + _fixedBottomHeight;
|
||||
|
||||
Vector2 size = new Vector2(_fixedWidth, targetHeight);
|
||||
View.contentRectTransform.sizeDelta = size;
|
||||
}
|
||||
|
||||
private void ApplyClampedTargetPos()
|
||||
{
|
||||
RectTransform parent = View.contentRectTransform.parent as RectTransform;
|
||||
if (parent == null)
|
||||
// --- 双面板横向排版与左右自适应翻转 ---
|
||||
Vector2 detailSize = detailRect.sizeDelta;
|
||||
if (detailSize.x <= 0f || detailSize.y <= 0f)
|
||||
{
|
||||
return;
|
||||
detailSize = detailRect.rect.size;
|
||||
}
|
||||
|
||||
Vector2 size = View.contentRectTransform.sizeDelta;
|
||||
if (size.x <= 0f || size.y <= 0f)
|
||||
float detailWidth = detailSize.x > 0f ? detailSize.x : 420f;
|
||||
float detailHeight = detailSize.y > 0f ? detailSize.y : 250f;
|
||||
|
||||
float screenMinX = -halfWidth + _screenEdgePadding;
|
||||
float screenMaxX = halfWidth - _screenEdgePadding;
|
||||
|
||||
float basicCenterX = _targetPos.x;
|
||||
float basicRight = basicCenterX + basicWidth * 0.5f;
|
||||
float detailRight = basicRight + _panelSpacing + detailWidth;
|
||||
|
||||
float basicFinalX;
|
||||
float detailFinalX;
|
||||
|
||||
if (detailRight <= screenMaxX)
|
||||
{
|
||||
size = View.contentRectTransform.rect.size;
|
||||
// 1. 右侧空间充足,副面板放在右侧
|
||||
float basicLeft = basicCenterX - basicWidth * 0.5f;
|
||||
if (basicLeft < screenMinX)
|
||||
{
|
||||
// 左侧轻微出界,向右微调
|
||||
basicCenterX += (screenMinX - basicLeft);
|
||||
}
|
||||
|
||||
basicFinalX = basicCenterX;
|
||||
float newBasicRight = basicFinalX + basicWidth * 0.5f;
|
||||
detailFinalX = newBasicRight + _panelSpacing + detailWidth * 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2. 右侧空间不足,副面板自动翻转至左侧
|
||||
float basicLeft = basicCenterX - basicWidth * 0.5f;
|
||||
float detailLeft = basicLeft - _panelSpacing - detailWidth;
|
||||
|
||||
if (detailLeft < screenMinX)
|
||||
{
|
||||
// 翻到左侧后若超出左屏边缘,向右贴边微调
|
||||
basicCenterX += (screenMinX - detailLeft);
|
||||
}
|
||||
|
||||
if (basicCenterX + basicWidth * 0.5f > screenMaxX)
|
||||
{
|
||||
// 右侧也不超界
|
||||
basicCenterX -= (basicCenterX + basicWidth * 0.5f - screenMaxX);
|
||||
}
|
||||
|
||||
basicFinalX = basicCenterX;
|
||||
float newBasicLeft = basicFinalX - basicWidth * 0.5f;
|
||||
detailFinalX = newBasicLeft - _panelSpacing - detailWidth * 0.5f;
|
||||
}
|
||||
|
||||
Vector2 pivot = View.contentRectTransform.pivot;
|
||||
float halfWidth = parent.rect.width * 0.5f;
|
||||
float halfHeight = parent.rect.height * 0.5f;
|
||||
// --- 副面板纵向对齐(以 pivot=(0.5, 1) 顶部对齐主面板顶部)---
|
||||
float basicTopEdge = basicY + basicHeight;
|
||||
float detailY = basicTopEdge;
|
||||
|
||||
float minX = -halfWidth + size.x * pivot.x + _screenEdgePadding;
|
||||
float maxX = halfWidth - size.x * (1f - pivot.x) - _screenEdgePadding;
|
||||
float minY = -halfHeight + size.y * pivot.y + _screenEdgePadding;
|
||||
float maxY = halfHeight - size.y * (1f - pivot.y) - _screenEdgePadding;
|
||||
// 限制副面板顶部不超出屏幕顶端
|
||||
if (detailY > halfHeight - _screenEdgePadding)
|
||||
{
|
||||
detailY = halfHeight - _screenEdgePadding;
|
||||
}
|
||||
|
||||
float clampedX = minX <= maxX ? Mathf.Clamp(_targetPos.x, minX, maxX) : 0f;
|
||||
float clampedY = minY <= maxY ? Mathf.Clamp(_targetPos.y, minY, maxY) : 0f;
|
||||
// 限制副面板底端不超出屏幕底端,且不低于物品按钮顶部
|
||||
float detailBottom = detailY - detailHeight;
|
||||
float minDetailBottom = Mathf.Max(-halfHeight + _screenEdgePadding, _targetPos.y + _verticalGap);
|
||||
if (detailBottom < minDetailBottom)
|
||||
{
|
||||
detailY = minDetailBottom + detailHeight;
|
||||
}
|
||||
|
||||
View.contentRectTransform.anchoredPosition3D = new Vector3(clampedX, clampedY, _targetPos.z);
|
||||
basicRect.anchoredPosition = new Vector2(basicFinalX, basicY);
|
||||
detailRect.anchoredPosition = new Vector2(detailFinalX, detailY);
|
||||
}
|
||||
|
||||
private Vector3 ConvertWorldToAnchored(Vector3 worldPos)
|
||||
{
|
||||
RectTransform parent = View.contentRectTransform.parent as RectTransform;
|
||||
if (parent == null)
|
||||
RectTransform container = View.contentRectTransform;
|
||||
if (container == null)
|
||||
{
|
||||
return worldPos;
|
||||
}
|
||||
|
||||
Canvas canvas = View.contentRectTransform.GetComponentInParent<Canvas>();
|
||||
Canvas canvas = container.GetComponentInParent<Canvas>();
|
||||
Canvas rootCanvas = canvas != null ? canvas.rootCanvas : null;
|
||||
Camera uiCamera = null;
|
||||
if (rootCanvas != null && rootCanvas.renderMode != RenderMode.ScreenSpaceOverlay)
|
||||
@@ -164,14 +199,13 @@ namespace SepCore.UI
|
||||
}
|
||||
|
||||
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(uiCamera, worldPos);
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, screenPoint, uiCamera,
|
||||
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(container, screenPoint, uiCamera,
|
||||
out Vector2 localPoint))
|
||||
{
|
||||
return worldPos;
|
||||
}
|
||||
|
||||
float z = View.contentRectTransform.anchoredPosition3D.z;
|
||||
return new Vector3(localPoint.x, localPoint.y, z);
|
||||
return localPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,7 @@ namespace SepCore.UI
|
||||
public partial class ItemTooltipView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public global::UnityEngine.RectTransform contentRectTransform;
|
||||
[SerializeField] public global::SepCore.UI.IconArea iconArea;
|
||||
[SerializeField] public global::TMPro.TextMeshProUGUI titleText;
|
||||
[SerializeField] public global::TMPro.TextMeshProUGUI typeText;
|
||||
[SerializeField] public global::TMPro.TextMeshProUGUI infoText;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton recycleButton;
|
||||
[SerializeField] public global::SepCore.UI.FormatTextUI textFormatText;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton cancelButton;
|
||||
[SerializeField] public global::SepCore.UI.ItemBasicTooltipForm basicForm;
|
||||
[SerializeField] public global::SepCore.UI.ItemDetailTooltipForm detailForm;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user