加入武器 tag 的羁绊效果
This commit is contained in:
@@ -43,6 +43,8 @@ namespace SepCore.Entity
|
||||
public IReadOnlyList<StatModifierConfig> Modifiers => Config.StatModifierConfigs;
|
||||
|
||||
public IReadOnlyList<WeaponTag> Tags => Config.Tags;
|
||||
|
||||
public int LastWaveDamage { get; set; }
|
||||
|
||||
public float GetParamFloat(ParamType paramType)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd82ef91c90c6494d982e3cea80a4443
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,92 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.AsyncTask;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public partial class ItemBasicTooltipForm
|
||||
{
|
||||
[SerializeField] private bool _autoResizeHeight = true;
|
||||
[SerializeField] private float _fixedTopHeight = 150f;
|
||||
[SerializeField] private float _fixedBottomHeight = 250f;
|
||||
[SerializeField] private float _fixedWidth = 600f;
|
||||
|
||||
private ItemBasicTooltipContext _context;
|
||||
private bool _listenersBound;
|
||||
|
||||
public RectTransform RectTransform => View.contentRectTransform;
|
||||
|
||||
public void RefreshUI(ItemBasicTooltipContext context)
|
||||
{
|
||||
EnsureListeners();
|
||||
_context = context;
|
||||
|
||||
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);
|
||||
|
||||
ResizeToFitContent();
|
||||
|
||||
if (!string.IsNullOrEmpty(_context.IconAssetName))
|
||||
{
|
||||
LoadIconAsync(_context.IconAssetName, _context.Rarity).Forget();
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTaskVoid LoadIconAsync(string iconAssetName, Rarity rarity)
|
||||
{
|
||||
var sprite = await SpriteLoader.LoadSpriteByKeyAsync(iconAssetName);
|
||||
if (_context != null && _context.IconAssetName == iconAssetName)
|
||||
{
|
||||
View.iconArea.OnInit(sprite, rarity);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRecycleButtonClick()
|
||||
{
|
||||
if (_context != null)
|
||||
{
|
||||
GameEntry.Event.Fire(this, ItemTooltipRecycleEventArgs.Create(_context.Index, _context.Price));
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCancelButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, ItemTooltipHideEventArgs.Create());
|
||||
}
|
||||
|
||||
private void EnsureListeners()
|
||||
{
|
||||
if (_listenersBound)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_listenersBound = true;
|
||||
View.recycleButton.onClick.AddListener(OnRecycleButtonClick);
|
||||
View.cancelButton.onClick.AddListener(OnCancelButtonClick);
|
||||
}
|
||||
|
||||
public void ResizeToFitContent()
|
||||
{
|
||||
if (!_autoResizeHeight)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f497c7815cf0c24eb7c51b51faebb64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
// <auto-generated />
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public partial class ItemBasicTooltipForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private ItemBasicTooltipView _view = null;
|
||||
|
||||
public ItemBasicTooltipView View => _view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d3c71ad8d7c52d48b5b25ab50f4bf5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
// <auto-generated />
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public partial class ItemBasicTooltipView : 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 370e44750fcddb741a7762eb69bf3ef8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ed15075c4b29014fa34ed8afd600634
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf21d1b61ba4ee648b4676f28e8167e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
// <auto-generated />
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public partial class ItemDetailTooltipForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private ItemDetailTooltipView _view = null;
|
||||
|
||||
public ItemDetailTooltipView View => _view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b50c309a8e2b95b4e8d205dd9a4d9760
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
// <auto-generated />
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public partial class ItemDetailTooltipView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public global::UnityEngine.RectTransform contentRectTransform;
|
||||
[SerializeField] public global::UnityEngine.RectTransform tagSynergyRoot;
|
||||
[SerializeField] public global::TMPro.TextMeshProUGUI tagTitleText;
|
||||
[SerializeField] public global::TMPro.TextMeshProUGUI tagTiersText;
|
||||
[SerializeField] public global::UnityEngine.RectTransform lastWaveDamageRoot;
|
||||
[SerializeField] public global::TMPro.TextMeshProUGUI lastWaveDamageText;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb1d34a67bf82f94db0396a32459f1f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Event;
|
||||
using SepCore.Definition;
|
||||
@@ -192,10 +193,36 @@ namespace SepCore.UI
|
||||
ItemType = ItemType.Weapon,
|
||||
Price = _useCase.CalculateRecyclePrice(weapon.WeaponData.Price),
|
||||
OnRecycle = RecycleWeapon,
|
||||
LastWaveDamage = weapon.WeaponData.LastWaveDamage,
|
||||
CurrentTagCounts = GetEquippedTagCounts(),
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
private Dictionary<WeaponTag, int> GetEquippedTagCounts()
|
||||
{
|
||||
Dictionary<WeaponTag, int> counts = new Dictionary<WeaponTag, int>();
|
||||
if (_rawData?.WeaponItems != null)
|
||||
{
|
||||
for (int i = 0; i < _rawData.WeaponItems.Count; i++)
|
||||
{
|
||||
WeaponBase w = _rawData.WeaponItems[i];
|
||||
if (w?.WeaponData?.Tags != null)
|
||||
{
|
||||
for (int t = 0; t < w.WeaponData.Tags.Count; t++)
|
||||
{
|
||||
WeaponTag tag = w.WeaponData.Tags[t];
|
||||
if (tag != WeaponTag.None)
|
||||
{
|
||||
counts[tag] = counts.GetValueOrDefault(tag, 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
private bool TryGetPropInfoRawData(int index, Vector3 targetPos, out ItemTooltipRawData rawData)
|
||||
{
|
||||
rawData = null;
|
||||
|
||||
@@ -210,5 +210,187 @@ namespace SepCore.CustomUtility
|
||||
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
public static void BuildTagSynergyInfo(WeaponData weaponData, IReadOnlyDictionary<WeaponTag, int> tagCounts,
|
||||
out string tagTitle, out string tagTiersContent)
|
||||
{
|
||||
if (weaponData == null || weaponData.Tags == null || weaponData.Tags.Count == 0)
|
||||
{
|
||||
tagTitle = string.Empty;
|
||||
tagTiersContent = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
BuildTagSynergyInfo(weaponData.Tags, tagCounts, out tagTitle, out tagTiersContent);
|
||||
}
|
||||
|
||||
public static void BuildTagSynergyInfo(IReadOnlyList<WeaponTag> tags, IReadOnlyDictionary<WeaponTag, int> tagCounts,
|
||||
out string tagTitle, out string tagTiersContent)
|
||||
{
|
||||
if (GameEntry.Luban == null || !GameEntry.Luban.IsReady)
|
||||
{
|
||||
tagTitle = string.Empty;
|
||||
tagTiersContent = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
var allTagConfigs = GameEntry.Luban.GetTable<WeaponTagConfig>();
|
||||
BuildTagSynergyInfo(tags, tagCounts, allTagConfigs, out tagTitle, out tagTiersContent);
|
||||
}
|
||||
|
||||
public static void BuildTagSynergyInfo(IReadOnlyList<WeaponTag> tags, IReadOnlyDictionary<WeaponTag, int> tagCounts,
|
||||
IReadOnlyList<WeaponTagConfig> allTagConfigs, out string tagTitle, out string tagTiersContent)
|
||||
{
|
||||
if (tags == null || tags.Count == 0 || allTagConfigs == null || allTagConfigs.Count == 0)
|
||||
{
|
||||
tagTitle = string.Empty;
|
||||
tagTiersContent = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
List<WeaponTag> validTags = new List<WeaponTag>();
|
||||
for (int i = 0; i < tags.Count; i++)
|
||||
{
|
||||
WeaponTag tag = tags[i];
|
||||
if (tag != WeaponTag.None && !validTags.Contains(tag))
|
||||
{
|
||||
validTags.Add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
if (validTags.Count == 0)
|
||||
{
|
||||
tagTitle = string.Empty;
|
||||
tagTiersContent = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
if (validTags.Count == 1)
|
||||
{
|
||||
WeaponTag singleTag = validTags[0];
|
||||
string tiers = BuildSingleTagTiers(singleTag, tagCounts, allTagConfigs);
|
||||
if (string.IsNullOrEmpty(tiers))
|
||||
{
|
||||
tagTitle = string.Empty;
|
||||
tagTiersContent = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
tagTitle = GetWeaponTagName(singleTag);
|
||||
tagTiersContent = tiers;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int t = 0; t < validTags.Count; t++)
|
||||
{
|
||||
WeaponTag tag = validTags[t];
|
||||
string tiers = BuildSingleTagTiers(tag, tagCounts, allTagConfigs);
|
||||
if (string.IsNullOrEmpty(tiers))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sb.Length > 0)
|
||||
{
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
sb.AppendLine($"<b><size=117%><color=#F5F5F5>{GetWeaponTagName(tag)}</color></size></b>");
|
||||
sb.AppendLine(tiers);
|
||||
}
|
||||
|
||||
tagTitle = string.Empty;
|
||||
tagTiersContent = sb.ToString().TrimEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildSingleTagTiers(WeaponTag tag, IReadOnlyDictionary<WeaponTag, int> tagCounts,
|
||||
IReadOnlyList<WeaponTagConfig> allTagConfigs)
|
||||
{
|
||||
int currentCount = tagCounts != null && tagCounts.TryGetValue(tag, out int c) ? c : 0;
|
||||
List<WeaponTagConfig> tiers = new List<WeaponTagConfig>();
|
||||
for (int i = 0; i < allTagConfigs.Count; i++)
|
||||
{
|
||||
WeaponTagConfig cfg = allTagConfigs[i];
|
||||
if (cfg.Tag == tag)
|
||||
{
|
||||
tiers.Add(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
if (tiers.Count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
tiers.Sort((a, b) => a.RequiredCount.CompareTo(b.RequiredCount));
|
||||
|
||||
int activeCount = -1;
|
||||
for (int i = tiers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (currentCount >= tiers[i].RequiredCount)
|
||||
{
|
||||
activeCount = tiers[i].RequiredCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < tiers.Count; i++)
|
||||
{
|
||||
WeaponTagConfig tier = tiers[i];
|
||||
bool isActive = tier.RequiredCount == activeCount;
|
||||
|
||||
StringBuilder modSb = new StringBuilder();
|
||||
if (tier.StatModifierConfigs != null)
|
||||
{
|
||||
for (int m = 0; m < tier.StatModifierConfigs.Count; m++)
|
||||
{
|
||||
StatModifierConfig mod = tier.StatModifierConfigs[m];
|
||||
if (modSb.Length > 0)
|
||||
{
|
||||
modSb.Append(", ");
|
||||
}
|
||||
|
||||
int statIdx = (int)mod.StatType;
|
||||
string statName = (statIdx >= 0 && statIdx < _statTypeNames.Length)
|
||||
? _statTypeNames[statIdx]
|
||||
: mod.StatType.ToString();
|
||||
|
||||
StatConfig statConfig = (GameEntry.Luban != null && GameEntry.Luban.IsReady)
|
||||
? GameEntry.Luban.Get<StatConfig>(statIdx)
|
||||
: null;
|
||||
if (statConfig != null && !string.IsNullOrEmpty(statConfig.Name))
|
||||
{
|
||||
statName = statConfig.Name;
|
||||
}
|
||||
|
||||
string sign = mod.Value >= 0 ? "+" : "";
|
||||
bool isPercent = statConfig != null && statConfig.IsPercentDisplay;
|
||||
if (isPercent || mod.ModifierType == ModifierType.PercentAdd)
|
||||
{
|
||||
modSb.Append($"{sign}{mod.Value * 100:0.##}% {statName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
modSb.Append($"{sign}{mod.Value:0.##} {statName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string tierText = modSb.ToString();
|
||||
if (isActive)
|
||||
{
|
||||
sb.AppendLine($"<b><color=#38E038>({tier.RequiredCount}) {tierText}</color></b>");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($"<color=#707070>({tier.RequiredCount}) {tierText}</color>");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace SepCore.Battle
|
||||
public sealed class AttributePipeline : IAttributeProvider
|
||||
{
|
||||
private readonly Dictionary<StatType, CharacterStat> _stats = new();
|
||||
private int _batchDepth;
|
||||
private readonly HashSet<StatType> _batchedChangedStats = new();
|
||||
|
||||
/// <summary>
|
||||
/// 当某个属性的值发生变动(添加/移除修饰器、修改基础值)时触发。
|
||||
@@ -19,6 +21,65 @@ namespace SepCore.Battle
|
||||
/// </summary>
|
||||
public event Action<StatType, float> OnStatChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 开启批量修饰器更新作用域。在作用域内添加/移除修饰器不会立即触发 OnStatChanged,
|
||||
/// 而是在作用域 Dispose 时对所有发生变更的属性统一触发一次最终值的 OnStatChanged。
|
||||
/// </summary>
|
||||
public BatchScope BeginBatchUpdate()
|
||||
{
|
||||
_batchDepth++;
|
||||
return new BatchScope(this);
|
||||
}
|
||||
|
||||
public void EndBatchUpdate()
|
||||
{
|
||||
if (_batchDepth <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_batchDepth--;
|
||||
if (_batchDepth == 0 && _batchedChangedStats.Count > 0)
|
||||
{
|
||||
StatType[] changed = new StatType[_batchedChangedStats.Count];
|
||||
_batchedChangedStats.CopyTo(changed);
|
||||
_batchedChangedStats.Clear();
|
||||
|
||||
for (int i = 0; i < changed.Length; i++)
|
||||
{
|
||||
StatType statType = changed[i];
|
||||
OnStatChanged?.Invoke(statType, GetValue(statType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifyStatChanged(StatType statType, float newValue)
|
||||
{
|
||||
if (_batchDepth > 0)
|
||||
{
|
||||
_batchedChangedStats.Add(statType);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnStatChanged?.Invoke(statType, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct BatchScope : IDisposable
|
||||
{
|
||||
private readonly AttributePipeline _pipeline;
|
||||
|
||||
public BatchScope(AttributePipeline pipeline)
|
||||
{
|
||||
_pipeline = pipeline;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_pipeline?.EndBatchUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public AttributePipeline()
|
||||
{
|
||||
// 预初始化已定义的所有 StatType 枚举
|
||||
@@ -64,7 +125,7 @@ namespace SepCore.Battle
|
||||
|
||||
if (Math.Abs(oldValue - newValue) > 1e-6f)
|
||||
{
|
||||
OnStatChanged?.Invoke(statType, newValue);
|
||||
NotifyStatChanged(statType, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +141,7 @@ namespace SepCore.Battle
|
||||
|
||||
CharacterStat stat = Get(statType);
|
||||
stat.AddModifier(modifier);
|
||||
OnStatChanged?.Invoke(statType, stat.Value);
|
||||
NotifyStatChanged(statType, stat.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,7 +158,7 @@ namespace SepCore.Battle
|
||||
bool removed = stat.RemoveModifier(modifier);
|
||||
if (removed)
|
||||
{
|
||||
OnStatChanged?.Invoke(statType, stat.Value);
|
||||
NotifyStatChanged(statType, stat.Value);
|
||||
}
|
||||
|
||||
return removed;
|
||||
@@ -165,7 +226,7 @@ namespace SepCore.Battle
|
||||
if (removed > 0)
|
||||
{
|
||||
totalRemoved += removed;
|
||||
OnStatChanged?.Invoke(pair.Key, pair.Value.Value);
|
||||
NotifyStatChanged(pair.Key, pair.Value.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +241,7 @@ namespace SepCore.Battle
|
||||
foreach (KeyValuePair<StatType, CharacterStat> pair in _stats)
|
||||
{
|
||||
pair.Value.ClearModifiers();
|
||||
OnStatChanged?.Invoke(pair.Key, pair.Value.Value);
|
||||
NotifyStatChanged(pair.Key, pair.Value.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
using System.Collections.Generic;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
|
||||
namespace SepCore.Battle
|
||||
{
|
||||
/// <summary>
|
||||
/// 武器标签羁绊管理器。
|
||||
/// 维护当前装备武器的标签统计、计算最高阶梯羁绊,并向属性管线派发/撤销带来源标记(Source)的 StatModifier。
|
||||
/// 纯 C# 类,保证数据唯一真相源与零高频 GC。
|
||||
/// </summary>
|
||||
public sealed class WeaponSynergyManager
|
||||
{
|
||||
private readonly Dictionary<WeaponTag, List<WeaponTagConfig>> _tagTierConfigs = new();
|
||||
private readonly Dictionary<WeaponTag, int> _tagCounts = new();
|
||||
private readonly Dictionary<WeaponTag, WeaponTagConfig> _activeTiers = new();
|
||||
|
||||
public IReadOnlyDictionary<WeaponTag, int> TagCounts => _tagCounts;
|
||||
public IReadOnlyDictionary<WeaponTag, WeaponTagConfig> ActiveTiers => _activeTiers;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_tagTierConfigs.Clear();
|
||||
if (GameEntry.Luban == null || !GameEntry.Luban.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var allConfigs = GameEntry.Luban.GetTable<WeaponTagConfig>();
|
||||
for (int i = 0; i < allConfigs.Count; i++)
|
||||
{
|
||||
WeaponTagConfig config = allConfigs[i];
|
||||
if (config.Tag == WeaponTag.None)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_tagTierConfigs.TryGetValue(config.Tag, out List<WeaponTagConfig> list))
|
||||
{
|
||||
list = new List<WeaponTagConfig>();
|
||||
_tagTierConfigs.Add(config.Tag, list);
|
||||
}
|
||||
|
||||
list.Add(config);
|
||||
}
|
||||
|
||||
foreach (var kvp in _tagTierConfigs)
|
||||
{
|
||||
kvp.Value.Sort((a, b) => a.RequiredCount.CompareTo(b.RequiredCount));
|
||||
}
|
||||
}
|
||||
|
||||
public int GetTagCount(WeaponTag tag)
|
||||
{
|
||||
return _tagCounts.TryGetValue(tag, out int count) ? count : 0;
|
||||
}
|
||||
|
||||
public WeaponTagConfig GetActiveTier(WeaponTag tag)
|
||||
{
|
||||
return _activeTiers.TryGetValue(tag, out WeaponTagConfig tier) ? tier : null;
|
||||
}
|
||||
|
||||
public IReadOnlyList<WeaponTagConfig> GetTiersForTag(WeaponTag tag)
|
||||
{
|
||||
return _tagTierConfigs.TryGetValue(tag, out List<WeaponTagConfig> list)
|
||||
? list
|
||||
: System.Array.Empty<WeaponTagConfig>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全量刷新羁绊状态并同步属性管线(强幂等)。
|
||||
/// 档位变动时执行旧档位 Source 移除与新档位挂载。
|
||||
/// </summary>
|
||||
public void RefreshSynergies(IReadOnlyList<WeaponBase> weapons, AttributePipeline pipeline)
|
||||
{
|
||||
if (pipeline == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 重新统计 Tag 计数
|
||||
_tagCounts.Clear();
|
||||
if (weapons != null)
|
||||
{
|
||||
for (int i = 0; i < weapons.Count; i++)
|
||||
{
|
||||
WeaponBase weapon = weapons[i];
|
||||
if (weapon?.WeaponData == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IReadOnlyList<WeaponTag> tags = weapon.WeaponData.Tags;
|
||||
if (tags == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int t = 0; t < tags.Count; t++)
|
||||
{
|
||||
WeaponTag tag = tags[t];
|
||||
if (tag == WeaponTag.None)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_tagCounts[tag] = _tagCounts.GetValueOrDefault(tag, 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 检查每个 Tag 的阶梯阈值达成情况(最高生效原则 / Milestone Replacement)
|
||||
// 使用 BeginBatchUpdate 作用域原子性批量替换修饰器,确保旧档卸载与新档挂载完成后统一通知一次属性变更,
|
||||
// 避免生命值上限临时下降导致当前生命值被意外裁剪。
|
||||
using (pipeline.BeginBatchUpdate())
|
||||
{
|
||||
foreach (var kvp in _tagTierConfigs)
|
||||
{
|
||||
WeaponTag tag = kvp.Key;
|
||||
List<WeaponTagConfig> tiers = kvp.Value;
|
||||
int currentCount = _tagCounts.GetValueOrDefault(tag, 0);
|
||||
|
||||
WeaponTagConfig bestTier = null;
|
||||
for (int i = tiers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (currentCount >= tiers[i].RequiredCount)
|
||||
{
|
||||
bestTier = tiers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_activeTiers.TryGetValue(tag, out WeaponTagConfig oldTier);
|
||||
if (oldTier != bestTier)
|
||||
{
|
||||
// 卸载旧档位的修饰器
|
||||
if (oldTier != null)
|
||||
{
|
||||
pipeline.RemoveAllModifiersFromSource(oldTier);
|
||||
}
|
||||
|
||||
// 挂载新档位的修饰器
|
||||
if (bestTier != null && bestTier.StatModifierConfigs != null)
|
||||
{
|
||||
for (int m = 0; m < bestTier.StatModifierConfigs.Count; m++)
|
||||
{
|
||||
pipeline.AddModifier(bestTier.StatModifierConfigs[m], bestTier);
|
||||
}
|
||||
}
|
||||
|
||||
_activeTiers[tag] = bestTier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5575d5d9f07dd147b64aa0070d63914
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using SepCore.Battle;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using UnityEngine;
|
||||
@@ -27,6 +28,11 @@ namespace SepCore.Components
|
||||
/// </summary>
|
||||
private StatComponent _statComponent;
|
||||
|
||||
/// <summary>
|
||||
/// 武器标签羁绊管理器。
|
||||
/// </summary>
|
||||
private readonly WeaponSynergyManager _synergyManager = new();
|
||||
|
||||
/// <summary>
|
||||
/// 武器装备槽,在 Editor 中进行配置,表示武器在世界中的显示位置。
|
||||
/// </summary>
|
||||
@@ -35,6 +41,7 @@ namespace SepCore.Components
|
||||
public IReadOnlyList<WeaponBase> Weapons => _weapons;
|
||||
public IReadOnlyList<PropItem> Props => _props;
|
||||
public int WeaponCapacity => GameEntry.Luban.Global.WeaponCapacity;
|
||||
public WeaponSynergyManager SynergyManager => _synergyManager;
|
||||
|
||||
public void OnInit(Player player)
|
||||
{
|
||||
@@ -43,12 +50,14 @@ namespace SepCore.Components
|
||||
_weapons = new List<WeaponBase>(WeaponCapacity);
|
||||
_props = new List<PropItem>();
|
||||
_statComponent = GetComponent<StatComponent>();
|
||||
_synergyManager.Initialize();
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
_weapons.Clear();
|
||||
_props.Clear();
|
||||
_synergyManager.RefreshSynergies(_weapons, _statComponent.Pipeline);
|
||||
}
|
||||
|
||||
public bool AttachWeapon(WeaponBase weapon)
|
||||
@@ -57,6 +66,7 @@ namespace SepCore.Components
|
||||
GameEntry.Entity.AttachEntity(weapon.Id, _player.Id, _weaponSlots[_weapons.Count]);
|
||||
_weapons.Add(weapon);
|
||||
weapon.SetEnabled(true);
|
||||
_synergyManager.RefreshSynergies(_weapons, _statComponent.Pipeline);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,6 +76,7 @@ namespace SepCore.Components
|
||||
if (result)
|
||||
{
|
||||
GameEntry.Entity.DetachEntity(weapon.Id, _player.Id);
|
||||
_synergyManager.RefreshSynergies(_weapons, _statComponent.Pipeline);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using UnityEngine;
|
||||
@@ -22,5 +23,7 @@ namespace SepCore.UI
|
||||
public int Price;
|
||||
public Vector3 TargetPos;
|
||||
public Action<int, int> OnRecycle;
|
||||
public int LastWaveDamage;
|
||||
public IReadOnlyDictionary<WeaponTag, int> CurrentTagCounts;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user