ActivityVisitNpcView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. using UnityEngine;
  2. using FairyGUI;
  3. using System;
  4. using System.Collections.Generic;
  5. using UI.ActivityAfternoonTea;
  6. using UI.Task;
  7. using Assets.Game.HotUpdate.Data;
  8. using ET;
  9. namespace GFGGame
  10. {
  11. public class ActivityVisitNpcView : BaseWindow
  12. {
  13. private UI_ActivityVisitNPCUI _ui;
  14. private int npcId;
  15. private int activityId;
  16. private bool redDot = false;
  17. private bool canGetReward;
  18. private string _currentWords;
  19. private bool isNextChat = false;
  20. private int indexChat;
  21. private GTextField _wordTextField;
  22. TypingFadeEffectPro _typingEffect;
  23. public override void Dispose()
  24. {
  25. if (_ui != null)
  26. {
  27. _ui.Dispose();
  28. _ui = null;
  29. }
  30. _wordTextField = null;
  31. _typingEffect = null;
  32. base.Dispose();
  33. }
  34. protected override void Init()
  35. {
  36. base.Init();
  37. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. packageName = UI_ActivityVisitNPCUI.PACKAGE_NAME;
  42. _ui = UI_ActivityVisitNPCUI.Create();
  43. viewCom = _ui.target;
  44. isfullScreen = true;
  45. isReturnView = true;
  46. _ui.m_taskList.itemRenderer = RenderTaskList;
  47. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  48. _ui.m_nextChatBtn.onClick.Add(OnClickNextChat);
  49. _ui.m_taskIcon.target.onClick.Add(OnClickRewardTIps);
  50. }
  51. protected override void AddEventListener()
  52. {
  53. }
  54. protected override void RemoveEventListener()
  55. {
  56. EventAgent.RemoveEventListener(ConstMessage.NOTICE_BATCH_TASK_STATE_CHANGE, OnTasksChange);
  57. }
  58. protected override void OnShown()
  59. {
  60. base.OnShown();
  61. if (ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.NewYearVisit) == 0)
  62. {
  63. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  64. this.Hide();
  65. ViewManager.Show<ActivityTeaMainView>();
  66. return;
  67. }
  68. EventAgent.AddEventListener(ConstMessage.NOTICE_BATCH_TASK_STATE_CHANGE, OnTasksChange);
  69. npcId = (int)this.viewData;
  70. var taskCfgs = TaskDataManager.Instance.GetTaskCfgs(ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr);
  71. _ui.m_taskList.data = taskCfgs;
  72. _ui.m_npcIcon.url = ResPathUtil.GetNpcPicSPath(ActivityVisitCfgArray.Instance.dataArray[npcId].picRes);
  73. _ui.m_loaBg.url = ResPathUtil.GetSceneBgPath(ActivityVisitCfgArray.Instance.dataArray[npcId].bgRes);
  74. _ui.m_name.text = ActivityVisitCfgArray.Instance.dataArray[npcId].name;
  75. _ui.m_taskList.numItems = ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr.Length;
  76. redDot = true;
  77. for (int i = 0; i < taskCfgs.Count; i++)
  78. {
  79. var taskCfg = taskCfgs[i];
  80. if (TaskDataManager.Instance.GetTaskStateById(taskCfg.id) == 0)
  81. {
  82. redDot = false;
  83. }
  84. }
  85. GetRewardState();
  86. _ui.m_DialogText.m_txtName.text = ActivityVisitCfgArray.Instance.dataArray[npcId].name;
  87. _ui.m_DialogText.m_txtContent.text = "";
  88. _ui.m_DialogText.m_In.Play();
  89. _wordTextField = null;
  90. isNextChat = false;
  91. indexChat = 0;
  92. SetTypeWriting();
  93. }
  94. protected override void OnHide()
  95. {
  96. EventAgent.RemoveEventListener(ConstMessage.NOTICE_BATCH_TASK_STATE_CHANGE, OnTasksChange);
  97. base.OnHide();
  98. }
  99. private void OnClickBtnBack()
  100. {
  101. ViewManager.GoBackFrom(typeof(ActivityVisitNpcView).FullName);
  102. }
  103. private async void OnClickRewardTIps()
  104. {
  105. if (ActivityTeaDataManager.Instance.NpcInfoList[npcId].RewrdStatus == 1)
  106. {
  107. bool result = await ActivityTeaSProxy.ReqGetNPCVisitReward(activityId, npcId + 1);
  108. if (!result) return;
  109. bool res = await ActivityTeaSProxy.ReqGetNPCVisitInfo(activityId);
  110. if (!res) return;
  111. RedDotController.Instance.SetComRedDot(_ui.m_taskIcon.target, false);
  112. }
  113. else
  114. {
  115. ViewManager.Show<ReWardTipsView>(npcId);
  116. }
  117. }
  118. private void GetRewardState()
  119. {
  120. foreach (NpcVisitProto t in ActivityTeaDataManager.Instance.NpcInfoList)
  121. {
  122. if (t.NpcId == npcId + 1)
  123. {
  124. activityId = t.ActivityId;
  125. switch (t.RewrdStatus)
  126. {
  127. case 0:
  128. canGetReward = false;
  129. _ui.m_gotReward.visible = false;
  130. break;
  131. case 1:
  132. canGetReward = true;
  133. _ui.m_gotReward.visible = false;
  134. RedDotController.Instance.SetComRedDot(_ui.m_taskIcon.target, ActivityTeaDataManager.Instance.NpcInfoList[npcId].RewrdStatus == 1);
  135. break;
  136. case 2:
  137. canGetReward = false;
  138. _ui.m_gotReward.visible = true;
  139. break;
  140. default:
  141. break;
  142. }
  143. }
  144. }
  145. }
  146. private void RenderTaskList(int index, GObject obj)
  147. {
  148. UI_ActivityVIsitRewardItemUI item = UI_ActivityVIsitRewardItemUI.Proxy(obj);
  149. var tasks = (List<TaskCfg>)obj.parent.data;
  150. var taskCfg = tasks[index];
  151. item.m_c1.selectedIndex = TaskDataManager.Instance.GetTaskStateById(taskCfg.id);
  152. if (taskCfg.jumpId == "" && TaskDataManager.Instance.GetTaskStateById(taskCfg.id) == 0)
  153. {
  154. item.m_c2.selectedIndex = taskCfg.jumpId == "" ? 1 : 0;
  155. }
  156. else
  157. {
  158. item.m_c2.selectedIndex = 0;
  159. }
  160. item.m_txtDesc.text = TaskDataManager.Instance.GetTaskDesc(taskCfg.id);
  161. item.m_txtCount.text =
  162. $"{TaskDataManager.Instance.GetTaskProgressById(taskCfg.id)}/{taskCfg.GetTargetCount()}";
  163. if (item.m_GetRewardBt.target.data == null)
  164. {
  165. item.m_GetRewardBt.target.onClick.Add(OnBtnGetClick);
  166. }
  167. item.m_GetRewardBt.target.data = taskCfg.id;
  168. if (item.m_ComeBt.target.data == null)
  169. {
  170. item.m_ComeBt.target.onClick.Add(OnBtnGoClick);
  171. }
  172. item.m_ComeBt.target.data = taskCfg;
  173. if (item.m_listTaskReward.data == null)
  174. {
  175. item.m_listTaskReward.itemRenderer = ListTaskRewardItemRender;
  176. }
  177. item.m_listTaskReward.data = TaskDataManager.Instance.GetReward(taskCfg);
  178. item.m_listTaskReward.numItems = TaskDataManager.Instance.GetReward(taskCfg).Length;
  179. UI_ActivityVIsitRewardItemUI.ProxyEnd();
  180. }
  181. private async void OnBtnGetClick(EventContext context)
  182. {
  183. if (!(context.sender is GObject btnGet)) return;
  184. int id = (int)btnGet.data;
  185. var result = await TaskSProxy.GetTaskBonus(id);
  186. if (!result) return;
  187. bool res = await ActivityTeaSProxy.ReqGetNPCVisitInfo(activityId);
  188. if (!res) return;
  189. RedDotController.Instance.SetComRedDot(_ui.m_taskIcon.target, ActivityTeaDataManager.Instance.NpcInfoList[npcId].RewrdStatus == 1);
  190. _ui.m_taskList.numItems = ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr.Length;
  191. }
  192. private void OnBtnGoClick(EventContext context)
  193. {
  194. if (!(context.sender is GObject btnGo)) return;
  195. var taskCfg = (TaskCfg)btnGo.data;
  196. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(taskCfg.jumpId)) return;
  197. var param = new object[taskCfg.jumpParamArr.Length];
  198. for (var i = 0; i < taskCfg.jumpParamArr.Length; i++)
  199. {
  200. param[i] = taskCfg.jumpParamArr[i];
  201. }
  202. ViewManager.JumpToView(taskCfg.jumpId, param);
  203. }
  204. private void ListTaskRewardItemRender(int index, GObject obj)
  205. {
  206. var rewards = (int[][])obj.parent.data;
  207. UI_RewardItemUI item = UI_RewardItemUI.Proxy(obj);
  208. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(rewards[index][0]);
  209. item.m_rewardIcon.url = ResPathUtil.GetIconPath(itemCfg);
  210. item.m_rewardNum.text = rewards[index][1].ToString();
  211. if (item.target.data == null)
  212. {
  213. item.target.onClick.Add(OnClickVisitRewardItem);
  214. }
  215. item.target.data = itemCfg.id;
  216. UI_RewardItemUI.ProxyEnd();
  217. }
  218. private void OnClickVisitRewardItem(EventContext context)
  219. {
  220. if (!(context.sender is GObject btnVisit)) return;
  221. int itemID = (int)btnVisit.data;
  222. GoodsItemTipsController.ShowItemTips(itemID);
  223. }
  224. private void OnTasksChange(EventContext context)
  225. {
  226. _ui.m_taskList.numItems = ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr.Length;
  227. }
  228. private void SetTypeWriting()
  229. {
  230. int ind = Math.Min(indexChat, ActivityVisitCfgArray.Instance.dataArray[npcId].taskIdArr.Length - 1);
  231. _currentWords = ActivityVisitCfgArray.Instance.dataArray[npcId].chatArr[ind];
  232. _wordTextField = _ui.m_DialogText.m_txtContent;
  233. _typingEffect = new TypingFadeEffectPro(_wordTextField);
  234. _typingEffect.typeFinishedAction = ShowCurrentWords;
  235. _wordTextField.text = _currentWords;
  236. _typingEffect.SetSpeed(1.0f);
  237. _typingEffect.Start();
  238. }
  239. private void ShowCurrentWords()
  240. {
  241. StopTyping();
  242. _typingEffect?.Cancel();
  243. _wordTextField.text = _currentWords;
  244. isNextChat = true;
  245. indexChat++;
  246. }
  247. private void StopTyping()
  248. {
  249. _typingEffect.Cancel();
  250. }
  251. private void OnClickNextChat()
  252. {
  253. if(isNextChat)
  254. {
  255. isNextChat = false;
  256. if(indexChat == ActivityVisitCfgArray.Instance.dataArray[npcId].chatArr.Length)
  257. {
  258. indexChat = 0;
  259. }
  260. SetTypeWriting();
  261. }
  262. else
  263. {
  264. ShowCurrentWords();
  265. isNextChat = true;
  266. }
  267. }
  268. }
  269. }