FriendView.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. private FriendInfoData _curSelectedInfo;
  12. public override void Dispose()
  13. {
  14. if (_sceneObject != null)
  15. {
  16. GameObject.Destroy(_sceneObject);
  17. _sceneObject = null;
  18. }
  19. if (_ui != null)
  20. {
  21. _ui.Dispose();
  22. _ui = null;
  23. }
  24. base.Dispose();
  25. }
  26. protected override void Init()
  27. {
  28. base.Init();
  29. packageName = UI_FriendUI.PACKAGE_NAME;
  30. _ui = UI_FriendUI.Create();
  31. viewCom = _ui.target;
  32. isfullScreen = true;
  33. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFriend"));
  34. _ui.m_list.SetVirtual();
  35. _ui.m_list.itemRenderer = RenderListItem;
  36. _ui.m_list.onClickItem.Add(OnListItemClick);
  37. _ui.m_btnSolgan.onClick.Add(OnBtnSloganClick);
  38. _ui.m_btnDelete.onClick.Add(OnBtnDeleteClick);
  39. _ui.m_btnAdd.onClick.Add(OnBtnAddClick);
  40. _ui.m_btnSendAll.onClick.Add(OnBtnSendAllClick);
  41. }
  42. protected override void OnInit()
  43. {
  44. base.OnInit();
  45. _ui.m_btnBack.onClick.Add(OnHide);
  46. }
  47. protected override void AddEventListener()
  48. {
  49. base.AddEventListener();
  50. EventAgent.AddEventListener(ConstMessage.FRIEND_REFRESH, RefreshView);
  51. EventAgent.AddEventListener(ConstMessage.FRIEND_REMOVE, RefreshRemoveFriend);
  52. EventAgent.AddEventListener(ConstMessage.FRIEND_ADD, RefreshAddFriend);
  53. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdaterRed);
  54. }
  55. protected override void OnShown()
  56. {
  57. base.OnShown();
  58. if (_sceneObject == null)
  59. {
  60. _sceneObject = GameObject.Instantiate(_scenePrefab);
  61. EquipDataCache.cacher.setSceneObj(_sceneObject);
  62. }
  63. _ui.m_grpSlogan.visible = false;
  64. _ui.m_list.numItems = FriendDataManager.Instance.FriendDatas.Count;
  65. if (_ui.m_list.numItems > 0)
  66. {
  67. _ui.m_list.selectedIndex = 0;
  68. ReqFriendDetialInfo(0);
  69. }
  70. else
  71. {
  72. ReqFriendDetialInfo(-1);
  73. }
  74. RefreshView();
  75. UpdaterRed();
  76. }
  77. protected override void OnHide()
  78. {
  79. if (_sceneObject != null)
  80. {
  81. GameObject.Destroy(_sceneObject);
  82. _sceneObject = null;
  83. }
  84. _ui.m_list.numItems = 0;
  85. ViewManager.GoBackFrom(typeof(FriendView).FullName);
  86. }
  87. protected override void RemoveEventListener()
  88. {
  89. base.RemoveEventListener();
  90. EventAgent.RemoveEventListener(ConstMessage.FRIEND_REFRESH, RefreshView);
  91. EventAgent.RemoveEventListener(ConstMessage.FRIEND_REMOVE, RefreshRemoveFriend);
  92. EventAgent.RemoveEventListener(ConstMessage.FRIEND_ADD, RefreshAddFriend);
  93. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdaterRed);
  94. }
  95. private void RefreshView()
  96. {
  97. _ui.m_list.RefreshVirtualList();
  98. _ui.m_txtCount.text = string.Format("好友数:{0}/{1}", _ui.m_list.numItems, GlobalCfgArray.globalCfg.maxFriendCount);
  99. _ui.m_btnSendAll.text = RedDotDataManager.Instance.GetFriendGiftRed() ? "一键领取并赠送" : "一键赠送";
  100. }
  101. private void RenderListItem(int index, GObject obj)
  102. {
  103. FriendInfoData friendInfo = FriendDataManager.Instance.FriendDatas[index];
  104. UI_ListItem item = UI_ListItem.Proxy(obj);
  105. item.m_txtName.text = friendInfo.roleInfo.roleName;
  106. item.m_txtLvl.text = friendInfo.roleInfo.roleLv.ToString();
  107. item.m_c2.selectedIndex = friendInfo.roleInfo.offlineTimeSec == 0 ? 0 : 1;
  108. item.m_c1.selectedIndex = FriendDataManager.Instance.GetGiftState(friendInfo.roleInfo.roleId);
  109. if (item.m_btnSend.data == null)
  110. {
  111. item.m_btnSend.onClick.Add(OnClickBtnSend);
  112. }
  113. item.m_btnSend.data = friendInfo;
  114. item.target.data = index;
  115. UI_ListItem.ProxyEnd();
  116. }
  117. private void OnClickBtnSend(EventContext context)
  118. {
  119. GObject item = context.data as GObject;
  120. FriendInfoData friendInfo = item.data as FriendInfoData;
  121. if (friendInfo.takeGiftState == ConstBonusStatus.CAN_GET)
  122. {
  123. if (FriendDataManager.Instance.Count >= GlobalCfgArray.globalCfg.maxGetPowerCount)
  124. {
  125. PromptController.Instance.ShowFloatTextPrompt("今日体力已全部领取");
  126. return;
  127. }
  128. FriendSProxy.ReqTakeGiftFromFriend(friendInfo.roleInfo.roleId).Coroutine();
  129. }
  130. else if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.CanGave)
  131. {
  132. FriendSProxy.ReqGiveGiftToFriend(friendInfo.roleInfo.roleId).Coroutine();
  133. }
  134. }
  135. private void OnListItemClick(EventContext context)
  136. {
  137. GObject item = context.data as GObject;
  138. int index = (int)item.data;
  139. ReqFriendDetialInfo(index);
  140. }
  141. private void OnBtnSendAllClick()
  142. {
  143. if (RedDotDataManager.Instance.GetFriendGiftRed() && FriendDataManager.Instance.Count < GlobalCfgArray.globalCfg.maxGetPowerCount)
  144. {
  145. FriendSProxy.ReqTakeGiftFromAllFriend().Coroutine();
  146. }
  147. else
  148. {
  149. FriendSProxy.ReqGiveGiftToAllFriend().Coroutine();
  150. }
  151. }
  152. private void OnBtnDeleteClick()
  153. {
  154. if (_ui.m_list.numItems == 0)
  155. {
  156. PromptController.Instance.ShowFloatTextPrompt("暂无好友可删除");
  157. return;
  158. }
  159. AlertUI.Show("是否删除好友?").SetLeftButton(true).SetRightButton(true, "确定", (object data) =>
  160. {
  161. int index = _ui.m_list.selectedIndex;
  162. long roleId = FriendDataManager.Instance.FriendDatas[index].roleInfo.roleId;
  163. FriendSProxy.ReqDeleteFriend(roleId).Coroutine();
  164. });
  165. }
  166. private void RefreshRemoveFriend()
  167. {
  168. int index = _ui.m_list.selectedIndex;
  169. _ui.m_list.numItems = FriendDataManager.Instance.FriendDatas.Count;
  170. if (FriendDataManager.Instance.FriendDatas.Count > 0)
  171. {
  172. if (index >= FriendDataManager.Instance.FriendDatas.Count)
  173. {
  174. index = FriendDataManager.Instance.FriendDatas.Count - 1;//选中最后一个
  175. }
  176. _ui.m_list.selectedIndex = index;
  177. }
  178. else
  179. {
  180. index = -1;//无好友
  181. }
  182. ReqFriendDetialInfo(index);
  183. _ui.m_txtCount.text = string.Format("好友数:{0}/{1}", _ui.m_list.numItems, GlobalCfgArray.globalCfg.maxFriendCount);
  184. }
  185. private void RefreshAddFriend()
  186. {
  187. int selectedIndex = 0;
  188. if (_ui.m_list.numItems > 0)
  189. {
  190. int childIndex = _ui.m_list.ItemIndexToChildIndex(_ui.m_list.selectedIndex);
  191. GButton item = _ui.m_list.GetChildAt(childIndex).asButton.GetChild("btnSend").asButton;
  192. FriendInfoData friendInfo = item.data as FriendInfoData;
  193. selectedIndex = FriendDataManager.Instance.FriendDatas.IndexOf(friendInfo);
  194. }
  195. _ui.m_list.numItems = FriendDataManager.Instance.FriendDatas.Count;
  196. _ui.m_list.selectedIndex = selectedIndex;
  197. ReqFriendDetialInfo(selectedIndex);
  198. _ui.m_txtCount.text = string.Format("好友数:{0}/{1}", _ui.m_list.numItems, GlobalCfgArray.globalCfg.maxFriendCount);
  199. }
  200. private async void ReqFriendDetialInfo(int index)
  201. {
  202. if (index >= 0)
  203. {
  204. long roleId = FriendDataManager.Instance.FriendDatas[index].roleInfo.roleId;
  205. RoleInfoDetailData roleInfoDetail = await FriendSProxy.ReqOtherRoleDetailInfo(roleId);
  206. if (roleInfoDetail != null)
  207. {
  208. UpdateScene(roleInfoDetail.customSuitData);
  209. _ui.m_txtSlogan.text = string.IsNullOrEmpty(roleInfoDetail.slogan) ? "暂无简介" : roleInfoDetail.slogan;
  210. }
  211. }
  212. else
  213. {
  214. CustomSuitData customSuit = CustomSuitDataManager.GetSuitList(CustomSuitDataManager.currentIndex);
  215. UpdateScene(customSuit);
  216. _ui.m_txtSlogan.text = string.IsNullOrEmpty(RoleDataManager.slogan) ? "暂无简介" : RoleDataManager.slogan;
  217. }
  218. }
  219. private void UpdateScene(CustomSuitData suitSavedData)
  220. {
  221. if (suitSavedData != null)
  222. {
  223. EquipDataCache.cacher.PutOnSuitMemory(suitSavedData);
  224. _ui.m_txtName.text = string.Format("我的套装{0}", NumberUtil.GetChiniseNumberText(suitSavedData.pos + 1));
  225. }
  226. else
  227. {
  228. EquipDataCache.cacher.PutOnDefaultSuitSaved();
  229. _ui.m_txtName.text = string.Format("我的套装{0}", NumberUtil.GetChiniseNumberText(1));
  230. }
  231. }
  232. private void OnBtnSloganClick()
  233. {
  234. _ui.m_grpSlogan.visible = !_ui.m_grpSlogan.visible;
  235. }
  236. private void OnBtnAddClick()
  237. {
  238. ViewManager.Show<FriendAddView>();
  239. }
  240. private void UpdaterRed()
  241. {
  242. RedDotController.Instance.SetComRedDot(_ui.m_btnAdd, RedDotDataManager.Instance.GetFriendApplyRed());
  243. RedDotController.Instance.SetComRedDot(_ui.m_btnSendAll, RedDotDataManager.Instance.GetFriendGiftRed());
  244. }
  245. }
  246. }