少年修仙传客户端代码仓库
client_linchunjie
2018-08-18 f4f07847775c12b338d8bccedbbabc067dc1ae2c
System/Treasure/TreasureSoulWin.cs
@@ -19,27 +19,31 @@
        [SerializeField] Button m_CloseBtn;
        [SerializeField] Image m_SelectSoulImg;
        [SerializeField] Text m_SelectTreasureName;
        [SerializeField] Text m_SoulName;
        [SerializeField] Text m_SoulDescription;
        [SerializeField] Image m_SoulTarget;
        [SerializeField] Button m_GotoGetBtn;
        [SerializeField] Button m_Active;
        [SerializeField] Text m_ActiveText;
        [SerializeField] Button m_GotoRealm;
        [SerializeField] List<TreasureSoulPattern> m_TreasureSouls;
        [SerializeField] RectTransform m_ContainerPreview;
        [SerializeField] Text m_PropertyTitle;
        [SerializeField] List<PropertyBehaviour> propertys;
        [SerializeField] ScrollerController m_ScollerControl;
        TreasureModel m_Model;
        TreasureModel model
        [SerializeField] RectTransform m_ContainerPreview;
        [SerializeField] Text m_PreviewTitle;
        [SerializeField] List<PropertyBehaviour> m_PreviewPropretys;
        [SerializeField] RectTransform m_ContainerCondition;
        [SerializeField] ScrollerController m_ConditonControl;
        TreasureSoulModel m_Model;
        TreasureSoulModel model
        {
            get
            {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<TreasureModel>());
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<TreasureSoulModel>());
            }
        }
        PlayerSuitModel suitModel { get { return ModelCenter.Instance.GetModel<PlayerSuitModel>(); } }
@@ -53,8 +57,12 @@
            }
        }
        AchievementModel achievementModel
        {
            get { return ModelCenter.Instance.GetModel<AchievementModel>(); }
        }
        bool m_CorrectClose = true;
        int m_SelectSoul = 0;
        List<int> sortSouls = new List<int>();
