PoemPhotoPreView.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Poem;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class PoemPhotoPreView : BaseWindow
  9. {
  10. private UI_PoemPhotoPreviewUI _ui;
  11. private List<PoemPhotoData> _photoInfos;
  12. private int _curIndex = 0;
  13. private int _sourceType = 0;
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_PoemPhotoPreviewUI.PACKAGE_NAME;
  27. _ui = UI_PoemPhotoPreviewUI.Create();
  28. this.viewCom = _ui.target;
  29. isfullScreen = true;
  30. _ui.m_grhBg.onClick.Add(OnBtnBackClick);
  31. _ui.m_list.SetVirtual();
  32. _ui.m_list.itemRenderer = RenderListItem;
  33. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  34. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  35. _ui.m_btnLock.target.onClick.Add(OnBtnLockClick);
  36. _ui.m_btnUp.target.onClick.Add(OnBtnUpClick);
  37. _ui.m_btnShare.onClick.Add(OnBtnShareClick);
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. }
  43. protected override void OnShown()
  44. {
  45. base.OnShown();
  46. _curIndex = (int)(this.viewData as object[])[0];
  47. _sourceType = (int)(this.viewData as object[])[1];
  48. if (_sourceType == (int)PictureSourceType.PersonalAlbum)
  49. {
  50. _photoInfos = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  51. }
  52. else
  53. {
  54. _photoInfos = PoemPhotoDataManager.Instance.WsqsPhotoInfos;
  55. }
  56. _ui.m_list.numItems = _photoInfos.Count;
  57. if (_photoInfos.Count > 0) _ui.m_list.ScrollToView(_curIndex);
  58. UpdateView();
  59. }
  60. protected override void OnHide()
  61. {
  62. base.OnHide();
  63. }
  64. protected override void RemoveEventListener()
  65. {
  66. base.RemoveEventListener();
  67. }
  68. private void OnBtnBackClick()
  69. {
  70. ViewManager.GoBackFrom(typeof(PoemPhotoPreView).FullName);
  71. }
  72. private void UpdateView()
  73. {
  74. _ui.m_btnLeft.enabled = _curIndex > 0;
  75. _ui.m_btnRight.enabled = _curIndex < _ui.m_list.numItems - 1;
  76. _ui.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[_curIndex].CreationTime);
  77. if (_ui.m_btnLock.target.data == null)
  78. {
  79. _ui.m_btnLock.target.onClick.Add(OnBtnLockClick);
  80. }
  81. _ui.m_btnLock.target.data = _curIndex;
  82. if (_ui.m_btnUp.target.data == null)
  83. {
  84. _ui.m_btnUp.target.onClick.Add(OnBtnUpClick);
  85. }
  86. _ui.m_btnUp.target.data = _curIndex;
  87. }
  88. private void RenderListItem(int index, GObject obj)
  89. {
  90. UI_ListPhotoPreviewItem item = UI_ListPhotoPreviewItem.Proxy(obj);
  91. item.m_comPhoto.m_loaPhoto.texture = PoemPhotoDataManager.Instance.BytesToTexture2D(_photoInfos[index].Bytes);
  92. UI_ListPhotoPreviewItem.ProxyEnd();
  93. }
  94. private void OnBtnLeftClick()
  95. {
  96. _curIndex--;
  97. _curIndex = Mathf.Max(0, _curIndex);
  98. UpdateView();
  99. }
  100. private void OnBtnRightClick()
  101. {
  102. _curIndex++;
  103. _curIndex = Mathf.Min(_ui.m_list.numItems - 1, _curIndex);
  104. UpdateView();
  105. }
  106. private void OnBtnLockClick()
  107. {
  108. PoemPhotoData photoData = _photoInfos[_curIndex];
  109. if (photoData.LockingStatus == false)
  110. {
  111. AlertUI.Show("是否确认锁定此照片?", "(锁住的照片无法被删除)")
  112. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  113. {
  114. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, true, _sourceType).Coroutine();
  115. });
  116. }
  117. else
  118. {
  119. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  120. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  121. {
  122. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, false, _sourceType).Coroutine();
  123. });
  124. }
  125. }
  126. private void OnBtnUpClick()
  127. {
  128. PoemPhotoData photoData = _photoInfos[_curIndex];
  129. if (photoData.ToppingStatus == false)
  130. {
  131. AlertUI.Show("是否确认置顶此照片?")
  132. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  133. {
  134. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, true, _sourceType).Coroutine();
  135. });
  136. }
  137. else
  138. {
  139. AlertUI.Show("是否确认取消置顶此照片?")
  140. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  141. {
  142. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, false, _sourceType).Coroutine();
  143. });
  144. }
  145. }
  146. private void OnBtnShareClick()
  147. {
  148. ViewManager.Show<PoemPhotoShareView>(new object[] { _curIndex, _sourceType }, new object[] { typeof(PoemPhotoPreView).FullName, _curIndex });
  149. }
  150. }
  151. }