FashionShowCommentPanel.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class FashionShowCommentPanel : Regist
  6. {
  7. #region Config
  8. private static Text NicknameTitle;
  9. private static Text ContentTitle;
  10. private static Text Title;
  11. private static Text CloseButtonText;
  12. private static Text SendCommentButtonText;
  13. private static Text Placeholder;
  14. private static Button CloseButton;
  15. private static Button SendCommentButton;
  16. private static Transform Mask;
  17. private static InputField commentInputField;
  18. private static VirtualScrollRectPlus VirtualScrollRectPlus;
  19. private static int currentCommentPage;
  20. private static int currentCommentIndex;
  21. private static bool requesting;
  22. private static ShowCommentsHttp commentDataHttp;
  23. private static GetFashionShowData showData;
  24. private static List<ShowCommentData> commentDatas = new List<ShowCommentData>();
  25. private static List<ShowComment> commentItems = new List<ShowComment>();
  26. #endregion
  27. public override void RegistReference()
  28. {
  29. base.RegistReference();
  30. NicknameTitle = ResourceManager.Get<Text>(CanvasLabel.Ph_NicknameTitle);
  31. ContentTitle = ResourceManager.Get<Text>(CanvasLabel.Ph_ContentTitle);
  32. Title = ResourceManager.Get<Text>(CanvasLabel.Ph_Title);
  33. CloseButtonText = ResourceManager.Get<Text>(CanvasLabel.Ph_CloseButtonText);
  34. SendCommentButtonText = ResourceManager.Get<Text>(CanvasLabel.Ph_SendCommentButtonText);
  35. Placeholder = ResourceManager.Get<Text>(CanvasLabel.Ph_Placeholder);
  36. CloseButton = ResourceManager.Get<Button>(CanvasLabel.Ph_CloseButton);
  37. SendCommentButton = ResourceManager.Get<Button>(CanvasLabel.Ph_SendCommentButton);
  38. Mask = ResourceManager.Get(CanvasLabel.Ph_CommentMask);
  39. commentInputField = ResourceManager.Get<InputField>(CanvasLabel.Ph_InputField);
  40. VirtualScrollRectPlus = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Ph_ScrollRect);
  41. LanguageManager.Add(Title, new MulLanStr(LanguageLabel.UI__Ph_Tit));
  42. LanguageManager.Add(NicknameTitle, new MulLanStr(LanguageLabel.UI__Ph_NicknameTitle));
  43. LanguageManager.Add(ContentTitle, new MulLanStr(LanguageLabel.UI__Ph_ContentTitle));
  44. LanguageManager.Add(CloseButtonText, new MulLanStr(LanguageLabel.UI__Ph_CloseLab));
  45. LanguageManager.Add(SendCommentButtonText, new MulLanStr(LanguageLabel.UI__Ph_CommentLab));
  46. LanguageManager.Add(Placeholder, new MulLanStr(LanguageLabel.UI__Ph_Placeholder));
  47. Mask.CreateTweenCG(0, 1, 0.25f, false, true, Curve.EaseOutQuad);
  48. VirtualScrollRectPlus.Init(1, 1000000);
  49. VirtualScrollRectPlus.OnGetNextItem += OnGetNextItem;
  50. CloseButton.onClick.AddListener(OnCloseButtonClick);
  51. SendCommentButton.onClick.AddListener(OnSendCommentButtonClick);
  52. }
  53. public static void ShowPanel(GetFashionShowData data)
  54. {
  55. ResetPanel(data);
  56. Mask.TweenForCG();
  57. }
  58. private static void ResetPanel(GetFashionShowData data)
  59. {
  60. showData = data;
  61. requesting = false;
  62. currentCommentPage = 0;
  63. currentCommentIndex = 0;
  64. commentDatas = new List<ShowCommentData>();
  65. foreach (var commentItem in commentItems)
  66. {
  67. DestroyImmediate(commentItem.gameObject);
  68. }
  69. commentItems = new List<ShowComment>();
  70. commentInputField.text = "";
  71. OnGetNextItem(0);
  72. }
  73. public static void HidePanel()
  74. {
  75. Mask.TweenBacCG();
  76. }
  77. private static void OnCloseButtonClick()
  78. {
  79. if (commentDataHttp != null)
  80. {
  81. commentDataHttp.disable = true;
  82. }
  83. AudioManager.PlayClip(ResourceLabel.CloseClip);
  84. HidePanel();
  85. }
  86. private static VirtualScrollRectItem OnGetNextItem(int index)
  87. {
  88. if (commentDatas.Count > currentCommentIndex)
  89. {
  90. ShowCommentData data = commentDatas[currentCommentIndex];
  91. ShowComment item = ResourceManager.GetShowComment(data);
  92. commentItems.Add(item);
  93. currentCommentIndex++;
  94. return null;
  95. }
  96. else
  97. {
  98. GetCommentData();
  99. return null;
  100. }
  101. }
  102. private static void OnSendCommentButtonClick()
  103. {
  104. AudioManager.PlayClip(ResourceLabel.BtnClip);
  105. SendComment();
  106. }
  107. private static void SendComment()
  108. {
  109. string comment = commentInputField.text;
  110. if (StringFilter.ContainSensitiveWord(comment))
  111. {
  112. Bubble.Show(null, Language.GetStr(LanguageLabel.Common__ContainSensitiveWord));
  113. return;
  114. }
  115. SendCommentButton.interactable = false;
  116. long playerId = HttpManager.GetPlayerId();
  117. CommentShowHttp.Comment(playerId, showData.showId, comment,
  118. OnSendCommentSuccees, OnSendCommentFail);
  119. }
  120. private static void OnSendCommentSuccees()
  121. {
  122. commentInputField.text = "";
  123. SendCommentButton.interactable = true;
  124. ResetPanel(showData);
  125. }
  126. private static void OnSendCommentFail()
  127. {
  128. SendCommentButton.interactable = true;
  129. }
  130. private static void GetCommentData()
  131. {
  132. if (requesting)
  133. {
  134. return;
  135. }
  136. requesting = true;
  137. commentDataHttp = ShowCommentsHttp.Get(currentCommentPage, showData.showId,
  138. OnGetCommentDataSuccess, OnGetCommentDataFail);
  139. }
  140. private static void OnGetCommentDataSuccess(object obj)
  141. {
  142. requesting = false;
  143. currentCommentPage++;
  144. List<ShowCommentData> datas = (List<ShowCommentData>) obj;
  145. foreach (var data in datas)
  146. {
  147. commentDatas.AddUnique(data, (data0, data1) => data0.id == data1.id);
  148. }
  149. if (commentItems.Count == 0)
  150. {
  151. OnGetNextItem(0);
  152. OnGetNextItem(0);
  153. OnGetNextItem(0);
  154. OnGetNextItem(0);
  155. OnGetNextItem(0);
  156. }
  157. }
  158. private static void OnGetCommentDataFail()
  159. {
  160. requesting = false;
  161. }
  162. }