//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, December 26, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
//剧情对话面板
|
namespace Snxxz.UI
|
{
|
|
public class DialogueDuidanceWin : Window
|
{
|
[SerializeField] GameObject m_ContainerNpc;
|
[SerializeField] RawImage m_RawNpc;
|
[SerializeField] Text m_NpcName;
|
[SerializeField] Text m_NpcDialogue;
|
[SerializeField] Transform m_NpcRewardContainer;
|
|
[SerializeField] GameObject m_ContainerPlayer;
|
[SerializeField] RawImage m_RawPlayer;
|
[SerializeField] Text m_PlayerName;
|
[SerializeField] Text m_PlayerDialogue;
|
[SerializeField] Transform m_PlayerRewardContainer;
|
|
[SerializeField] Transform m_ContainerReward;
|
[SerializeField] ItemCell[] m_Items;
|
|
[SerializeField] Text m_Remind;
|
|
[SerializeField] Button m_EmptyAccepter;
|
[SerializeField] Button m_Skip;
|
|
int taskIndex = 0;//获取当前的任务
|
float timer = 0f;
|
|
public static int storyMissionId = 0;
|
public static int taskId = 0;
|
|
static int autoContinueSeconds;
|
|
TaskModel model { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
|
PlayerMainDate mainModel { get { return ModelCenter.Instance.GetModel<PlayerMainDate>(); } }
|
|
#region Built-in
|
private enum TaskType
|
{
|
OK = 0,
|
FB = 1,
|
Double = 2,
|
}
|
protected override void BindController()
|
{
|
var config = FuncConfigConfig.Get("TaskContinue");
|
autoContinueSeconds = int.Parse(config.Numerical2);
|
}
|
|
protected override void AddListeners()
|
{
|
m_EmptyAccepter.AddListener(EmptyAccepter);
|
m_Skip.AddListener(OnSkip);
|
}
|
|
protected override void OnPreOpen()
|
{
|
timer = 0;
|
taskIndex = 0;
|
|
var config = StoryMissionsConfig.Get(storyMissionId);
|
if (config.TaskMusic != 0)
|
{
|
SoundPlayer.Instance.PlayNpcAudio(config.TaskMusic);
|
}
|
|
DisplayTimer();
|
VerifyCloseOtherWindow();
|
DisplayDialogue();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
UI3DModelExhibition.Instance.StopShow();
|
}
|
|
protected override void OnAfterClose()
|
{
|
if (MapUtility.IsDungeon(PlayerDatas.Instance.baseData.MapID))
|
{
|
WindowCenter.Instance.Open<DungeonFightWin>();
|
}
|
if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
|
protected override void LateUpdate()
|
{
|
if (WindowCenter.Instance.IsOpen("MainInterfaceWin"))
|
{
|
WindowCenter.Instance.Close<DialogueDuidanceWin>();
|
}
|
|
timer += Time.deltaTime;
|
if (timer >= autoContinueSeconds)
|
{
|
OnSkip();
|
mainModel.IsSelfMotionTask = true;
|
}
|
|
DisplayTimer();
|
|
if (this is BossShowDialogueWin)
|
{
|
return;
|
}
|
|
var hero = PlayerDatas.Instance.hero;
|
if (hero != null && hero.LockTarget != null)
|
{
|
var checkDistSqrt = MathUtility.DistanceSqrtXZ(hero.Pos, hero.LockTarget.Pos);
|
if (checkDistSqrt > Mathf.Pow(GeneralDefine.FarawayNpcDist, 2))
|
{
|
WindowCenter.Instance.Close<DialogueDuidanceWin>();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
hero.LockTarget = null;
|
}
|
}
|
}
|
|
private void VerifyCloseOtherWindow()
|
{
|
if (WindowCenter.Instance.IsOpen<DungeonFightWin>())
|
{
|
WindowCenter.Instance.Close<DungeonFightWin>();
|
}
|
if (WindowCenter.Instance.IsOpen<DungeonMissionDetailsWin>())
|
{
|
WindowCenter.Instance.Close<DungeonMissionDetailsWin>();
|
}
|
}
|
|
void DisplayTimer()
|
{
|
if (timer >= autoContinueSeconds)
|
{
|
m_Remind.text = string.Format(Language.Get("TaskContinueCount"), 0);
|
}
|
else
|
{
|
m_Remind.text = string.Format(Language.Get("TaskContinueCount"), autoContinueSeconds - (int)timer);
|
}
|
}
|
|
|
private void EmptyAccepter()
|
{
|
timer = 0;
|
var config = StoryMissionsConfig.Get(storyMissionId);
|
|
taskIndex += 1;
|
|
if (taskIndex >= config.Speaker1.Length)
|
{
|
SendCompleteTask(TaskType.OK);
|
CloseClick();
|
}
|
else
|
{
|
DisplayDialogue();
|
}
|
}
|
|
|
#endregion
|
private void OnSkip()
|
{
|
SendCompleteTask(TaskType.OK);
|
mainModel.IsSelfMotionTask = false;
|
CloseClick();
|
HeroAIRecorder.ClearRecord();
|
}
|
|
private void DisplayDialogue()
|
{
|
var config = StoryMissionsConfig.Get(storyMissionId);
|
|
timer = 0f;
|
DisplayTimer();
|
|
var talkType = config.Speaker1[taskIndex];
|
|
m_ContainerNpc.gameObject.SetActive(talkType == 1);
|
m_ContainerPlayer.gameObject.SetActive(talkType == 0);
|
|
var state = 0;
|
model.TryGetCustomTaskState(taskId, out state);
|
|
m_ContainerReward.gameObject.SetActive(false);
|
|
var displayReward = state == -5 && taskIndex == config.Speaker1.Length - 1;
|
if (displayReward)
|
{
|
List<RewardAnalysis.RewardInfo> rewardInfos = new List<RewardAnalysis.RewardInfo>();
|
if (model.allMissionDict.ContainsKey(taskId))
|
{
|
var taskInfoKey = model.allMissionDict[taskId].RewardList;
|
var taskInfoConfig = TASKINFOConfig.Get(taskInfoKey);
|
if (taskInfoConfig != null)
|
{
|
var rewardContent = TaskAllocation.Instance.GetTaskInfo(taskInfoConfig.show_writing, taskId);
|
RewardAnalysis.Inst.GetReward(rewardContent, ref rewardInfos);
|
}
|
}
|
|
displayReward = rewardInfos.Count > 0;
|
|
if (displayReward)
|
{
|
m_ContainerReward.gameObject.SetActive(true);
|
m_ContainerReward.SetParent(talkType == 0 ? m_PlayerRewardContainer : m_NpcRewardContainer);
|
for (int i = 0; i < m_Items.Length; i++)
|
{
|
if (i < rewardInfos.Count)
|
{
|
m_Items[i].gameObject.SetActive(true);
|
var itemId = rewardInfos[i].itemCfg.ID;
|
ulong count = (ulong)rewardInfos[i].num;
|
if (rewardInfos[i].expPoint != 0)
|
{
|
count += (ulong)rewardInfos[i].expPoint * 100000000;
|
}
|
var itemData = new ItemCellModel(itemId, true, count);
|
m_Items[i].Init(itemData);
|
m_Items[i].button.SetListener(() =>
|
{
|
ItemTipUtility.Show(itemId);
|
});
|
}
|
else
|
{
|
m_Items[i].gameObject.SetActive(false);
|
}
|
}
|
}
|
}
|
|
if (talkType == 0)
|
{
|
int playerJob = PlayerDatas.Instance.baseData.Job;
|
m_RawPlayer.gameObject.SetActive(true);
|
UI3DModelExhibition.Instance.ShowPlayer(m_RawPlayer, playerJob, true);
|
|
m_PlayerName.text = PlayerDatas.Instance.baseData.PlayerName;
|
|
var taskInfoKey = StoryMissionsConfig.Get(storyMissionId).content;
|
var taskInfoConfig = TASKINFOConfig.Get(string.Format(taskInfoKey, config.TalkNum[0] + taskIndex));
|
|
if (taskInfoConfig != null)
|
{
|
m_PlayerDialogue.text = taskInfoConfig.show_writing;
|
}
|
else
|
{
|
DebugEx.LogError("TaskInFo中没有这个Key。。" + string.Format(taskInfoKey, config.TalkNum[0] + taskIndex));
|
}
|
}
|
else if (talkType == 1)
|
{
|
int npcId = config.NpcID;
|
var npcConfig = NPCConfig.Get(npcId);
|
m_NpcName.text = npcConfig.charName;
|
|
var taskInfoKey = config.content;
|
var taskInfoConfig = TASKINFOConfig.Get(string.Format(taskInfoKey, config.TalkNum[0] + taskIndex));
|
if (taskInfoConfig == null)
|
{
|
DebugEx.LogError("TASKINFOConfig中没有找到对应的Key" + string.Format(taskInfoKey, config.TalkNum[0] + taskIndex));
|
}
|
else
|
{
|
m_NpcDialogue.text = taskInfoConfig.show_writing;
|
}
|
|
var data = new UI3DNPCExhibitionData()
|
{
|
npcId = npcId,
|
isDialogue = true,
|
};
|
|
m_RawNpc.gameObject.SetActive(true);
|
UI3DModelExhibition.Instance.ShowNPC(m_RawNpc, data);
|
}
|
}
|
|
private void SendCompleteTask(TaskType taskType)
|
{
|
switch (taskType)
|
{
|
case TaskType.OK:
|
case TaskType.FB:
|
model.RequestGetTaskAward("OK", taskId);
|
break;
|
}
|
}
|
}
|
}
|
|
|
|
|