PersonalPhotoView.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. this.viewCom.Center();
  26. this.modal = true;
  27. _ui.m_list.SetVirtual();
  28. _ui.m_list.itemRenderer = RenderListItem;
  29. _ui.m_list.onClickItem.Add(OnListItemClick);
  30. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("xc_bjbj");
  31. }
  32. protected override void OnShown()
  33. {
  34. base.OnShown();
  35. _showIndex = (int)this.viewData;
  36. _showPictureId = RoleDataManager.photoDatas[_showIndex];
  37. _ui.m_list.numItems = PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count;
  38. }
  39. protected override void OnHide()
  40. {
  41. base.OnHide();
  42. }
  43. private void RenderListItem(int index, GObject obj)
  44. {
  45. PoemPhotoData photoData = PoemPhotoDataManager.Instance.PersonalPhotoInfos[index];
  46. UI_ListPhotoItem1 item = UI_ListPhotoItem1.Proxy(obj);
  47. item.m_comIcon.m_loaIcon.texture = photoData.Ntexture;
  48. bool curSelect = photoData.PictureId == _showPictureId;
  49. bool otherSelect = !curSelect && RoleDataManager.photoDatas.IndexOf(photoData.PictureId) >= 0;
  50. item.m_imgSelect.visible = curSelect;
  51. item.m_imgOtherSelect.visible = otherSelect;
  52. item.target.data = photoData.PictureId;
  53. UI_ListPhotoItem1.ProxyEnd();
  54. }
  55. private void OnListItemClick(EventContext context)
  56. {
  57. GObject obj = context.data as GObject;
  58. long selectPictureId = (long)obj.data;
  59. if (selectPictureId == _showPictureId)//删除:点击相同id照片
  60. {
  61. RoleDataManager.photoDatas[_showIndex] = 0;
  62. }
  63. else
  64. {
  65. if (_showPictureId == 0)//添加:原来未展示图片
  66. {
  67. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  68. }
  69. else//原来有展示图片
  70. {
  71. if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//更换:选中的图片未被选中
  72. {
  73. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  74. }
  75. else
  76. {
  77. int selectPictureIndex = RoleDataManager.photoDatas.IndexOf(selectPictureId);
  78. RoleDataManager.photoDatas[_showIndex] = selectPictureId;
  79. RoleDataManager.photoDatas[selectPictureIndex] = _showPictureId;
  80. }
  81. }
  82. }
  83. ViewManager.GoBackFrom(typeof(PersonalPhotoView).FullName);
  84. }
  85. }
  86. }