//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, April 23, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class NormalDialogueWin : Window
|
{
|
[SerializeField] Button m_Skip;
|
[SerializeField] Button m_EmptyAccepter;
|
|
[SerializeField] Transform m_ContainerNpc;
|
[SerializeField] RawImage m_RawNpc;
|
[SerializeField] Text m_NpcName;
|
[SerializeField] Text m_NpcDialogue;
|
[SerializeField] Transform m_NpcRewardContainer;
|
|
[SerializeField] Transform 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_Time;
|
|
int dialogueIndex = 0;
|
|
public static CustomDialogueInfo customDialogueInfo;
|
|
float timer = 0f;
|
float displayTimer = 0f;
|
|
public static event Action onDialogueComplete;
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_EmptyAccepter.AddListener(OnClickEmpty);
|
m_Skip.AddListener(OnSkip);
|
}
|
|
protected override void OnPreOpen()
|
{
|
dialogueIndex = 0;
|
|
timer = 0f;
|
|
DisplayDialogue();
|
DisplayTime();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
protected override void OnPreClose()
|
{
|
UI3DModelExhibition.Instance.StopShow();
|
}
|
|
protected override void OnAfterClose()
|
{
|
if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
|
protected override void LateUpdate()
|
{
|
timer += Time.deltaTime;
|
if (timer >= customDialogueInfo.autoSeconds)
|
{
|
OnClickEmpty();
|
}
|
|
displayTimer += Time.deltaTime;
|
if (displayTimer >= 0.5f)
|
{
|
displayTimer = 0f;
|
DisplayTime();
|
}
|
|
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))
|
{
|
_hero.LockTarget = null;
|
Close();
|
}
|
}
|
|
#endregion
|
|
private void DisplayDialogue()
|
{
|
timer = 0f;
|
DisplayTime();
|
|
if (customDialogueInfo.speakTypes == null || customDialogueInfo.dialogues == null)
|
{
|
return;
|
}
|
|
var speakType = customDialogueInfo.speakTypes[dialogueIndex];
|
|
m_ContainerNpc.SetActive(speakType == 0);
|
m_ContainerPlayer.SetActive(speakType == 1);
|
|
if (customDialogueInfo.musics != null && dialogueIndex < customDialogueInfo.musics.Length)
|
{
|
SoundPlayer.Instance.PlayNpcAudio(customDialogueInfo.musics[dialogueIndex]);
|
}
|
|
|
var displayReward = dialogueIndex == customDialogueInfo.dialogues.Length - 1 && customDialogueInfo.items != null;
|
m_ContainerReward.SetActive(displayReward);
|
|
if (displayReward)
|
{
|
m_ContainerReward.SetParent(speakType == 1 ? m_PlayerRewardContainer : m_NpcRewardContainer);
|
for (int i = 0; i < m_Items.Length; i++)
|
{
|
if (i < customDialogueInfo.items.Count)
|
{
|
m_Items[i].SetActive(true);
|
var itemId = customDialogueInfo.items[i].id;
|
ulong count = (ulong)customDialogueInfo.items[i].count;
|
var itemData = new ItemCellModel(itemId, true, count);
|
m_Items[i].Init(itemData);
|
m_Items[i].button.SetListener(() =>
|
{
|
ItemTipUtility.Show(itemId);
|
});
|
}
|
else
|
{
|
m_Items[i].SetActive(false);
|
}
|
}
|
}
|
|
|
switch (speakType)
|
{
|
case 1:
|
var job = PlayerDatas.Instance.baseData.Job;
|
UI3DModelExhibition.Instance.ShowPlayer(m_RawPlayer, job, true);
|
m_PlayerName.text = PlayerDatas.Instance.baseData.PlayerName;
|
m_PlayerDialogue.text = Language.Get(customDialogueInfo.dialogues[dialogueIndex]);
|
break;
|
case 0:
|
var npcConfig = NPCConfig.Get(customDialogueInfo.npcId);
|
m_NpcName.text = npcConfig.charName;
|
m_NpcDialogue.text = Language.Get(customDialogueInfo.dialogues[dialogueIndex]);
|
var data = new UI3DNPCExhibitionData()
|
{
|
npcId = customDialogueInfo.npcId,
|
isDialogue = true,
|
};
|
UI3DModelExhibition.Instance.ShowNPC(m_RawNpc, data);
|
break;
|
}
|
}
|
|
private void OnSkip()
|
{
|
Close();
|
if (onDialogueComplete != null)
|
{
|
onDialogueComplete();
|
}
|
}
|
|
private void DisplayTime()
|
{
|
var seconds = (int)(customDialogueInfo.autoSeconds - timer);
|
m_Time.text = Language.Get("TaskContinueCount", seconds);
|
}
|
|
private void OnClickEmpty()
|
{
|
if (customDialogueInfo.dialogues != null && dialogueIndex < customDialogueInfo.dialogues.Length - 1)
|
{
|
dialogueIndex += 1;
|
DisplayDialogue();
|
}
|
else
|
{
|
Close();
|
if (onDialogueComplete != null)
|
{
|
onDialogueComplete();
|
}
|
}
|
}
|
|
}
|
|
public struct CustomDialogueInfo
|
{
|
public int npcId;
|
public int[] speakTypes;
|
public string[] dialogues;
|
public int[] musics;
|
public int autoSeconds;
|
public List<Item> items;
|
}
|
}
|
|
|
|
|