using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class ComposeSelectItemCell : MonoBehaviour { [SerializeField] Text nameText; [SerializeField] ItemCell itemCell; [SerializeField] Text remainTimeText; [SerializeField] Button selectBtn; SelectEquipModel _selectModel; SelectEquipModel selectModel { get { return _selectModel ?? (_selectModel = ModelCenter.Instance.GetModel()); } } ItemModel itemModel = null; private void OnEnable() { KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct += UpdateRemainTime; } private void OnDisable() { KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct -= UpdateRemainTime; } public void SetDisplay(ItemModel _itemModel) { itemModel = _itemModel; selectBtn.RemoveAllListeners(); if (itemModel == null) return; itemCell.Init(itemModel); nameText.color = UIHelper.GetUIColor(itemModel.config.ItemColor, true); nameText.text = itemModel.config.ItemName; selectBtn.onClick.RemoveAllListeners(); selectBtn.onClick.AddListener(() => { OnClickSelectItem(itemModel); }); UpdateRemainTime(); } private void UpdateRemainTime(string guid) { if (itemModel == null || guid != itemModel.guid) return; UpdateRemainTime(); } private void UpdateRemainTime() { remainTimeText.gameObject.SetActive(false); if (itemModel == null || itemModel.config.EquipPlace != (int)RoleEquipType.Guard) return; ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(itemModel.guid); bool isShow = itemModel.config.ExpireTime > 0; remainTimeText.gameObject.SetActive(isShow); if (isShow) { List itemEffectTime = itemModel.GetUseData((int)ItemUseDataKey.createTime); double remianTime = itemModel.config.ExpireTime; if (itemEffectTime != null && itemEffectTime[0] != 0 && itemModel.guid != "") { remianTime = cool == null ? 0 : cool.GetRemainTime(); } if (remianTime > 0) { remainTimeText.text = Language.Get("Remaining_Z", SecondsToHM((int)remianTime)); } else { selectModel.UpdateSelectItems(); } } } public string SecondsToHM(int _seconds) { string timeStr = string.Empty; int hours = _seconds / 3600; int mins = _seconds % 3600 / 60; if (hours > 0) { timeStr = StringUtility.Contact(hours, Language.Get("Hour")); } if (mins > 0) { timeStr = StringUtility.Contact(timeStr,mins, Language.Get("Minute")); } return timeStr; } public void OnClickSelectItem(ItemModel itemModel) { switch (selectModel.selectItem) { case SelectItemType.unfixed: selectModel.AddHaveUnfixedSelectItem(itemModel.gridIndex); break; case SelectItemType.addons: selectModel.AddHaveAddSelectItem(itemModel.gridIndex); break; } selectModel.UpdateSelectItem(itemModel.gridIndex); WindowCenter.Instance.Close(); } } }