PersonalPhotoView.cs 4.6 KB

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