using System;
using Core.Language;
using Excel2Json;
using Fort23.Core;
using Fort23.UTool;
using Mono.Utility;
using UnityEngine;
using UnityEngine.UI;
namespace Fort23.Mono
{
public class DialogBox
{
///
/// 对话内容.
///
public Text Content;
public Text Text_Dialogue01;
public Text Text_Dialogue02;
public Text Text_Dialogue03;
// public BoxCollider boxCol;
public Transform MessageBG;
public Transform di;
public MyImage NpcIcon;
public MyImage HeroIcon;
private BetterList dialogTextList;
private int curIdx;
public Action onAction;
public UISpiritLoader UISpiritLoader;
public Text NpcNameText;
public void Init()
{
GuidePanel guidePanel = UIManager.Instance.GetComponent();
// guidePanel.DialogBoxState.gameObject.SetActive(true);
NpcIcon = guidePanel.Image_Npc;
HeroIcon = guidePanel.HeroIcon;
MessageBG = guidePanel.MessageBG;
UISpiritLoader = NpcIcon.transform.parent.GetComponent();
NpcNameText = guidePanel.Text_NpcName;
Text_Dialogue01 = guidePanel.Text_Dialogue01;
Text_Dialogue02 = guidePanel.Text_Dialogue02;
Text_Dialogue03 = guidePanel.Text_Dialogue03;
}
public void Open(BetterList list, Action action)
{
GuidePanel guidePanel = UIManager.Instance.GetComponent();
guidePanel.DialogBoxState.gameObject.SetActive(true);
if (list == null || list.size <= 0)
{
Close();
return;
}
if (action == null) Debug.Log("action == null");
onAction = action;
curIdx = 0;
dialogTextList = list;
OnClickScreen();
}
// private AssetHandle assetHandle;
///
///
///
///
/// 1:默认 2:剧情1 3:boss
public async CTask SetDiTex(PlayerGuideConfig playerGuideConfig, int id)
{
HeroModelConfig heroModelConfig = ConfigComponent.Instance.Get(id);
NpcIcon.gameObject.SetActive(false);
CTask cTask = CTask.Create();
NpcIcon.onSpriteAlter = () =>
{
NpcIcon.SetNativeSize();
NpcIcon.gameObject.SetActive(true);
cTask.SetResult();
};
// NpcIcon.icon_name = heroModelConfig.LiHuiName;
// HeroIcon.icon_name = heroModelConfig.HeroUIIconName;
if (playerGuideConfig.reversalBox == 1)
{
NpcIcon.transform.rotation = Quaternion.Euler(0, 180, 0);
}
else
{
NpcIcon.transform.rotation = Quaternion.Euler(0, 0, 0);
}
// NpcNameText.text = LanguageManager.Instance.Text(heroModelConfig.HeroNameID);
NpcIcon.enabled = true;
await cTask;
}
public void OnClickScreen()
{
// for (int i = 0; i < 100; i++)
// {
//
// }
if (dialogTextList == null)
{
return;
}
if (dialogTextList.size > curIdx)
{
Content.text = dialogTextList[curIdx++];
//最后一条
if (dialogTextList.size == curIdx)
{
if (PlayerGuideManager.Instance.guideConfig.forceText == 0)
{
// PlayerGuideManager.Instance.SetFingerVisiable(true);
PlayerGuideManager.Instance.CanDoNextCTask = CTask.Create();
onAction?.Invoke();
onAction = null;
PlayerGuideManager.Instance.CanDoNextCTask.SetResult();
}
}
}
else
{
PlayerGuideManager.Instance.CanDoNextCTask = CTask.Create();
onAction?.Invoke();
onAction = null;
PlayerGuideManager.Instance.CanDoNextCTask.SetResult();
}
}
public void Close()
{
PlayerGuideManager.Instance.CanDoNextCTask = CTask.Create();
onAction?.Invoke();
onAction = null;
PlayerGuideManager.Instance.CanDoNextCTask.SetResult();
}
public void ChangeState(int guideConfigSpeakerStyle)
{
switch (guideConfigSpeakerStyle)
{
case 1:
Content = Text_Dialogue01;
break;
case 2:
Content = Text_Dialogue02;
break;
case 3:
Content = Text_Dialogue03;
break;
}
}
}
}