//--------------------------------------------------------
|
// [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] Button m_MarkRay;
|
[SerializeField] Button m_SKIPButton;
|
|
[SerializeField] GameObject m_BaseboardImageNPC;
|
[SerializeField] RawImage m_NPCIcon;
|
[SerializeField] Text m_NPCNameText;
|
[SerializeField] Text m_ContentText_Npc;
|
|
[SerializeField] GameObject m_BaseboardImagePlayer;
|
[SerializeField] RawImage m_playerIcon;
|
[SerializeField] Text m_PlayerNameText;
|
[SerializeField] Text m_ContentText;
|
|
[SerializeField] Text m_NextText;
|
|
int[] sPeaker;//对话对应半身像(0为主角/1为NPC)
|
int taskIndex = 0;//获取当前的任务
|
int typesPeaker = -1;
|
|
public static int storyMissionId = 0;
|
|
private float timeType = 0f;
|
TaskModel m_TaskModel;
|
TaskModel taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<TaskModel>()); } }
|
|
TreasureModel m_treasureModel;
|
TreasureModel treasureModel { get { return m_treasureModel ?? (m_treasureModel = ModelCenter.Instance.GetModel<TreasureModel>()); } }
|
|
PlayerMainDate m_MainModel;
|
PlayerMainDate mainModel { get { return m_MainModel ?? (m_MainModel = ModelCenter.Instance.GetModel<PlayerMainDate>()); } }
|
private int IsMultistage = 0;//是否有多段对话0,没有1,有
|
private int FabaoId;
|
private int AwaitSecond;
|
#region Built-in
|
private enum TaskType
|
{
|
OK = 0,
|
FB = 1,
|
Double = 2,
|
}
|
protected override void BindController()
|
{
|
var config = FuncConfigConfig.Get("TaskContinue");
|
FabaoId = int.Parse(config.Numerical1);
|
AwaitSecond = int.Parse(config.Numerical2);
|
}
|
|
protected override void AddListeners()
|
{
|
m_MarkRay.AddListener(OnClickMarkRay);
|
m_SKIPButton.AddListener(OnClickSKIPButton);
|
}
|
|
protected override void OnPreOpen()
|
{
|
MainInterfaceWin.IsOpenMaininterface += IsOpenMaininterface;
|
timeType = 0;
|
m_NextText.text = string.Format(Language.Get("TaskContinueCount"), AwaitSecond);
|
IsCloseWindow();
|
typesPeaker = -1;
|
var config = StoryMissionsConfig.Get(storyMissionId);
|
if (config.TaskMusic != 0)
|
{
|
SoundPlayer.Instance.PlayNpcAudio(config.TaskMusic);
|
}
|
if (config == null)
|
{
|
return;
|
}
|
|
sPeaker = config.Speaker1;
|
|
taskIndex = config.TalkNum[0];
|
ShowDialogSelect(sPeaker[0], taskIndex);
|
}
|
|
private void IsCloseWindow()
|
{
|
if (WindowCenter.Instance.IsOpen<DungeonFightWin>())
|
{
|
WindowCenter.Instance.Close<DungeonFightWin>();
|
}
|
if (WindowCenter.Instance.IsOpen<DungeonMissionDetailsWin>())
|
{
|
WindowCenter.Instance.Close<DungeonMissionDetailsWin>();
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
protected override void OnPreClose()
|
{
|
MainInterfaceWin.IsOpenMaininterface -= IsOpenMaininterface;
|
UI3DModelExhibition.Instance.StopShow();
|
}
|
|
private void IsOpenMaininterface()
|
{
|
Close();
|
}
|
|
protected override void OnAfterClose()
|
{
|
bool _bool = IsDungeon();
|
if (_bool)
|
{
|
WindowCenter.Instance.Open<DungeonFightWin>();
|
}
|
if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
protected override void LateUpdate()
|
{
|
timeType += Time.deltaTime;
|
if (timeType >= AwaitSecond)
|
{
|
m_NextText.text = string.Format(Language.Get("TaskContinueCount"), 0);
|
OnClickSKIPButton();
|
mainModel.IsSelfMotionTask = true;
|
}
|
else
|
{
|
m_NextText.text= string.Format(Language.Get("TaskContinueCount"), AwaitSecond - (int)timeType);
|
}
|
|
if (this is BossShowDialogueWin)
|
{
|
return;
|
}
|
|
if (!WindowCenter.Instance.IsOpen<DialogueDuidanceWin>())
|
{
|
return;
|
}
|
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
if (_hero == null)
|
{
|
return;
|
}
|
|
if (_hero.LockTarget == null)
|
{
|
return;
|
}
|
|
float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, _hero.LockTarget.Pos);
|
if (_chkDistSqrt > Mathf.Pow(GeneralDefine.FarawayNpcDist, 2))
|
{
|
|
WindowCenter.Instance.Close<DialogueDuidanceWin>();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
|
_hero.LockTarget = null;
|
}
|
}
|
private void OnClickMarkRay()
|
{
|
timeType = 0;
|
var config = StoryMissionsConfig.Get(storyMissionId);
|
if (config == null)
|
{
|
return;
|
}
|
|
taskIndex += 1;
|
var end = config.TalkNum.Length > 1 ? config.TalkNum[1] : config.TalkNum[0];
|
|
if (taskIndex <= end)//下一条
|
{
|
ShowDialogSelect(sPeaker[taskIndex], taskIndex);
|
}
|
else//最后一条
|
{
|
SessionEnd(TaskType.OK);
|
Close();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
bool _bool = IsDungeon();
|
if (_bool)
|
{
|
WindowCenter.Instance.Open<DungeonFightWin>();
|
}
|
}
|
|
|
}
|
private void OnClickSKIPButton()
|
{
|
var config = StoryMissionsConfig.Get(storyMissionId);
|
if (config != null)
|
{
|
SessionEnd(TaskType.OK);
|
}
|
mainModel.IsSelfMotionTask = false;
|
Close();
|
HeroAIRecorder.ClearRecord();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
#endregion
|
private void ShowDialogSelect(int type, int stepNum)
|
{
|
|
if (type == 0)
|
{
|
if (typesPeaker != type)
|
{
|
m_BaseboardImageNPC.SetActive(false);
|
m_BaseboardImagePlayer.SetActive(true);
|
}
|
|
int playerJob = PlayerDatas.Instance.baseData.Job;
|
|
UI3DModelExhibition.Instance.ShowPlayer(m_playerIcon, playerJob, true);
|
|
m_PlayerNameText.text = PlayerDatas.Instance.baseData.PlayerName;
|
|
string platercContentKey = StoryMissionsConfig.Get(storyMissionId).content;
|
var config = TASKINFOConfig.Get(string.Format(platercContentKey, stepNum));
|
if (config != null)
|
{
|
m_ContentText.text = config.show_writing;
|
}
|
else
|
{
|
DebugEx.LogError("TaskInFo中没有这个Key。。" + string.Format(platercContentKey, stepNum));
|
}
|
|
}
|
if (type == 1)
|
{
|
if (typesPeaker != type)
|
{
|
m_BaseboardImageNPC.SetActive(true);
|
m_BaseboardImagePlayer.SetActive(false);
|
}
|
var configStoryMissions = StoryMissionsConfig.Get(storyMissionId);
|
if (configStoryMissions == null)
|
{
|
return;
|
}
|
int npcId = configStoryMissions.NpcID;
|
var npcConfig = NPCConfig.Get(npcId);
|
m_NPCNameText.text = npcConfig.charName;
|
string npcContentKey = configStoryMissions.content;
|
var taskInfo = TASKINFOConfig.Get(string.Format(npcContentKey, stepNum));
|
if (taskInfo == null)
|
{
|
DebugEx.LogError("TASKINFOConfig中没有找到对应的Key");
|
}
|
else
|
{
|
m_ContentText_Npc.text = taskInfo.show_writing;
|
}
|
|
var data = new UI3DNPCExhibitionData()
|
{
|
npcId = npcId,
|
isDialogue = true,
|
};
|
UI3DModelExhibition.Instance.ShowNPC(m_NPCIcon,data);
|
}
|
typesPeaker = type;
|
}
|
|
private void SessionEnd(TaskType taskType)
|
{
|
switch (taskType)
|
{
|
case TaskType.OK:
|
case TaskType.FB:
|
taskmodel.RequestGetTaskAward("OK");
|
break;
|
case TaskType.Double:
|
taskmodel.RequestGetTaskAward("Double");
|
break;
|
default:
|
break;
|
}
|
}
|
|
private bool IsDungeon()
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
var mapConfig = MapConfig.Get(mapId);
|
return mapConfig != null && mapConfig.MapFBType != 0;
|
}
|
}
|
|
}
|
|
|
|
|