优化道具稀有度的 UI 表现
This commit is contained in:
@@ -6,10 +6,18 @@ namespace SepCore.UI
|
||||
{
|
||||
public class IconArea : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image _board;
|
||||
public enum RarityDisplayMode
|
||||
{
|
||||
Background = 1,
|
||||
Neutral = 2
|
||||
}
|
||||
|
||||
[SerializeField] private Image _icon;
|
||||
|
||||
[SerializeField] private Image _background = null;
|
||||
[SerializeField] private RarityPalette _rarityPalette = null;
|
||||
[SerializeField] private RarityDisplayMode _rarityDisplayMode = RarityDisplayMode.Background;
|
||||
|
||||
public void OnInit(Sprite sprite, Rarity rarity)
|
||||
{
|
||||
SetIcon(sprite);
|
||||
@@ -23,14 +31,8 @@ namespace SepCore.UI
|
||||
|
||||
public void SetRarity(Rarity rarity)
|
||||
{
|
||||
_board.color = rarity switch
|
||||
{
|
||||
Rarity.White => Color.white,
|
||||
Rarity.Blue => Color.blue,
|
||||
Rarity.Purple => Color.magenta,
|
||||
Rarity.Red => Color.red,
|
||||
_ => Color.clear,
|
||||
};
|
||||
Rarity displayRarity = _rarityDisplayMode == RarityDisplayMode.Background ? rarity : Rarity.None;
|
||||
_background.color = _rarityPalette.Get(displayRarity).IconBackground;
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using SepCore.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
[CreateAssetMenu(menuName = "UI/Rarity Palette")]
|
||||
public class RarityPalette : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public struct Colors
|
||||
{
|
||||
public Color Border;
|
||||
public Color CardBackground;
|
||||
public Color IconBackground;
|
||||
}
|
||||
|
||||
[SerializeField] private Colors _none;
|
||||
[SerializeField] private Colors _white;
|
||||
[SerializeField] private Colors _blue;
|
||||
[SerializeField] private Colors _purple;
|
||||
[SerializeField] private Colors _red;
|
||||
|
||||
public Colors Get(Rarity rarity)
|
||||
{
|
||||
return rarity switch
|
||||
{
|
||||
Rarity.None => _none,
|
||||
Rarity.White => _white,
|
||||
Rarity.Blue => _blue,
|
||||
Rarity.Purple => _purple,
|
||||
Rarity.Red => _red,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(rarity), rarity, "Unsupported UI rarity.")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05db5e8e6e7f7e14c84c787effce4933
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using SepCore.Definition;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class RarityPanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RarityPalette _palette = null;
|
||||
[SerializeField] private Image _background = null;
|
||||
[SerializeField] private Image _border = null;
|
||||
|
||||
public void SetRarity(Rarity rarity)
|
||||
{
|
||||
RarityPalette.Colors colors = _palette.Get(rarity);
|
||||
_background.color = colors.CardBackground;
|
||||
_border.color = colors.Border;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95abff91edc12444c880476c4cf00ab6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,5 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.AsyncTask;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -28,21 +27,22 @@ namespace SepCore.UI
|
||||
View.infoText.text = _context.Description;
|
||||
View.textFormatText.Set(_context.Price);
|
||||
View.recycleButton.gameObject.SetActive(_context.ShowRecycleButton);
|
||||
View.iconArea.SetRarity(_context.Rarity);
|
||||
|
||||
ResizeToFitContent();
|
||||
|
||||
if (!string.IsNullOrEmpty(_context.IconAssetName))
|
||||
{
|
||||
LoadIconAsync(_context.IconAssetName, _context.Rarity).Forget();
|
||||
LoadIconAsync(_context.IconAssetName).Forget();
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTaskVoid LoadIconAsync(string iconAssetName, Rarity rarity)
|
||||
private async UniTaskVoid LoadIconAsync(string iconAssetName)
|
||||
{
|
||||
var sprite = await SpriteLoader.LoadSpriteByKeyAsync(iconAssetName);
|
||||
if (_context != null && _context.IconAssetName == iconAssetName)
|
||||
{
|
||||
View.iconArea.OnInit(sprite, rarity);
|
||||
View.iconArea.SetIcon(sprite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace SepCore.UI
|
||||
[SerializeField] private float _screenEdgePadding = 32f;
|
||||
[SerializeField] private float _verticalGap = 10f;
|
||||
|
||||
[SerializeField] private RarityPanel[] _rarityPanels = null;
|
||||
|
||||
private ItemTooltipContext _context;
|
||||
private Vector3 _targetPos;
|
||||
|
||||
@@ -17,6 +19,11 @@ namespace SepCore.UI
|
||||
_context = context;
|
||||
_targetPos = ConvertWorldToAnchored(_context.TargetPos);
|
||||
|
||||
foreach (RarityPanel panel in _rarityPanels)
|
||||
{
|
||||
panel.SetRarity(_context.BasicContext.Rarity);
|
||||
}
|
||||
|
||||
// 1. 刷新基础信息面板(同步执行,立即完成文本排版与尺寸自适应)
|
||||
View.basicForm.RefreshUI(_context.BasicContext);
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace SepCore.UI
|
||||
|
||||
[SerializeField] private TMP_Text _descriptionText;
|
||||
|
||||
[SerializeField] private RarityPanel _rarityPanel = null;
|
||||
|
||||
private LevelUpRewardItemContext _context;
|
||||
|
||||
|
||||
@@ -30,6 +32,8 @@ namespace SepCore.UI
|
||||
|
||||
_context = context;
|
||||
|
||||
_rarityPanel.SetRarity(context.Rarity);
|
||||
|
||||
_titleText.text = context.Title;
|
||||
_descriptionText.text = context.Description;
|
||||
_iconArea.OnInit(context.Icon, context.Rarity);
|
||||
@@ -45,4 +49,4 @@ namespace SepCore.UI
|
||||
_iconArea.SetIcon(sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ using System;
|
||||
using SepCore.Event;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using SepCore.Definition;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
@@ -19,6 +21,9 @@ namespace SepCore.UI
|
||||
[SerializeField] private CommonButton _purchaseButton = null;
|
||||
[SerializeField] private TMP_Text _purchaseLabel = null;
|
||||
[SerializeField] private CanvasGroup _canvasGroup = null;
|
||||
[SerializeField] private RarityPalette _rarityPalette = null;
|
||||
[SerializeField] private Image _rarityBackground = null;
|
||||
[SerializeField] private Image _rarityBorder = null;
|
||||
|
||||
private GoodsItemContext _data;
|
||||
|
||||
@@ -35,6 +40,7 @@ namespace SepCore.UI
|
||||
_canvasGroup.alpha = 1f;
|
||||
_purchaseLabel.text = "购买";
|
||||
|
||||
SetRarity(data.Rarity);
|
||||
_iconArea.OnInit(data.Icon, data.Rarity);
|
||||
_titleText.text = data.Name;
|
||||
_typeText.text = data.TypeName;
|
||||
@@ -46,16 +52,26 @@ namespace SepCore.UI
|
||||
{
|
||||
_index = -1;
|
||||
_data = null;
|
||||
_iconArea.OnReset();
|
||||
SetRarity(Rarity.None);
|
||||
}
|
||||
|
||||
public void MarkPurchased()
|
||||
{
|
||||
OnReset();
|
||||
_index = -1;
|
||||
_data = null;
|
||||
_canvasGroup.alpha = 0.5f;
|
||||
_purchaseButton.interactable = false;
|
||||
_purchaseLabel.text = "已购买";
|
||||
}
|
||||
|
||||
private void SetRarity(Rarity rarity)
|
||||
{
|
||||
RarityPalette.Colors colors = _rarityPalette.Get(rarity);
|
||||
_rarityBackground.color = colors.CardBackground;
|
||||
_rarityBorder.color = colors.Border;
|
||||
}
|
||||
|
||||
public void RefreshAvailability(int playerCoin, bool weaponCapacityFull)
|
||||
{
|
||||
if (_index < 0)
|
||||
|
||||
Reference in New Issue
Block a user