【拆分mono】临时拆分 UI_CurrencyList

main
刘涛 2025-04-29 18:45:52 +08:00
parent 63e1a2311d
commit 14c859dcdf
12 changed files with 308 additions and 236 deletions

View File

@ -0,0 +1,14 @@
namespace GameWrapper.UI.Common
{
public interface ICurrencyItem
{
void FakeAwake();
void FakeOnDestroy();
void Refresh();
void OnCurrencyIDChanged();
bool IsShowPlus { get; set; }
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 896b5de1912f4a9c98bb66ef82d61486
timeCreated: 1745922249

View File

@ -0,0 +1,47 @@
using GameWrapper.UI.Common;
using Sirenix.OdinInspector;
using UnityEngine;
public class UI_CurrencyItem : MonoBehaviour
{
//[DelayedProperty]
[SerializeField] [OnValueChanged("OnCurrencyIDChanged")]
private int _currencyID;
UI_CurrencyList.NumberType numberType = UI_CurrencyList.NumberType.Default;
public UI_CurrencyList.NumberType NumberType
{
get { return numberType; }
set
{
numberType = value;
}
}
public int currencyID
{
get { return _currencyID; }
set
{
_currencyID = value;
logic.Refresh();
}
}
public ICurrencyItem logic;
private void Awake()
{
logic.FakeAwake();
}
void OnCurrencyIDChanged()
{
logic.OnCurrencyIDChanged();
}
private void OnDestroy()
{
logic.FakeOnDestroy();
}
}

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using GameWrapper.UI.Common;
using UnityEngine;
using Gameplay;
public class UI_CurrencyList: UINode
{
@ -59,6 +59,24 @@ public class UI_CurrencyList: UINode
_currencyIDList.Reverse();
}
private void _ProtectItem(UI_CurrencyItem currencyItemMono)
{
if (currencyItemMono.logic == null)
{
// Gameplay.UI.Common.UI_CurrencyItemLogic
// TODO: 临时通过反射创建
var type = System.Type.GetType("Gameplay.UI.Common.UI_CurrencyItemLogic");
if (type != null)
{
currencyItemMono.logic = (ICurrencyItem)System.Activator.CreateInstance(type, currencyItemMono);
}
else
{
Debug.LogError("找不到类型: Gameplay.UI.Common.UI_CurrencyItemLogic");
}
}
}
public void Refresh()
{
for (int i = 0; i < _itemList.Count; i++)
@ -70,15 +88,16 @@ public class UI_CurrencyList: UINode
}
_itemList[i].SetActive(true);
var currencyItem = _itemList[i].GetComponent<UI_CurrencyItem>();
if (currencyItem)
var currencyItemMono = _itemList[i].GetComponent<UI_CurrencyItem>();
if (currencyItemMono)
{
currencyItem.NumberType = numberType;
_ProtectItem(currencyItemMono);
currencyItemMono.NumberType = numberType;
if(ShowPlusBtn.ContainsKey(_currencyIDList[i]))
{
currencyItem.IsShowPlus = ShowPlusBtn[_currencyIDList[i]];
currencyItemMono.logic.IsShowPlus = ShowPlusBtn[_currencyIDList[i]];
}
currencyItem.currencyID = _currencyIDList[i];
currencyItemMono.currencyID = _currencyIDList[i];
}
}
}
@ -90,6 +109,7 @@ public class UI_CurrencyList: UINode
var currencyItem = _itemList[i].GetComponent<UI_CurrencyItem>();
if (currencyItem)
{
_ProtectItem(currencyItem);
currencyItem.NumberType = numberType;
currencyItem.currencyID = _currencyIDList[i];
}

View File