@@ -66,16 +74,19 @@
        protected override void AddListeners()
        {
            m_GotoGetBtn.onClick.AddListener(OnGotoGet);
            m_Active.onClick.AddListener(Active);
            m_GotoRealm.onClick.AddListener(GotoRealm);
            m_CloseBtn.onClick.AddListener(CloseClick);
            m_ScollerControl.OnRefreshCell += OnRefreshCell;
            m_ConditonControl.OnRefreshCell += OnRefreshConditionCell;
        }
        protected override void OnPreOpen()
        {
            m_CorrectClose = true;
            model.treasureSelectSoulChangeEvent += TreasureSelectSoulChangeEvent;
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
            model.treasureSoulEvent += TreasureSoulEvent;
            achievementModel.achievementCompletedEvent += AchievementCompletedEvent;
            m_TreasureSoulBtn.state = TitleBtnState.Click;
            Display();
            DisplaySelect();
@@ -97,6 +108,8 @@
        {
            model.treasureSelectSoulChangeEvent -= TreasureSelectSoulChangeEvent;
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent;
            model.treasureSoulEvent -= TreasureSoulEvent;
            achievementModel.achievementCompletedEvent -= AchievementCompletedEvent;
            for (int i = 0; i < m_TreasureSouls.Count; i++)
            {
                m_TreasureSouls[i].Dispose();
@@ -106,19 +119,31 @@
        protected override void OnAfterClose()
        {
            if (m_CorrectClose)
            {
                WindowCenter.Instance.Open<MainInterfaceWin>();
            }
            WindowCenter.Instance.Open<MainInterfaceWin>();
        }
        #endregion
        private void AchievementCompletedEvent(int _id)
        {
            List<int> list;
            if (model.TryGetAchievements(model.selectSoul, out list) && list.Contains(_id))
            {
                DisplaySelect();
            }
        }
        private void Display()
        {
            sortSouls.Clear();
            var _list = model.GetTreasureCategory(TreasureCategory.Human);
            sortSouls.AddRange(_list);
            if (m_ScollerControl.GetNumberOfCells(m_ScollerControl.m_Scorller) == 0)
            var _list = model.GetTreasureSouls();
            for (int i = 0; i < _list.Count; i++)
            {
                if (model.IsOpenTreasureSoul(_list[i]))
                {
                    sortSouls.Add(_list[i]);
                }
            }
            if (m_ScollerControl.GetNumberOfCells(m_ScollerControl.m_Scorller) != sortSouls.Count)
            {
                m_ScollerControl.Refresh();
                for (int i = 0; i < sortSouls.Count; i++)
@@ -146,38 +171,17 @@
                return _soul;
            }
            model.gotoSoul = 0;
            var _list = model.GetTreasureCategory(TreasureCategory.Human);
            var _select = _list[0];
            for (int i = 0; i < _list.Count; i++)
            var _select = sortSouls[sortSouls.Count - 1];
            for (int i = 0; i < sortSouls.Count; i++)
            {
                Treasure treasure;
                if (model.TryGetTreasure(_list[i], out treasure))
                TreasureSpecialData special;
                if (model.TryGetTreasureSoul(sortSouls[i], out special))
                {
                    if (treasure.specialData.privilegeRedpoint != null
                        && treasure.specialData.privilegeRedpoint.state == RedPointState.Simple)
                    if (special.redpoint.state == RedPointState.Simple)
                    {
                        return _list[i];
                        return sortSouls[i];
                    }
                }
            }
            for (int i = 0; i < _list.Count; i++)
            {
                Treasure treasure;
                if (model.TryGetTreasure(_list[i], out treasure))
                {
                    if (treasure.state == TreasureState.Collected)
                    {
                        if (!treasure.IsMaxStage())
                        {
                            return _list[i];
                        }
                        _select = treasure.id;
                    }
                }
            }
            if (_list.Contains(m_SelectSoul))
            {
                return m_SelectSoul;
            }
            return _select;
        }
@@ -196,48 +200,81 @@
            DisplaySelect();
        }
        private void OnGotoGet()
        private void TreasureSoulEvent(int _id)
        {
            m_CorrectClose = false;
            CloseImmediately();
            model.currentCategory = TreasureCategory.Human;
            model.selectedTreasure = model.selectSoul;
            model.openFromTreasureSoul = true;
            WindowCenter.Instance.Open<TreasureLevelUpWin>();
            if (_id == model.selectSoul)
            {
                TreasureSpecialData special;
                if (model.TryGetTreasureSoul(_id, out special))
                {
                    m_SelectSoulImg.material = special.active ? MaterialUtility.GetUIDefaultGraphicMaterial() : MaterialUtility.GetDefaultSpriteGrayMaterial();
                }
            }
        }
        private void Active()
        {
            model.ActiveTreasureSoul(model.selectSoul);
        }
        private void GotoRealm()
        {
            WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.RealmFunc1);
        }
        private void DisplaySelect()
        {
            Treasure treasure;
            model.TryGetTreasure(model.selectSoul, out treasure);
            if (treasure != null)
            TreasureSpecialData special;
            model.TryGetTreasureSoul(model.selectSoul, out special);
            m_ContainerCondition.gameObject.SetActive(false);
            if (special != null)
            {
                var _privilege = treasure.unLockPrivilege;
                var config = ConfigManager.Instance.GetTemplate<TreasurePrivilegeConfig>(_privilege);
                var config = ConfigManager.Instance.GetTemplate<TreasurePrivilegeConfig>((int)special.type);
                if (config != null)
                {
                    m_SoulName.text = config.Name;
                    m_SoulDescription.text = UIHelper.ReplaceNewLine(config.Description);
                    m_SoulTarget.SetSprite(config.targetDescription);
                    m_SoulTarget.SetNativeSize();
                    m_GotoGetBtn.gameObject.SetActive(!treasure.IsMaxStage());
                    DisplayPrivilege(treasure);
                    DisplayPrivilege(special);
                    m_SelectSoulImg.SetSprite(config.Icon);
                    m_SelectSoulImg.material = treasure.IsMaxStage() ? MaterialUtility.GetUIDefaultGraphicMaterial() : MaterialUtility.GetDefaultSpriteGrayMaterial();
                    m_SelectSoulImg.material = special.active ? MaterialUtility.GetUIDefaultGraphicMaterial() : MaterialUtility.GetDefaultSpriteGrayMaterial();
                    if (special.active)
                    {
                        m_Active.gameObject.SetActive(false);
                        m_GotoRealm.gameObject.SetActive(false);
                    }
                    else
                    {
                        if (!model.IsCompleteRealmAchievement(model.selectSoul))
                        {
                            m_Active.gameObject.SetActive(false);
                            m_GotoRealm.gameObject.SetActive(true);
                        }
                        else
                        {
                            m_Active.gameObject.SetActive(true);
                            m_GotoRealm.gameObject.SetActive(false);
                            m_Active.SetInteractable(m_ActiveText, model.IsCompleteAllAchievement(model.selectSoul));
                            m_ContainerCondition.gameObject.SetActive(true);
                            DisplayCondition();
                        }
                    }
                    m_ContainerPreview.gameObject.SetActive(!special.active);
                    if (!special.active)
                    {
                        DisplayPreview(model.selectSoul);
                    }
                }
                var treasureConfig = ConfigManager.Instance.GetTemplate<TreasureConfig>(model.selectSoul);
                m_SelectTreasureName.text = treasureConfig.Name;
                DisplyPreview(treasure);
            }
        }
        private void DisplayPrivilege(Treasure treasure)
        private void DisplayPrivilege(TreasureSpecialData special)
        {
            int _pattern = -1;
            switch (treasure.specialData.type)
            switch (special.type)
            {
                case TreasurePrivilege.Property:
                case TreasurePrivilege.Suit:
@@ -247,7 +284,7 @@
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.Boss:
                case TreasurePrivilege.Sp:
                    _pattern = 0;
                    break;
                case TreasurePrivilege.StrengthenAdd:
@@ -260,56 +297,53 @@
            for (int i = 0; i < m_TreasureSouls.Count; i++)
            {
                m_TreasureSouls[i].Dispose();
                m_TreasureSouls[i].gameObject.SetActive(_pattern == i && treasure.IsMaxStage());
                if (_pattern == i && treasure.IsMaxStage())
                m_TreasureSouls[i].gameObject.SetActive(_pattern == i && model.IsGetTreasureSoul(model.selectSoul));
                if (_pattern == i)
                {
                    m_TreasureSouls[i].Display(treasure.id);
                    m_TreasureSouls[i].Display((int)special.type);
                }
            }
        }
        private void DisplyPreview(Treasure treasure)
        private void DisplayPreview(int _id)
        {
            m_ContainerPreview.gameObject.SetActive(false);
            if (treasure.IsMaxStage())
            {
                return;
            }
            switch (treasure.specialData.type)
            TreasureSpecialData special;
            model.TryGetTreasureSoul(_id, out special);
            switch (special.type)
            {
                case TreasurePrivilege.Wing:
                case TreasurePrivilege.Suit:
                case TreasurePrivilege.Property:
                    m_PropertyTitle.text = Language.Get("TreasureSoulAddPropertyTitle");
                    m_PreviewTitle.text = Language.Get("TreasureSoulAddPropertyTitle");
                    break;
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.StrengthenAdd:
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.Boss:
                    m_PropertyTitle.text = Language.Get("TreasureSoulGetPropertyTitle");
                case TreasurePrivilege.Sp:
                    m_PreviewTitle.text = Language.Get("TreasureSoulGetPropertyTitle");
                    break;
            }
            var specialData = treasure.specialData;
            for (int i = 0; i < propertys.Count; i++)
            for (int i = 0; i < m_PreviewPropretys.Count; i++)
            {
                propertys[i].gameObject.SetActive(false);
                m_PreviewPropretys[i].gameObject.SetActive(false);
            }
            switch (specialData.type)
            switch (special.type)
            {
                case TreasurePrivilege.Property:
                    var _index = 0;
                    m_ContainerPreview.gameObject.SetActive(true);
                    foreach (var _key in specialData.propertyDict.Keys)
                    foreach (var _key in special.propertyDict.Keys)
                    {
                        var _value = specialData.propertyDict[_key];
                        propertys[_index].gameObject.SetActive(true);
                        propertys[_index].DisplayUpper(_key, _value);
                        var _value = special.propertyDict[_key];
                        m_PreviewPropretys[_index].gameObject.SetActive(true);
                        m_PreviewPropretys[_index].DisplayUpper(_key, _value);
                        _index++;
                    }
                    break;
                case TreasurePrivilege.Suit:
                    var percentSuit = (float)specialData.propertyDict[87] / 10000;
                    var percentSuit = (float)special.propertyDict[87] / 10000;
                    var dict = suitModel.GetActiveSuitAttr();
                    var _suitIndex = 0;
                    foreach (var _key in dict.Keys)
@@ -319,14 +353,14 @@
                        {
                            continue;
                        }
                        propertys[_suitIndex].gameObject.SetActive(true);
                        propertys[_suitIndex].DisplayUpper(_key, (int)(percentSuit * dict[_key]));
                        m_PreviewPropretys[_suitIndex].gameObject.SetActive(true);
                        m_PreviewPropretys[_suitIndex].DisplayUpper(_key, (int)(percentSuit * dict[_key]));
                        _suitIndex++;
                    }
                    m_ContainerPreview.gameObject.SetActive(_suitIndex > 0);
                    break;
                case TreasurePrivilege.Wing:
                    var percentWing = (float)specialData.propertyDict[86] / 10000;
                    var percentWing = (float)special.propertyDict[86] / 10000;
                    var itemModel = pack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retWing);
                    m_ContainerPreview.gameObject.SetActive(itemModel != null);
                    if (itemModel != null)
@@ -340,26 +374,26 @@
                                value += strengthengmodel.BackpackWings(itemModel.itemId, itemModel.GetUseDataModel(42)[0])[1];
                            }
                        }
                        propertys[0].gameObject.SetActive(true);
                        propertys[0].Display(6, (int)(value * percentWing));
                        m_PreviewPropretys[0].gameObject.SetActive(true);
                        m_PreviewPropretys[0].Display(6, (int)(value * percentWing));
                    }
                    break;
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.Boss:
                case TreasurePrivilege.Sp:
                    var index = 0;
                    m_ContainerPreview.gameObject.SetActive(true);
                    foreach (var _key in specialData.propertyDict.Keys)
                    foreach (var _key in special.propertyDict.Keys)
                    {
                        var _value = specialData.propertyDict[_key] * (specialData.presentGetCount / specialData.progress);
                        var _value = special.propertyDict[_key] * (special.presentGetCount / special.progress);
                        if (_value <= 0)
                        {
                            m_ContainerPreview.gameObject.SetActive(false);
                            break;
                        }
                        propertys[index].gameObject.SetActive(true);
                        propertys[index].DisplayUpper(_key, _value);
                        m_PreviewPropretys[index].gameObject.SetActive(true);
                        m_PreviewPropretys[index].DisplayUpper(_key, _value);
                        index++;
                    }
                    break;
