using System.Collections.Generic; using System.Linq; using UnityEngine.UI; public partial class PhantasmPavilionManager : GameSystemManager { //头像入口用 public Redpoint parentRedpoint = new Redpoint(MainRedDot.PhantasmPavilionRepoint); //内政用 public Redpoint parentRedpoint2 = new Redpoint(MainRedDot.MainAffairsRedpoint, MainRedDot.PhantasmPavilionRepoint * 100 + (int)PhantasmPavilionRepointType.MainAffairs); public Dictionary tabRedPointDict = new Dictionary(); private void InitTabRedPoint() { tabRedPointDict[PhantasmPavilionRepointType.Model] = new Redpoint(MainRedDot.PhantasmPavilionRepoint, GetRedpointId(PhantasmPavilionRepointType.Model)); tabRedPointDict[PhantasmPavilionRepointType.Face] = new Redpoint(MainRedDot.PhantasmPavilionRepoint, GetRedpointId(PhantasmPavilionRepointType.Face)); tabRedPointDict[PhantasmPavilionRepointType.Title] = new Redpoint(MainRedDot.PhantasmPavilionRepoint, GetRedpointId(PhantasmPavilionRepointType.Title)); tabRedPointDict[PhantasmPavilionRepointType.ModelNormal] = new Redpoint(GetRedpointId(PhantasmPavilionRepointType.Model), GetRedpointId(PhantasmPavilionRepointType.ModelNormal)); tabRedPointDict[PhantasmPavilionRepointType.ModelEvent] = new Redpoint(GetRedpointId(PhantasmPavilionRepointType.Model), GetRedpointId(PhantasmPavilionRepointType.ModelEvent)); tabRedPointDict[PhantasmPavilionRepointType.FaceAvatar] = new Redpoint(GetRedpointId(PhantasmPavilionRepointType.Face), GetRedpointId(PhantasmPavilionRepointType.FaceAvatar)); tabRedPointDict[PhantasmPavilionRepointType.FaceFrame] = new Redpoint(GetRedpointId(PhantasmPavilionRepointType.Face), GetRedpointId(PhantasmPavilionRepointType.FaceFrame)); tabRedPointDict[PhantasmPavilionRepointType.FaceBubble] = new Redpoint(GetRedpointId(PhantasmPavilionRepointType.Face), GetRedpointId(PhantasmPavilionRepointType.FaceBubble)); tabRedPointDict[PhantasmPavilionRepointType.TitlePalace] = new Redpoint(GetRedpointId(PhantasmPavilionRepointType.Title), GetRedpointId(PhantasmPavilionRepointType.TitlePalace)); tabRedPointDict[PhantasmPavilionRepointType.TitleEvent] = new Redpoint(GetRedpointId(PhantasmPavilionRepointType.Title), GetRedpointId(PhantasmPavilionRepointType.TitleEvent)); } public int GetRedpointId(PhantasmPavilionRepointType type) { return MainRedDot.PhantasmPavilionRepoint * 100 + (int)type; } void UpdateRedPointByCanActivate(PhantasmPavilionType type, PhantasmPavilionRepointType redType, int tabType = 0) { List list = ShowItemList(type, tabType); if (list.IsNullOrEmpty() || !tabRedPointDict.ContainsKey(redType)) return; foreach (var id in list) { if (!Has(type, id)) continue; PhantasmPavilionState state = GetUnLockState(type, id); if (state == PhantasmPavilionState.CanActivate) { tabRedPointDict[redType].state = RedPointState.Simple; } } } void UpdateRedPointByCanUpStar(PhantasmPavilionType type, PhantasmPavilionRepointType redType, int tabType = 0) { List list = ShowItemList(type, tabType); if (list.IsNullOrEmpty() || !tabRedPointDict.ContainsKey(redType)) return; foreach (var id in list) { if (!Has(type, id)) continue; bool isCanUpStar = CheckCanUpByItem(type, id); if (isCanUpStar) { tabRedPointDict[redType].state = RedPointState.Simple; } } } void UpdateRedPointByNoSee(PhantasmPavilionType type, PhantasmPavilionRepointType redType, int tabType = 0) { List list = ShowItemList(type, tabType); if (list.IsNullOrEmpty() || !tabRedPointDict.ContainsKey(redType)) return; foreach (var id in list) { if (!Has(type, id)) continue; int unlockWay = GetUnlockWay(type, id); int unlockValue = GetUnlockValue(type, id); if (unlockWay != 3 && unlockWay != 4) continue; if (unlockWay == 3) { bool hasNewHero = HasNewHero(type, unlockValue); if (hasNewHero) { tabRedPointDict[redType].state = RedPointState.Simple; } } else if (unlockWay == 4) { if (HasNewSkin(type, unlockValue)) tabRedPointDict[redType].state = RedPointState.Simple; } } } public void UpdateItemRedPoint(Image imgRed, PhantasmPavilionType type, int id) { imgRed.SetActive(false); if (!Has(type, id)) return; PhantasmPavilionState state = GetUnLockState(type, id); if (state == PhantasmPavilionState.CanActivate) { imgRed.SetActive(true); } bool isCanUpStar = CheckCanUpByItem(type, id); if (isCanUpStar) { imgRed.SetActive(true); } int unlockWay = GetUnlockWay(type, id); if (unlockWay != 3 && unlockWay != 4) return; int unlockValue = GetUnlockValue(type, id); if (unlockWay == 3) { if (HasNewHero(type, unlockValue)) imgRed.SetActive(true); } else if (unlockWay == 4) { if (HasNewSkin(type, unlockValue)) imgRed.SetActive(true); } } readonly int funcId = 3;//内政 //内政没开不刷红点 public bool IsFuncOpen() { return FuncOpen.Instance.IsFuncOpen(funcId); } public void UpdateRedPoint() { parentRedpoint.state = RedPointState.None; parentRedpoint2.state = RedPointState.None; if (!tabRedPointDict.IsNullOrEmpty()) { foreach (var item in tabRedPointDict) { item.Value.state = RedPointState.None; } } // 有可手动解锁的 UpdateRedPointByCanActivate(PhantasmPavilionType.Model, PhantasmPavilionRepointType.ModelNormal, 1); UpdateRedPointByCanActivate(PhantasmPavilionType.Model, PhantasmPavilionRepointType.ModelEvent, 2); UpdateRedPointByCanActivate(PhantasmPavilionType.Face, PhantasmPavilionRepointType.FaceAvatar); UpdateRedPointByCanActivate(PhantasmPavilionType.FacePic, PhantasmPavilionRepointType.FaceFrame); UpdateRedPointByCanActivate(PhantasmPavilionType.ChatBox, PhantasmPavilionRepointType.FaceBubble); UpdateRedPointByCanActivate(PhantasmPavilionType.Title, PhantasmPavilionRepointType.TitlePalace, 1); UpdateRedPointByCanActivate(PhantasmPavilionType.Title, PhantasmPavilionRepointType.TitleEvent, 2); // 有可升级的 UpdateRedPointByCanUpStar(PhantasmPavilionType.Model, PhantasmPavilionRepointType.ModelNormal, 1); UpdateRedPointByCanUpStar(PhantasmPavilionType.Model, PhantasmPavilionRepointType.ModelEvent, 2); UpdateRedPointByCanUpStar(PhantasmPavilionType.Face, PhantasmPavilionRepointType.FaceAvatar); UpdateRedPointByCanUpStar(PhantasmPavilionType.FacePic, PhantasmPavilionRepointType.FaceFrame); UpdateRedPointByCanUpStar(PhantasmPavilionType.ChatBox, PhantasmPavilionRepointType.FaceBubble); UpdateRedPointByCanUpStar(PhantasmPavilionType.Title, PhantasmPavilionRepointType.TitlePalace, 1); UpdateRedPointByCanUpStar(PhantasmPavilionType.Title, PhantasmPavilionRepointType.TitleEvent, 2); // 自动解锁未查看的 UpdateRedPointByNoSee(PhantasmPavilionType.Model, PhantasmPavilionRepointType.ModelNormal, 1); UpdateRedPointByNoSee(PhantasmPavilionType.Model, PhantasmPavilionRepointType.ModelEvent, 2); UpdateRedPointByNoSee(PhantasmPavilionType.Face, PhantasmPavilionRepointType.FaceAvatar); UpdateRedPointByNoSee(PhantasmPavilionType.FacePic, PhantasmPavilionRepointType.FaceFrame); UpdateRedPointByNoSee(PhantasmPavilionType.ChatBox, PhantasmPavilionRepointType.FaceBubble); UpdateRedPointByNoSee(PhantasmPavilionType.Title, PhantasmPavilionRepointType.TitlePalace, 1); UpdateRedPointByNoSee(PhantasmPavilionType.Title, PhantasmPavilionRepointType.TitleEvent, 2); if (IsFuncOpen()) { parentRedpoint2.state = parentRedpoint.state; } } public List newSkinIDModelList = new List(); public List newSkinIDFaceList = new List(); string modelSkinKey { get { return StringUtility.Concat("PhantasmPavilion_Redponit_ModelSkin_", PlayerDatas.Instance.PlayerId.ToString()); } } string faceSkinKey { get { return StringUtility.Concat("PhantasmPavilion_Redponit_FaceSkin_", PlayerDatas.Instance.PlayerId.ToString()); } } public void AddNewSkin(int skinID) { AddNew(newSkinIDModelList, skinID); AddNew(newSkinIDFaceList, skinID); } // 抽象添加逻辑 void AddNew(List list, int id) { if (list.Contains(id)) return; list.Add(id); SaveLocal(); UpdateRedPoint(); } public bool HasNewSkin(PhantasmPavilionType type, int skinID) { switch (type) { case PhantasmPavilionType.Model: return newSkinIDModelList.Contains(skinID); case PhantasmPavilionType.Face: return newSkinIDFaceList.Contains(skinID); default: return false; } } public List newHeroIDModelList = new List(); public List newHeroIDFaceList = new List(); public void AddNewHero(int heroID) { AddNew(newHeroIDModelList, heroID); AddNew(newHeroIDFaceList, heroID); } public void RemoveAllNewHeroByTabType(PhantasmPavilionType type, int tabType = 0) { List list = null; switch (type) { case PhantasmPavilionType.Model: list = ShowItemList(type, tabType); break; case PhantasmPavilionType.Face: list = GetTableKeys(type); break; default: return; } if (list.IsNullOrEmpty()) return; foreach (var id in list) { RemoveNewHero(type, id, false); } SaveLocal(); } public void RemoveNewHero(PhantasmPavilionType type, int id, bool isSave = true) { if (!Has(type, id)) return; int unlockWay = GetUnlockWay(type, id); int unlockValue = GetUnlockValue(type, id); if (unlockWay != 3 && unlockWay != 4) return; switch (type) { case PhantasmPavilionType.Model: if (unlockWay == 3) RemoveNew(newHeroIDModelList, unlockValue, isSave); else if (unlockWay == 4) RemoveNew(newSkinIDModelList, unlockValue, isSave); // 皮肤 break; case PhantasmPavilionType.Face: if (unlockWay == 3) RemoveNew(newHeroIDFaceList, unlockValue, isSave); else if (unlockWay == 4) RemoveNew(newSkinIDFaceList, unlockValue, isSave); // 皮肤 break; } } void RemoveNew(List list, int id, bool isSave = true) { if (!list.Contains(id)) return; list.Remove(id); if (isSave) SaveLocal(); UpdateRedPoint(); } public bool HasNewHero(PhantasmPavilionType type, int heroID) { switch (type) { case PhantasmPavilionType.Model: return newHeroIDModelList.Contains(heroID); case PhantasmPavilionType.Face: return newHeroIDFaceList.Contains(heroID); default: return false; } } string modelkey { get { return StringUtility.Concat("PhantasmPavilion_Redponit_Model_", PlayerDatas.Instance.PlayerId.ToString()); } } string facekey { get { return StringUtility.Concat("PhantasmPavilion_Redponit_Face_", PlayerDatas.Instance.PlayerId.ToString()); } } public void SaveLocal() { LocalSave.SetIntArray(modelkey, newHeroIDModelList.ToArray()); LocalSave.SetIntArray(facekey, newHeroIDFaceList.ToArray()); LocalSave.SetIntArray(modelSkinKey, newSkinIDModelList.ToArray()); LocalSave.SetIntArray(faceSkinKey, newSkinIDFaceList.ToArray()); } public void LoadLocal() { LoadLocalModel(); LoadLocalFace(); LoadLocalSkin(); } void LoadLocalSkin() { if (LocalSave.HasKey(modelSkinKey)) { int[] arr = LocalSave.GetIntArray(modelSkinKey); newSkinIDModelList = arr.IsNullOrEmpty() ? new List() : arr.ToList(); } else { newSkinIDModelList = new List(); } if (LocalSave.HasKey(faceSkinKey)) { int[] arr = LocalSave.GetIntArray(faceSkinKey); newSkinIDFaceList = arr.IsNullOrEmpty() ? new List() : arr.ToList(); }else { newSkinIDFaceList = new List(); } } void LoadLocalModel() { if (!LocalSave.HasKey(modelkey)) { newHeroIDModelList = new List(); return; } int[] arr = LocalSave.GetIntArray(modelkey); if (arr.IsNullOrEmpty()) { newHeroIDModelList = new List(); return; } newHeroIDModelList = arr.ToList(); } void LoadLocalFace() { if (!LocalSave.HasKey(facekey)) { newHeroIDFaceList = new List(); return; } int[] arr = LocalSave.GetIntArray(facekey); if (arr.IsNullOrEmpty()) { newHeroIDFaceList = new List(); return; } newHeroIDFaceList = arr.ToList(); } } public enum PhantasmPavilionRepointType { MainAffairs = 99, //内政入口用 Model = 10, Face = 20, Title = 30, ModelNormal = 11, ModelEvent = 12, FaceAvatar = 21, FaceFrame = 22, FaceBubble = 23, TitlePalace = 31, TitleEvent = 32, }