@ -1,6 +1,4 @@
using UnityEngine;
public static class DisplayIDForCeHua
public static class DisplayIDForCeHua
{
private static bool _isDisplayID;

View File

@ -1,5 +1,4 @@
using System;
using Gameplay;
using UnityEngine;
using UnityEngine.UI;

View File

@ -1,225 +0,0 @@
using Framework;
using Gameplay;
using Gameplay.Common;
using Gameplay.Guide;
using Gameplay.Net;
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using cfg.FunctionLockCfg;
using Gameplay.FunctionLock;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UI_CurrencyItem : MonoBehaviour
{
//[DelayedProperty]
[SerializeField] [OnValueChanged("OnCurrencyIDChanged")]
private int _currencyID;
UI_CurrencyList.NumberType numberType = UI_CurrencyList.NumberType.Default;
public UI_CurrencyList.NumberType NumberType
{
get { return numberType; }
set
{
numberType = value;
}
}
public int currencyID
{
get { return _currencyID; }
set
{
_currencyID = value;
Refresh();
}
}
private bool isShowPlus = true;
/// <summary>
/// 加号按钮是否显示 (由于特殊界面需要隐藏默认为true)
/// </summary>
public bool IsShowPlus
{
get { return isShowPlus; }
set { isShowPlus = value; }
}
private TMP_Text _num;
private GameObject moneyObj;
private GameObject energyObj;
private TMP_Text nowEnergy;
private TMP_Text maxEnergy;
private TMP_Text _energyNum;
private GameObject _btnPlus;
private bool Vaild => currencyID > 0;
private void Awake()
{
BindProperty();
BindEvent();
RegisterSignal();
Refresh();
}
private void BindProperty()
{
_num = transform.Find("Money/num")?.GetComponent<TMP_Text>();
moneyObj = transform.Find("Money").gameObject;
energyObj = transform.Find("Energy").gameObject;
nowEnergy = transform.Find("Energy/now").GetComponent<TMP_Text>();
maxEnergy = transform.Find("Energy/max").GetComponent<TMP_Text>();
_energyNum = transform.Find("Energy/num").GetComponent<TMP_Text>();
_btnPlus = transform.Find("btn_plus").gameObject;
}
private void BindEvent()
{
_btnPlus.GetComponent<Button>().onClick.AddListener(OnClickPlus);
}
private void RegisterSignal()
{
EventManager.Instance.Register<uint>(EventManager.EventName.ItemChange, OnItemChange);
//等后期player有等级了要加上监听等级提升带来的体力影响
}
private void UnRegisterSignal()
{
EventManager.Instance.Unregister<uint>(EventManager.EventName.ItemChange, OnItemChange);
}
private void OnItemChange(uint id)
{
if (id == currencyID)
{
Refresh();
}
}
private void Refresh()
{
if (!Application.isPlaying)
return;
if (Vaild)
{
if (IsEnergy())
{
RefreshEnergy();
}
else
{
RefreshMoney();
}
energyObj.SetActive(IsEnergy());
moneyObj.SetActive(!IsEnergy());
CommonUtils.GetGameObject(this.gameObject, "icon/gold")
.SetActive(currencyID == GLConfig.Inst.data.GoldItemId);
CommonUtils.GetGameObject(this.gameObject, "icon/diamond")
.SetActive(currencyID == GLConfig.Inst.data.DiamondItemId);
CommonUtils.GetGameObject(this.gameObject, "icon/PvpCoins")
.SetActive(currencyID == GLConfig.Inst.data.PvpCoinId);
CommonUtils.GetGameObject(this.gameObject, "icon/PieceExchange")
.SetActive(currencyID == GLConfig.Inst.data.PieceExchangeId);
CommonUtils.GetGameObject(this.gameObject, "icon/purchase_diamond")
.SetActive(currencyID == 11); //GLConfig.Inst.data.PurchaseDiamondID
CommonUtils.GetGameObject(this.gameObject, "icon/VehicleExp")
.SetActive(currencyID == 12); //GLConfig.Inst.data.VehicleExpID
CommonUtils.GetGameObject(this.gameObject, "icon/energy").SetActive(IsEnergy());
if (IsShowPlus)
_btnPlus.SetActive(IsCreditPoint() || currencyID == GLConfig.Inst.data.DiamondItemId || IsEnergy());
else
_btnPlus.SetActive(false);
}
}
private void RefreshMoney()
{
switch (numberType)
{
case UI_CurrencyList.NumberType.Default:
_num.text = Actor.Instance.Item.GetItemCount(currencyID).ToString();
break;
case UI_CurrencyList.NumberType.English:
_num.text = CommonUtils.NumToEnglish(Actor.Instance.Item.GetItemCount(currencyID));
break;
case UI_CurrencyList.NumberType.Chinese:
_num.text = CommonUtils.ToMetricNotation(Actor.Instance.Item.GetItemCount(currencyID));
break;
case UI_CurrencyList.NumberType.Formatted:
_num.text = CommonUtils.ToFormatNumber(Actor.Instance.Item.GetItemCount(currencyID));
break;
}
_num.text = CommonUtils.ToFormatNumber(Actor.Instance.Item.GetItemCount(currencyID));
//CommonUtils.NumToEnglish(Actor.Instance.Item.GetItemCount(currencyID));英文缩写
}
private void RefreshEnergy()
{
var cur = EnergyManager.Instance.GetNowEnergy().ToString();
var max = EnergyManager.Instance.GetMaxEnergyPoint().ToString();
_energyNum.text = cur + "/" + max;
}
private bool IsEnergy()
{
return currencyID == GLConfig.Inst.data.EnergyPointID;
}
private bool IsCreditPoint()
{
return currencyID == GLConfig.Inst.data.PurchaseDiamondID;
}
private async void OnClickPlus()
{
AudioManager.Instance.PlayAudio(Constants.Sound.COMMON_CLICK);
if (GuideManager.Instance.IsGuiding)
return;
if (IsCreditPoint())
{
if(!FunctionLockManager.Instance.IsUnlock(E_Function.Store))
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("ui_functionLockTip"));
return;
}
UIManager.Instance.CloseWindow(UINameConst.UI_CreditPointExchangePanel);
if(!UIManager.Instance.CheckWindowCreated(UINameConst.UI_ShopNew))
await UI_ShopNewController.Open(ShopManager.RechargeShopId);
else
UI_ShopNewController.OpenToCharge();
}
else if (currencyID == GLConfig.Inst.data.DiamondItemId)
{
await UI_CreditPointExchangePanelController.Open();
}
else if (IsEnergy())
{
await UI_BuyEnergyController.Open(GLConfig.Inst.data.EnergyPointID);
}
}
private void OnCurrencyIDChanged()
{
if (Vaild)
{
Refresh();
}
}
private void OnDestroy()
{
UnRegisterSignal();
}
}

