using Snxxz.UI; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class GuardTip : MonoBehaviour { #region TopUI [SerializeField] Button closeBtn; [SerializeField] GameObject putOnIcon; [SerializeField] Text titleText; [SerializeField] Text equipScoreDes; [SerializeField] Text equipScoreValue; [SerializeField] Text needLvDes; [SerializeField] Text needLvValue; [SerializeField] List needPointTextlist = new List(); [SerializeField] List needPointNumlist = new List(); [SerializeField] Text dateText; [SerializeField] ItemCell itemCell; #endregion #region MidUI [SerializeField] RectTransform attrContent; [SerializeField] ScrollRect scrollRect; [SerializeField] LayoutElement scrollLayout; [SerializeField] GameObject basicAttr; [SerializeField] Text basicTitleText; [SerializeField] Text basicAttrDes; #endregion #region BottomUI [SerializeField] GameObject bottomPart; [SerializeField] EquipSource equipSource; #endregion [SerializeField] RectTransform btnGroup; [SerializeField] GameObject operateBtn; [SerializeField] CanvasGroup tipAlpha; Dictionary needPointDict = new Dictionary(); ItemTipsModel _itemTipsModel; ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel()); } } PackModelInterface _modelInterface; PackModelInterface modelInterface { get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel()); } } ItemAttrData itemAttrData; Color32 conditionColor = new Color32(255, 244, 205, 255); public void InitModel(ItemAttrData attrData) { KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct += RefreshRemainTime; itemAttrData = attrData; InitUI(); closeBtn.AddListener(OnClickCloseBtn); } private void OnEnable() { bottomPart.gameObject.SetActive(false); StartCoroutine(SetScrollSize()); } IEnumerator SetScrollSize() { yield return null; yield return null; attrContent.anchoredPosition3D = new Vector3(attrContent.anchoredPosition3D.x, 0, 0); SetMidUIHeight(attrContent.rect.height); StartCoroutine(ShowBottomPart()); } IEnumerator ShowBottomPart() { yield return null; bottomPart.gameObject.SetActive(true); SetBottomUI(); StartCoroutine(SetPanelScale()); } IEnumerator SetPanelScale() { yield return null; if(itemAttrData.isCompare) { if (itemAttrData.packType != PackType.rptEquip) { itemTipsModel.SetCurTips(this.GetComponent()); } else { itemTipsModel.SetCompareTips(this.GetComponent()); } } else { itemTipsModel.SetCurTips(this.GetComponent()); } tipAlpha.alpha = 1; } private void InitUI() { #region 设置TopUI titleText.text = itemTipsModel.GetItemTipsTitle(itemAttrData); titleText.color = UIHelper.GetUIColor(itemAttrData.itemConfig.ItemColor); ItemCellModel cellModel = new ItemCellModel(itemAttrData.itemId,itemAttrData.isPreview, (ulong)itemAttrData.count, itemAttrData.isBind, itemAttrData.guid,itemAttrData.packType,itemAttrData.isCompare, itemAttrData.useDataDict); itemCell.Init(cellModel); if (itemAttrData.packType == PackType.rptEquip) { putOnIcon.SetActive(true); } else { putOnIcon.SetActive(false); } equipScoreDes.text = Language.Get("EquipWin_EquipPointText_1"); equipScoreValue.text = itemAttrData.score.ToString(); RefreshNeedPointUI(); needLvDes.text = Language.Get("KnapS110"); if (itemAttrData.itemConfig.UseLV > 1) { needLvDes.gameObject.SetActive(true); needLvValue.gameObject.SetActive(true); } else { needLvDes.gameObject.SetActive(false); needLvValue.gameObject.SetActive(false); } if(itemAttrData.isHavePutLimit) { needLvValue.text = itemAttrData.itemConfig.UseLV.ToString(); if (PlayerDatas.Instance.baseData.LV >= itemAttrData.itemConfig.UseLV) { needLvDes.color = conditionColor; needLvValue.color = conditionColor; } else { needLvDes.color = UIHelper.GetUIColor(TextColType.Red); needLvValue.color = UIHelper.GetUIColor(TextColType.Red); } } else { needLvValue.text = 1.ToString(); needLvDes.color = conditionColor; needLvValue.color = conditionColor; } if (itemAttrData.itemConfig.ExpireTime > 0) { List itemEffectTime = itemAttrData.GetUseDataModel((int)ItemUseDataKey.Def_IudetCreateTime); if (itemEffectTime != null && itemEffectTime[0] != 0 && itemAttrData.guid != "") { RefreshRemainTime(itemAttrData.guid); } else { SetDateLimitUI(itemAttrData.itemConfig.ExpireTime); } } else { dateText.gameObject.SetActive(false); } #endregion #region 设置MidUI SetBasicAttrUI(); #endregion #region 设置功能按钮 operateBtn.SetActive(false); if(itemAttrData.isCompare) { if(itemAttrData.packType != PackType.rptEquip) { CreateFuncBtn(); } } else { CreateFuncBtn(); } #endregion } private void OnDisable() { KnapsackTimeCDMgr.Instance.RefreshItemOverdueTimeAct -= RefreshRemainTime; } private void RefreshRemainTime(string guid) { if (guid != itemAttrData.guid) { return; } ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(guid); if (cool != null) { SetDateLimitUI(cool.GetRemainTime()); } else { SetDateLimitUI(0); } } private void SetDateLimitUI(double time) { dateText.gameObject.SetActive(true); TimeSpan t = TimeSpan.FromSeconds(time); if (t.TotalDays > 1) { dateText.text = Language.Get("EquipInfo_OverdueDay", (int)t.TotalDays); } else if (t.TotalHours > 1) { dateText.text = Language.Get("EquipInfo_OverdueHour", (int)t.TotalHours); } else if (t.TotalMinutes > 1) { dateText.text = Language.Get("EquipInfo_OverdueMin", (int)t.TotalMinutes); } else if (t.TotalMinutes > 0) { dateText.text = Language.Get("EquipInfo_OverdueMin", 1); } else if (t.TotalSeconds <= 0) { dateText.text = Language.Get("EquipInfo_Overdued"); } } private void RefreshNeedPointUI() { needPointDict.Clear(); if (itemAttrData.itemConfig.LimitSTR > 0) { needPointDict.Add(AttrEnum.POWER, itemAttrData.itemConfig.LimitSTR); } if (itemAttrData.itemConfig.LimitPHY > 0) { needPointDict.Add(AttrEnum.AGILITY, itemAttrData.itemConfig.LimitPHY); } if (itemAttrData.itemConfig.LimitPNE > 0) { needPointDict.Add(AttrEnum.MENTALITY, itemAttrData.itemConfig.LimitPNE); } List needlist = needPointDict.Keys.ToList(); int i = 0; float offset = 0; for (i = 0; i < needPointTextlist.Count; i++) { if (i < needlist.Count) { needPointTextlist[i].gameObject.SetActive(true); needPointNumlist[i].gameObject.SetActive(true); offset = needPointDict[needlist[i]] - UIHelper.GetPropertyMapPlayerData(needlist[i]); switch (needlist[i]) { case AttrEnum.POWER: if (itemAttrData.isHavePutLimit) { SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS113")); } else { SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS113")); } break; case AttrEnum.AGILITY: if (itemAttrData.isHavePutLimit) { SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS112")); } else { SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS112")); } break; case AttrEnum.MENTALITY: if (itemAttrData.isHavePutLimit) { SetNeedPointUI(needPointDict[needlist[i]], offset, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS111")); } else { SetNeedPointUI(1, 0, needPointTextlist[i], needPointNumlist[i], Language.Get("KnapS111")); } break; } } else { needPointTextlist[i].gameObject.SetActive(false); needPointNumlist[i].gameObject.SetActive(false); } } } private void SetNeedPointUI(float needPoint, float offset, Text needPoinText, Text needPoinNum, string msg) { if (offset > 0) { needPoinNum.text = UIHelper.GetTextColorByItemColor(TextColType.Red, StringUtility.Contact(needPoint, Language.Get("KnapS118", offset))); needPoinText.text = UIHelper.GetTextColorByItemColor(TextColType.Red, msg); } else { needPoinNum.color = conditionColor; needPoinText.color = conditionColor; needPoinNum.text = needPoint.ToString(); needPoinText.text = msg; } } #region 设置属性UI private void SetBasicAttrUI() { basicAttr.SetActive(true); basicTitleText.text = Language.Get("RolePanel_BaseAttrText_1"); basicAttrDes.text = itemTipsModel.GetBasicAttr(itemAttrData); } private void SetMidUIHeight(float midHeight) { scrollRect.enabled = false; if (midHeight < itemTipsModel.equipMidHeights[0]) { scrollLayout.preferredHeight = itemTipsModel.equipMidHeights[0]; } else if (midHeight > itemTipsModel.equipMidHeights[1]) { scrollRect.enabled = true; scrollLayout.preferredHeight = itemTipsModel.equipMidHeights[1]; } else { scrollLayout.preferredHeight = midHeight; } } #endregion private void SetBottomUI() { SetBottomText(equipSource); } private void SetBottomText(EquipSource source) { source.jobTitleText.text = Language.Get("EquipWin_JobTitleText_1"); source.jobText.text = itemTipsModel.GetEquipJobName(itemAttrData); source.partTitleText.text = Language.Get("EquipWin_PartTitleText_1"); source.partText.text = itemTipsModel.guardDesDict[itemAttrData.itemId][0]; source.itemDesText.text = itemAttrData.itemConfig.Description; source.sourceText.text = itemTipsModel.guardDesDict[itemAttrData.itemId][1]; } private void CreateFuncBtn() { btnGroup.anchoredPosition3D = Vector3.zero; if (itemAttrData.tipsFuncBtnDic.Count > 0) { foreach (ItemWinBtnType key in itemAttrData.tipsFuncBtnDic.Keys) { Button btn = OnGUIButton(btnGroup.gameObject, operateBtn, key.ToString(), Language.Get(StringUtility.Contact("ItemHandle_", key.ToString()))); btn.RemoveAllListeners(); btn.onClick.AddListener(() => { OnClickCloseBtn(); itemAttrData.tipsFuncBtnDic[key](key,""); }); } } } private Button OnGUIButton(GameObject parent, GameObject sourceBtn, string btnName, string textName) { GameObject go = Instantiate(sourceBtn); go.name = btnName; go.transform.SetParent(parent.transform); go.transform.Find("BtnText").GetComponent().text = textName; go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; Button btn = go.GetComponent