PersonalPhotoView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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("tjbg");
  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_ListPhotoItemDetail item = UI_ListPhotoItemDetail.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. if (curSelect)
  57. {
  58. item.m_c1.SetSelectedIndex(2);
  59. }
  60. else if (otherSelect)
  61. {
  62. item.m_c1.SetSelectedIndex(1);
  63. }
  64. else
  65. {
  66. item.m_c1.SetSelectedIndex(0);
  67. }
  68. string[] timeStr = TimeUtil.FormattingTime1(photoData.CreationTime, '/').Split(' ');
  69. item.m_txtTime.text = timeStr[0];
  70. item.target.data = photoData.PictureId;
  71. UI_ListPhotoItemDetail.ProxyEnd();
  72. }
  73. private async void OnListItemClick(EventContext context)
  74. {
  75. GObject obj = context.data as GObject;
  76. long selectPictureId = (long)obj.data;
  77. if (selectPictureId == _showPictureId)//删除:点击相同id照片
  78. {
  79. RoleDataManager.photoDatas[_showIndex] = 0;
  80. }
  81. else
  82. {
  83. if (_showPictureId == 0)//添加:原来未展示图片
  84. {
  85. if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//选中的图片未被选中
  86. {
  87. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  88. }
  89. }
  90. else//原来有展示图片
  91. {
  92. if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//更换:选中的图片未被选中
  93. {
  94. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  95. }
  96. else
  97. {
  98. int selectPictureIndex = RoleDataManager.photoDatas.IndexOf(selectPictureId);
  99. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  100. RoleDataManager.photoDatas[selectPictureIndex] = _showPictureId;
  101. }
  102. }
  103. }
  104. bool result = await RoleInfoSProxy.ReqModifyShowPhoto(RoleDataManager.photoDatas);
  105. if (result)
  106. {
  107. Hide();
  108. }
  109. }
  110. }
  111. }