FashionShowCloseBox.cs 7.9 KB

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