FriendView.cs 11 KB

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