FashionShowCloseBox.cs 7.6 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 FashionShowData 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, FashionShowData data)
  26. {
  27. FashionShowData = data;
  28. Praised = data.Praised;
  29. if (Praised)
  30. {
  31. PraiseButton.image.color = Lib.Pink;
  32. }
  33. else
  34. {
  35. PraiseButton.image.color = Color.white;
  36. }
  37. PraiseText.text = data.PraisedAmount.ToString();
  38. DisplayButton.transform.SetActive(true);
  39. List<string> closeNames = Player.DressIDToDressName(data.CloseIDs);
  40. Player = PlayerManager.Instance.GetRawPlayer();
  41. Player.transform.SetParent(DisplayButton.transform);
  42. Player.transform.localPosition = Vector3.zero;
  43. Player.ChangeClose(BodyPart.Head, closeNames[0], false);
  44. Player.ChangeClose(BodyPart.Dress, closeNames[1], false);
  45. Player.ChangeClose(BodyPart.Shoe, closeNames[2], false);
  46. Player.ChangeClose(BodyPart.Headwear, closeNames[3], false);
  47. Player.ChangeClose(BodyPart.Top, closeNames[4], false);
  48. Player.ChangeClose(BodyPart.Eye, closeNames[5], false);
  49. Player.ChangeClose(BodyPart.Mouse, closeNames[6], false);
  50. Player.ChangeClose(BodyPart.Wing, closeNames[7], false);
  51. DelayCall.Call(1, ()=> { Player.DisplayInUI(scale); Player.ResetDepth(); });
  52. }
  53. public void Save()
  54. {
  55. DisplayButton.SetActive(false);
  56. if (Player != null)
  57. {
  58. Player.DisplayInScene();
  59. ResourceManager.Save(Player);
  60. Player = null;
  61. }
  62. }
  63. private void OnShareButtonClick()
  64. {
  65. AudioManager.PlayClip(ResourceLabel.BtnClip);
  66. }
  67. private void OnPraiseButtonClick()
  68. {
  69. AudioManager.PlayClip(ResourceLabel.BtnClip);
  70. if (Praised)
  71. {
  72. Praised = false;
  73. PraiseButton.image.color = Color.white;
  74. PraiseText.text = (int.Parse(PraiseText.text) - 1).ToString();
  75. HttpManager.UnpraiseFashionShow(null, null);
  76. }
  77. else
  78. {
  79. Praised = true;
  80. PraiseButton.image.color = Lib.Pink;
  81. PraiseText.text = (int.Parse(PraiseText.text) + 1).ToString();
  82. HttpManager.PraiseFashionShow(null, null);
  83. }
  84. }
  85. private void OnDisplayButtonClick()
  86. {
  87. AudioManager.PlayClip(ResourceLabel.BtnClip);
  88. FashionShowEditPage.ShowEditPanel(FashionShowData);
  89. }
  90. }
  91. public class FashionShowCloseBox : VirtualScrollRectItem
  92. {
  93. #region Config
  94. //StartMark-Used by LabelUtility-Do not remove
  95. private Text A_PraiseText;
  96. private Text B_PraiseText;
  97. private Text C_PraiseText;
  98. private Text D_PraiseText;
  99. private Text E_PraiseText;
  100. private Button A_DisplayBackground;
  101. private Button A_PraiseButton;
  102. private Button A_ShareButton;
  103. private Button B_DisplayBackground;
  104. private Button B_PraiseButton;
  105. private Button B_ShareButton;
  106. private Button C_DisplayBackground;
  107. private Button C_PraiseButton;
  108. private Button C_ShareButton;
  109. private Button D_DisplayBackground;
  110. private Button D_PraiseButton;
  111. private Button D_ShareButton;
  112. private Button E_DisplayBackground;
  113. private Button E_PraiseButton;
  114. private Button E_ShareButton;
  115. //EndMark-Used by LabelUtility-Do not remove
  116. public List<FashionShowCloseCell> Cells = new List<FashionShowCloseCell>();
  117. public List<FashionShowCloseCell> UnusedCells = new List<FashionShowCloseCell>();
  118. #endregion
  119. public override bool Init()
  120. {
  121. if (base.Init()) return true;
  122. //RegistStartMark-Used by LabelUtility-Do not remove
  123. Dictionary<string, Transform> childDictionary = new Dictionary<string, Transform>();
  124. Auxiliary.CompileDic(transform, childDictionary);
  125. A_PraiseText = childDictionary[FashionShowCloseBoxLabel.A_PraiseText].GetComponent<Text>();
  126. B_PraiseText = childDictionary[FashionShowCloseBoxLabel.B_PraiseText].GetComponent<Text>();
  127. C_PraiseText = childDictionary[FashionShowCloseBoxLabel.C_PraiseText].GetComponent<Text>();
  128. D_PraiseText = childDictionary[FashionShowCloseBoxLabel.D_PraiseText].GetComponent<Text>();
  129. E_PraiseText = childDictionary[FashionShowCloseBoxLabel.E_PraiseText].GetComponent<Text>();
  130. A_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.A_DisplayBackground].GetComponent<Button>();
  131. A_PraiseButton = childDictionary[FashionShowCloseBoxLabel.A_PraiseButton].GetComponent<Button>();
  132. A_ShareButton = childDictionary[FashionShowCloseBoxLabel.A_ShareButton].GetComponent<Button>();
  133. B_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.B_DisplayBackground].GetComponent<Button>();
  134. B_PraiseButton = childDictionary[FashionShowCloseBoxLabel.B_PraiseButton].GetComponent<Button>();
  135. B_ShareButton = childDictionary[FashionShowCloseBoxLabel.B_ShareButton].GetComponent<Button>();
  136. C_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.C_DisplayBackground].GetComponent<Button>();
  137. C_PraiseButton = childDictionary[FashionShowCloseBoxLabel.C_PraiseButton].GetComponent<Button>();
  138. C_ShareButton = childDictionary[FashionShowCloseBoxLabel.C_ShareButton].GetComponent<Button>();
  139. D_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.D_DisplayBackground].GetComponent<Button>();
  140. D_PraiseButton = childDictionary[FashionShowCloseBoxLabel.D_PraiseButton].GetComponent<Button>();
  141. D_ShareButton = childDictionary[FashionShowCloseBoxLabel.D_ShareButton].GetComponent<Button>();
  142. E_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.E_DisplayBackground].GetComponent<Button>();
  143. E_PraiseButton = childDictionary[FashionShowCloseBoxLabel.E_PraiseButton].GetComponent<Button>();
  144. E_ShareButton = childDictionary[FashionShowCloseBoxLabel.E_ShareButton].GetComponent<Button>();
  145. //RegistEndMark-Used by LabelUtility-Do not remove
  146. Cells.Add(new FashionShowCloseCell(A_PraiseText, A_PraiseButton, A_ShareButton, A_DisplayBackground));
  147. Cells.Add(new FashionShowCloseCell(B_PraiseText, B_PraiseButton, B_ShareButton, B_DisplayBackground));
  148. Cells.Add(new FashionShowCloseCell(C_PraiseText, C_PraiseButton, C_ShareButton, C_DisplayBackground));
  149. Cells.Add(new FashionShowCloseCell(D_PraiseText, D_PraiseButton, D_ShareButton, D_DisplayBackground));
  150. Cells.Add(new FashionShowCloseCell(E_PraiseText, E_PraiseButton, E_ShareButton, E_DisplayBackground));
  151. reset();
  152. return false;
  153. }
  154. public bool HaveUnusedCell()
  155. {
  156. return UnusedCells.Count > 0;
  157. }
  158. public void SetNextCell(FashionShowData data)
  159. {
  160. float scale = UnusedCells.Count == 5 ? 50 : 20;
  161. FashionShowCloseCell cell = UnusedCells.Forward(0, true);
  162. cell.Init(scale, data);
  163. }
  164. public void reset()
  165. {
  166. UnusedCells = new List<FashionShowCloseCell>(Cells);
  167. foreach (var cell in Cells)
  168. {
  169. cell.Save();
  170. }
  171. }
  172. }