CommentItem.cs 3.5 KB

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