//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Friday, August 17, 2018 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; using System; //神兽强化右侧材料吸收列表 namespace Snxxz.UI { public class GodBeastBagClass { public int ItemId;//ID public int Index;//下标 public int IsEquipment;//是否装备0水晶,1装备 public int Color;//品质颜色 public int Star;//星级 public int LV;//等级 public int Proficiency;//熟练度 public int EquipScore;//装备评分 public int Part;//装备位 } public class GodBeastSlidingList : MonoBehaviour { [SerializeField] ScrollerController m_ScrollerController; [SerializeField] Text m_Label; [SerializeField] Button m_Arrow; [SerializeField] GameObject m_ScrollViewFirst; [SerializeField] Button m_ButtonAll;//所有 [SerializeField] Button m_ButtonCrystal;//水晶 [SerializeField] Button m_ButtonBlue;//蓝 [SerializeField] Button m_ButtonPurple;//紫色 [SerializeField] Button m_ButtonOrange;//橙色 [SerializeField] Toggle m_ToggleAll; public int LINE = 10; private List GodBeastBagList = new List(); private List DeleteIndexList = new List(); private int Quality = 10; PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } GodBeastModel godBeastModel { get { return ModelCenter.Instance.GetModel(); } } private void Start() { m_Arrow.AddListener(OnClickArrow); m_ButtonAll.AddListener(() => { OnClickSwith(10); if (m_ToggleAll.isOn) { m_ToggleAll.isOn = false; } GetGodBeastBag(); FilterQuality(); godBeastModel.AbsorbEventUpdate(); m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 }); m_ButtonCrystal.AddListener(() => { OnClickSwith(0); if (m_ToggleAll.isOn) { m_ToggleAll.isOn = false; } GetGodBeastBag(); FilterQuality(); godBeastModel.AbsorbEventUpdate(); m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 }); m_ButtonBlue.AddListener(() => { OnClickSwith(2); if (m_ToggleAll.isOn) { m_ToggleAll.isOn = false; } GetGodBeastBag(); FilterQuality(); godBeastModel.AbsorbEventUpdate(); m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 }); m_ButtonPurple.AddListener(() => { OnClickSwith(3); if (m_ToggleAll.isOn) { m_ToggleAll.isOn = false; } GetGodBeastBag(); FilterQuality(); godBeastModel.AbsorbEventUpdate(); m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 }); m_ButtonOrange.AddListener(() => { OnClickSwith(4); if (m_ToggleAll.isOn) { m_ToggleAll.isOn = false; } GetGodBeastBag(); FilterQuality(); godBeastModel.AbsorbEventUpdate(); m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 }); m_ToggleAll.onValueChanged.AddListener(OnClickToggle); } private void OnEnable() { playerPack.RefreshItemCountAct += RefreshItemCountAct; playerPack.ItemCntReduceAct += ItemCntReduceAct; godBeastModel.AbsorbEvent += AbsorbEvent; } private void OnDisable() { playerPack.RefreshItemCountAct -= RefreshItemCountAct; playerPack.ItemCntReduceAct -= ItemCntReduceAct; godBeastModel.AbsorbEvent -= AbsorbEvent; } public void Init() { Quality = 10; ContentSelect(Quality); if (m_ScrollViewFirst.activeSelf) { m_ScrollViewFirst.SetActive(false); } if (m_ToggleAll.isOn) { m_ToggleAll.isOn = false; } GetGodBeastBag();//获取神兽背包数据排序 FilterQuality();//分类筛选 godBeastModel.AbsorbEventUpdate(); m_ScrollerController.OnRefreshCell += OnRefreshGridCell; OnCreateGridLineCell(m_ScrollerController); } public void Unit() { m_ScrollerController.OnRefreshCell -= OnRefreshGridCell; } private void ItemCntReduceAct(PackType arg1, int arg2, int arg3) { if (arg1 == PackType.rptDogzItem) { if (m_ToggleAll.isOn) { m_ToggleAll.isOn = false; } GetGodBeastBag(); FilterQuality(); godBeastModel.AbsorbEventUpdate(); m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 } } private void RefreshItemCountAct(PackType arg1, int arg2, int arg3) { if (arg1 == PackType.rptDogzItem) { if (m_ToggleAll.isOn) { m_ToggleAll.isOn = false; } GetGodBeastBag(); FilterQuality(); godBeastModel.AbsorbEventUpdate(); m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 } } private void AbsorbEvent() { m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 } private void GetGodBeastBag()//获取神兽背包数据排序 { GodBeastBagList.Clear(); if (playerPack.GetSinglePackModel(PackType.rptDogzItem) == null) { return; } Dictionary BackpackDic = playerPack.GetSinglePackModel(PackType.rptDogzItem).GetPackModelIndexDict(); foreach (var key in BackpackDic.Keys) { var itemModel = BackpackDic[key]; GodBeastBagClass godBeastBagClass = new GodBeastBagClass(); godBeastBagClass.ItemId = itemModel.itemId; godBeastBagClass.Index = key; if (itemModel.chinItemModel.Type != 70) { godBeastBagClass.IsEquipment = 1; } else { godBeastBagClass.IsEquipment = 0; } godBeastBagClass.Color = itemModel.chinItemModel.ItemColor; godBeastBagClass.Star = itemModel.chinItemModel.StarLevel; godBeastBagClass.EquipScore = itemModel.equipScore; godBeastBagClass.Part = itemModel.EquipPlace; var IudetDogzEquipPlus = itemModel.GetUseDataModel((int)ItemUseDataKey.Def_IudetDogzEquipPlus);// 神兽装备强化信息列表 [强化等级, 强化熟练度] if (IudetDogzEquipPlus == null) { godBeastBagClass.LV = 0; godBeastBagClass.Proficiency = 0; } else { godBeastBagClass.LV = IudetDogzEquipPlus[0]; godBeastBagClass.Proficiency = IudetDogzEquipPlus[1]; } GodBeastBagList.Add(godBeastBagClass); } GodBeastBagList.Sort(Compare); } int Compare(GodBeastBagClass x, GodBeastBagClass y) { if (x.IsEquipment.CompareTo(y.IsEquipment) != 0)//是否强化水晶 { return x.IsEquipment.CompareTo(y.IsEquipment); } if (x.Proficiency.CompareTo(y.Proficiency) != 0)//强化熟练度 { return -x.Proficiency.CompareTo(y.Proficiency); } if (x.Color.CompareTo(y.Color) != 0)//品质 { return -x.Color.CompareTo(y.Color); } if (x.Star.CompareTo(y.Star) != 0)//星级 { return -x.Star.CompareTo(y.Star); } if (x.Part.CompareTo(y.Part) != 0)//装备位 { return x.Part.CompareTo(y.Part); } if (x.EquipScore.CompareTo(y.EquipScore) != 0)//装备评分 { return x.EquipScore.CompareTo(y.EquipScore); } return 1; } private void FilterQuality()//分类筛选 { DeleteIndexList.Clear(); godBeastModel.Absorption_Dic.Clear(); for (int i = 0; i < GodBeastBagList.Count; i++) { if (Quality <= 0)//只有水晶 { if (GodBeastBagList[i].IsEquipment != 0) { int type = i; DeleteIndexList.Add(type); } } else { if (Quality < 10 && (GodBeastBagList[i].IsEquipment != 1 || GodBeastBagList[i].Color > Quality))//过滤掉只剩所选品质装备 { int type = i; DeleteIndexList.Add(type); } } } for (int j = DeleteIndexList.Count; j > 0; j--) { int Inedex = DeleteIndexList[j - 1]; if (Inedex <= GodBeastBagList.Count - 1) { GodBeastBagList.RemoveAt(Inedex); } } if (m_ToggleAll.isOn) { for (int k = 0; k < GodBeastBagList.Count; k++) { godBeastModel.Absorption_Dic.Add(GodBeastBagList[k].Index, 1); } } } private void OnClickArrow() { m_ScrollViewFirst.SetActive(!m_ScrollViewFirst.activeSelf); } private void OnClickToggle(bool IsBool) { if (IsBool) { } else { if (godBeastModel.Absorption_Dic.Count != 0) { godBeastModel.Absorption_Dic.Clear(); } } GetGodBeastBag(); FilterQuality(); godBeastModel.AbsorbEventUpdate(); m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 } private void OnClickSwith(int Type) { Quality = Type; if (m_ScrollViewFirst.activeSelf) { m_ScrollViewFirst.SetActive(false); } ContentSelect(Quality); } private void ContentSelect(int Type) { switch (Type) { case 0: m_Label.text = "强化水晶"; break; case 2: m_Label.text = "蓝色以下"; break; case 3: m_Label.text = "紫色以下"; break; case 4: m_Label.text = "橙色以下"; break; case 10: m_Label.text = "全部"; break; default: break; } } void OnCreateGridLineCell(ScrollerController gridCtrl) { gridCtrl.Refresh(); int code = 0; for (code = 0; code < LINE; code++) { gridCtrl.AddCell(ScrollerDataType.Header, code); } gridCtrl.Restart(); } private void OnRefreshGridCell(ScrollerDataType type, CellView cell) { int gridlineIndex = cell.index; int childCode = 0; for (childCode = 0; childCode < cell.transform.childCount; childCode++) { GodBeastChildNodes GodBeastChildNodes = cell.transform.GetChild(childCode).GetComponent(); GodBeastChildNodes.ItemCell.gameObject.SetActive(false); GodBeastChildNodes.ChoosenImg.SetActive(false); GodBeastChildNodes.TextNumber.gameObject.SetActive(false); GodBeastChildNodes.NumberNow.gameObject.SetActive(false); int cellCount = (cell.transform.childCount) * gridlineIndex + (childCode + 1); GodBeastChildNodes.ButtonDown.RemoveAllListeners(); if (cellCount - 1 < GodBeastBagList.Count) { int index = cellCount - 1; GodBeastChildNodes.ItemCell.gameObject.SetActive(true); GodBeastBagClass godBeastBagClass = GodBeastBagList[index]; ItemModel itemModel = playerPack.GetItemModelByIndex(PackType.rptDogzItem, godBeastBagClass.Index); if (itemModel == null) { return; } if (godBeastModel.Absorption_Dic.ContainsKey(godBeastBagClass.Index)) { GodBeastChildNodes.ChoosenImg.SetActive(true); if (itemModel.EquipPlace <= 0) { GodBeastChildNodes.NumberNow.gameObject.SetActive(true); GodBeastChildNodes.NumberNow.text = godBeastModel.Absorption_Dic[godBeastBagClass.Index].ToString(); } } GodBeastChildNodes.GetGodBeastIndex(godBeastBagClass.Index); GodBeastChildNodes.ButtonDown.AddListener(() => { if (itemModel.EquipPlace > 0)//选中的物品为装备 { if (godBeastModel.Absorption_Dic.ContainsKey(godBeastBagClass.Index)) { godBeastModel.Absorption_Dic.Remove(godBeastBagClass.Index); } else { godBeastModel.Absorption_Dic.Add(godBeastBagClass.Index, 1); } m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见 } else//选中的物品为水晶 { godBeastModel.Crystal_ItemModel = itemModel; godBeastModel.ItemInde = godBeastBagClass.Index; WindowCenter.Instance.Open(); } godBeastModel.AbsorbEventUpdate(); }); } } } } }