CommentItem.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using LitJson;
  7. using Random = UnityEngine.Random;
  8. public class CommentData
  9. {
  10. public string SerialNumber;
  11. public string Content;
  12. public string NickName;
  13. public CommentData(JsonData jsonData)
  14. {
  15. SerialNumber = jsonData["s"].ToString();
  16. Content = jsonData["c"].ToString();
  17. NickName = jsonData["n"].ToString();
  18. }
  19. public static bool operator ==(CommentData r1, CommentData r2)
  20. {
  21. if ((r1.SerialNumber == r2.SerialNumber) && (r1.Content == r2.Content) && (r1.NickName == r2.NickName))
  22. {
  23. return true;
  24. }
  25. else
  26. {
  27. return false;
  28. }
  29. }
  30. public static bool operator !=(CommentData r1, CommentData r2)
  31. {
  32. return !(r1 == r2);
  33. }
  34. public override bool Equals(object obj)
  35. {
  36. return this == (CommentData)obj;
  37. }
  38. public override int GetHashCode()
  39. {
  40. return SerialNumber.GetHashCode() + Content.GetHashCode() + NickName.GetHashCode();
  41. }
  42. }
  43. public class CommentItem : Regist
  44. {
  45. #region Config
  46. public Text Tit;
  47. public Text VisitLab;
  48. public Button VisitBtn;
  49. public BestfitText ContentLab;
  50. public string Content;
  51. public string SerialNumber;
  52. #endregion
  53. public override bool InitAtOnce()
  54. {
  55. if (base.InitAtOnce())
  56. {
  57. return true;
  58. }
  59. Dictionary<string, Transform> childDic = new Dictionary<string, Transform>();
  60. Auxiliary.CompileDic(transform, childDic);
  61. Tit = childDic["Tit"].GetComponent<Text>();
  62. VisitLab = childDic["VisitLab"].GetComponent<Text>();
  63. VisitBtn = childDic["VisitBtn"].GetComponent<Button>();
  64. ContentLab = childDic["ContentLab"].GetComponent<BestfitText>();
  65. ContentLab.VerticalMaxSize = 20;
  66. VisitLab.text = ResourceManager.Get<Text>(ObjectLabel.C_CostLab).text;
  67. VisitBtn.onClick.AddListener(Visit);
  68. Manager.OnLevelChange += () =>
  69. {
  70. VisitLab.text = ResourceManager.Get<Text>(ObjectLabel.C_CostLab).text;
  71. };
  72. return false;
  73. }
  74. public void Visit()
  75. {
  76. SocialManager.CloseCommentPanel();
  77. SocialManager.RecordCommentPanel();
  78. VisitManager.Visit(ArchiveSource.SerialNumber, SerialNumber);
  79. }
  80. public void Reset(string nickname, string serialNumber, string content)
  81. {
  82. Content = content;
  83. SerialNumber = serialNumber;
  84. if (serialNumber == HttpManager.SerialNumber)
  85. {
  86. VisitBtn.SetActive(false);
  87. }
  88. else
  89. {
  90. VisitBtn.SetActive(true);
  91. }
  92. if (!string.IsNullOrEmpty(nickname))
  93. {
  94. Tit.text = nickname;
  95. }
  96. else
  97. {
  98. if (Tit.text.Length >= 4)
  99. {
  100. Tit.text = "****" + serialNumber.Substring(serialNumber.Length - 4);
  101. }
  102. else
  103. {
  104. Tit.text = "****" + Random.Range(1000, 10000);
  105. }
  106. }
  107. ContentLab.text = content;
  108. }
  109. }