FriendView.cs 10 KB

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