FriendView.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Friend;
  4. namespace GFGGame
  5. {
  6. public class FriendView : BaseView
  7. {
  8. private UI_FriendUI _ui;
  9. private GameObject _scenePrefab;
  10. private GameObject _sceneObject;
  11. public override void Dispose()
  12. {
  13. if (_sceneObject != null)
  14. {
  15. GameObject.Destroy(_sceneObject);
  16. _sceneObject = null;
  17. }
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void Init()
  26. {
  27. base.Init();
  28. packageName = UI_FriendUI.PACKAGE_NAME;
  29. _ui = UI_FriendUI.Create();
  30. viewCom = _ui.target;
  31. isfullScreen = true;
  32. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFriend"));
  33. _ui.m_list.SetVirtual();
  34. _ui.m_list.itemRenderer = RenderListItem;
  35. _ui.m_list.onClickItem.Add(OnListItemClick);
  36. _ui.m_btnSolgan.onClick.Add(OnBtnSloganClick);
  37. _ui.m_btnDelete.onClick.Add(OnBtnDeleteClick);
  38. _ui.m_btnAdd.onClick.Add(OnBtnAddClick);
  39. }
  40. protected override void OnInit()
  41. {
  42. base.OnInit();
  43. _ui.m_btnBack.onClick.Add(OnHide);
  44. }
  45. protected override void AddEventListener()
  46. {
  47. base.AddEventListener();
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. _ui.m_grpSlogan.visible = false;
  53. UpdateList();
  54. CustomSuitData suitSavedData = CustomSuitDataManager.GetCurrentSuitList();
  55. // if (_ui.m_list.numItems > 0)
  56. // {
  57. // _ui.m_list.selectedIndex = 0;
  58. // suitSavedData = _ui.m_list.GetChildAt(0).asCom.data as CustomSuitData;
  59. // }
  60. UpdateScene(suitSavedData);
  61. }
  62. protected override void OnHide()
  63. {
  64. if (_sceneObject != null)
  65. {
  66. GameObject.Destroy(_sceneObject);
  67. _sceneObject = null;
  68. }
  69. ViewManager.GoBackFrom(typeof(FriendView).FullName);
  70. }
  71. protected override void RemoveEventListener()
  72. {
  73. base.RemoveEventListener();
  74. }
  75. private void UpdateList()
  76. {
  77. _ui.m_list.numItems = 20;
  78. }
  79. private void RenderListItem(int index, GObject obj)
  80. {
  81. UI_ListItem item = UI_ListItem.Proxy(obj);
  82. UI_ListItem.ProxyEnd();
  83. }
  84. private void OnListItemClick(EventContext context)
  85. {
  86. GObject item = context.data as GObject;
  87. CustomSuitData suitSavedData = item.data as CustomSuitData;
  88. UpdateScene(suitSavedData);
  89. }
  90. private void UpdateScene(CustomSuitData suitSavedData)
  91. {
  92. if (_sceneObject == null)
  93. {
  94. _sceneObject = GameObject.Instantiate(_scenePrefab);
  95. EquipDataCache.cacher.setSceneObj(_sceneObject);
  96. }
  97. EquipDataCache.cacher.PutOnSuitMemory(suitSavedData);
  98. }
  99. private void OnBtnSloganClick()
  100. {
  101. _ui.m_grpSlogan.visible = !_ui.m_grpSlogan.visible;
  102. }
  103. private void OnBtnDeleteClick()
  104. {
  105. AlertUI.Show("是否删除好友?").SetLeftButton(true).SetRightButton(true, "确定", (object data) =>
  106. {
  107. });
  108. }
  109. private void OnBtnAddClick()
  110. {
  111. ViewManager.Show<FriendAddView>();
  112. }
  113. }
  114. }