View File

@ -0,0 +1,211 @@
using cfg.FunctionLockCfg;
using Framework;
using Gameplay.Common;
using Gameplay.FunctionLock;
using Gameplay.Guide;
using Gameplay.Net;
using GameWrapper.UI.Common;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Gameplay.UI.Common
{
public class UI_CurrencyItemLogic : ICurrencyItem
{
public UI_CurrencyItem monoInst;
private TMP_Text _num;
private GameObject moneyObj;
private GameObject energyObj;
private TMP_Text nowEnergy;
private TMP_Text maxEnergy;
private TMP_Text _energyNum;
private GameObject _btnPlus;
public Transform transform => monoInst.transform;
public int currencyID => monoInst.currencyID;
public GameObject gameObject => monoInst.gameObject;
private bool Vaild => currencyID > 0;
private bool isShowPlus = true;
/// <summary>
/// 加号按钮是否显示 (由于特殊界面需要隐藏默认为true)
/// </summary>
public bool IsShowPlus
{
get { return isShowPlus; }
set { isShowPlus = value; }
}
public UI_CurrencyItemLogic(UI_CurrencyItem inst)
{
monoInst = inst;
}
public void FakeAwake()
{
BindProperty();
BindEvent();
RegisterSignal();
Refresh();
}
public void FakeOnDestroy()
{
UnRegisterSignal();
}
private void BindProperty()
{
_num = transform.Find("Money/num")?.GetComponent<TMP_Text>();
moneyObj = transform.Find("Money").gameObject;
energyObj = transform.Find("Energy").gameObject;
nowEnergy = transform.Find("Energy/now").GetComponent<TMP_Text>();
maxEnergy = transform.Find("Energy/max").GetComponent<TMP_Text>();
_energyNum = transform.Find("Energy/num").GetComponent<TMP_Text>();
_btnPlus = transform.Find("btn_plus").gameObject;
}
private void BindEvent()
{
_btnPlus.GetComponent<Button>().onClick.AddListener(OnClickPlus);
}
private void RegisterSignal()
{
EventManager.Instance.Register<uint>(EventManager.EventName.ItemChange, OnItemChange);
//等后期player有等级了要加上监听等级提升带来的体力影响
}
private void UnRegisterSignal()
{
EventManager.Instance.Unregister<uint>(EventManager.EventName.ItemChange, OnItemChange);
}
private void OnItemChange(uint id)
{
if (id == monoInst.currencyID)
{
Refresh();
}
}
public void Refresh()
{
if (!Application.isPlaying)
return;
if (Vaild)
{
if (IsEnergy())
{
RefreshEnergy();
}
else
{
RefreshMoney();
}
energyObj.SetActive(IsEnergy());
moneyObj.SetActive(!IsEnergy());
CommonUtils.GetGameObject(this.gameObject, "icon/gold")
.SetActive(currencyID == GLConfig.Inst.data.GoldItemId);
CommonUtils.GetGameObject(this.gameObject, "icon/diamond")
.SetActive(currencyID == GLConfig.Inst.data.DiamondItemId);
CommonUtils.GetGameObject(this.gameObject, "icon/PvpCoins")
.SetActive(currencyID == GLConfig.Inst.data.PvpCoinId);
CommonUtils.GetGameObject(this.gameObject, "icon/PieceExchange")
.SetActive(currencyID == GLConfig.Inst.data.PieceExchangeId);
CommonUtils.GetGameObject(this.gameObject, "icon/purchase_diamond")
.SetActive(currencyID == 11); //GLConfig.Inst.data.PurchaseDiamondID
CommonUtils.GetGameObject(this.gameObject, "icon/VehicleExp")
.SetActive(currencyID == 12); //GLConfig.Inst.data.VehicleExpID
CommonUtils.GetGameObject(this.gameObject, "icon/energy").SetActive(IsEnergy());
if (IsShowPlus)
_btnPlus.SetActive(IsCreditPoint() || currencyID == GLConfig.Inst.data.DiamondItemId || IsEnergy());
else
_btnPlus.SetActive(false);
}
}
private void RefreshMoney()
{
switch (monoInst.NumberType)
{
case UI_CurrencyList.NumberType.Default:
_num.text = Actor.Instance.Item.GetItemCount(currencyID).ToString();
break;
case UI_CurrencyList.NumberType.English:
_num.text = CommonUtils.NumToEnglish(Actor.Instance.Item.GetItemCount(currencyID));
break;
case UI_CurrencyList.NumberType.Chinese:
_num.text = CommonUtils.ToMetricNotation(Actor.Instance.Item.GetItemCount(currencyID));
break;
case UI_CurrencyList.NumberType.Formatted:
_num.text = CommonUtils.ToFormatNumber(Actor.Instance.Item.GetItemCount(currencyID));
break;
}
_num.text = CommonUtils.ToFormatNumber(Actor.Instance.Item.GetItemCount(currencyID));
//CommonUtils.NumToEnglish(Actor.Instance.Item.GetItemCount(currencyID));英文缩写
}
private void RefreshEnergy()
{
var cur = EnergyManager.Instance.GetNowEnergy().ToString();
var max = EnergyManager.Instance.GetMaxEnergyPoint().ToString();
_energyNum.text = cur + "/" + max;
}
private bool IsEnergy()
{
return currencyID == GLConfig.Inst.data.EnergyPointID;
}
private bool IsCreditPoint()
{
return currencyID == GLConfig.Inst.data.PurchaseDiamondID;
}
private async void OnClickPlus()
{
AudioManager.Instance.PlayAudio(Constants.Sound.COMMON_CLICK);
if (GuideManager.Instance.IsGuiding)
return;
if (IsCreditPoint())
{
if (!FunctionLockManager.Instance.IsUnlock(E_Function.Store))
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("ui_functionLockTip"));
return;
}
UIManager.Instance.CloseWindow(UINameConst.UI_CreditPointExchangePanel);
if (!UIManager.Instance.CheckWindowCreated(UINameConst.UI_ShopNew))
await UI_ShopNewController.Open(ShopManager.RechargeShopId);
else
UI_ShopNewController.OpenToCharge();
}
else if (currencyID == GLConfig.Inst.data.DiamondItemId)
{
await UI_CreditPointExchangePanelController.Open();
}
else if (IsEnergy())
{
await UI_BuyEnergyController.Open(GLConfig.Inst.data.EnergyPointID);
}
}
public void OnCurrencyIDChanged()
{
if (Vaild)
{
Refresh();
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5ffcdfd2baab485c8030e98e1f9e2bd9
timeCreated: 1745922019

View File

@ -1,10 +1,12 @@
using Gameplay.UI.Common;
using UnityEditor;
using UnityEngine;
public class TestCode: Editor
{
[MenuItem("Test/测试")]
public static void Test()
{
Debug.LogError(typeof(UI_CurrencyItemLogic).FullName);
}
}