FriendView.cs 11 KB

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