FashionShowCloseBox.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. public class FashionShowCloseCell
  5. {
  6. #region Config
  7. //public bool Praised;
  8. public Text PraiseText;
  9. public Button PraiseButton;
  10. public Button ShareButton;
  11. public Button DisplayButton;
  12. public Player Player;
  13. public GetFashionShowData FashionShowData;
  14. #endregion
  15. public FashionShowCloseCell(Text praiseText, Button praiseButton, Button shareButton, Button displayButton)
  16. {
  17. PraiseText = praiseText;
  18. PraiseButton = praiseButton;
  19. ShareButton = shareButton;
  20. DisplayButton = displayButton;
  21. PraiseButton.onClick.AddListener(OnPraiseButtonClick);
  22. ShareButton.onClick.AddListener(OnShareButtonClick);
  23. DisplayButton.onClick.AddListener(OnDisplayButtonClick);
  24. }
  25. public void Init(float scale, GetFashionShowData data)
  26. {
  27. FashionShowData = data;
  28. RefreshPraiseButton();
  29. PraiseText.text = data.praiseCnt.ToString();
  30. DisplayButton.transform.SetActive(true);
  31. Player = PlayerManager.Instance.GetRawPlayer();
  32. Player.transform.SetParent(DisplayButton.transform);
  33. Player.transform.SetSiblingIndex(1);
  34. Player.transform.localPosition = Vector3.zero;
  35. foreach (var closeID in data.GetCloseIds())
  36. {
  37. CloseItem closeItem = PlayerManager.CloseItemDictionary[closeID];
  38. closeItem.ChangeDress(Player, false);
  39. }
  40. DelayCall.Call(1, ()=> { Player.DisplayInUI(scale); Player.ResetDepth(); });
  41. }
  42. public void Save()
  43. {
  44. DisplayButton.SetActive(false);
  45. if (Player != null)
  46. {
  47. Player.DisplayInScene();
  48. ResourceManager.Save(Player, true);
  49. }
  50. }
  51. private void OnShareButtonClick()
  52. {
  53. AudioManager.PlayClip(ResourceLabel.BtnClip);
  54. }
  55. private void OnPraiseButtonClick()
  56. {
  57. AudioManager.PlayClip(ResourceLabel.BtnClip);
  58. FashionShowData.praised = !FashionShowData.praised;
  59. if (FashionShowData.praised)
  60. {
  61. FashionShowData.praiseCnt++;
  62. }
  63. else
  64. {
  65. FashionShowData.praiseCnt--;
  66. }
  67. RefreshPraiseButton();
  68. PraiseShowHttp.Praise(HttpManager.GetPlayerId(), FashionShowData.showId, null, null);
  69. }
  70. private void RefreshPraiseButton()
  71. {
  72. if (FashionShowData.praised)
  73. {
  74. PraiseButton.image.color = Lib.Pink;
  75. }
  76. else
  77. {
  78. PraiseButton.image.color = Color.white;
  79. }
  80. PraiseText.text = FashionShowData.praiseCnt.ToString();
  81. }
  82. private void OnDisplayButtonClick()
  83. {
  84. AudioManager.PlayClip(ResourceLabel.BtnClip);
  85. TweenRoot tween = FashionShowHomePage.HideSidePanel();
  86. bool belongSelf = FashionShowData.playerId == long.Parse(HttpManager.SerialNumber);
  87. tween.AddEventOnetime(EventType.BackwardFinish, ()=> { FashionShowEditPage.ShowRatePanel(belongSelf, FashionShowData); FashionShowEditPage.LeaveToHomePage = true; });
  88. }
  89. }
  90. public class FashionShowCloseBox : VirtualScrollRectItem
  91. {
  92. #region Config
  93. //StartMark-Used by LabelUtility-Do not remove
  94. private Text A_PraiseText;
  95. private Text B_PraiseText;
  96. private Text C_PraiseText;
  97. private Text D_PraiseText;
  98. private Text E_PraiseText;
  99. private Button A_DisplayBackground;
  100. private Button A_PraiseButton;
  101. private Button A_ShareButton;
  102. private Button B_DisplayBackground;
  103. private Button B_PraiseButton;
  104. private Button B_ShareButton;
  105. private Button C_DisplayBackground;
  106. private Button C_PraiseButton;
  107. private Button C_ShareButton;
  108. private Button D_DisplayBackground;
  109. private Button D_PraiseButton;
  110. private Button D_ShareButton;
  111. private Button E_DisplayBackground;
  112. private Button E_PraiseButton;
  113. private Button E_ShareButton;
  114. //EndMark-Used by LabelUtility-Do not remove
  115. public List<FashionShowCloseCell> Cells = new List<FashionShowCloseCell>();
  116. public List<FashionShowCloseCell> UnusedCells = new List<FashionShowCloseCell>();
  117. #endregion
  118. public override bool Init()
  119. {
  120. if (base.Init()) return true;
  121. //RegistStartMark-Used by LabelUtility-Do not remove
  122. Dictionary<string, Transform> childDictionary = new Dictionary<string, Transform>();
  123. Auxiliary.CompileDic(transform, childDictionary);
  124. A_PraiseText = childDictionary[FashionShowCloseBoxLabel.A_PraiseText].GetComponent<Text>();
  125. B_PraiseText = childDictionary[FashionShowCloseBoxLabel.B_PraiseText].GetComponent<Text>();
  126. C_PraiseText = childDictionary[FashionShowCloseBoxLabel.C_PraiseText].GetComponent<Text>();
  127. D_PraiseText = childDictionary[FashionShowCloseBoxLabel.D_PraiseText].GetComponent<Text>();
  128. E_PraiseText = childDictionary[FashionShowCloseBoxLabel.E_PraiseText].GetComponent<Text>();
  129. A_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.A_DisplayBackground].GetComponent<Button>();
  130. A_PraiseButton = childDictionary[FashionShowCloseBoxLabel.A_PraiseButton].GetComponent<Button>();
  131. A_ShareButton = childDictionary[FashionShowCloseBoxLabel.A_ShareButton].GetComponent<Button>();
  132. B_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.B_DisplayBackground].GetComponent<Button>();
  133. B_PraiseButton = childDictionary[FashionShowCloseBoxLabel.B_PraiseButton].GetComponent<Button>();
  134. B_ShareButton = childDictionary[FashionShowCloseBoxLabel.B_ShareButton].GetComponent<Button>();
  135. C_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.C_DisplayBackground].GetComponent<Button>();
  136. C_PraiseButton = childDictionary[FashionShowCloseBoxLabel.C_PraiseButton].GetComponent<Button>();
  137. C_ShareButton = childDictionary[FashionShowCloseBoxLabel.C_ShareButton].GetComponent<Button>();
  138. D_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.D_DisplayBackground].GetComponent<Button>();
  139. D_PraiseButton = childDictionary[FashionShowCloseBoxLabel.D_PraiseButton].GetComponent<Button>();
  140. D_ShareButton = childDictionary[FashionShowCloseBoxLabel.D_ShareButton].GetComponent<Button>();
  141. E_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.E_DisplayBackground].GetComponent<Button>();
  142. E_PraiseButton = childDictionary[FashionShowCloseBoxLabel.E_PraiseButton].GetComponent<Button>();
  143. E_ShareButton = childDictionary[FashionShowCloseBoxLabel.E_ShareButton].GetComponent<Button>();
  144. //RegistEndMark-Used by LabelUtility-Do not remove
  145. Cells.Add(new FashionShowCloseCell(A_PraiseText, A_PraiseButton, A_ShareButton, A_DisplayBackground));
  146. Cells.Add(new FashionShowCloseCell(B_PraiseText, B_PraiseButton, B_ShareButton, B_DisplayBackground));
  147. Cells.Add(new FashionShowCloseCell(C_PraiseText, C_PraiseButton, C_ShareButton, C_DisplayBackground));
  148. Cells.Add(new FashionShowCloseCell(D_PraiseText, D_PraiseButton, D_ShareButton, D_DisplayBackground));
  149. Cells.Add(new FashionShowCloseCell(E_PraiseText, E_PraiseButton, E_ShareButton, E_DisplayBackground));
  150. reset();
  151. return false;
  152. }
  153. public bool HaveUnusedCell()
  154. {
  155. return UnusedCells.Count > 0;
  156. }
  157. public void SetNextCell(GetFashionShowData data)
  158. {
  159. float scale = UnusedCells.Count == 5 ? 37.5f : 17.5f;
  160. FashionShowCloseCell cell = UnusedCells.Forward(0, true);
  161. cell.Init(scale, data);
  162. }
  163. public void reset()
  164. {
  165. UnusedCells = new List<FashionShowCloseCell>(Cells);
  166. foreach (var cell in Cells)
  167. {
  168. cell.Save();
  169. }
  170. }
  171. }