From d5bf165ef28b530ed531aed097ad301278c5fcae Mon Sep 17 00:00:00 2001
From: client_Wu Xijin <364452445@qq.com>
Date: 星期四, 15 十一月 2018 14:33:35 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.0.87:10010/r/snxxz_scripts

---
 System/Treasure/DemonTreasureWin.cs |  442 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 438 insertions(+), 4 deletions(-)

diff --git a/System/Treasure/DemonTreasureWin.cs b/System/Treasure/DemonTreasureWin.cs
index 8c484fc..85eac32 100644
--- a/System/Treasure/DemonTreasureWin.cs
+++ b/System/Treasure/DemonTreasureWin.cs
@@ -6,6 +6,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using TableConfig;
 using UnityEngine;
 using UnityEngine.UI;
 
@@ -14,10 +15,58 @@
     public class DemonTreasureWin : Window
     {
         [SerializeField] TreasureDemonBehaviour m_TreasureDemonBehaviour;
+        [SerializeField] Text m_PropertyTitle;
+        [SerializeField] PropertyBehaviour[] m_Propertys;
+        [SerializeField] Text m_SkillTitle;
+        [SerializeField] Image m_SkillIcon;
+        [SerializeField] Text m_SkillState;
+        [SerializeField] Text m_SkillName;
+        [SerializeField] Text m_SkillDescription;
+        [SerializeField] RectTransform m_DungeonsContent;
+        [SerializeField] Transform m_ContainerDungeons;
+        [SerializeField] DemonDungeonBehaviour[] m_DungeonBehaviours;
+
+        [SerializeField] Transform m_ContainerChallenge;
+        [SerializeField] Button m_Challenge;
+        [SerializeField] Text m_RecommondPower;
+        [SerializeField] Button m_ViewProperty;
+
+        [SerializeField] float m_Expand = 1.05f;
+
+        [SerializeField] PositionTween m_TreasureGainTween;
+        [SerializeField] PositionTween m_DescriptionTween;
+        [SerializeField] PositionTween m_SkillTween;
+        [SerializeField] PositionTween m_NameTween;
+        [SerializeField] UIAlphaTween m_DungeonAlphaTween;
 
         TreasureModel model
         {
             get { return ModelCenter.Instance.GetModel<TreasureModel>(); }
+        }
+
+        DungeonModel dungeonModel
+        {
+            get { return ModelCenter.Instance.GetModel<DungeonModel>(); }
+        }
+
+        static Dictionary<int, int> currentPropertyDict = new Dictionary<int, int>();
+        static List<int> displayPropertys = new List<int>();
+        static Dictionary<int, int> addPropertyDict = new Dictionary<int, int>();
+
+        public static float expand = 1.05f;
+
+        AnimationStep m_Step = AnimationStep.None;
+        AnimationStep step
+        {
+            get { return m_Step; }
+            set
+            {
+                if (m_Step != value)
+                {
+                    m_Step = value;
+                    DisplayAnimation();
+                }
+            }
         }
         #region Built-in
         protected override void BindController()
@@ -26,18 +75,38 @@
 
         protected override void AddListeners()
         {
+            m_ViewProperty.onClick.AddListener(ViewProperty);
+            m_Challenge.onClick.AddListener(Challenge);
         }
 
         protected override void OnPreOpen()
         {
-            UI3DTreasureSelectStage.Instance.SetStartState();
+            expand = m_Expand;
+            m_Step = AnimationStep.None;
         }
 
         protected override void OnActived()
         {
             base.OnActived();
             model.treasureSelectedEvent += TreasureSelectedEvent;
-            m_TreasureDemonBehaviour.Display(model.selectedTreasure, true);
+            model.treasureStateChangeEvent += TreasureStateChangeEvent;
+            model.demonTreasureDungeonUpdate += DemonTreasureDungeonUpdate;
+            Display();
+
+            Treasure treasure;
+            if (model.TryGetTreasure(model.selectedTreasure, out treasure))
+            {
+                switch (treasure.state)
+                {
+                    case TreasureState.Collecting:
+                    case TreasureState.Collected:
+                        step = AnimationStep.None2Collect;
+                        break;
+                    case TreasureState.Locked:
+                        step = AnimationStep.None2Lock;
+                        break;
+                }
+            }
         }
 
         protected override void OnAfterOpen()
@@ -48,6 +117,8 @@
         protected override void OnPreClose()
         {
             model.treasureSelectedEvent -= TreasureSelectedEvent;
+            model.treasureStateChangeEvent -= TreasureStateChangeEvent;
+            model.demonTreasureDungeonUpdate -= DemonTreasureDungeonUpdate;
             model.SetTreasureUnlockShow(TreasureCategory.Demon, 0);
         }
 
@@ -56,11 +127,374 @@
         }
         #endregion
 
