using UnityEngine.UI; using UnityEngine; using TableConfig; using System; using System.Collections.Generic; using DG.Tweening; using Snxxz.UI; using System.Collections; namespace Snxxz.UI { public class GetItemPathWin : Window { #region 成员变量 [SerializeField] protected ItemCell _itemCell; [SerializeField] protected Text _nameText; [SerializeField] private Text _conditionText; [SerializeField] private Text needLvText; [SerializeField] Text realmTitleText; [SerializeField] Image realmImg; [SerializeField] private Text _itemTypeText; [SerializeField] protected Button _closeBtn; [SerializeField] protected Text _describeText; [SerializeField] RectTransform itemDesContent; [SerializeField] private ScrollRect scrollRect; [SerializeField] private LayoutElement scrollLayout; [SerializeField] protected GameObject _bottomPart; [SerializeField] private Button _getItemBtn; [SerializeField] protected RectTransform _itemInfoTips; [SerializeField] protected RectTransform _getWaysPosTips; [SerializeField] protected CanvasGroup _getWaysTips; [SerializeField] private ScrollerController _waysCtrl; [SerializeField] private Transform waysLineCell; [SerializeField] private Button _closeWaysBtn; [SerializeField] ModelShowPerfab modelShow; [SerializeField] [Header("初始移动坐标")] protected float startPosX = 400f; [SerializeField] [Header("结束坐标")] protected float endPosX = 272f; [SerializeField] [Header("移动时间")] protected float _moveTime = 0.3f; [SerializeField] protected CanvasGroup tipAlpha; #endregion GetItemPathModel _itemPathModel; protected GetItemPathModel itemPathModel { get { return _itemPathModel ?? (_itemPathModel = ModelCenter.Instance.GetModel()); } } DailyQuestModel _questModel; protected DailyQuestModel QuestModel { get { return _questModel ?? (_questModel = ModelCenter.Instance.GetModel()); } } ItemTipsModel _itemTipsModel; ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel()); } } Color32 conditionColor = new Color32(255, 244, 205, 255); Color32 conditionRedColor = new Color32(255, 1, 1, 255); Dictionary petSkillDict; Dictionary> mountSkillDict; protected override void BindController() { _waysCtrl.OnRefreshCell += RefreshWayCell; } protected override void AddListeners() { _closeBtn.onClick.AddListener(CloseWin); _getItemBtn.onClick.AddListener(OnClickGetItemBtn); _closeWaysBtn.onClick.AddListener(CloseWin); } protected override void OnPreOpen() { _bottomPart.gameObject.SetActive(false); InitUI(); } protected override void OnAfterOpen() { transform.SetAsLastSibling(); StartCoroutine(SetScrollSize()); } protected override void OnPreClose() { } protected override void OnAfterClose() { } protected override void OnActived() { base.OnActived(); NewBieCenter.Instance.CheckNewBieGuides(new int[] { 41 }); } #region iteminfoTips逻辑 protected virtual IEnumerator SetScrollSize() { yield return null; yield return null; SetMidUIHeight(itemDesContent.rect.height); StartCoroutine(ShowBottomPart()); } IEnumerator ShowBottomPart() { yield return null; _bottomPart.SetActive(true); StartCoroutine(SetPanelScale()); } IEnumerator SetPanelScale() { yield return null; if (modelShow == null || !modelShow.gameObject.activeInHierarchy) { startPosX = -476; endPosX = -668; _getWaysPosTips.anchoredPosition3D = new Vector3(670, 0, 0); } else { startPosX = -270; endPosX = -476; _getWaysPosTips.anchoredPosition3D = new Vector3(860, 0, 0); } _itemInfoTips.anchoredPosition3D = new Vector3(startPosX, 0, 0); _itemPathModel.SetInfoTipsPos(_itemInfoTips,_getWaysPosTips); tipAlpha.alpha = 1; } private void InitUI() { if (itemPathModel.chinItemModel == null) return; _closeBtn.gameObject.SetActive(true); _getWaysTips.alpha = 0; tipAlpha.alpha = 0; SetTopUI(); SetMidUI(); switch (itemPathModel.chinItemModel.Type) { case 125: modelShow.gameObject.SetActive(true); PetInfoConfig petInfo = itemTipsModel.unlockPetDict[itemPathModel.chinItemModel.EffectValueA1]; petSkillDict = itemTipsModel.GetPetSkillDict(itemPathModel.chinItemModel.EffectValueA1); modelShow.SetModelShow(petInfo.ID, ModelShowType.pet, Language.Get("TreasureEffect103"), petInfo.ShowFightPower); break; case 124: modelShow.gameObject.SetActive(true); HorseConfig horseConfig = itemTipsModel.unlockMountDict[itemPathModel.chinItemModel.EffectValueA1]; mountSkillDict = itemTipsModel.GetMountSkillDict(itemPathModel.chinItemModel.EffectValueA1); modelShow.SetModelShow(horseConfig.Model, ModelShowType.mount, Language.Get("TreasureEffect103"), horseConfig.ShowFightPower); break; default: modelShow.gameObject.SetActive(false); break; } } private void SetTopUI() { ItemCellModel cellModel = new ItemCellModel(itemPathModel.chinItemModel.ID, false, 0, itemPathModel.isBind); _itemCell.Init(cellModel); _nameText.text = itemPathModel.chinItemModel.ItemName; _nameText.color = UIHelper.GetUIColor(itemPathModel.chinItemModel.ItemColor); _itemTypeText.text = itemPathModel.chinItemModel.ItemTypeName.ToString(); CheckUselimit(); } private void CheckUselimit() { int[] uselimits = itemPathModel.chinItemModel.UseCondiType; if (uselimits == null) return; _conditionText.gameObject.SetActive(false); needLvText.gameObject.SetActive(false); realmTitleText.gameObject.SetActive(false); realmImg.gameObject.SetActive(false); for (int i = 0; i < uselimits.Length; i++) { switch (uselimits[i]) { case 0: if (itemPathModel.chinItemModel.UseLV > 1) { _conditionText.gameObject.SetActive(true); needLvText.gameObject.SetActive(true); } _conditionText.text = Language.Get("KnapS110"); needLvText.text = itemPathModel.chinItemModel.UseLV.ToString(); if (PlayerDatas.Instance.baseData.LV >= itemPathModel.chinItemModel.UseLV) { _conditionText.color = conditionColor; needLvText.color = conditionColor; } else { _conditionText.color = conditionRedColor; needLvText.color = conditionRedColor; } break; case 1: realmTitleText.gameObject.SetActive(true); realmImg.gameObject.SetActive(true); realmTitleText.text = Language.Get("RealmLimit1"); RealmConfig realmConfig = Config.Instance.Get(itemPathModel.chinItemModel.RealmLimit); if (itemPathModel.chinItemModel.RealmLimit <= 0) { realmImg.SetSprite("NoRealm"); } else { if (realmConfig != null) { realmImg.SetSprite(realmConfig.Img); } } if (PlayerDatas.Instance.baseData.realmLevel >= itemPathModel.chinItemModel.RealmLimit) { realmTitleText.color = conditionColor; } else { realmTitleText.color = conditionRedColor; } break; case 2: break; } } } private void SetMidUI() { _describeText.alignment = TextAnchor.UpperLeft; if (itemPathModel.chinItemModel.Effect1 != 215) { _describeText.text = itemPathModel.GetAllInfoDes(); } else { ulong expValue = itemTipsModel.GetAddExpValue(itemPathModel.chinItemModel.EffectValueA1, itemPathModel.chinItemModel.EffectValueB1); _describeText.text = itemPathModel.GetAllInfoDes().Replace("{0}", UIHelper.ReplaceLargeNum(expValue)); } } #region 点击事件 private void OnClickGetItemBtn() { if (_getWaysTips.alpha <= 0) { Vector3 pos = new Vector3(endPosX, _itemInfoTips.anchoredPosition3D.y, 0); _itemInfoTips.DOAnchorPos3D(pos, _moveTime); _getWaysTips.DOFade(1, _moveTime); _closeBtn.gameObject.SetActive(false); CreateWayCell(); } else { Vector3 pos = new Vector3(startPosX, _itemInfoTips.anchoredPosition3D.y, 0); _itemInfoTips.DOAnchorPos3D(pos, _moveTime); _getWaysTips.DOFade(0, _moveTime); _closeBtn.gameObject.SetActive(true); } } private void CloseWin() { itemPathModel.ResetAllModel(); Close(); } #endregion protected virtual 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 #region getWaysTips逻辑 private List getWayslist; protected virtual void CreateWayCell() { getWayslist = itemPathModel.GetWaysList(); _waysCtrl.Refresh(); int i = 0; int remain = getWayslist.Count % waysLineCell.childCount; int line = (int)getWayslist.Count / waysLineCell.childCount; if (remain > 0) { line += 1; } for (i = 0; i < line; i++) { _waysCtrl.AddCell(ScrollerDataType.Header, i); } _waysCtrl.Restart(); } private void RefreshWayCell(ScrollerDataType type, CellView cell) { int i = 0; for (i = 0; i < cell.transform.childCount; i++) { WayCell wayCell = cell.transform.GetChild(i).GetComponent(); if (wayCell == null) wayCell = cell.transform.GetChild(i).gameObject.AddComponent(); int index = (cell.transform.childCount) * cell.index + i; if (index <= getWayslist.Count - 1) { cell.transform.GetChild(i).gameObject.SetActive(true); GetItemWaysConfig itemWaysModel = getWayslist[index]; wayCell.icon.SetSprite(itemWaysModel.Icon); wayCell.wayName.text = itemWaysModel.Text; wayCell.funcName.text = itemWaysModel.name; wayCell.wayButton.RemoveAllListeners(); wayCell.wayButton.AddListener(() => { ClickWayCell(itemWaysModel); }); } else { cell.transform.GetChild(i).gameObject.SetActive(false); } } } public void ClickWayCell(GetItemWaysConfig itemWaysModel) { if (!string.IsNullOrEmpty(itemWaysModel.SelectActive) && itemWaysModel.SelectActive != "") { QuestModel.currentDailyQuest = int.Parse(itemWaysModel.SelectActive); } CloseImmediately(); WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)itemWaysModel.OpenpanelId); } #endregion } }