| using System.Collections; | 
| using System.Collections.Generic; | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
|   | 
| /// <summary> | 
| /// 加入公会界面 :公会查找列表,也是排行榜 | 
| /// </summary> | 
| public class GuildJoinWin : UIBase | 
| { | 
|     [SerializeField] InputField findText; | 
|     [SerializeField] Button findBtn; | 
|     [SerializeField] Button createGuildBtn; | 
|     [SerializeField] Button quicklyJoinGuildBtn; | 
|     [SerializeField] ScrollerController guildListScroller; | 
|     [SerializeField] Transform noGuildTf; | 
|   | 
|     string lastQuery = ""; | 
|     int lastPage = 0; | 
|     protected override void InitComponent() | 
|     { | 
|         findBtn.AddListener(() => OnFindBtnClick()); | 
|         createGuildBtn.AddListener(OnCreateGuildBtnClick); | 
|         quicklyJoinGuildBtn.AddListener(OnQuicklyJoinGuildBtnClick); | 
|     } | 
|     protected override void OnPreOpen() | 
|     { | 
|         findText.text = ""; | 
|         //打开界面默认请求,滚动的时候需要处理页数 | 
|         QueryGuild(); | 
|         GuildManager.Instance.OnRefreshFairyList += OnRefreshGuildList; | 
|         GuildManager.Instance.MyRequestJoinEvent += MyRequestJoinEvent; | 
|         PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo; | 
|         guildListScroller.OnRefreshCell += RefreshCell; | 
|         Display(); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         GuildManager.Instance.OnRefreshFairyList -= OnRefreshGuildList; | 
|         GuildManager.Instance.MyRequestJoinEvent -= MyRequestJoinEvent; | 
|         guildListScroller.OnRefreshCell -= RefreshCell; | 
|         PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo; | 
|   | 
|         UIManager.Instance.GetUI<MainWin>()?.RestoreFuncBtn(); | 
|   | 
|     } | 
|   | 
|     void OnRefreshFairyInfo() | 
|     { | 
|         //当前界面下有刷新自家的公会数据,说明一定是加入了公会,需主动跳转到公会界面 | 
|         CloseWindow(); | 
|         UIManager.Instance.GetUI<MainWin>()?.ClickFunc(4); | 
|     } | 
|   | 
|     void Display() | 
|     { | 
|         CreateScroller(); | 
|     } | 
|   | 
|     void MyRequestJoinEvent() | 
|     { | 
|         guildListScroller.m_Scorller.RefreshActiveCellViews(); | 
|     } | 
|   | 
|      | 
|     //列表变小的话 重新创建;列表变大的话,只添加 | 
|     void CreateScroller() | 
|     { | 
|         if (GuildManager.Instance.pageIndexList.Count == 0) | 
|         { | 
|             noGuildTf.SetActive(true); | 
|             guildListScroller.SetActive(false); | 
|             return; | 
|         } | 
|         noGuildTf.SetActive(false); | 
|         guildListScroller.SetActive(true); | 
|   | 
|         var startCount = guildListScroller.GetNumberOfCells(); | 
|         if (startCount > GuildManager.Instance.pageIndexList.Count) | 
|         { | 
|             guildListScroller.Refresh(); | 
|         } | 
|         for (int i = startCount; i < GuildManager.Instance.pageIndexList.Count; i++) | 
|         { | 
|             guildListScroller.AddCell(ScrollerDataType.Header, i); | 
|         } | 
|         guildListScroller.Restart(); | 
|     } | 
|   | 
|   | 
|   | 
|     void OnRefreshGuildList() | 
|     { | 
|         CreateScroller(); | 
|     } | 
|   | 
|     void RefreshCell(ScrollerDataType type, CellView cell) | 
|     { | 
|         var _cell = cell.GetComponent<GuildViewListCell>(); | 
|         _cell.Display(cell.index); | 
|     } | 
|   | 
|     private void OnFindBtnClick() | 
|     { | 
|         var nowQuery = findText.text; | 
|         if (string.IsNullOrEmpty(nowQuery) && string.IsNullOrEmpty(lastQuery)) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("GuildSys5"); | 
|             return; | 
|         } | 
|         if (nowQuery.Length < 2 && nowQuery.Length > 0) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("GuildSys7"); | 
|             return; | 
|         } | 
|   | 
|         lastQuery = nowQuery; | 
|         lastPage = 0; | 
|         guildListScroller.Refresh(); | 
|         GuildManager.Instance.SendFindGuild(lastQuery); | 
|     } | 
|   | 
|   | 
|     void QueryGuild() | 
|     { | 
|         lastQuery = ""; | 
|         lastPage = 0; | 
|         guildListScroller.Refresh(); | 
|         GuildManager.Instance.SendFindGuild(lastQuery); | 
|     } | 
|   | 
|     private void OnCreateGuildBtnClick() | 
|     { | 
|         UIManager.Instance.OpenWindow<GuildCreateWin>(); | 
|     } | 
|   | 
|     private void OnQuicklyJoinGuildBtnClick() | 
|     { | 
|         if (GuildManager.Instance.pageIndexList.Count == 0) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("QuickEnterFamilyFail"); | 
|             return; | 
|         } | 
|         GuildManager.Instance.SendApplyGuild(0, 0); | 
|   | 
|     } | 
|   | 
| } |