优化 UI 效果
This commit is contained in:
@@ -36,32 +36,23 @@ namespace SepCore.UI
|
||||
|
||||
if (ItemType == ItemType.Weapon)
|
||||
{
|
||||
DamageType damageType;
|
||||
if (rawData.DataRow is WeaponConfig weaponConfig)
|
||||
{
|
||||
Name = weaponConfig.WeaponName;
|
||||
Description = ItemDescUtility.CreateWeaponDescription(weaponConfig);
|
||||
damageType = weaponConfig.DamageType;
|
||||
TypeName = ItemDescUtility.FormatWeaponTags(weaponConfig);
|
||||
}
|
||||
else if (rawData.DataRow is WeaponData weaponData)
|
||||
{
|
||||
Name = weaponData.Title;
|
||||
Description = ItemDescUtility.CreateWeaponDescription(weaponData);
|
||||
damageType = weaponData.DamageType;
|
||||
TypeName = ItemDescUtility.FormatWeaponTags(weaponData);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Weapon data row is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
TypeName = damageType switch
|
||||
{
|
||||
DamageType.Melee => "近战武器",
|
||||
DamageType.Ranged => "远程武器",
|
||||
DamageType.Element => "元素武器",
|
||||
_ => "武器"
|
||||
};
|
||||
}
|
||||
else if (ItemType == ItemType.Prop)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
@@ -55,11 +56,19 @@ namespace SepCore.UI
|
||||
View.statForm.OnInit(context.StatContext);
|
||||
context.NeedRefreshStat = false;
|
||||
}
|
||||
|
||||
bool weaponCapacityFull = context.WeaponListContext.CurrentCount >= context.WeaponListContext.MaxCount;
|
||||
foreach (ShopGoodsItem item in _goodsItems)
|
||||
{
|
||||
item.RefreshAvailability(context.PlayerCoin, weaponCapacityFull);
|
||||
}
|
||||
View.refreshButton.interactable = context.PlayerCoin >= context.RefreshPrice;
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
SetAttributesVisible(false);
|
||||
|
||||
if (userData is not ShopContext context)
|
||||
{
|
||||
@@ -72,6 +81,7 @@ namespace SepCore.UI
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
SetAttributesVisible(false);
|
||||
_context = null;
|
||||
|
||||
for (int i = 0; i < _goodsItems.Count; i++)
|
||||
@@ -96,6 +106,9 @@ namespace SepCore.UI
|
||||
|
||||
View.continueButton.onClick.AddListener(OnContinueButtonClick);
|
||||
View.refreshButton.onClick.AddListener(OnRefreshButtonClick);
|
||||
View.attributeToggleButton.onClick.AddListener(ShowAttributes);
|
||||
View.attributeCloseButton.onClick.AddListener(HideAttributes);
|
||||
View.attributeDismissButton.onClick.AddListener(HideAttributes);
|
||||
}
|
||||
|
||||
private void RefreshGoodsItems(List<GoodsItemContext> goodsItems)
|
||||
@@ -112,8 +125,16 @@ namespace SepCore.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
item.OnReset();
|
||||
item.gameObject.SetActive(false);
|
||||
if (i < goodsItems.Count)
|
||||
{
|
||||
item.MarkPurchased();
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.OnReset();
|
||||
item.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,5 +157,40 @@ namespace SepCore.UI
|
||||
{
|
||||
GameEntry.Event.Fire(this, ShopRefreshEventArgs.Create(_context.RefreshPrice));
|
||||
}
|
||||
|
||||
private void ShowAttributes()
|
||||
{
|
||||
SetAttributesVisible(true);
|
||||
}
|
||||
|
||||
private void HideAttributes()
|
||||
{
|
||||
SetAttributesVisible(false);
|
||||
}
|
||||
|
||||
private void SetAttributesVisible(bool visible)
|
||||
{
|
||||
View.attributeDrawer.gameObject.SetActive(visible);
|
||||
View.attributeToggleButton.gameObject.SetActive(!visible);
|
||||
}
|
||||
|
||||
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
base.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
if (!View.attributeDrawer.gameObject.activeSelf)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
var keyboard = UnityEngine.InputSystem.Keyboard.current;
|
||||
if (keyboard != null && keyboard.escapeKey.wasPressedThisFrame)
|
||||
#else
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
#endif
|
||||
{
|
||||
HideAttributes();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ namespace SepCore.UI
|
||||
[SerializeField] private TMP_Text _descriptionText;
|
||||
|
||||
[SerializeField] private TMP_Text _costText;
|
||||
[SerializeField] private CommonButton _purchaseButton = null;
|
||||
[SerializeField] private TMP_Text _purchaseLabel = null;
|
||||
[SerializeField] private CanvasGroup _canvasGroup = null;
|
||||
|
||||
private GoodsItemContext _data;
|
||||
|
||||
private int _index = -1;
|
||||
|
||||
@@ -26,6 +31,9 @@ namespace SepCore.UI
|
||||
EnsureListeners();
|
||||
|
||||
_index = index;
|
||||
_data = data;
|
||||
_canvasGroup.alpha = 1f;
|
||||
_purchaseLabel.text = "购买";
|
||||
|
||||
_iconArea.OnInit(data.Icon, data.Rarity);
|
||||
_titleText.text = data.Name;
|
||||
@@ -37,6 +45,28 @@ namespace SepCore.UI
|
||||
public void OnReset()
|
||||
{
|
||||
_index = -1;
|
||||
_data = null;
|
||||
}
|
||||
|
||||
public void MarkPurchased()
|
||||
{
|
||||
OnReset();
|
||||
_canvasGroup.alpha = 0.5f;
|
||||
_purchaseButton.interactable = false;
|
||||
_purchaseLabel.text = "已购买";
|
||||
}
|
||||
|
||||
public void RefreshAvailability(int playerCoin, bool weaponCapacityFull)
|
||||
{
|
||||
if (_index < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool weaponFull = _data.ItemType == ItemType.Weapon && weaponCapacityFull;
|
||||
bool affordable = playerCoin >= _data.Price;
|
||||
_purchaseButton.interactable = affordable && !weaponFull;
|
||||
_purchaseLabel.text = weaponFull ? "武器已满" : affordable ? "购买" : "金币不足";
|
||||
}
|
||||
|
||||
private void EnsureListeners()
|
||||
@@ -48,8 +78,7 @@ namespace SepCore.UI
|
||||
|
||||
_listenersBound = true;
|
||||
|
||||
CommonButton button = GetComponentInChildren<CommonButton>(true);
|
||||
button.onClick.AddListener(OnPurchaseClick);
|
||||
_purchaseButton.onClick.AddListener(OnPurchaseClick);
|
||||
}
|
||||
|
||||
private void OnPurchaseClick()
|
||||
|
||||
@@ -8,12 +8,16 @@ namespace SepCore.UI
|
||||
{
|
||||
[SerializeField] public global::SepCore.UI.FormatTextUI titleFormatText;
|
||||
[SerializeField] public global::SepCore.UI.FormatTextUI playerCoinFormatText;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton refreshButton;
|
||||
[SerializeField] public global::SepCore.UI.FormatTextUI refreshButtonFormatText;
|
||||
[SerializeField] public global::UnityEngine.RectTransform GoodsItemRoot;
|
||||
[SerializeField] public global::SepCore.UI.ShopGoodsItem goodsItemTemplate;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton refreshButton;
|
||||
[SerializeField] public global::SepCore.UI.FormatTextUI refreshButtonFormatText;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton continueButton;
|
||||
[SerializeField] public global::SepCore.UI.FormatTextUI continueButtonFormatText;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton attributeToggleButton;
|
||||
[SerializeField] public global::UnityEngine.RectTransform attributeDrawer;
|
||||
[SerializeField] public global::UnityEngine.UI.Button attributeDismissButton;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton attributeCloseButton;
|
||||
[SerializeField] public global::SepCore.UI.DisplayListForm weaponList;
|
||||
[SerializeField] public global::SepCore.UI.DisplayListForm propList;
|
||||
[SerializeField] public global::SepCore.UI.StatForm statForm;
|
||||
|
||||
Reference in New Issue
Block a user