//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Thursday, September 21, 2017 //-------------------------------------------------------- using vnxbqy.UI; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class TaskBoxBGMWin : Window { [SerializeField] Text _NpcName;//NPC名 [SerializeField] Text _TextTaskDescription;//对话内容 [SerializeField] Text _TextRewards;//按钮内容 [SerializeField] Button _BtnRewards;//领取奖励按钮 [SerializeField] Button _Close;//关闭按钮 [SerializeField] Transform _Grid;//动态创建节点 [SerializeField] Text _TextTaskName;//任务名称 [SerializeField] GameObject m_ImageReward; [SerializeField] Text m_AutomaticThreadTask_Text; private int _TaskId = 0;//获取任务ID private int _NpcID = 0;//获取NPCID private int _Gold = 0;//获取流动仙玉 private string StrConversa = null;//对话内容接收 Dictionary _AllMissionDict;//任务初始化接收字典 private List rewardList = new List(); TaskModel m_TaskModel; TaskModel taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel()); } } PackModel _playerPack; PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } VipModel m_Vipmodel; VipModel vipmodel { get { return m_Vipmodel ?? (m_Vipmodel = ModelCenter.Instance.GetModel()); } } TreasureModel m_treasureModel; TreasureModel treasureModel { get { return m_treasureModel ?? (m_treasureModel = ModelCenter.Instance.GetModel()); } } PlayerMainDate m_MainModel; PlayerMainDate mainModel { get { return m_MainModel ?? (m_MainModel = ModelCenter.Instance.GetModel()); } } private int FabaoId; private int AwaitSecond; private int AwaitSecondNext; private float LatencyTime = 0;//等待时间 #region Built-in protected override void BindController() { var config = FuncConfigConfig.Get("TaskContinue"); FabaoId = int.Parse(config.Numerical1); AwaitSecond = int.Parse(config.Numerical2); AwaitSecondNext = int.Parse(config.Numerical3); } protected override void AddListeners() { _BtnRewards.onClick.AddListener(BtnRewards); _Close.onClick.AddListener(Closee); } protected override void OnPreOpen() { LatencyTime = 0; _TextTaskDescription.text = ""; _Gold = (int)PlayerDatas.Instance.baseData.diamond; _BtnRewards.SetActive(false); _AllMissionDict = taskmodel.allMissionDict; _TaskId = taskmodel._TaskNow; _NpcID = taskmodel.NPCid; if (taskmodel.MainTaskDic.ContainsKey(_TaskId)) { m_AutomaticThreadTask_Text.SetActive(true); } else { m_AutomaticThreadTask_Text.SetActive(false); } StrConversa = null; StrConversa = taskmodel._conversation; TypeJudgment();//类型判断 ContentAssignment();//内容赋值 if (!taskmodel.MainTaskDic.ContainsKey(_TaskId)) { var npcConfig = NPCConfig.Get(_NpcID); if (npcConfig != null) { if (npcConfig.NPCSpeakID != 0) { SoundPlayer.Instance.PlayNpcAudio(npcConfig.NPCSpeakID); } } } } protected override void OnAfterOpen() { StartCoroutine("GetEnumerator");//自动任务 } protected override void OnPreClose() { if (PlayerDatas.Instance.hero.State != E_ActorState.AutoRun) { MapTransferUtility.Instance.Clear(); } StopCoroutine("GetEnumerator"); StopCoroutine("LateRelease"); } protected override void OnAfterClose() { } private void IsOpenMaininterface() { Close(); } #endregion IEnumerator GetEnumerator() { yield return WaitingForSecondConst.WaitMS1500; TheAutomaticTask(); yield break; } void TheAutomaticTask()//自动任务 { if (_AllMissionDict.ContainsKey(_TaskId)) { if (_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12) { if (!ModelCenter.Instance.GetModel().teamPrepare.isPreparing) { taskmodel.RequestGetTaskAward("OK", _TaskId); WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); } } } } void BtnRewards() { int blank = playerPack.GetEmptyGridCount(PackType.Item); if (blank < 1) { ServerTipDetails.DisplayNormalTip(Language.Get("BackpackReward_Z")); return; } if (!_AllMissionDict.ContainsKey(_TaskId)) { Closee(); return; } taskmodel.RequestGetTaskAward("OK", _TaskId); mainModel.IsSelfMotionTask = false; SelectionManager.Release(SelectionManager.E_Type.Green); StartCoroutine("LateRelease"); } IEnumerator LateRelease() { yield return WaitingForSecondConst.WaitMS500; WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); yield break; } void Closee() { C080A_tagCCancelEvent _C080A = new C080A_tagCCancelEvent(); GameNetSystem.Instance.SendInfo(_C080A); Close(); WindowCenter.Instance.Open(); SelectionManager.Release(SelectionManager.E_Type.Green); StopCoroutine("GetEnumerator"); StopCoroutine("LateRelease"); } void ContentAssignment()//内容赋值 { NPCConfig Npc = NPCConfig.Get(_NpcID); _NpcName.text = Npc.charName; var config = TASKINFOConfig.Get(_AllMissionDict[_TaskId].Name); if (config == null) { DebugEx.LogError("任务表格配置错误"); return; } _TextTaskName.text = config.show_writing; var taskInfoConfig = TASKINFOConfig.Get(StrConversa); if (taskInfoConfig == null) { taskInfoConfig = TASKINFOConfig.Get(StrConversa.ToLower()); if(taskInfoConfig == null) { DebugEx.LogError("任务表格配置错误"); return; } } if (taskmodel.BountyDic.ContainsKey(_TaskId) || taskmodel.FairyAuDic.ContainsKey(_TaskId)) { string _taskInfoKey = string.Format("d_{0}_0_1", _NpcID); if (TASKINFOConfig.Get(_taskInfoKey) == null) return; TASKINFOConfig DefaultDialogContent = TASKINFOConfig.Get(_taskInfoKey); _TextTaskDescription.text= DefaultDialogContent.show_writing; } else { _TextTaskDescription.text = taskInfoConfig.show_writing; } var rewardTaskInfoConfig = TASKINFOConfig.Get(_AllMissionDict[_TaskId].RewardList); if (rewardTaskInfoConfig == null) { DebugEx.LogError("任务表格配置错误"); return; } string _RewardStr = TaskAllocation.Instance.GetTaskInfo(rewardTaskInfoConfig.show_writing, _TaskId);//获取奖励信息 RewardAnalysis.Inst.GetReward(_RewardStr, ref rewardList); RewardInformationDisplay(rewardList); } void TypeJudgment()//类型判断 { _AllMissionDict = taskmodel.allMissionDict; if (_TaskId == 0 || !_AllMissionDict.ContainsKey(_TaskId)) { foreach (int key in _AllMissionDict.Keys) { if (_AllMissionDict[key].LightList.Equals(default(TsakLight))) { continue; } for (int i = 0; i < _AllMissionDict[key].LightList.Count; i++) { if (_AllMissionDict[key].LightList[i].NpcId == _NpcID) { _TaskId = key; } } if (_NpcID == _AllMissionDict[key].NPC_ID) { _TaskId = key; } //if (_NpcID == _AllMissionDict[key].LightList.NpcId) // _TaskId = key; //else if (_NpcID == _AllMissionDict[key].NPC_ID) // _TaskId = key; } } int _TaskType = 0; _TaskType = int.Parse(FuncConfigConfig.Get("MissionType").Numerical1); _BtnRewards.SetActive(true); if (_AllMissionDict[_TaskId].ColorLV == 2 && _AllMissionDict[_TaskId].MissionState == 1) { _TextRewards.text = Language.Get("EnterACopy_Z"); m_ImageReward.SetActive(true); } else if ((_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12) && _AllMissionDict[_TaskId].MissionState == 1) { _TextRewards.text = Language.Get("TaskBoxWin_BtnReward_Text_1"); m_ImageReward.SetActive(true); } else { _TextRewards.text = Language.Get("TaskBoxWin_BtnGetReward_Text_1"); m_ImageReward.SetActive(true); } if (_AllMissionDict[_TaskId].Type == 13 || _AllMissionDict[_TaskId].Type == 14) { _TextRewards.text = Language.Get("TaskBoxWin_BtnReward_Text_1"); m_ImageReward.SetActive(false); } } void RewardInformationDisplay(List rewardList)//奖励信息 { if (_Grid.childCount != 0) { for (int i = 0; i < _Grid.childCount; i++) { DestroyObject(_Grid.GetChild(i).gameObject); } } if (rewardList.Count == 0) return; if ((_AllMissionDict[_TaskId].Type == 7 || _AllMissionDict[_TaskId].Type == 12) && _AllMissionDict[_TaskId].MissionState == 1) return; for (int i = 0; i < rewardList.Count; i++) { GameObject go = GameObject.Instantiate(UILoader.LoadPrefab("ItemCell")); ItemCell itemcell = go.GetComponent(); go.transform.SetParent(_Grid); go.transform.localScale = Vector3.one; Vector3 pos = go.transform.localPosition; go.transform.localPosition = pos.SetZ(0); Button _button = go.transform.GetComponent