//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, September 12, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class DungeonVictoryWin : Window { [SerializeField] protected Transform m_ContainerPoivt; [SerializeField, Header("通关时间")] Transform m_ContainerPassTime; [SerializeField] Text m_PassTime; [SerializeField, Header("经验")] protected Transform m_ContainerExp; [SerializeField] Text m_Experience; [SerializeField, Header("金钱")] protected Transform m_ContainerMoney; [SerializeField] Text m_Money; [SerializeField, Header("精华")] protected Transform m_ContainerEssence; [SerializeField] Text m_Essence; [SerializeField, Header("魔晶")] protected Transform m_ContainerMagicEssence; [SerializeField] Text m_MagicEssence; [SerializeField, Header("仙缘币")] protected Transform m_ContainerXianyuanCoins; [SerializeField] Text m_XianyuanCoins; [SerializeField, Header("退出按钮")] protected ButtonEx m_Exit; [SerializeField] protected Text m_ExitTimer; [SerializeField, Header("评级")] GameObject m_GradeBottom; [SerializeField] Image m_Grade; [SerializeField, Header("杀怪数量")] protected Transform m_ContainerKillMonster; [SerializeField] Text m_KillMonsterCnt; [SerializeField, Header("新记录")] protected Transform m_ContainerNewRecord; [SerializeField] Text m_Record; [SerializeField, Header("Sp")] protected Transform m_ContainerSP; [SerializeField] Text m_SP; [SerializeField, Header("物品奖励")] protected Transform m_ContainerReward; [SerializeField] protected ItemBehaviour m_SpecialItemCollect; [SerializeField] protected DungeonRewardItem[] passRewardBehaviours; [SerializeField] protected ScaleTween[] m_RewardTweens; protected DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel(); } } protected float timer = 0f; protected List m_RewardIndexs = new List(); private List m_RewardSorts = new List(); #region Built-in protected override void BindController() { } protected override void AddListeners() { if (m_Exit != null) { m_Exit.AddListener(ExitDungeon); } } protected override void OnPreOpen() { timer = 0f; if (m_ContainerMagicEssence != null) { m_ContainerMagicEssence.gameObject.SetActive(false); } if (m_ContainerEssence != null) { m_ContainerEssence.gameObject.SetActive(false); } if (m_ContainerMoney != null) { m_ContainerMoney.gameObject.SetActive(false); } if (m_ContainerReward != null) { m_ContainerReward.gameObject.SetActive(false); } if (m_ContainerNewRecord != null) { m_ContainerNewRecord.gameObject.SetActive(false); } if (m_ContainerKillMonster != null) { m_ContainerKillMonster.gameObject.SetActive(false); } if (m_ContainerPoivt != null) { m_ContainerPoivt.gameObject.SetActive(false); } } protected override void OnAfterOpen() { if (PlayerDatas.Instance.baseData.MapID == IceCrystalVeinModel.ICECRYSTALVEIN_MAPID) { var iceCrystalVeinModel = ModelCenter.Instance.GetModel(); iceCrystalVeinModel.IsIceCrystalVein_Copy = true; } } protected override void OnPreClose() { } protected override void OnAfterClose() { var iceCrystalVeinModel = ModelCenter.Instance.GetModel(); if (iceCrystalVeinModel.IsIceCrystalVein_Copy) { iceCrystalVeinModel.IsIceCrystalVein_Copy = false; PopupWindowsProcessor.Instance.Add("IceCrystalVeinWin"); } } protected override void OnActived() { base.OnActived(); var config = DungeonOpenTimeConfig.Get(dungeonModel.dungeonResult.dataMapID); StartCoroutine(Co_DelayDisplay(config.DelayTime * 0.001f)); } #endregion protected override void LateUpdate() { base.LateUpdate(); if (m_ExitTimer != null && !m_ExitTimer.gameObject.activeInHierarchy) { m_ExitTimer.gameObject.SetActive(true); } timer -= Time.deltaTime; if (timer < 0f) { timer += 0.5f; var endTime = dungeonModel.GetCoolDownEndTime(DungeonCoolDownType.LeaveMap); var seconds = (endTime - TimeUtility.ServerNow).TotalSeconds; DrawExitTimer((int)seconds); } } protected virtual void ExitDungeon() { dungeonModel.ExitCurrentDungeon(); } protected virtual void DrawExitTimer(int seconds) { if (m_ExitTimer != null) { m_ExitTimer.text = Language.Get("DungeonVictoryWin_Btn_Exit_1", Mathf.Clamp(seconds, 0, int.MaxValue)); } } protected virtual void DrawItemRewards() { var merged = false; var serveritems = dungeonModel.dungeonResult.itemInfo; var hasReward = (serveritems != null && serveritems.Length > 0) || dungeonModel.specialItemCollectRecord.count > 0; m_ContainerReward.gameObject.SetActive(hasReward); m_RewardSorts.Clear(); if (serveritems != null) { m_RewardSorts.AddRange(serveritems); int _mapid = dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID); if (_mapid == 60010 || _mapid == 31130) { m_RewardSorts.Sort(CompareTrialItemIndex); } } m_RewardIndexs.Clear(); if (m_RewardTweens != null && m_RewardTweens.Length > 0) { for (int i = 0; i < m_RewardTweens.Length; i++) { m_RewardTweens[i].SetEndState(); } } if (m_RewardSorts.Count > 0) { var items = new List(); for (int i = 0; i < m_RewardSorts.Count; i++) { var serverItem = m_RewardSorts[i]; var itemInfo = new ItemInfo(); itemInfo.itemId = serverItem.ItemID; itemInfo.userData = serverItem.UserData; if (!merged && itemInfo.itemId == dungeonModel.specialItemCollectRecord.id) { itemInfo.count = serverItem.Count + dungeonModel.specialItemCollectRecord.count; merged = true; } else { itemInfo.count = serverItem.Count; } items.Add(new ItemModel(PackType.Item, itemInfo)); } for (int i = 0; i < passRewardBehaviours.Length; i++) { var behaviour = passRewardBehaviours[i]; if (i < items.Count) { behaviour.transform.parent.gameObject.SetActive(true); behaviour.gameObject.SetActive(false); behaviour.serverItem = m_RewardSorts[i]; behaviour.Init(items[i]); m_RewardIndexs.Add(m_SpecialItemCollect == null ? i : i + 1); } else { behaviour.transform.parent.gameObject.SetActive(false); behaviour.gameObject.SetActive(false); } } if (m_SpecialItemCollect != null) { if (!merged && dungeonModel.specialItemCollectRecord.count > 0) { m_SpecialItemCollect.transform.parent.gameObject.SetActive(true); m_SpecialItemCollect.gameObject.SetActive(false); m_SpecialItemCollect.SetItem(dungeonModel.specialItemCollectRecord); m_RewardIndexs.Insert(0, 0); } else { m_SpecialItemCollect.transform.parent.gameObject.SetActive(false); m_SpecialItemCollect.gameObject.SetActive(false); } } } if (m_RewardIndexs.Count > 0 && m_RewardTweens != null && m_RewardTweens.Length > 0) { PlayRewardTween(0); } } protected virtual void PlayRewardTween(int _playIndex) { if (_playIndex < m_RewardIndexs.Count) { var _index = m_RewardIndexs[_playIndex]; if (_index < m_RewardTweens.Length) { m_RewardTweens[_index].SetStartState(); m_RewardTweens[_index].gameObject.SetActive(true); m_RewardTweens[_index].Play(() => { _playIndex += 1; PlayRewardTween(_playIndex); }); } } } protected virtual void DrawPassGrade() { if (m_Grade != null) { var grade = dungeonModel.dungeonResult.grade; if (grade > 0) { m_GradeBottom.SetActive(true); switch (grade) { case 5: m_Grade.SetSprite("Remark_S"); m_Grade.SetNativeSize(); break; case 4: m_Grade.SetSprite("Remark_A"); m_Grade.SetNativeSize(); break; case 3: m_Grade.SetSprite("Remark_B"); m_Grade.SetNativeSize(); break; case 2: m_Grade.SetSprite("Remark_C"); m_Grade.SetNativeSize(); break; case 1: m_Grade.SetSprite("Remark_D"); m_Grade.SetNativeSize(); break; default: break; } m_Grade.SetNativeSize(); } else { m_GradeBottom.SetActive(false); } } } protected virtual void DrawNewRecord() { if (dungeonModel.dungeonResult.upPer > 0) { m_ContainerNewRecord.gameObject.SetActive(true); m_Record.text = Language.Get("FairyLand_Func26", dungeonModel.dungeonResult.upPer); } else { m_ContainerNewRecord.gameObject.SetActive(false); } } protected virtual void DrawKillMonster() { if (dungeonModel.dungeonResult.npcTotal > 0) { m_ContainerKillMonster.gameObject.SetActive(true); m_KillMonsterCnt.text = dungeonModel.dungeonResult.npcTotal.ToString(); } else { m_ContainerKillMonster.gameObject.SetActive(false); } } protected virtual void DrawGetExp(bool _force = false) { if (m_ContainerExp != null) { if (dungeonModel.dungeonResult.totalExp > 0 || _force) { m_ContainerExp.gameObject.SetActive(true); m_Experience.text = UIHelper.ReplaceLargeNum((ulong)dungeonModel.dungeonResult.totalExp); } else { m_ContainerExp.gameObject.SetActive(false); } } } protected virtual void DrawPassTime() { m_ContainerPassTime.gameObject.SetActive(dungeonModel.dungeonResult.costTime > 0); m_PassTime.text = StringUtility.Contact((int)(dungeonModel.dungeonResult.costTime * 0.001f), Language.Get("RealmWin_Bewrite_35")); } protected virtual void DrawGetXianYuanCoins() { var fbEndInfo = dungeonModel.dungeonResult; var results = fbEndInfo.xianyuanCoin; bool isShow = true; if (fbEndInfo.dataMapID == 51010) { if (m_ContainerXianyuanCoins == null) { isShow = false; } } else { if (m_ContainerXianyuanCoins == null || results == null || results.Length < 1) { isShow = false; } } m_ContainerXianyuanCoins.gameObject.SetActive(isShow); if (!isShow) return; int getCoins = 0; int reason = 0; if (results != null && results.Length > 1) { getCoins = results[0]; reason = results[1]; } if (getCoins > 0 && reason == 0) { m_XianyuanCoins.text = UIHelper.ReplaceLargeNum((ulong)getCoins); } else { switch (reason) { case 1: m_XianyuanCoins.text = UIHelper.AppendColor(TextColType.Red, Language.Get("DungeonAssist145")); break; case 2: m_XianyuanCoins.text = UIHelper.AppendColor(TextColType.Red, Language.Get("DungeonAssist144")); break; default: if (fbEndInfo.dataMapID == 51010) { if (fbEndInfo.startRewardLineID != 0) { m_XianyuanCoins.text = UIHelper.AppendColor(TextColType.Red, Language.Get("DungeonAssist146")); } } break; } } } protected virtual void DrawGetMoney() { if (m_ContainerMoney != null) { m_ContainerMoney.gameObject.SetActive(false); } if (m_ContainerMagicEssence != null) { m_ContainerMagicEssence.gameObject.SetActive(false); } if (m_ContainerEssence != null) { m_ContainerEssence.gameObject.SetActive(false); } if (dungeonModel.dungeonResult.money != null && dungeonModel.dungeonResult.money.Length > 0) { var dungeonMoney = dungeonModel.dungeonResult.money; for (int i = 0; i < dungeonMoney.Length; i++) { var money = dungeonMoney[i]; switch (money.moneyType) { case 3: if (m_ContainerMoney != null && money.moneyValue > 0) { m_ContainerMoney.gameObject.SetActive(true); m_Money.text = UIHelper.ReplaceLargeNum((ulong)money.moneyValue); } break; case 14: if (m_ContainerMagicEssence != null && money.moneyValue > 0) { m_ContainerMagicEssence.gameObject.SetActive(true); m_MagicEssence.text = UIHelper.ReplaceLargeNum((ulong)money.moneyValue); } break; case 23: if (m_ContainerEssence != null && money.moneyValue > 0) { m_ContainerEssence.gameObject.SetActive(true); m_Essence.text = UIHelper.ReplaceLargeNum((ulong)money.moneyValue); } break; } } } } protected virtual void DrawSP() { var mapId = dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID); if (dungeonModel.dungeonResult.sp > 0) { m_ContainerSP.gameObject.SetActive(true); m_SP.text = dungeonModel.dungeonResult.sp.ToString(); } else { m_ContainerSP.gameObject.SetActive(false); } } IEnumerator Co_DelayDisplay(float _delay) { yield return new WaitForSeconds(_delay); Display(); } protected virtual void RequireDungeonExit() { if (m_Exit != null) { m_Exit.gameObject.SetActive(true); } var endTime = dungeonModel.GetCoolDownEndTime(DungeonCoolDownType.LeaveMap); var seconds = (endTime - TimeUtility.ServerNow).TotalSeconds; timer = (float)seconds - (int)seconds; DrawExitTimer((int)seconds); } protected virtual void Display() { m_ContainerPoivt.gameObject.SetActive(true); RequireDungeonExit(); DrawPassTime(); DrawGetExp(); DrawGetMoney(); DrawItemRewards(); DrawPassGrade(); DrawSP(); DrawKillMonster(); DrawNewRecord(); DrawGetXianYuanCoins(); } protected int CompareTrialItemIndex(ServerItem x, ServerItem y) { var config_x = ItemConfig.Get(x.ItemID); var config_y = ItemConfig.Get(y.ItemID); bool equip_x = config_x.Type >= 101 && config_x.Type <= 109; bool equip_y = config_y.Type >= 101 && config_y.Type <= 109; if (equip_x.CompareTo(equip_y) != 0) { return equip_x.CompareTo(equip_y); } if (!equip_x && !equip_y) { bool type_13_x = config_x.Type == 13; bool type_13_y = config_y.Type == 13; if (type_13_x.CompareTo(type_13_y) != 0) { return -type_13_x.CompareTo(type_13_y); } if (config_x.ItemColor.CompareTo(config_y.ItemColor) != 0) { return -config_x.ItemColor.CompareTo(config_y.ItemColor); } return x.ItemID.CompareTo(y.ItemID); } else { bool type_108109_x = config_x.Type >= 108; bool type_108109_y = config_y.Type >= 108; if (type_108109_x || type_108109_y) { if (config_x.Type.CompareTo(config_y.Type) != 0) { return -config_x.Type.CompareTo(config_y.Type); } } if (config_x.ItemColor.CompareTo(config_y.ItemColor) != 0) { return -config_x.ItemColor.CompareTo(config_y.ItemColor); } if (config_x.StarLevel.CompareTo(config_y.StarLevel) != 0) { return -config_x.StarLevel.CompareTo(config_y.StarLevel); } if (config_x.LV.CompareTo(config_y.LV) != 0) { return -config_x.LV.CompareTo(config_y.LV); } return x.ItemID.CompareTo(y.ItemID); } } } }