ManaSocial.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using LitJson;
  7. using UnityEngine.EventSystems;
  8. public class ManaSocial : Regist
  9. {
  10. #region Variable
  11. public static int LastCommentIndex;
  12. public static int FirstCommentIndex;
  13. public static Text PraiseText;
  14. public static Button PraiseBtn;
  15. public static ScrollRectPlus ScrollRectPlus;
  16. public static bool IsPlayer;
  17. public static float PraiseTimer;
  18. public static List<List<string>> PlayerCommentDatas;
  19. public static List<List<string>> VisiteeCommentDatas;
  20. #endregion
  21. public void Update()
  22. {
  23. if (ManaVisit.InVisit)
  24. {
  25. return;
  26. }
  27. PraiseTimer += Time.deltaTime;
  28. if (PraiseTimer >= 10)
  29. {
  30. PraiseTimer = 0;
  31. PraiseText.text = ManaServer.PraiseAmt.ToString();
  32. ManaServer.GetComment(ManaServer.SerialNumber, "0", CommentType.Garden, data => { InputCommentData(true, data); });
  33. }
  34. }
  35. public override void RegistValueA()
  36. {
  37. PraiseText = ManaReso.Get<Text>("C_PraiseText");
  38. PraiseBtn = ManaReso.Get<Button>("C_Praise");
  39. ScrollRectPlus = ManaReso.Get<ScrollRectPlus>("Q_ScrollRect");
  40. ScrollRectPlus.onValueChanged.AddListener(OnScroll);
  41. }
  42. public static void Praise()
  43. {
  44. if (ManaVisit.InVisit)
  45. {
  46. PraiseText.text = (int.Parse(PraiseText.text) + 1).ToString();
  47. ManaServer.Praise(ManaServer.SerialNumber, ManaVisit.VisiteeSerialNumber);
  48. DisablePraise();
  49. }
  50. else
  51. {
  52. DisablePraise();
  53. }
  54. }
  55. public static void EnablePraise()
  56. {
  57. PraiseBtn.image.color = Color.white;
  58. PraiseBtn.interactable = true;
  59. }
  60. public static void DisablePraise()
  61. {
  62. PraiseBtn.image.color = Lib.Pink;
  63. PraiseBtn.interactable = false;
  64. }
  65. public static void InputCommentData(bool isPlayer, JsonData jsonData)
  66. {
  67. if (isPlayer)
  68. {
  69. PlayerCommentDatas = new List<List<string>>();
  70. foreach (JsonData commentData in jsonData["l"])
  71. {
  72. PlayerCommentDatas.Add(new List<string>() { commentData["s"].ToString(), commentData["c"].ToString() });
  73. }
  74. }
  75. else
  76. {
  77. VisiteeCommentDatas = new List<List<string>>();
  78. foreach (JsonData commentData in jsonData["l"])
  79. {
  80. VisiteeCommentDatas.Add(new List<string>() { commentData["s"].ToString(), commentData["c"].ToString() });
  81. }
  82. }
  83. }
  84. public static void InitializeCommentPanel(bool isPlayer)
  85. {
  86. for (int i = 0; i < ManaReso.Get("Q_Grid").childCount; i++)
  87. {
  88. ManaReso.Save(ManaReso.Get("Q_Grid").GetChild(i));
  89. }
  90. if (isPlayer)
  91. {
  92. IsPlayer = true;
  93. GetCommentItem(6, PlayerCommentDatas);
  94. }
  95. else
  96. {
  97. IsPlayer = false;
  98. GetCommentItem(6, VisiteeCommentDatas);
  99. }
  100. }
  101. public static void UpdateCommentPanel(int direction)
  102. {
  103. if (IsPlayer)
  104. {
  105. UpdateCommentItem(direction, PlayerCommentDatas);
  106. }
  107. else
  108. {
  109. UpdateCommentItem(direction, VisiteeCommentDatas);
  110. }
  111. }
  112. public static void GetCommentItem(int amt, List<List<string>> commentDatas)
  113. {
  114. if (commentDatas == null)
  115. {
  116. return;
  117. }
  118. for (int i = 0; i < amt; i++)
  119. {
  120. if (i < PlayerCommentDatas.Count)
  121. {
  122. FirstCommentIndex = 0;
  123. LastCommentIndex = i;
  124. ManaReso.GetCommentItem(PlayerCommentDatas[i][0], PlayerCommentDatas[i][1]);
  125. }
  126. }
  127. }
  128. public static void UpdateCommentItem(int direction, List<List<string>> commentDatas)
  129. {
  130. if (commentDatas.Count-1 == LastCommentIndex)
  131. {
  132. return;
  133. }
  134. LastCommentIndex += 1;
  135. ManaReso.Save(ManaReso.Get("Q_Grid").GetChild(0).gameObject);
  136. ManaReso.GetCommentItem(commentDatas[LastCommentIndex][0], commentDatas[LastCommentIndex][1]);
  137. ScrollRectPlus.AddContentOffset(new Vector2(0, -120));
  138. }
  139. static bool Lock;
  140. public static void OnScroll(Vector2 position)
  141. {
  142. if (Lock)
  143. {
  144. return;
  145. }
  146. if (position.y < 0.5f)
  147. {
  148. Lock = true;
  149. UpdateCommentPanel(1);
  150. }
  151. }
  152. public static void OpenCommentPanel()
  153. {
  154. ManaReso.Get("Q_CommentBK").TweenForCG();
  155. ManaReso.SetActive("Q_InputBK", ManaVisit.InVisit);
  156. if (ManaVisit.InVisit)
  157. {
  158. InitializeCommentPanel(false);
  159. }
  160. else
  161. {
  162. InitializeCommentPanel(true);
  163. }
  164. }
  165. public static void CloseCommentPanel()
  166. {
  167. ManaReso.Get("Q_CommentBK").TweenBacCG();
  168. }
  169. }