FashionShowCloseBox.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using repeatCallUtility;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class FashionShowCloseCell
  8. {
  9. #region Config
  10. //public bool Praised;
  11. public Text PraiseText;
  12. public Image ShadowImg;
  13. public Button PraiseButton;
  14. public Button ShareButton;
  15. public Button DisplayButton;
  16. public Player Player;
  17. public GetFashionShowData FashionShowData;
  18. #endregion
  19. public FashionShowCloseCell(Text praiseText, Image shadowImg, Button praiseButton, Button shareButton, Button displayButton)
  20. {
  21. PraiseText = praiseText;
  22. ShadowImg = shadowImg;
  23. PraiseButton = praiseButton;
  24. ShareButton = shareButton;
  25. DisplayButton = displayButton;
  26. PraiseButton.onClick.AddListener(OnPraiseButtonClick);
  27. ShareButton.onClick.AddListener(OnShareButtonClick);
  28. DisplayButton.onClick.AddListener(OnDisplayButtonClick);
  29. }
  30. public void Init(float uiScale, Vector3 playerScale, GetFashionShowData data)
  31. {
  32. FashionShowData = data;
  33. RefreshPraiseButton();
  34. PraiseText.text = data.praiseCnt.ToString();
  35. DisplayButton.transform.SetActive(true);
  36. Player = PlayerManager.Instance.GetRawPlayer();
  37. Player.transform.SetParent(DisplayButton.transform);
  38. Player.transform.SetSiblingIndex(1);
  39. Player.transform.localPosition = Vector3.zero;
  40. Player.transform.localScale = playerScale;
  41. foreach (var closeID in data.GetCloseIds())
  42. {
  43. CloseItem closeItem = PlayerManager.CloseItemDictionary[closeID];
  44. closeItem.ChangeDress(Player, false);
  45. }
  46. DelayCall.Call(1, ()=> { Player.DisplayInUI(uiScale, false); Player.ResetDepth(); });
  47. }
  48. public void Save()
  49. {
  50. DisplayButton.SetActive(false);
  51. if (Player != null)
  52. {
  53. Object.DestroyImmediate(Player.gameObject);
  54. //Player.DisplayInScene();
  55. //ResourceManager.Save(Player, true);
  56. }
  57. }
  58. public static Player photoShopPlayer;
  59. public string path = Application.persistentDataPath + Path.DirectorySeparatorChar + "FashionShow.png";
  60. private void OnShareButtonClick()
  61. {
  62. if (photoShopPlayer != null)
  63. {
  64. Object.Destroy(photoShopPlayer.gameObject);
  65. }
  66. AudioManager.PlayClip(ResourceLabel.BtnClip);
  67. ResourceManager.Get("PhotoShop").SetParent(null);
  68. ResourceManager.Get("PhotoShop").SetActive(true);
  69. photoShopPlayer = PlayerManager.Instance.GetRawPlayer();
  70. PlayerManager.BuildPlayer(Player.GetAllDressNames(), photoShopPlayer);
  71. photoShopPlayer.SetParent(ResourceManager.Get("PhotoShopPlayer"));
  72. photoShopPlayer.transform.localPosition = new Vector3(0, 0, -1);
  73. photoShopPlayer.ResetDepth();
  74. Camera camera = ResourceManager.Get<Camera>("PhotoShopCamera");
  75. PhotoShopCamera shopCamera = camera.GetComponent<PhotoShopCamera>();
  76. if (shopCamera == null)
  77. {
  78. shopCamera = camera.AddComponent<PhotoShopCamera>();
  79. }
  80. shopCamera.onRenderFinish = null;
  81. shopCamera.onRenderFinish += ScreenShot;
  82. }
  83. private void ScreenShot(Texture2D tex)
  84. {
  85. float left = 0.02f;
  86. float right = 0.4f;
  87. float top = 0.8f;
  88. float bottom = 0.05f;
  89. int width = (int)(tex.width * (right - left));
  90. int height = (int)(tex.height * (top - bottom));
  91. int leftOffset = (int)(tex.width * left);
  92. int bottomOffset = (int)(tex.height * bottom);
  93. Texture2D newTex = new Texture2D(width, height);
  94. newTex.SetPixels(tex.GetPixels(leftOffset, bottomOffset, width, height));
  95. newTex.Apply();
  96. File.WriteAllBytes(path, newTex.EncodeToJPG());
  97. ResourceManager.Get("PhotoShop").SetActive(false);
  98. IAPManager.Share(path, Language.GetStr(LanguageLabel.Common__ScreenShotShareContent));
  99. }
  100. private void OnPraiseButtonClick()
  101. {
  102. AudioManager.PlayClip(ResourceLabel.BtnClip);
  103. FashionShowData.praised = !FashionShowData.praised;
  104. if (FashionShowData.praised)
  105. {
  106. FashionShowData.praiseCnt++;
  107. }
  108. else
  109. {
  110. FashionShowData.praiseCnt--;
  111. }
  112. RefreshPraiseButton();
  113. PraiseShowHttp.Praise(HttpManager.GetPlayerId(), FashionShowData.showId, null, null);
  114. }
  115. public void RefreshPraiseButton()
  116. {
  117. if (FashionShowData.praised)
  118. {
  119. PraiseButton.image.color = Lib.Pink;
  120. PraiseText.color = Color.white;
  121. }
  122. else
  123. {
  124. PraiseButton.image.color = Color.white;
  125. PraiseText.color = Lib.PraiseTextBlue;
  126. }
  127. PraiseText.text = FashionShowData.praiseCnt.ToString();
  128. }
  129. private void OnDisplayButtonClick()
  130. {
  131. FashionShowEditPage.closeCell = this;
  132. AudioManager.PlayClip(ResourceLabel.BtnClip);
  133. TweenRoot tween = FashionShowHomePage.HideSidePanel();
  134. bool belongSelf = FashionShowData.playerId == long.Parse(HttpManager.SerialNumber);
  135. tween.AddEventOnetime(EventType.BackwardFinish, ()=> { FashionShowEditPage.ShowRatePanel(belongSelf, FashionShowData); FashionShowEditPage.LeaveToHomePage = true; });
  136. }
  137. }
  138. public class FashionShowCloseBox : VirtualScrollRectItem
  139. {
  140. #region Config
  141. //StartMark-Used by LabelUtility-Do not remove
  142. private Text A_PraiseText;
  143. private Text B_PraiseText;
  144. private Text C_PraiseText;
  145. private Text D_PraiseText;
  146. private Text E_PraiseText;
  147. private Image A_Img;
  148. private Image B_Img;
  149. private Image C_Img;
  150. private Image D_Img;
  151. private Image E_Img;
  152. private Button A_DisplayBackground;
  153. private Button A_PraiseButton;
  154. private Button A_ShareButton;
  155. private Button B_DisplayBackground;
  156. private Button B_PraiseButton;
  157. private Button B_ShareButton;
  158. private Button C_DisplayBackground;
  159. private Button C_PraiseButton;
  160. private Button C_ShareButton;
  161. private Button D_DisplayBackground;
  162. private Button D_PraiseButton;
  163. private Button D_ShareButton;
  164. private Button E_DisplayBackground;
  165. private Button E_PraiseButton;
  166. private Button E_ShareButton;
  167. //EndMark-Used by LabelUtility-Do not remove
  168. public RectTransform rectTrans
  169. {
  170. get
  171. {
  172. if (m_rectTrans == null)
  173. {
  174. m_rectTrans = GetComponent<RectTransform>();
  175. }
  176. return m_rectTrans;
  177. }
  178. }
  179. public RectTransform m_rectTrans;
  180. public Canvas canvas
  181. {
  182. get
  183. {
  184. if (m_canvas == null)
  185. {
  186. m_canvas = ResourceManager.Get<Canvas>(CanvasLabel.Canvas);
  187. RectTransform trans = m_canvas.GetComponent<RectTransform>();
  188. canvasMin = trans.position.x + trans.rect.xMin* m_canvas.scaleFactor;
  189. canvasMax = trans.position.x + trans.rect.xMax* m_canvas.scaleFactor;
  190. }
  191. return m_canvas;
  192. }
  193. }
  194. public Canvas m_canvas;
  195. public float canvasMin;
  196. public float canvasMax;
  197. public List<FashionShowCloseCell> Cells = new List<FashionShowCloseCell>();
  198. public List<FashionShowCloseCell> UnusedCells = new List<FashionShowCloseCell>();
  199. #endregion
  200. public override bool Init()
  201. {
  202. if (base.Init()) return true;
  203. //RegistStartMark-Used by LabelUtility-Do not remove
  204. Dictionary<string, Transform> childDictionary = new Dictionary<string, Transform>();
  205. Auxiliary.CompileDic(transform, childDictionary);
  206. A_PraiseText = childDictionary[FashionShowCloseBoxLabel.A_PraiseText].GetComponent<Text>();
  207. B_PraiseText = childDictionary[FashionShowCloseBoxLabel.B_PraiseText].GetComponent<Text>();
  208. C_PraiseText = childDictionary[FashionShowCloseBoxLabel.C_PraiseText].GetComponent<Text>();
  209. D_PraiseText = childDictionary[FashionShowCloseBoxLabel.D_PraiseText].GetComponent<Text>();
  210. E_PraiseText = childDictionary[FashionShowCloseBoxLabel.E_PraiseText].GetComponent<Text>();
  211. A_Img = childDictionary["A_Image"].GetComponent<Image>();
  212. B_Img = childDictionary["A_Image"].GetComponent<Image>();
  213. C_Img = childDictionary["A_Image"].GetComponent<Image>();
  214. D_Img = childDictionary["A_Image"].GetComponent<Image>();
  215. E_Img = childDictionary["A_Image"].GetComponent<Image>();
  216. A_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.A_DisplayBackground].GetComponent<Button>();
  217. A_PraiseButton = childDictionary[FashionShowCloseBoxLabel.A_PraiseButton].GetComponent<Button>();
  218. A_ShareButton = childDictionary[FashionShowCloseBoxLabel.A_ShareButton].GetComponent<Button>();
  219. B_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.B_DisplayBackground].GetComponent<Button>();
  220. B_PraiseButton = childDictionary[FashionShowCloseBoxLabel.B_PraiseButton].GetComponent<Button>();
  221. B_ShareButton = childDictionary[FashionShowCloseBoxLabel.B_ShareButton].GetComponent<Button>();
  222. C_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.C_DisplayBackground].GetComponent<Button>();
  223. C_PraiseButton = childDictionary[FashionShowCloseBoxLabel.C_PraiseButton].GetComponent<Button>();
  224. C_ShareButton = childDictionary[FashionShowCloseBoxLabel.C_ShareButton].GetComponent<Button>();
  225. D_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.D_DisplayBackground].GetComponent<Button>();
  226. D_PraiseButton = childDictionary[FashionShowCloseBoxLabel.D_PraiseButton].GetComponent<Button>();
  227. D_ShareButton = childDictionary[FashionShowCloseBoxLabel.D_ShareButton].GetComponent<Button>();
  228. E_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.E_DisplayBackground].GetComponent<Button>();
  229. E_PraiseButton = childDictionary[FashionShowCloseBoxLabel.E_PraiseButton].GetComponent<Button>();
  230. E_ShareButton = childDictionary[FashionShowCloseBoxLabel.E_ShareButton].GetComponent<Button>();
  231. //RegistEndMark-Used by LabelUtility-Do not remove
  232. Cells.Add(new FashionShowCloseCell(A_PraiseText, A_Img, A_PraiseButton, A_ShareButton, A_DisplayBackground));
  233. Cells.Add(new FashionShowCloseCell(B_PraiseText, B_Img, B_PraiseButton, B_ShareButton, B_DisplayBackground));
  234. Cells.Add(new FashionShowCloseCell(C_PraiseText, C_Img, C_PraiseButton, C_ShareButton, C_DisplayBackground));
  235. Cells.Add(new FashionShowCloseCell(D_PraiseText, D_Img, D_PraiseButton, D_ShareButton, D_DisplayBackground));
  236. Cells.Add(new FashionShowCloseCell(E_PraiseText, E_Img, E_PraiseButton, E_ShareButton, E_DisplayBackground));
  237. reset();
  238. return false;
  239. }
  240. public bool HaveUnusedCell()
  241. {
  242. return UnusedCells.Count > 0;
  243. }
  244. public void SetNextCell(GetFashionShowData data)
  245. {
  246. float scale = UnusedCells.Count == 5 ? 37.5f : 17.5f;
  247. Vector3 playerScale = UnusedCells.Count == 5 ? new Vector3(0.8442904f, 0.8442904f, 0.8442904f) :
  248. new Vector3(1.763814f, 1.763814f, 1.763814f);
  249. FashionShowCloseCell cell = UnusedCells.Forward(0, true);
  250. cell.Init(scale, playerScale, data);
  251. }
  252. public void reset()
  253. {
  254. UnusedCells = new List<FashionShowCloseCell>(Cells);
  255. foreach (var cell in Cells)
  256. {
  257. cell.Save();
  258. }
  259. EnableAll();
  260. }
  261. public void Update()
  262. {
  263. //Debug.Log(canvas);
  264. //Debug.Log(canvasMin);
  265. //Debug.Log(canvasMax);
  266. if (rectTrans.position.x + rectTrans.rect.xMax * canvas.scaleFactor < canvasMin)
  267. {
  268. DisableAll();
  269. }
  270. else if (rectTrans.position.x + rectTrans.rect.xMin * canvas.scaleFactor > canvasMax)
  271. {
  272. DisableAll();
  273. }
  274. else
  275. {
  276. EnableAll();
  277. }
  278. }
  279. public void EnableAll()
  280. {
  281. for (int i = 0; i < transform.childCount; i++)
  282. {
  283. transform.GetChild(i).SetActive(true);
  284. }
  285. }
  286. public void DisableAll()
  287. {
  288. for (int i = 0; i < transform.childCount; i++)
  289. {
  290. transform.GetChild(i).SetActive(false);
  291. }
  292. }
  293. }