PersonalPhotoView.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. UpdatePhotoData();
  79. if (selectPictureId == _showPictureId)//删除:点击相同id照片
  80. {
  81. RoleDataManager.photoDatas[_showIndex] = 0;
  82. UpdatePhotoData();
  83. }
  84. else
  85. {
  86. if (_showPictureId == 0)//添加:原来未展示图片
  87. {
  88. if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//选中的图片未被选中
  89. {
  90. // 找到第一个空位
  91. for(int i = 0; i < RoleDataManager.photoDatas.Count; i++)
  92. {
  93. if(RoleDataManager.photoDatas[i] == 0)
  94. {
  95. RoleDataManager.photoDatas[i] = selectPictureId;
  96. break;
  97. }
  98. }
  99. }
  100. }
  101. else//原来有展示图片
  102. {
  103. if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//更换:选中的图片未被选中
  104. {
  105. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  106. }
  107. else
  108. {
  109. int selectPictureIndex = RoleDataManager.photoDatas.IndexOf(selectPictureId);
  110. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  111. RoleDataManager.photoDatas[selectPictureIndex] = _showPictureId;
  112. }
  113. }
  114. }
  115. bool result = await RoleInfoSProxy.ReqModifyShowPhoto(RoleDataManager.photoDatas);
  116. if (result)
  117. {
  118. Hide();
  119. }
  120. }
  121. private void UpdatePhotoData()
  122. {
  123. List<long> numArr = new List<long>();
  124. // 提取有数据的位置
  125. for(int i=0;i< RoleDataManager.photoDatas.Count; i++)
  126. {
  127. if (RoleDataManager.photoDatas[i] != 0)
  128. {
  129. numArr.Add(RoleDataManager.photoDatas[i]);
  130. }
  131. }
  132. // 找到可用空位赋值
  133. int index = 0;
  134. for (int i = 0; i < RoleDataManager.photoDatas.Count; i++)
  135. {
  136. if (RoleInfoManager.GetPosType(i) == MonthCardType.Gold && !RoleDataManager.CheckIsMonthCardOpenByType(MonthCardType.Gold)
  137. || RoleInfoManager.GetPosType(i) == MonthCardType.BlackGold && !RoleDataManager.CheckIsMonthCardOpenByType(MonthCardType.BlackGold))
  138. {
  139. RoleDataManager.photoDatas[i] = -1;
  140. continue;
  141. }
  142. if (index < numArr.Count)
  143. {
  144. RoleDataManager.photoDatas[i] = numArr[index++];
  145. }
  146. }
  147. }
  148. }
  149. }