@@ -388,12 +422,12 @@
                    if (present >= 0)
                    {
                        var config = configs[present];
                        for (int i = 0; i < propertys.Count; i++)
                        for (int i = 0; i < m_PreviewPropretys.Count; i++)
                        {
                            propertys[i].gameObject.SetActive(i < config.attType.Length);
                            m_PreviewPropretys[i].gameObject.SetActive(i < config.attType.Length);
                            if (i < config.attType.Length)
                            {
                                propertys[i].DisplayUpper(config.attType[i], config.attValue[i]);
                                m_PreviewPropretys[i].DisplayUpper(config.attType[i], config.attValue[i]);
                            }
                        }
                    }
@@ -401,31 +435,45 @@
            }
        }
        private void DisplayCondition()
        {
            m_ContainerCondition.gameObject.SetActive(true);
            List<int> list;
            model.TryGetAchievements(model.selectSoul, out list);
            m_ConditonControl.Refresh();
            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    var config = ConfigManager.Instance.GetTemplate<SuccessConfig>(list[i]);
                    if (config != null && config.Type == 50)
                    {
                        continue;
                    }
                    m_ConditonControl.AddCell(ScrollerDataType.Header, list[i]);
                }
            }
            m_ConditonControl.Restart();
        }
        private void OnRefreshConditionCell(ScrollerDataType type, CellView cell)
        {
            var _cell = cell as TreasureSoulAchievementCell;
            _cell.Display(cell.index);
        }
        int Compare(int x, int y)
        {
            //Treasure treasure_x;
            //Treasure treasure_y;
            //if (model.TryGetTreasure(x, out treasure_x) && model.TryGetTreasure(y, out treasure_y))
            //{
            //    var stage_x = treasure_x.treasureStages[treasure_x.StageCount - 1];
            //    var stage_y = treasure_y.treasureStages[treasure_y.StageCount - 1];
            //    bool awaking_x = PlayerDatas.Instance.baseData.LV >= stage_x.limitLevel && !treasure_x.IsMaxStage();
            //    bool awaking_y = PlayerDatas.Instance.baseData.LV >= stage_y.limitLevel && !treasure_y.IsMaxStage();
            //    if (awaking_x != awaking_y)
            //    {
            //        return -awaking_x.CompareTo(awaking_y);
            //    }
            //    bool awoke_x = treasure_x.IsMaxStage();
            //    bool awoke_y = treasure_y.IsMaxStage();
            //    if (awoke_x != awoke_y)
            //    {
            //        return -awoke_x.CompareTo(awoke_y);
            //    }
            //}
            TreasureSpecialData special_x;
            TreasureSpecialData special_y;
            if (model.TryGetTreasureSoul(x, out special_x) && model.TryGetTreasureSoul(y, out special_y))
            {
                return special_x.treasureId.CompareTo(special_y.treasureId);
            }
            return x.CompareTo(y);
        }
        public bool ContainsProperty(ItemConfig config, int _property, out float value)
        bool ContainsProperty(ItemConfig config, int _property, out float value)
        {
            value = 0;
            if (config.Effect1 == _property && config.EffectValueA1 > 0)