UI调整
This commit is contained in:
@@ -15,15 +15,14 @@ namespace Cielonos.MainGame.UI
|
||||
public Image frame;
|
||||
private Sequence frameOutlineSequence;
|
||||
|
||||
public void Initialize(Sprite icon, string weaponName)
|
||||
public void Initialize(RuntimeFunctionUnit functionUnit, string weaponName)
|
||||
{
|
||||
rectIcon.sprite = icon;
|
||||
rectIcon.sprite = functionUnit.data.icon;
|
||||
weaponNameText.text = weaponName;
|
||||
}
|
||||
|
||||
public void SetFrameOutline(float totalDuration, Color color = default, float intensity = 2f)
|
||||
{
|
||||
return;
|
||||
color = color == default ? Color.cyan : color;
|
||||
Color hdrColor = color * Mathf.Pow(2f, intensity);
|
||||
GlowFilter glowFilter = frame.GetComponent<GlowFilter>();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using ChocDino.UIFX;
|
||||
using Cielonos.MainGame.Inventory;
|
||||
using DG.Tweening;
|
||||
using SLSUtilities.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
@@ -8,31 +11,87 @@ namespace Cielonos.MainGame.UI
|
||||
{
|
||||
public class MainWeaponFunctionIcon : UIElementBase
|
||||
{
|
||||
public RuntimeFunctionUnit functionUnit;
|
||||
[FormerlySerializedAs("timerFillImage")] public Image frame;
|
||||
public Image frame;
|
||||
public Image iconImage;
|
||||
public Image timer;
|
||||
|
||||
public Image timerImage;
|
||||
public TMP_Text timerText;
|
||||
public TMP_Text costText;
|
||||
|
||||
private Sequence _frameOutlineSequence;
|
||||
private RuntimeFunctionUnit _functionUnit;
|
||||
public void Initialize(RuntimeFunctionUnit functionUnit)
|
||||
{
|
||||
this.functionUnit = functionUnit;
|
||||
this._functionUnit = functionUnit;
|
||||
iconImage.sprite = functionUnit.data.icon != null ? functionUnit.data.icon : null;
|
||||
|
||||
if (_functionUnit.maxCooldown <= 0)
|
||||
{
|
||||
timerImage.gameObject.SetActive(false);
|
||||
timerText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if(_functionUnit.data.energyCost <= 0)
|
||||
{
|
||||
costText.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
costText.text = Mathf.CeilToInt(_functionUnit.data.energyCost).ToString("D");
|
||||
}
|
||||
|
||||
if (_functionUnit.data.tags.Contains("Disruption"))
|
||||
{
|
||||
Color newColor = Color.yellow;
|
||||
iconImage.color = newColor;
|
||||
newColor.a = 0.5f;
|
||||
frame.color = newColor;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateUI()
|
||||
{
|
||||
float fillAmount;
|
||||
|
||||
if (functionUnit.maxCooldown <= 0f)
|
||||
if (_functionUnit.maxCooldown <= 0f)
|
||||
{
|
||||
fillAmount = 1f;
|
||||
//无冷却
|
||||
}
|
||||
else
|
||||
{
|
||||
fillAmount = 1f - functionUnit.currentCooldown / functionUnit.maxCooldown;
|
||||
float fillAmount = 1f - _functionUnit.currentCooldown / _functionUnit.maxCooldown;
|
||||
timerImage.fillAmount = fillAmount;
|
||||
|
||||
if (_functionUnit.currentCooldown > 0f)
|
||||
{
|
||||
timerText.text = _functionUnit.currentCooldown.ToString("F1");
|
||||
}
|
||||
else
|
||||
{
|
||||
timerText.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
frame.fillAmount = fillAmount;
|
||||
|
||||
if (_functionUnit.data.energyCost > 0)
|
||||
{
|
||||
float playerCurrentEnergy = MainGameManager.Player.attributeSm[CharacterAttribute.Energy];
|
||||
costText.color = playerCurrentEnergy >= _functionUnit.data.energyCost ? Color.cyan : Color.orangeRed;
|
||||
costText.text = Mathf.CeilToInt(_functionUnit.data.energyCost).ToString("D");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFrameOutline(float totalDuration, Color color = default, float intensity = 0.5f)
|
||||
{
|
||||
color = color == default ? Color.white : color;
|
||||
Color hdrColor = color * Mathf.Pow(2f, intensity);
|
||||
GlowFilter glowFilter = frame.GetComponent<GlowFilter>();
|
||||
glowFilter.Color = hdrColor;
|
||||
float fadeDuration = Mathf.Clamp(totalDuration / 2f, 0.2f, totalDuration);
|
||||
float stayDuration = totalDuration - fadeDuration;
|
||||
float strengthPeak = 0.5f;
|
||||
_frameOutlineSequence?.Kill(true);
|
||||
_frameOutlineSequence = DOTween.Sequence();
|
||||
_frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, strengthPeak, fadeDuration).SetEase(Ease.OutQuad));
|
||||
_frameOutlineSequence.AppendInterval(stayDuration);
|
||||
_frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, 0f, fadeDuration).SetEase(Ease.InQuad));
|
||||
_frameOutlineSequence.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,29 +14,40 @@ namespace Cielonos.MainGame.UI
|
||||
public RectTransform functionIconContainer;
|
||||
|
||||
public MainWeaponDisplayer displayer;
|
||||
public MainWeaponFunctionIcon mainFunctionIcon;
|
||||
public List<MainWeaponFunctionIcon> functionIcons;
|
||||
|
||||
public Dictionary<string, MainWeaponFunctionIcon> functionIconDict;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
functionIcons = new List<MainWeaponFunctionIcon>();
|
||||
functionIconDict = new Dictionary<string, MainWeaponFunctionIcon>();
|
||||
}
|
||||
|
||||
public void Initialize(MainWeaponBase mainWeapon)
|
||||
{
|
||||
this.mainWeapon = mainWeapon;
|
||||
Sprite rectIcon = mainWeapon.contentData.rectIcon;
|
||||
string weaponName = mainWeapon.contentData.itemClass.Name; //TODO: 后续改为本地化显示
|
||||
displayer.Initialize(rectIcon, weaponName);
|
||||
string weaponName = mainWeapon.contentData.itemClass.Name;
|
||||
|
||||
ClearIcons();
|
||||
|
||||
foreach (KeyValuePair<string, RuntimeFunctionUnit> unit in mainWeapon.functionSm.functionUnits)
|
||||
{
|
||||
if (!unit.Value.data.shownInUI) continue;
|
||||
|
||||
MainWeaponFunctionIcon icon = Instantiate(functionIconPrefab, functionIconContainer).GetComponent<MainWeaponFunctionIcon>();
|
||||
icon.Initialize(unit.Value);
|
||||
functionIcons.Add(icon);
|
||||
if (unit.Value.data.isMain)
|
||||
{
|
||||
mainFunctionIcon.Initialize(unit.Value);
|
||||
functionIconDict[unit.Key] = mainFunctionIcon;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!unit.Value.data.shownInUI) continue;
|
||||
|
||||
MainWeaponFunctionIcon icon = Instantiate(functionIconPrefab, functionIconContainer).GetComponent<MainWeaponFunctionIcon>();
|
||||
icon.Initialize(unit.Value);
|
||||
functionIcons.Add(icon);
|
||||
functionIconDict[unit.Key] = icon;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +64,7 @@ namespace Cielonos.MainGame.UI
|
||||
}
|
||||
|
||||
functionIcons.Clear();
|
||||
functionIconDict.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using ChocDino.UIFX;
|
||||
using Cielonos.MainGame.Inventory;
|
||||
using DG.Tweening;
|
||||
using SLSUtilities.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -11,18 +12,21 @@ namespace Cielonos.MainGame.UI
|
||||
public class SupportEquipmentIcon : UIElementBase
|
||||
{
|
||||
public SupportEquipmentBase supportEquipment;
|
||||
public RuntimeFunctionUnit functionUnit;
|
||||
public Image frame;
|
||||
public Image iconImage;
|
||||
public Image timer;
|
||||
private Sequence frameOutlineSequence;
|
||||
public Image timerImage;
|
||||
public TMP_Text timerText;
|
||||
public TMP_Text costText;
|
||||
|
||||
private RuntimeFunctionUnit _functionUnit;
|
||||
private Sequence _frameOutlineSequence;
|
||||
|
||||
public void Initialize(SupportEquipmentBase supportEquipment)
|
||||
{
|
||||
if (supportEquipment == null)
|
||||
{
|
||||
iconImage.sprite = null;
|
||||
functionUnit = null;
|
||||
_functionUnit = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -35,40 +39,91 @@ namespace Cielonos.MainGame.UI
|
||||
|
||||
if (functionCount == 0)
|
||||
{
|
||||
|
||||
DisableAllParts();
|
||||
}
|
||||
else if (functionCount == 1)
|
||||
{
|
||||
functionUnit = supportEquipment.functionSm.functionUnits.Values.ToList()[0];
|
||||
_functionUnit = supportEquipment.functionSm.mainFunction;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//如果有多个功能单元,优先显示主功能单元
|
||||
_functionUnit = supportEquipment.functionSm.mainFunction;
|
||||
}
|
||||
|
||||
timerImage.gameObject.SetActive(true);
|
||||
timerText.gameObject.SetActive(true);
|
||||
costText.gameObject.SetActive(true);
|
||||
iconImage.color = Color.white;
|
||||
|
||||
if (_functionUnit.maxCooldown <= 0)
|
||||
{
|
||||
timerImage.gameObject.SetActive(false);
|
||||
timerText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if(_functionUnit.data.energyCost <= 0)
|
||||
{
|
||||
costText.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
costText.text = Mathf.CeilToInt(_functionUnit.data.energyCost).ToString("D");
|
||||
}
|
||||
|
||||
if (_functionUnit.data.tags.Contains("Disruption"))
|
||||
{
|
||||
Color newColor = Color.yellow;
|
||||
iconImage.color = newColor;
|
||||
newColor.a = 0.5f;
|
||||
frame.color = newColor;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
DisableAllParts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DisableAllParts()
|
||||
{
|
||||
iconImage.sprite = null;
|
||||
iconImage.color = Color.clear;
|
||||
timerImage.gameObject.SetActive(false);
|
||||
timerText.gameObject.SetActive(false);
|
||||
costText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public override void UpdateUI()
|
||||
{
|
||||
if (functionUnit == null) return;
|
||||
if (_functionUnit == null) return;
|
||||
|
||||
float fillAmount;
|
||||
|
||||
if (functionUnit.maxCooldown <= 0f)
|
||||
if (_functionUnit.maxCooldown <= 0f)
|
||||
{
|
||||
fillAmount = 0f;
|
||||
//无冷却
|
||||
}
|
||||
else
|
||||
{
|
||||
fillAmount = functionUnit.currentCooldown / functionUnit.maxCooldown;
|
||||
float fillAmount = 1f - _functionUnit.currentCooldown / _functionUnit.maxCooldown;
|
||||
timerImage.fillAmount = fillAmount;
|
||||
|
||||
if (_functionUnit.currentCooldown > 0f)
|
||||
{
|
||||
timerText.text = _functionUnit.currentCooldown.ToString("F1");
|
||||
}
|
||||
else
|
||||
{
|
||||
timerText.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (_functionUnit.data.energyCost > 0)
|
||||
{
|
||||
float playerCurrentEnergy = MainGameManager.Player.attributeSm[CharacterAttribute.Energy];
|
||||
costText.color = playerCurrentEnergy >= _functionUnit.data.energyCost ? Color.cyan : Color.orangeRed;
|
||||
costText.text = Mathf.CeilToInt(_functionUnit.data.energyCost).ToString("D");
|
||||
}
|
||||
|
||||
timer.fillAmount = fillAmount;
|
||||
}
|
||||
|
||||
public void UseOutlineAnimation() => SetFrameOutline(0.4f, Color.white);
|
||||
@@ -85,13 +140,13 @@ namespace Cielonos.MainGame.UI
|
||||
float fadeDuration = Mathf.Clamp(totalDuration / 2f, 0.2f, totalDuration);
|
||||
float stayDuration = totalDuration - fadeDuration;
|
||||
float strengthPeak = 0.25f;
|
||||
frameOutlineSequence?.Kill(true);
|
||||
frameOutlineSequence = DOTween.Sequence();
|
||||
frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, strengthPeak, fadeDuration).SetEase(Ease.OutQuad));
|
||||
frameOutlineSequence.AppendInterval(stayDuration);
|
||||
frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, 0f, fadeDuration).SetEase(Ease.InQuad));
|
||||
frameOutlineSequence.OnComplete(() => GetComponent<Canvas>().sortingOrder = 0);
|
||||
frameOutlineSequence.Play();
|
||||
_frameOutlineSequence?.Kill(true);
|
||||
_frameOutlineSequence = DOTween.Sequence();
|
||||
_frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, strengthPeak, fadeDuration).SetEase(Ease.OutQuad));
|
||||
_frameOutlineSequence.AppendInterval(stayDuration);
|
||||
_frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, 0f, fadeDuration).SetEase(Ease.InQuad));
|
||||
_frameOutlineSequence.OnComplete(() => GetComponent<Canvas>().sortingOrder = 0);
|
||||
_frameOutlineSequence.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ namespace Cielonos.MainGame.UI
|
||||
private void Awake()
|
||||
{
|
||||
icons = GetComponentsInChildren<SupportEquipmentIcon>(true).ToList();
|
||||
icons.ForEach(icon => icon.DisableAllParts());
|
||||
}
|
||||
|
||||
public void Initialize(SupportEquipmentBase supportEquipment, int slotIndex)
|
||||
|
||||
Reference in New Issue
Block a user