PersonalPhotoView.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UI.RoleInfo;
  2. using FairyGUI;
  3. namespace GFGGame
  4. {
  5. public class PersonalPhotoView : BaseWindow
  6. {
  7. private UI_PersonalPhotoUI _ui;
  8. private int _showIndex = 0;
  9. private long _showPictureId = 0;
  10. public override void Dispose()
  11. {
  12. if (_ui != null)
  13. {
  14. _ui.Dispose();
  15. _ui = null;
  16. }
  17. base.Dispose();
  18. }
  19. protected override void OnInit()
  20. {
  21. base.OnInit();
  22. packageName = UI_PersonalPhotoUI.PACKAGE_NAME;
  23. _ui = UI_PersonalPhotoUI.Create();
  24. this.viewCom = _ui.target;
  25. isfullScreen = true;
  26. isReturnView = true;
  27. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  28. _ui.m_list.SetVirtual();
  29. _ui.m_list.itemRenderer = RenderListItem;
  30. _ui.m_list.onClickItem.Add(OnListItemClick);
  31. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("xc_bjbj");
  32. }
  33. protected override void OnShown()
  34. {
  35. base.OnShown();
  36. _showIndex = (int)this.viewData;
  37. _showPictureId = RoleDataManager.photoDatas[_showIndex];
  38. _ui.m_list.numItems = PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count;
  39. _ui.m_grpNothing.visible = _ui.m_list.numItems == 0;
  40. }
  41. protected override void OnHide()
  42. {
  43. base.OnHide();
  44. }
  45. private void OnBtnBackClick()
  46. {
  47. ViewManager.GoBackFrom(typeof(PersonalPhotoView).FullName);
  48. }
  49. private void RenderListItem(int index, GObject obj)
  50. {
  51. PoemPhotoData photoData = PoemPhotoDataManager.Instance.PersonalPhotoInfos[index];
  52. UI_ListPhotoItem1 item = UI_ListPhotoItem1.Proxy(obj);
  53. item.m_comIcon.m_loaIcon.texture = photoData.Ntexture;
  54. bool curSelect = photoData.PictureId == _showPictureId;
  55. bool otherSelect = !curSelect && RoleDataManager.photoDatas.IndexOf(photoData.PictureId) >= 0;
  56. item.m_imgSelect.visible = curSelect;
  57. item.m_imgOtherSelect.visible = otherSelect;
  58. item.m_txtTime.text = TimeUtil.FormattingTime1(photoData.CreationTime);
  59. item.target.data = photoData.PictureId;
  60. UI_ListPhotoItem1.ProxyEnd();
  61. }
  62. private async void OnListItemClick(EventContext context)
  63. {
  64. GObject obj = context.data as GObject;
  65. long selectPictureId = (long)obj.data;
  66. if (selectPictureId == _showPictureId)//删除:点击相同id照片
  67. {
  68. RoleDataManager.photoDatas[_showIndex] = 0;
  69. }
  70. else
  71. {
  72. if (_showPictureId == 0)//添加:原来未展示图片
  73. {
  74. if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//选中的图片未被选中
  75. {
  76. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  77. }
  78. }
  79. else//原来有展示图片
  80. {
  81. if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//更换:选中的图片未被选中
  82. {
  83. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  84. }
  85. else
  86. {
  87. int selectPictureIndex = RoleDataManager.photoDatas.IndexOf(selectPictureId);
  88. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  89. RoleDataManager.photoDatas[selectPictureIndex] = _showPictureId;
  90. }
  91. }
  92. }
  93. bool result = await RoleInfoSProxy.ReqModifyShowPhoto(RoleDataManager.photoDatas);
  94. if (result)
  95. {
  96. ViewManager.GoBackFrom(typeof(PersonalPhotoView).FullName);
  97. }
  98. }
  99. }
  100. }