-        private void TreasureSelectedEvent(int obj)
+        private void ViewProperty()
         {
-            m_TreasureDemonBehaviour.Display(model.selectedTreasure, false);
+            WindowCenter.Instance.Open<DemonTreasurePropertyWin>();
         }
 
+        private void Challenge()
+        {
+            Treasure treasure;
+            if (!model.TryGetTreasure(model.selectedTreasure, out treasure))
+            {
+                return;
+            }
+            var fightPower = PlayerDatas.Instance.baseData.FightPoint;
+            var recommandPower = 0;
+            TreasureDungeon treasureDungeon;
+            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
+            {
+                var dungeonInfo = treasureDungeon.Get(treasureDungeon.currentLevel + 1);
+                if (!dungeonInfo.Equals(default(TreasureDungeonInfo)))
+                {
+                    recommandPower = dungeonInfo.fightPower;
+                }
+            }
+
+            var config = Config.Instance.Get<TreasureConfig>(model.selectedTreasure);
+            if (fightPower < recommandPower)
+            {
+                ConfirmCancel.ShowPopConfirm(Language.Get("DemonLackPowerTitle"), Language.Get("DemonLackFightPower", recommandPower)
+                    , (bool isOk) =>
+                     {
+                         if (isOk)
+                         {
+                             model.collectingDemon = model.selectedTreasure;
+                             dungeonModel.SingleChallenge(TreasureModel.TREASURE_DATAMAPID, config.LineId);
+                         }
+                     });
+            }
+            else
+            {
+                model.collectingDemon = model.selectedTreasure;
+                dungeonModel.SingleChallenge(TreasureModel.TREASURE_DATAMAPID, config.LineId);
+            }
+        }
+
+        private void Display()
+        {
+            m_TreasureDemonBehaviour.Display(model.selectedTreasure);
+            DisplayProperty();
+            DisplaySkill();
+            DisplayDungeons();
+            DisplayChallenge();
+            DisplayDungeonPosition();
+        }
+
+        private void DisplayAnimation()
+        {
+            switch (step)
+            {
+                case AnimationStep.None2Lock:
+                    m_DescriptionTween.Play();
+                    m_NameTween.Play();
+                    m_SkillTween.Play();
+                    m_TreasureGainTween.SetStartState();
+                    UI3DTreasureSelectStage.Instance.SetStartState();
+                    m_ContainerDungeons.gameObject.SetActive(false);
+                    break;
+                case AnimationStep.None2Collect:
+                    m_ContainerDungeons.gameObject.SetActive(true);
+                    m_DungeonAlphaTween.Play();
+                    UI3DTreasureSelectStage.Instance.Tween(null);
+                    m_DescriptionTween.SetStartState();
+                    m_NameTween.SetStartState();
+                    m_SkillTween.SetStartState();
+                    m_TreasureGainTween.Play();
+                    break;
+                case AnimationStep.Lock2Collect:
+                    m_ContainerDungeons.gameObject.SetActive(true);
+                    m_DungeonAlphaTween.Play();
+                    UI3DTreasureSelectStage.Instance.Tween(null);
+                    m_DescriptionTween.Play(true);
+                    m_NameTween.Play(true);
+                    m_SkillTween.Play(true);
+                    m_TreasureGainTween.Play();
+                    break;
+                case AnimationStep.Collect2Lock:
+                    m_ContainerDungeons.gameObject.SetActive(false);
+                    UI3DTreasureSelectStage.Instance.SetStartState();
+                    m_DescriptionTween.Play();
+                    m_NameTween.Play();
+                    m_SkillTween.Play();
+                    m_TreasureGainTween.Play(true);
+                    break;
+            }
+        }
+
+        private void DisplayProperty()
+        {
+            TreasureDungeon treasureDungeon;
+            currentPropertyDict.Clear();
+            addPropertyDict.Clear();
+            displayPropertys.Clear();
+            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
+            {
+                for (int i = 0; i < treasureDungeon.dungeonInfos.Count; i++)
+                {
+                    var info = treasureDungeon.dungeonInfos[i];
+                    if (treasureDungeon.currentLevel >= info.level)
+                    {
+                        foreach (var key in info.propertyDict.Keys)
+                        {
+                            if (!currentPropertyDict.ContainsKey(key))
+                            {
+                                currentPropertyDict.Add(key, 0);
+                            }
+                            currentPropertyDict[key] += info.propertyDict[key];
+                            if (!displayPropertys.Contains(key))
+                            {
+                                displayPropertys.Add(key);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        foreach (var key in info.propertyDict.Keys)
+                        {
+                            if (!addPropertyDict.ContainsKey(key))
+                            {
+                                addPropertyDict.Add(key, info.propertyDict[key]);
+                            }
+                            if (!displayPropertys.Contains(key))
+                            {
+                                displayPropertys.Add(key);
+                            }
+                        }
+                        break;
+                    }
+                }
+                if (treasureDungeon.currentLevel == treasureDungeon.maxLevel)
+                {
+                    m_PropertyTitle.text = Language.Get("GetTreasurePropertyTitle");
+                }
+                else
+                {
+                    m_PropertyTitle.text = Language.Get("PassTreasureDungeonPropertyTitle");
+                }
+            }
+            for (int i = 0; i < m_Propertys.Length; i++)
+            {
+                if (i < displayPropertys.Count)
+                {
+                    m_Propertys[i].gameObject.SetActive(true);
+                    var currentValue = 0;
+                    if (currentPropertyDict.ContainsKey(displayPropertys[i]))
+                    {
+                        currentValue = currentPropertyDict[displayPropertys[i]];
+                    }
+                    var addValue = 0;
+                    if (addPropertyDict.ContainsKey(displayPropertys[i]))
+                    {
+                        addValue = addPropertyDict[displayPropertys[i]];
+                    }
+                    m_Propertys[i].DisplayAdd(displayPropertys[i], currentValue, addValue);
+                }
+                else
+                {
+                    m_Propertys[i].gameObject.SetActive(false);
+                }
+            }
+        }
+
+        private void DisplaySkill()
+        {
+            Treasure treasure;
+            if (model.TryGetTreasure(model.selectedTreasure, out treasure))
+            {
+                var skillConfig = Config.Instance.Get<SkillConfig>(treasure.unlockSkill);
+                if (skillConfig != null)
+                {
+                    m_SkillIcon.SetSprite(skillConfig.IconName);
+                    m_SkillName.text = skillConfig.SkillName;
+                    m_SkillDescription.text = skillConfig.Description;
+                    if (treasure.state == TreasureState.Collected)
+                    {
+                        m_SkillState.text = Language.Get("DemonTreasureSkillGot");
+                        m_SkillState.color = UIHelper.GetUIColor(TextColType.Green, true);
+                    }
+                    else
+                    {
+                        m_SkillState.text = Language.Get("DemonTreasureSkillGetting");
+                        m_SkillState.color = UIHelper.GetUIColor(TextColType.Red, true);
+                    }
+                }
+            }
+            TreasureDungeon treasureDungeon;
+            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
+            {
+                var dungeonInfo = treasureDungeon.Get(treasureDungeon.maxLevel);
+                if (!dungeonInfo.Equals(default(TreasureDungeonInfo)))
+                {
+                    var config = Config.Instance.Get<TreasureDungeonConfig>(dungeonInfo.key);
+                    m_SkillTitle.text = Language.Get("PassTreasureDungeonSkillTitle", config.bossName);
+                }
+            }
+        }
+
+        private void DisplayChallenge()
+        {
+            Treasure treasure;
+            if (!model.TryGetTreasure(model.selectedTreasure, out treasure))
+            {
+                return;
+            }
+            m_ContainerChallenge.gameObject.SetActive(treasure.state == TreasureState.Collecting);
+            var fightPower = PlayerDatas.Instance.baseData.FightPoint;
+            var recommandPower = 0;
+            TreasureDungeon treasureDungeon;
+            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
+            {
+                var dungeonInfo = treasureDungeon.Get(treasureDungeon.currentLevel + 1);
+                if (!dungeonInfo.Equals(default(TreasureDungeonInfo)))
+                {
+                    recommandPower = dungeonInfo.fightPower;
+                }
+            }
+            m_RecommondPower.text = Language.Get("TreasureRecommendAttr", StringUtility.Contact(fightPower, "/", recommandPower));
+            m_RecommondPower.color = UIHelper.GetUIColor(fightPower >= recommandPower ? TextColType.Green : TextColType.Red);
+        }
+
+        private void DisplayDungeons()
+        {
+            TreasureDungeon treasureDungeon;
+            DemonDungeonScriptable config = ScriptableObjectLoader.LoadSoDemonDungeon(model.selectedTreasure);
+            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
+            {
+                for (int i = 0; i < m_DungeonBehaviours.Length; i++)
+                {
+                    if (i < treasureDungeon.dungeonInfos.Count)
+                    {
+                        m_DungeonBehaviours[i].gameObject.SetActive(true);
+                        m_DungeonBehaviours[i].Display(model.selectedTreasure, treasureDungeon.dungeonInfos[i].level);
+                        if (config != null)
+                        {
+                            m_DungeonBehaviours[i].transform.localPosition = config.GetPosition(i);
+                        }
+                    }
+                    else
+                    {
+                        m_DungeonBehaviours[i].gameObject.SetActive(false);
+                    }
+                }
+            }
+        }
+
+        private void TreasureStateChangeEvent(int id)
+        {
+            if (id == model.selectedTreasure)
+            {
+                DisplaySkill();
+                DisplayProperty();
+                DisplayChallenge();
+
+                UpdateAnimationStep();
+            }
+        }
+
+        private void TreasureSelectedEvent(int id)
+        {
+            Display();
+            UpdateAnimationStep();
+        }
+
+        private void DemonTreasureDungeonUpdate(int id)
+        {
+            if (id == model.selectedTreasure)
+            {
+                DisplayDungeons();
+                DisplayChallenge();
+            }
+        }
+
+        private void UpdateAnimationStep()
+        {
+            Treasure treasure;
+            if (model.TryGetTreasure(model.selectedTreasure, out treasure))
+            {
+                switch (treasure.state)
+                {
+                    case TreasureState.Collecting:
+                    case TreasureState.Collected:
+                        switch (step)
+                        {
+                            case AnimationStep.Collect2Lock:
+                            case AnimationStep.None2Lock:
+                                step = AnimationStep.Lock2Collect;
+                                break;
+                        }
+                        break;
+                    case TreasureState.Locked:
+                        switch (step)
+                        {
+                            case AnimationStep.None2Collect:
+                            case AnimationStep.Lock2Collect:
+                                step = AnimationStep.Collect2Lock;
+                                break;
+                        }
+                        break;
+                }
+            }
+        }
+
+        private void DisplayDungeonPosition()
+        {
+            TreasureDungeon treasureDungeon;
+            var scriptable = ScriptableObjectLoader.LoadSoDemonDungeon(model.selectedTreasure);
+            if (scriptable == null)
+            {
+                return;
+            }
+            var height = (m_DungeonBehaviours[0].transform as RectTransform).sizeDelta.y;
+            var viewAreaHeight = (m_ContainerDungeons as RectTransform).sizeDelta.y;
+            if (model.TryGetTreasureDungeon(model.selectedTreasure, out treasureDungeon))
+            {
+                var selectLevel = treasureDungeon.currentLevel == treasureDungeon.maxLevel ?
+                    treasureDungeon.maxLevel : (treasureDungeon.currentLevel + 1);
+                var selectPosition = scriptable.GetPosition(selectLevel - 1);
+                if (selectPosition.y + (height / 2) * expand <= viewAreaHeight)
+                {
+                    m_DungeonsContent.anchoredPosition = Vector3.zero;
+                    return;
+                }
+                else
+                {
+                    var delta = selectPosition.y + (height / 2) * expand - viewAreaHeight;
+                    m_DungeonsContent.anchoredPosition = m_DungeonsContent.localPosition.SetY(-delta);
+                }
+            }
+        }
+
+        enum AnimationStep
+        {
+            None,
+            None2Lock,
+            None2Collect,
+            Lock2Collect,
+            Collect2Lock,
+        }
+
+#if UNITY_EDITOR
+        [SerializeField] DemonDungeonScriptable m_EditorScriptable;
+
+        [ContextMenu("搴旂敤浣嶇疆淇℃伅")]
+        void ApplyPositions()
+        {
+            if (m_EditorScriptable == null)
+            {
+                return;
+            }
+            var index = 0;
+            for (int i = 0; i < m_DungeonBehaviours.Length; i++)
+            {
+                if (m_DungeonBehaviours[i].gameObject.activeSelf)
+                {
+                    m_EditorScriptable.ApplyPosition(index, m_DungeonBehaviours[i].transform.localPosition);
+                    index++;
+                }
+            }
+        }
+#endif
     }
 
 }

--
Gitblit v1.8.0