LeagueJoinView.cs 5.0 KB

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