|
@@ -0,0 +1,211 @@
|
|
|
+using UnityEngine;
|
|
|
+using FairyGUI;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UI.ActivityAfternoonTea;
|
|
|
+using UI.Task;
|
|
|
+
|
|
|
+namespace GFGGame
|
|
|
+{
|
|
|
+ public class ActivityVisitNpcView : BaseWindow
|
|
|
+ {
|
|
|
+ private UI_ActivityVisitNPCUI _ui;
|
|
|
+ private int npcId;
|
|
|
+ private string _currentWords;
|
|
|
+ private bool isNextChat = false;
|
|
|
+ private int indexChat;
|
|
|
+ private GTextField _wordTextField;
|
|
|
+ TypingFadeEffectPro _typingEffect;
|
|
|
+ public override void Dispose()
|
|
|
+ {
|
|
|
+ if (_ui != null)
|
|
|
+ {
|
|
|
+ _ui.Dispose();
|
|
|
+ _ui = null;
|
|
|
+ }
|
|
|
+ _wordTextField = null;
|
|
|
+ _typingEffect = null;
|
|
|
+ base.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void Init()
|
|
|
+ {
|
|
|
+ base.Init();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnInit()
|
|
|
+ {
|
|
|
+ base.OnInit();
|
|
|
+ packageName = UI_ActivityVisitNPCUI.PACKAGE_NAME;
|
|
|
+ _ui = UI_ActivityVisitNPCUI.Create();
|
|
|
+ viewCom = _ui.target;
|
|
|
+ isfullScreen = true;
|
|
|
+
|
|
|
+ _ui.m_taskList.itemRenderer = RenderTaskList;
|
|
|
+ _ui.m_btnBack.onClick.Add(OnClickBtnBack);
|
|
|
+ _ui.m_nextChatBtn.onClick.Add(OnClickNextChat);
|
|
|
+ _ui.m_taskIcon.onClick.Add(OnClickRewardTIps);
|
|
|
+ }
|
|
|
+ protected override void AddEventListener()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ protected override void RemoveEventListener()
|
|
|
+ {
|
|
|
+ EventAgent.RemoveEventListener(ConstMessage.NOTICE_BATCH_TASK_STATE_CHANGE, OnTasksChange);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnShown()
|
|
|
+ {
|
|
|
+ base.OnShown();
|
|
|
+ EventAgent.AddEventListener(ConstMessage.NOTICE_BATCH_TASK_STATE_CHANGE, OnTasksChange);
|
|
|
+
|
|
|
+ npcId = (int)this.viewData;
|
|
|
+
|
|
|
+ var taskCfgs = TaskDataManager.Instance.GetTaskCfgs(ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr);
|
|
|
+ _ui.m_taskList.data = taskCfgs;
|
|
|
+ _ui.m_npcIcon.url = ResPathUtil.GetNpcPicSPath(ActivityVisitCfgArray.Instance.dataArray[npcId].picRes);
|
|
|
+ _ui.m_loaBg.url = ResPathUtil.GetSceneBgPath(ActivityVisitCfgArray.Instance.dataArray[npcId].bgRes);
|
|
|
+ _ui.m_name.text = ActivityVisitCfgArray.Instance.dataArray[npcId].name;
|
|
|
+ _ui.m_taskList.numItems = ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr.Length;
|
|
|
+ _ui.m_DialogText.m_txtName.text = ActivityVisitCfgArray.Instance.dataArray[npcId].name;
|
|
|
+ _ui.m_DialogText.m_txtContent.text = "";
|
|
|
+ _ui.m_DialogText.m_In.Play();
|
|
|
+ _wordTextField = null;
|
|
|
+
|
|
|
+ isNextChat = false;
|
|
|
+ indexChat = 0;
|
|
|
+ SetTypeWriting();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnHide()
|
|
|
+ {
|
|
|
+ EventAgent.RemoveEventListener(ConstMessage.NOTICE_BATCH_TASK_STATE_CHANGE, OnTasksChange);
|
|
|
+ base.OnHide();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void OnClickBtnBack()
|
|
|
+ {
|
|
|
+ ViewManager.GoBackFrom(typeof(ActivityVisitNpcView).FullName);
|
|
|
+ }
|
|
|
+ private void OnClickRewardTIps()
|
|
|
+ {
|
|
|
+ ViewManager.Show<ReWardTipsView>(npcId);
|
|
|
+ }
|
|
|
+ private void RenderTaskList(int index, GObject obj)
|
|
|
+ {
|
|
|
+ UI_ActivityVIsitRewardItemUI item = UI_ActivityVIsitRewardItemUI.Proxy(obj);
|
|
|
+
|
|
|
+ var tasks = (List<TaskCfg>)obj.parent.data;
|
|
|
+ var taskCfg = tasks[index];
|
|
|
+ item.m_c1.selectedIndex = TaskDataManager.Instance.GetTaskStateById(taskCfg.id);
|
|
|
+ item.m_txtDesc.text = TaskDataManager.Instance.GetTaskDesc(taskCfg.id);
|
|
|
+ item.m_txtCount.text =
|
|
|
+ $"{TaskDataManager.Instance.GetTaskProgressById(taskCfg.id)}/{taskCfg.GetTargetCount()}";
|
|
|
+ if (item.m_GetRewardBt.data == null)
|
|
|
+ {
|
|
|
+ item.m_GetRewardBt.onClick.Add(OnBtnGetClick);
|
|
|
+ }
|
|
|
+ item.m_GetRewardBt.data = taskCfg.id;
|
|
|
+
|
|
|
+ if (item.m_ComeBt.data == null)
|
|
|
+ {
|
|
|
+ item.m_ComeBt.onClick.Add(OnBtnGoClick);
|
|
|
+ }
|
|
|
+ item.m_ComeBt.data = taskCfg;
|
|
|
+
|
|
|
+ if (item.m_listTaskReward.data == null)
|
|
|
+ {
|
|
|
+ item.m_listTaskReward.itemRenderer = ListTaskRewardItemRender;
|
|
|
+ }
|
|
|
+ item.m_listTaskReward.data = TaskDataManager.Instance.GetReward(taskCfg);
|
|
|
+ item.m_listTaskReward.numItems = TaskDataManager.Instance.GetReward(taskCfg).Length;
|
|
|
+
|
|
|
+ UI_ActivityVIsitRewardItemUI.ProxyEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void OnBtnGetClick(EventContext context)
|
|
|
+ {
|
|
|
+ if (!(context.sender is GObject btnGet)) return;
|
|
|
+ int id = (int)btnGet.data;
|
|
|
+ var result = await TaskSProxy.GetTaskBonus(id);
|
|
|
+ if (!result) return;
|
|
|
+ _ui.m_taskList.numItems = ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr.Length;
|
|
|
+ }
|
|
|
+ private void OnBtnGoClick(EventContext context)
|
|
|
+ {
|
|
|
+ if (!(context.sender is GObject btnGo)) return;
|
|
|
+ var taskCfg = (TaskCfg)btnGo.data;
|
|
|
+ if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(taskCfg.jumpId)) return;
|
|
|
+ var param = new object[taskCfg.jumpParamArr.Length];
|
|
|
+ for (var i = 0; i < taskCfg.jumpParamArr.Length; i++)
|
|
|
+ {
|
|
|
+ param[i] = taskCfg.jumpParamArr[i];
|
|
|
+ }
|
|
|
+ ViewManager.JumpToView(taskCfg.jumpId, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void ListTaskRewardItemRender(int index, GObject obj)
|
|
|
+ {
|
|
|
+ var rewards = (int[][])obj.parent.data;
|
|
|
+ UI_RewardItemUI item = UI_RewardItemUI.Proxy(obj);
|
|
|
+ ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(rewards[index][0]);
|
|
|
+ item.m_rewardIcon.url = ResPathUtil.GetIconPath(itemCfg);
|
|
|
+ item.m_rewardNum.text = rewards[index][1].ToString();
|
|
|
+ UI_RewardItemUI.ProxyEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnTasksChange(EventContext context)
|
|
|
+ {
|
|
|
+ _ui.m_taskList.numItems = ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr.Length;
|
|
|
+ }
|
|
|
+ private void SetTypeWriting()
|
|
|
+ {
|
|
|
+ int ind = Math.Min(indexChat, ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr.Length - 1);
|
|
|
+ _currentWords = ActivityVisitCfgArray.Instance.dataArray[npcId].chatArr[ind];
|
|
|
+
|
|
|
+ _wordTextField = _ui.m_DialogText.m_txtContent;
|
|
|
+ _typingEffect = new TypingFadeEffectPro(_wordTextField);
|
|
|
+ _typingEffect.typeFinishedAction = ShowCurrentWords;
|
|
|
+
|
|
|
+ _wordTextField.text = _currentWords;
|
|
|
+
|
|
|
+ _typingEffect.SetSpeed(1.0f);
|
|
|
+ _typingEffect.Start();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowCurrentWords()
|
|
|
+ {
|
|
|
+ StopTyping();
|
|
|
+ _typingEffect?.Cancel();
|
|
|
+ _wordTextField.text = _currentWords;
|
|
|
+ isNextChat = true;
|
|
|
+ indexChat++;
|
|
|
+ }
|
|
|
+ private void StopTyping()
|
|
|
+ {
|
|
|
+ _typingEffect.Cancel();
|
|
|
+ }
|
|
|
+ private void OnClickNextChat()
|
|
|
+ {
|
|
|
+ if(isNextChat)
|
|
|
+ {
|
|
|
+ isNextChat = false;
|
|
|
+ if(indexChat == ActivityVisitCfgArray.Instance.dataArray[npcId].chatArr.Length)
|
|
|
+ {
|
|
|
+ ViewManager.GoBackFrom(typeof(ActivityVisitNpcView).FullName);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SetTypeWriting();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ShowCurrentWords();
|
|
|
+ isNextChat = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|