//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, October 16, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Text.RegularExpressions;
|
|
namespace vnxbqy.UI
|
{
|
|
public class XMZZMissionDetailsWin : Window
|
{
|
[SerializeField] MissionBar[] m_Missions;
|
|
[SerializeField] Transform m_ContainerHint;
|
[SerializeField] RichText m_Hint;
|
|
[SerializeField] Transform m_ContainerMainLineTask;
|
[SerializeField] Text m_MainLineTask;
|
|
[SerializeField] GameObject winIconObj;
|
|
DungeonModel m_Model;
|
DungeonModel model { get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<DungeonModel>()); } }
|
|
bool isInitHintBaseInfo = false;
|
|
int dungeonStep = -1;
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
dungeonStep = -1;
|
ShowMission();
|
UpdateMissions();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
model.updateMissionEvent += UpdateMissions;
|
}
|
|
protected override void OnPreClose()
|
{
|
model.updateMissionEvent -= UpdateMissions;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
private void ShowMission()
|
{
|
var mission = model.mission;
|
var dataMapId = model.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);
|
var hintId = model.GetDungeonHintId(dataMapId, mission.lineID);
|
var config = DungeonHintConfig.Get(hintId);
|
|
if (config != null)
|
{
|
m_ContainerMainLineTask.SetActive(true);
|
if (mission.missionID > 0)
|
{
|
var taskConfig = PyTaskConfig.Get(mission.missionID);
|
var taskShowConfig = TASKINFOConfig.Get(taskConfig.name);
|
m_MainLineTask.text = taskShowConfig.show_writing;
|
}
|
else
|
{
|
var dungeonId = model.GetDungeonId(dataMapId, mission.lineID);
|
var dungeonConfig = DungeonConfig.Get(dungeonId);
|
m_MainLineTask.text = dungeonConfig.FBName;
|
}
|
}
|
}
|
|
private void UpdateMissions()
|
{
|
var mission = model.mission;
|
var dateMapId = model.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);
|
var hintId = model.GetDungeonHintId(dateMapId, mission.lineID);
|
var config = DungeonHintConfig.Get(hintId);
|
|
if (mission.step != dungeonStep)
|
{
|
m_Hint.text = string.Empty;
|
try
|
{
|
if (config.Info.Length > 0)
|
{
|
m_Hint.text = config.Info[Mathf.Min(Mathf.Clamp(mission.step - 1, 0, int.MaxValue), config.Info.Length - 1)];
|
}
|
}
|
catch (Exception ex)
|
{
|
DebugEx.LogError(ex);
|
}
|
}
|
|
if (config != null)
|
{
|
for (int i = 0; i < 3; i++)
|
{
|
if (i < config.targetNum)
|
{
|
m_Missions[i].container.SetActive(true);
|
UpdateMissionContent(mission, i + 1, m_Missions[i]);
|
}
|
else
|
{
|
m_Missions[i].container.SetActive(false);
|
}
|
}
|
}
|
|
dungeonStep = mission.step;
|
}
|
|
private void UpdateMissionContent(DungeonMissionData _mission, int _targetIndex, MissionBar _missionBar)
|
{
|
var dateMapId = model.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);
|
var hintId = model.GetDungeonHintId(dateMapId, _mission.lineID);
|
var config = DungeonHintConfig.Get(hintId);
|
if (config == null)
|
{
|
return;
|
}
|
|
var targetInfo = GetTargetInfo(config, Mathf.Clamp(_mission.step - 1, 0, int.MaxValue), _targetIndex);
|
|
if (dungeonStep != _mission.step)
|
{
|
var configDescription = targetInfo.decription;
|
var npcId = targetInfo.npcId;
|
|
var match = Regex.Match(configDescription, "@.*@");
|
switch (match.Value)
|
{
|
case "@NPCName@":
|
try
|
{
|
var npcConfig = NPCConfig.Get(npcId);
|
configDescription = configDescription.Replace(match.Value, npcConfig.charName);
|
}
|
catch (Exception e)
|
{
|
DebugEx.LogErrorFormat("不存在该Npc {0}", npcId);
|
}
|
break;
|
}
|
|
_missionBar.title.text = configDescription;
|
}
|
|
var progress = 0L;
|
switch ((DungeonTargetType)targetInfo.type)
|
{
|
//case DungeonTargetType.NPC:
|
// if (_mission.npc != null)
|
// {
|
// for (int i = 0; i < _mission.npc.Length; i++)
|
// {
|
// var npcInfo = _mission.npc[i];
|
// if (_targetIndex == NPCBelongToTargetIndex(npcInfo.NPCID, config, Mathf.Clamp(_mission.step - 1, 0, int.MaxValue)))
|
// {
|
// progress = npcInfo.killCnt;
|
// break;
|
// }
|
// }
|
// }
|
// break;
|
//case DungeonTargetType.Exp:
|
// progress = _mission.totalExp;
|
// break;
|
//case DungeonTargetType.Score:
|
// progress = _mission.score;
|
// break;
|
//case DungeonTargetType.Money:
|
// progress = _mission.money[0].moneyValue;
|
// break;
|
//case DungeonTargetType.Wave:
|
// progress = _mission.wheel;
|
// break;
|
//case DungeonTargetType.NpcTotal:
|
// progress = _mission.npcTotal;
|
// break;
|
//case DungeonTargetType.Stage:
|
// progress = _mission.step;
|
// break;
|
//case DungeonTargetType.NPCDialogue:
|
// progress = _mission.talkOver;
|
// break;
|
case DungeonTargetType.VictorySumCnt:
|
progress = HeavenBattleInfo.Instance.WinCnt;
|
break;
|
case DungeonTargetType.StageVictoryCnt:
|
progress = _mission.winCnt;
|
if (progress < 1)
|
{
|
winIconObj.SetActive(false);
|
}
|
else
|
{
|
winIconObj.SetActive(true);
|
}
|
break;
|
|
}
|
|
if (targetInfo.targetValue == 0)
|
{
|
_missionBar.progress.text = StringUtility.Contact(UIHelper.ReplaceLargeNum(progress),
|
(DungeonTargetType)targetInfo.type == DungeonTargetType.Exp && _mission.isFullExp == 1 ? StringUtility.Contact(" ", Language.Get("FullExp")) : string.Empty);
|
}
|
else
|
{
|
_missionBar.progress.text = StringUtility.Contact(UIHelper.ReplaceLargeNum(progress), "/", targetInfo.targetValue);
|
}
|
}
|
|
private int NPCBelongToTargetIndex(int _npcId, DungeonHintConfig _config, int _step)
|
{
|
if (_config.targetType1 == 1 && _config.NPC1ID[Mathf.Min(_step, _config.NPC1ID.Length - 1)] == _npcId)
|
{
|
return 1;
|
}
|
|
if (_config.targetType2 == 1 && _config.NPC2ID[Mathf.Min(_step, _config.NPC2ID.Length - 1)] == _npcId)
|
{
|
return 2;
|
}
|
|
if (_config.targetType3 == 1 && _config.NPC3ID[Mathf.Min(_step, _config.NPC3ID.Length - 1)] == _npcId)
|
{
|
return 3;
|
}
|
|
return 0;
|
}
|
|
TargetInfo GetTargetInfo(DungeonHintConfig _config, int _step, int _index)
|
{
|
TargetInfo targetInfo;
|
switch (_index)
|
{
|
case 1:
|
targetInfo.type = _config.targetType1;
|
targetInfo.npcId = _config.NPC1ID.Length == 0 ? 0 : (_config.targetType1 == 1 || _config.targetType1 == 8 || _config.targetType1 == 6) ? _config.NPC1ID[Mathf.Min(_step, _config.NPC1ID.Length - 1)] : 0;
|
targetInfo.decription = _config.targetDescription1[Mathf.Min(_step, _config.targetDescription1.Length - 1)];
|
targetInfo.targetValue = _config.targetValue1[Mathf.Min(_step, _config.targetValue1.Length - 1)];
|
break;
|
case 2:
|
targetInfo.type = _config.targetType2;
|
targetInfo.npcId = _config.NPC2ID.Length == 0 ? 0 : (_config.targetType2 == 1 || _config.targetType2 == 8 || _config.targetType2 == 6) ? _config.NPC2ID[Mathf.Min(_step, _config.NPC2ID.Length - 1)] : 0;
|
targetInfo.decription = _config.targetDescription2[Mathf.Min(_step, _config.targetDescription2.Length - 1)];
|
targetInfo.targetValue = _config.targetValue2[Mathf.Min(_step, _config.targetValue2.Length - 1)];
|
break;
|
case 3:
|
targetInfo.type = _config.targetType3;
|
targetInfo.npcId = _config.NPC3ID.Length == 0 ? 0 : (_config.targetType3 == 1 || _config.targetType3 == 8 || _config.targetType3 == 6) ? _config.NPC3ID[Mathf.Min(_step, _config.NPC3ID.Length - 1)] : 0;
|
targetInfo.decription = _config.targetDescription3[Mathf.Min(_step, _config.targetDescription3.Length - 1)];
|
targetInfo.targetValue = _config.targetValue3[Mathf.Min(_step, _config.targetValue3.Length - 1)];
|
break;
|
default:
|
targetInfo = default(TargetInfo);
|
break;
|
}
|
|
return targetInfo;
|
}
|
|
struct TargetInfo
|
{
|
public int type;
|
public int npcId;
|
public string decription;
|
public int targetValue;
|
}
|
|
[System.Serializable]
|
public class MissionBar
|
{
|
public Transform container;
|
public Text title;
|
public Text progress;
|
}
|
|
}
|
|
}
|
|
|
|
|