123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using repeatCallUtility;
- using UnityEngine;
- using UnityEngine.UI;
- public class FashionShowCloseCell
- {
- #region Config
- //public bool Praised;
- public Text PraiseText;
- public Image ShadowImg;
- public Button PraiseButton;
- public Button ShareButton;
- public Button DisplayButton;
- public Player Player;
- public GetFashionShowData FashionShowData;
- #endregion
- public FashionShowCloseCell(Text praiseText, Image shadowImg, Button praiseButton, Button shareButton, Button displayButton)
- {
- PraiseText = praiseText;
- ShadowImg = shadowImg;
- PraiseButton = praiseButton;
- ShareButton = shareButton;
- DisplayButton = displayButton;
- PraiseButton.onClick.AddListener(OnPraiseButtonClick);
- ShareButton.onClick.AddListener(OnShareButtonClick);
- DisplayButton.onClick.AddListener(OnDisplayButtonClick);
- }
- public void Init(float uiScale, Vector3 playerScale, GetFashionShowData data)
- {
- FashionShowData = data;
- RefreshPraiseButton();
- PraiseText.text = data.praiseCnt.ToString();
- DisplayButton.transform.SetActive(true);
- Player = PlayerManager.Instance.GetRawPlayer();
- Player.transform.SetParent(DisplayButton.transform);
- Player.transform.SetSiblingIndex(1);
- Player.transform.localPosition = Vector3.zero;
- Player.transform.localScale = playerScale;
- foreach (var closeID in data.GetCloseIds())
- {
- CloseItem closeItem = PlayerManager.CloseItemDictionary[closeID];
- closeItem.ChangeDress(Player, false);
- }
- DelayCall.Call(1, ()=> { Player.DisplayInUI(uiScale, false); Player.ResetDepth(); });
- }
- public void Save()
- {
- DisplayButton.SetActive(false);
- if (Player != null)
- {
- Object.DestroyImmediate(Player.gameObject);
- //Player.DisplayInScene();
- //ResourceManager.Save(Player, true);
- }
- }
- public static Player photoShopPlayer;
- public string path = Application.persistentDataPath + Path.DirectorySeparatorChar + "FashionShow.png";
- private void OnShareButtonClick()
- {
- if (photoShopPlayer != null)
- {
- Object.Destroy(photoShopPlayer.gameObject);
- }
- AudioManager.PlayClip(ResourceLabel.BtnClip);
- ResourceManager.Get("PhotoShop").SetParent(null);
- ResourceManager.Get("PhotoShop").SetActive(true);
- photoShopPlayer = PlayerManager.Instance.GetRawPlayer();
- PlayerManager.BuildPlayer(Player.GetAllDressNames(), photoShopPlayer);
- photoShopPlayer.SetParent(ResourceManager.Get("PhotoShopPlayer"));
- photoShopPlayer.transform.localPosition = new Vector3(0, 0, -1);
- photoShopPlayer.ResetDepth();
- Camera camera = ResourceManager.Get<Camera>("PhotoShopCamera");
- PhotoShopCamera shopCamera = camera.GetComponent<PhotoShopCamera>();
- if (shopCamera == null)
- {
- shopCamera = camera.AddComponent<PhotoShopCamera>();
- }
- shopCamera.onRenderFinish = null;
- shopCamera.onRenderFinish += ScreenShot;
- }
- private void ScreenShot(Texture2D tex)
- {
- float left = 0.02f;
- float right = 0.4f;
- float top = 0.8f;
- float bottom = 0.05f;
- int width = (int)(tex.width * (right - left));
- int height = (int)(tex.height * (top - bottom));
- int leftOffset = (int)(tex.width * left);
- int bottomOffset = (int)(tex.height * bottom);
- Texture2D newTex = new Texture2D(width, height);
- newTex.SetPixels(tex.GetPixels(leftOffset, bottomOffset, width, height));
- newTex.Apply();
- File.WriteAllBytes(path, newTex.EncodeToJPG());
- ResourceManager.Get("PhotoShop").SetActive(false);
- IAPManager.Share(path, Language.GetStr(LanguageLabel.Common__ScreenShotShareContent));
- }
- private void OnPraiseButtonClick()
- {
- AudioManager.PlayClip(ResourceLabel.BtnClip);
- FashionShowData.praised = !FashionShowData.praised;
- if (FashionShowData.praised)
- {
- FashionShowData.praiseCnt++;
- }
- else
- {
- FashionShowData.praiseCnt--;
- }
- RefreshPraiseButton();
- PraiseShowHttp.Praise(HttpManager.GetPlayerId(), FashionShowData.showId, null, null);
- }
- public void RefreshPraiseButton()
- {
- if (FashionShowData.praised)
- {
- PraiseButton.image.color = Lib.Pink;
- PraiseText.color = Color.white;
- }
- else
- {
- PraiseButton.image.color = Color.white;
- PraiseText.color = Lib.PraiseTextBlue;
- }
- PraiseText.text = FashionShowData.praiseCnt.ToString();
- }
- private void OnDisplayButtonClick()
- {
- FashionShowEditPage.closeCell = this;
- AudioManager.PlayClip(ResourceLabel.BtnClip);
- TweenRoot tween = FashionShowHomePage.HideSidePanel();
- bool belongSelf = FashionShowData.playerId == long.Parse(HttpManager.SerialNumber);
- tween.AddEventOnetime(EventType.BackwardFinish, ()=> { FashionShowEditPage.ShowRatePanel(belongSelf, FashionShowData); FashionShowEditPage.LeaveToHomePage = true; });
- }
- }
- public class FashionShowCloseBox : VirtualScrollRectItem
- {
- #region Config
- //StartMark-Used by LabelUtility-Do not remove
- private Text A_PraiseText;
- private Text B_PraiseText;
- private Text C_PraiseText;
- private Text D_PraiseText;
- private Text E_PraiseText;
- private Image A_Img;
- private Image B_Img;
- private Image C_Img;
- private Image D_Img;
- private Image E_Img;
- private Button A_DisplayBackground;
- private Button A_PraiseButton;
- private Button A_ShareButton;
- private Button B_DisplayBackground;
- private Button B_PraiseButton;
- private Button B_ShareButton;
- private Button C_DisplayBackground;
- private Button C_PraiseButton;
- private Button C_ShareButton;
- private Button D_DisplayBackground;
- private Button D_PraiseButton;
- private Button D_ShareButton;
- private Button E_DisplayBackground;
- private Button E_PraiseButton;
- private Button E_ShareButton;
- //EndMark-Used by LabelUtility-Do not remove
- public RectTransform rectTrans
- {
- get
- {
- if (m_rectTrans == null)
- {
- m_rectTrans = GetComponent<RectTransform>();
- }
- return m_rectTrans;
- }
- }
- public RectTransform m_rectTrans;
- public Canvas canvas
- {
- get
- {
- if (m_canvas == null)
- {
- m_canvas = ResourceManager.Get<Canvas>(CanvasLabel.Canvas);
- RectTransform trans = m_canvas.GetComponent<RectTransform>();
- canvasMin = trans.position.x + trans.rect.xMin* m_canvas.scaleFactor;
- canvasMax = trans.position.x + trans.rect.xMax* m_canvas.scaleFactor;
- }
- return m_canvas;
- }
- }
- public Canvas m_canvas;
- public float canvasMin;
- public float canvasMax;
- public List<FashionShowCloseCell> Cells = new List<FashionShowCloseCell>();
- public List<FashionShowCloseCell> UnusedCells = new List<FashionShowCloseCell>();
- #endregion
- public override bool Init()
- {
- if (base.Init()) return true;
- //RegistStartMark-Used by LabelUtility-Do not remove
- Dictionary<string, Transform> childDictionary = new Dictionary<string, Transform>();
- Auxiliary.CompileDic(transform, childDictionary);
- A_PraiseText = childDictionary[FashionShowCloseBoxLabel.A_PraiseText].GetComponent<Text>();
- B_PraiseText = childDictionary[FashionShowCloseBoxLabel.B_PraiseText].GetComponent<Text>();
- C_PraiseText = childDictionary[FashionShowCloseBoxLabel.C_PraiseText].GetComponent<Text>();
- D_PraiseText = childDictionary[FashionShowCloseBoxLabel.D_PraiseText].GetComponent<Text>();
- E_PraiseText = childDictionary[FashionShowCloseBoxLabel.E_PraiseText].GetComponent<Text>();
- A_Img = childDictionary["A_Image"].GetComponent<Image>();
- B_Img = childDictionary["A_Image"].GetComponent<Image>();
- C_Img = childDictionary["A_Image"].GetComponent<Image>();
- D_Img = childDictionary["A_Image"].GetComponent<Image>();
- E_Img = childDictionary["A_Image"].GetComponent<Image>();
- A_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.A_DisplayBackground].GetComponent<Button>();
- A_PraiseButton = childDictionary[FashionShowCloseBoxLabel.A_PraiseButton].GetComponent<Button>();
- A_ShareButton = childDictionary[FashionShowCloseBoxLabel.A_ShareButton].GetComponent<Button>();
- B_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.B_DisplayBackground].GetComponent<Button>();
- B_PraiseButton = childDictionary[FashionShowCloseBoxLabel.B_PraiseButton].GetComponent<Button>();
- B_ShareButton = childDictionary[FashionShowCloseBoxLabel.B_ShareButton].GetComponent<Button>();
- C_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.C_DisplayBackground].GetComponent<Button>();
- C_PraiseButton = childDictionary[FashionShowCloseBoxLabel.C_PraiseButton].GetComponent<Button>();
- C_ShareButton = childDictionary[FashionShowCloseBoxLabel.C_ShareButton].GetComponent<Button>();
- D_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.D_DisplayBackground].GetComponent<Button>();
- D_PraiseButton = childDictionary[FashionShowCloseBoxLabel.D_PraiseButton].GetComponent<Button>();
- D_ShareButton = childDictionary[FashionShowCloseBoxLabel.D_ShareButton].GetComponent<Button>();
- E_DisplayBackground = childDictionary[FashionShowCloseBoxLabel.E_DisplayBackground].GetComponent<Button>();
- E_PraiseButton = childDictionary[FashionShowCloseBoxLabel.E_PraiseButton].GetComponent<Button>();
- E_ShareButton = childDictionary[FashionShowCloseBoxLabel.E_ShareButton].GetComponent<Button>();
- //RegistEndMark-Used by LabelUtility-Do not remove
- Cells.Add(new FashionShowCloseCell(A_PraiseText, A_Img, A_PraiseButton, A_ShareButton, A_DisplayBackground));
- Cells.Add(new FashionShowCloseCell(B_PraiseText, B_Img, B_PraiseButton, B_ShareButton, B_DisplayBackground));
- Cells.Add(new FashionShowCloseCell(C_PraiseText, C_Img, C_PraiseButton, C_ShareButton, C_DisplayBackground));
- Cells.Add(new FashionShowCloseCell(D_PraiseText, D_Img, D_PraiseButton, D_ShareButton, D_DisplayBackground));
- Cells.Add(new FashionShowCloseCell(E_PraiseText, E_Img, E_PraiseButton, E_ShareButton, E_DisplayBackground));
- reset();
- return false;
- }
- public bool HaveUnusedCell()
- {
- return UnusedCells.Count > 0;
- }
- public void SetNextCell(GetFashionShowData data)
- {
- float scale = UnusedCells.Count == 5 ? 37.5f : 17.5f;
- Vector3 playerScale = UnusedCells.Count == 5 ? new Vector3(0.8442904f, 0.8442904f, 0.8442904f) :
- new Vector3(1.763814f, 1.763814f, 1.763814f);
- FashionShowCloseCell cell = UnusedCells.Forward(0, true);
- cell.Init(scale, playerScale, data);
- }
- public void reset()
- {
- UnusedCells = new List<FashionShowCloseCell>(Cells);
- foreach (var cell in Cells)
- {
- cell.Save();
- }
- EnableAll();
- }
- public void Update()
- {
- //Debug.Log(canvas);
- //Debug.Log(canvasMin);
- //Debug.Log(canvasMax);
- if (rectTrans.position.x + rectTrans.rect.xMax * canvas.scaleFactor < canvasMin)
- {
- DisableAll();
- }
- else if (rectTrans.position.x + rectTrans.rect.xMin * canvas.scaleFactor > canvasMax)
- {
- DisableAll();
- }
- else
- {
- EnableAll();
- }
- }
- public void EnableAll()
- {
- for (int i = 0; i < transform.childCount; i++)
- {
- transform.GetChild(i).SetActive(true);
- }
- }
- public void DisableAll()
- {
- for (int i = 0; i < transform.childCount; i++)
- {
- transform.GetChild(i).SetActive(false);
- }
- }
- }
|