LeagueJoinView.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.League;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. //申请加入联盟
  9. public class LeagueJoinView : BaseWindow
  10. {
  11. private UI_LeagueJoinUI _ui;
  12. private List<long> _leagueIds;
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. packageName = UI_LeagueJoinUI.PACKAGE_NAME;
  26. _ui = UI_LeagueJoinUI.Create();
  27. this.viewCom = _ui.target;
  28. isfullScreen = true;
  29. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("lm_beijing");
  30. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  31. _ui.m_btnSearch.onClick.Add(OnBtnSearchClick);
  32. _ui.m_btnChange.onClick.Add(OnBtnChangeClick);
  33. _ui.m_btnCreat.onClick.Add(OnBtnCreatClick);
  34. _ui.m_txtSearch.onFocusOut.Add(OnFocuseOut);
  35. _ui.m_list.itemRenderer = RenderListItem;
  36. }
  37. protected override void AddEventListener()
  38. {
  39. base.AddEventListener();
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. _leagueIds = new List<long>(LeagueDataManager.Instance.ListDatas.Keys);
  45. _ui.m_list.numItems = _leagueIds.Count;
  46. }
  47. protected override void OnHide()
  48. {
  49. base.OnHide();
  50. }
  51. protected override void RemoveEventListener()
  52. {
  53. base.RemoveEventListener();
  54. }
  55. private void OnBtnBackClick()
  56. {
  57. ViewManager.GoBackFrom(typeof(LeagueJoinView).FullName);
  58. }
  59. private void OnBtnSearchClick()
  60. {
  61. ReqLeagueList(_ui.m_txtSearch.text);
  62. }
  63. private void OnBtnChangeClick()
  64. {
  65. ReqLeagueList("");
  66. }
  67. private void OnFocuseOut()
  68. {
  69. if (string.IsNullOrEmpty(_ui.m_txtSearch.text))
  70. {
  71. ReqLeagueList("");
  72. }
  73. }
  74. private void OnBtnCreatClick()
  75. {
  76. ViewManager.Show<LeagueCreatView>(null, new object[] { typeof(LeagueJoinView).FullName, null });
  77. }
  78. private async void ReqLeagueList(string leagueName)
  79. {
  80. bool result = await LeagueSproxy.ReqSearchLeagueInfo(leagueName);
  81. if (result)
  82. {
  83. _leagueIds = new List<long>(LeagueDataManager.Instance.ListDatas.Keys);
  84. _ui.m_list.numItems = _leagueIds.Count;
  85. }
  86. }
  87. private void RenderListItem(int index, GObject obj)
  88. {
  89. LeagueListData leagueListData = LeagueDataManager.Instance.ListDatas[_leagueIds[index]];
  90. UI_ListJoinItem item = UI_ListJoinItem.Proxy(obj);
  91. item.m_comLeagueHead.m_loaUnionIcon.url = ResPathUtil.GetLeagueIconPath(leagueListData.Icon);
  92. item.m_comLeagueHead.m_txtUnionLv.text = leagueListData.Level.ToString();
  93. item.m_txtLeagueName.text = leagueListData.Name;
  94. item.m_imgAd.visible = leagueListData.IsAd;
  95. item.m_txtMemberCount.SetVar("value", leagueListData.Num.ToString()).FlushVars();
  96. item.m_txtMemberCount.SetVar("maxValue", leagueListData.MaxNum.ToString()).FlushVars();
  97. item.m_txtCheck.text = leagueListData.NeedAudit ? "是" : "否";
  98. item.m_btnJoin.title = "申请";
  99. if (item.m_btnJoin.data == null)
  100. {
  101. item.m_btnJoin.onClick.Add(OnBtnJoinClick);
  102. }
  103. item.m_btnJoin.data = leagueListData.LeagueId;
  104. UI_ListJoinItem.ProxyEnd();
  105. }
  106. private async void OnBtnJoinClick(EventContext context)
  107. {
  108. GButton obj = context.sender as GButton;
  109. long leagueId = (long)obj.data;
  110. LeagueListData listData = LeagueDataManager.Instance.ListDatas[leagueId];
  111. if (listData.Num == listData.MaxNum)
  112. {
  113. PromptController.Instance.ShowFloatTextPrompt("雅集满员啦,换个雅集申请吧");
  114. return;
  115. }
  116. if (LeagueDataManager.Instance.ListDatas[leagueId].NeedAudit)
  117. {
  118. AlertUI.Show("该雅集需要审批同意后才可加入,是否仍需要申请?").
  119. SetLeftButton(true, "取消").
  120. SetRightButton(true, "申请", async (object param) =>
  121. {
  122. bool result = await LeagueSproxy.ReqJoinLeague(leagueId);
  123. if (result)
  124. {
  125. obj.title = "已申请";
  126. }
  127. });
  128. }
  129. else
  130. {
  131. bool result = await LeagueSproxy.ReqJoinLeague(leagueId);
  132. if (result)
  133. {
  134. OnBtnBackClick();
  135. ViewManager.Show<LeagueView>(null, new object[] { typeof(MainUIView).FullName, null });
  136. }
  137. }
  138. }
  139. }
  140. }