//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, December 26, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using TableConfig;
|
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] List<int> MysteriousTaskID = new List<int>();//新添神秘任务
|
Dictionary<int, string> PlayerIcon = new Dictionary<int, string>();
|
private int storyMissionsID = 0;//剧情任务ID
|
private int taskCount = 0;//获取对话总条数
|
private int[] sPeaker;//对话对应半身像(0为主角/1为NPC)
|
private int nowTaskNum = 0;//获取当前的任务
|
private int typesPeaker = -1;
|
PlayerTaskDatas m_TaskModel;
|
PlayerTaskDatas taskmodel { get { return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<PlayerTaskDatas>()); } }
|
|
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 = Config.Instance.Get<FuncConfigConfig>("TaskContinue");
|
FabaoId = int.Parse(config.Numerical1);
|
AwaitSecond = int.Parse(config.Numerical2);
|
PlayerHead();
|
}
|
|
protected override void AddListeners()
|
{
|
m_MarkRay.AddListener(OnClickMarkRay);
|
m_SKIPButton.AddListener(OnClickSKIPButton);
|
}
|
|
protected override void OnPreOpen()
|
{
|
MainInterfaceWin.IsOpenMaininterface += IsOpenMaininterface;
|
IsCloseWindow();
|
typesPeaker = -1;
|
storyMissionsID = taskmodel._TaskNow;
|
var config = Config.Instance.Get<StoryMissionsConfig>(storyMissionsID);
|
if (config.TaskMusic != 0)
|
{
|
SoundPlayer.Instance.PlayNpcAudio(config.TaskMusic);
|
}
|
if (config == null)
|
{
|
return;
|
}
|
if (config.NpcID[0] == taskmodel.NPCid)
|
{
|
taskCount = config.TalkNum[0];
|
sPeaker = config.Speaker1;
|
IsMultistage = 0;
|
}
|
else
|
{
|
taskCount = config.TalkNum[0];
|
sPeaker = config.Speaker2;
|
IsMultistage = 1;
|
}
|
//taskCount = config.TalkNum;
|
//sPeaker = config.Speaker;
|
nowTaskNum = 0;
|
ShowDialogSelect(sPeaker[0], nowTaskNum);
|
}
|
|
private void IsCloseWindow()
|
{
|
if (WindowCenter.Instance.CheckOpen<DungeonFightWin>())
|
{
|
WindowCenter.Instance.CloseImmediately<DungeonFightWin>();
|
}
|
if (WindowCenter.Instance.CheckOpen<DungeonMissionDetailsWin>())
|
{
|
WindowCenter.Instance.CloseImmediately<DungeonMissionDetailsWin>();
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
Treasure treasure = null;
|
if (treasureModel.TryGetTreasure(FabaoId, out treasure))
|
{
|
if (treasure.state != TreasureState.Collecting && !NewBieCenter.Instance.inGuiding)
|
{
|
StartCoroutine("GetMainSelfMotion");
|
}
|
|
}
|
}
|
IEnumerator GetMainSelfMotion()
|
{
|
if (mainModel.IsSelfMotionTask)
|
{
|
yield return WaitingForSecondConst.WaitMS1500;
|
}
|
else
|
{
|
yield return new WaitForSeconds(AwaitSecond);
|
}
|
OnClickSKIPButton();
|
mainModel.IsSelfMotionTask = true;
|
yield break;
|
}
|
protected override void OnPreClose()
|
{
|
MainInterfaceWin.IsOpenMaininterface -= IsOpenMaininterface;
|
UI3DModelExhibition.Instance.StopShow();
|
StopCoroutine("GetMainSelfMotion");
|
}
|
|
private void IsOpenMaininterface()
|
{
|
Close();
|
}
|
|
protected override void OnAfterClose()
|
{
|
if (MysteriousTaskID.Contains(storyMissionsID))
|
{
|
mainModel.MysteriousTaskID = storyMissionsID;
|
CoroutineMgr.Instance.OnMysteriousTask();
|
}
|
bool _bool = IsDungeon();
|
if (_bool)
|
{
|
WindowCenter.Instance.Open<DungeonFightWin>();
|
}
|
if (!WindowCenter.Instance.CheckOpen<MainInterfaceWin>())
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
|
if (this is BossShowDialogueWin)
|
{
|
return;
|
}
|
|
if (!WindowCenter.Instance.CheckOpen<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(GeneralConfig.Instance.FarawayNpcDist, 2))
|
{
|
|
WindowCenter.Instance.Close<DialogueDuidanceWin>();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
|
_hero.LockTarget = null;
|
}
|
}
|
private void OnClickMarkRay()
|
{
|
var config = Config.Instance.Get<StoryMissionsConfig>(storyMissionsID);
|
if (config == null)
|
{
|
return;
|
}
|
nowTaskNum += 1;
|
if (taskCount - 1 >= nowTaskNum)//下一条
|
{
|
ShowDialogSelect(sPeaker[nowTaskNum], nowTaskNum);
|
}
|
if (taskCount - 1 < nowTaskNum)//最后一条
|
{
|
SessionEnd(TaskType.OK);
|
Close();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
bool _bool = IsDungeon();
|
if (_bool)
|
{
|
WindowCenter.Instance.Open<DungeonFightWin>();
|
}
|
}
|
|
|
}
|
private void OnClickSKIPButton()
|
{
|
var config = Config.Instance.Get<StoryMissionsConfig>(storyMissionsID);
|
if (config != null)
|
{
|
SessionEnd(TaskType.OK);
|
}
|
mainModel.IsSelfMotionTask = false;
|
Close();
|
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.BeginShowPlayer(m_playerIcon, playerJob, true);
|
|
m_PlayerNameText.text = PlayerDatas.Instance.baseData.PlayerName;
|
|
string platercContentKey = Config.Instance.Get<StoryMissionsConfig>(storyMissionsID).content[IsMultistage];
|
var config = Config.Instance.Get<TASKINFOConfig>(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 = Config.Instance.Get<StoryMissionsConfig>(storyMissionsID);
|
if (configStoryMissions == null)
|
{
|
return;
|
}
|
int npcId = configStoryMissions.NpcID[IsMultistage];
|
var npcConfig = Config.Instance.Get<NPCConfig>(npcId);
|
m_NPCNameText.text = npcConfig.charName;
|
string npcContentKey = configStoryMissions.content[IsMultistage];
|
var taskInfo = Config.Instance.Get<TASKINFOConfig>(string.Format(npcContentKey, stepNum));
|
if (taskInfo == null)
|
{
|
DebugEx.LogError("TASKINFOConfig中没有找到对应的Key");
|
}
|
else
|
{
|
m_ContentText_Npc.text = taskInfo.show_writing;
|
}
|
|
string npcIcon = configStoryMissions.NpcIcon[IsMultistage];
|
|
UI3DModelExhibition.Instance.BeginShowNPC(npcId, npcConfig.UIModeLOffset, npcConfig.UIModelRotation, m_NPCIcon, false, true);
|
}
|
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 void PlayerHead()
|
{
|
string[] headStr1 = Config.Instance.Get<FuncConfigConfig>("StoryTaskIcon").Numerical1.Split('|');
|
string[] headStr2 = Config.Instance.Get<FuncConfigConfig>("StoryTaskIcon").Numerical2.Split('|');
|
for (int i = 0; i < headStr1.Length; i++)
|
{
|
if (!PlayerIcon.ContainsKey(int.Parse(headStr1[i])))
|
{
|
PlayerIcon.Add(int.Parse(headStr1[i]), headStr2[i]);
|
|
}
|
}
|
}
|
|
private bool IsDungeon()
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
var mapConfig = Config.Instance.Get<MapConfig>(mapId);
|
return mapConfig != null && mapConfig.MapFBType != 0;
|
}
|
}
|
|
}
|
|
|
|
|