using System; 
 | 
using System.Collections.Generic; 
 | 
using System.Linq; 
 | 
using Cysharp.Threading.Tasks; 
 | 
using UnityEngine; 
 | 
using UnityEngine.UI; 
 | 
  
 | 
  
 | 
/// <summary> 
 | 
/// 淘金派遣总管理 
 | 
/// </summary> 
 | 
public class GoldRushWorkerWin : UIBase 
 | 
{ 
 | 
    [SerializeField] GroupButtonEx workMgrBtn; //派遣管理 
 | 
    [SerializeField] GroupButtonEx workersBtn;  //监工人员管理 
 | 
  
 | 
    [SerializeField] Transform workMgrRect; 
 | 
    [SerializeField] Transform workersRect; 
 | 
  
 | 
    //派遣管理 
 | 
    [SerializeField] ScrollerController workMgrScroller; 
 | 
    [SerializeField] Transform workMgrEmpty; 
 | 
    [SerializeField] Text lazyWorkerCntText;    //空闲监工数量 
 | 
    [SerializeField] Text warehouseCntText;     //仓库数量 
 | 
    [SerializeField] Button getAllAwardBtn; 
 | 
  
 | 
    //监工人员管理 
 | 
    [SerializeField] ScrollerController workersScroller; 
 | 
    [SerializeField] Text unlockWorkerCntText;  //解锁监工数量 
 | 
    [SerializeField] Text totalWorkFinishCount; //淘金完成总次数 
 | 
  
 | 
    [NonSerialized] public List<int> goldRushMissionList = new List<int>(); 
 | 
  
 | 
    protected override void InitComponent() 
 | 
    { 
 | 
        workMgrBtn.AddListener(OnWorkMgrBtnClick); 
 | 
        workersBtn.AddListener(OnWorkerBtnClick); 
 | 
        getAllAwardBtn.AddListener(GetAllAward); 
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
    protected override void OnPreOpen() 
 | 
    { 
 | 
         
 | 
        CreateWorkersScroller(); 
 | 
        GoldRushManager.Instance.OnGoldRushCampEvent += OnGoldRushCampEvent; 
 | 
        GoldRushManager.Instance.OnGoldRushInfoEvent += OnGoldRushInfoEvent; 
 | 
        workMgrScroller.OnRefreshCell += OnRefreshWorkMgrCell; 
 | 
        workersScroller.OnRefreshCell += OnRefreshWorkersCell; 
 | 
        GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; 
 | 
        PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent; 
 | 
  
 | 
        if (functionOrder == 0) 
 | 
        { 
 | 
            workMgrBtn.SelectBtn(); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            workersBtn.SelectBtn(); 
 | 
        } 
 | 
        Display(); 
 | 
    } 
 | 
  
 | 
    protected override void OnPreClose() 
 | 
    { 
 | 
        GoldRushManager.Instance.OnGoldRushCampEvent -= OnGoldRushCampEvent; 
 | 
        GoldRushManager.Instance.OnGoldRushInfoEvent -= OnGoldRushInfoEvent; 
 | 
        workMgrScroller.OnRefreshCell -= OnRefreshWorkMgrCell; 
 | 
        workersScroller.OnRefreshCell -= OnRefreshWorkersCell; 
 | 
        GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; 
 | 
        PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent; 
 | 
    } 
 | 
  
 | 
  
 | 
    void OnPlayerDataRefreshEvent(PlayerDataType type) 
 | 
    { 
 | 
        if (type == GoldRushManager.Instance.unLockMoneyType) 
 | 
        { 
 | 
            workersScroller.m_Scorller.RefreshActiveCellViews(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    void Display() 
 | 
    { 
 | 
        if (functionOrder == 0) 
 | 
        { 
 | 
            RefreshWorkingList(); 
 | 
            CreateManagerScroller(); 
 | 
            DispalyWorkMgr(); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            DispalyWorkers(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    //派遣中管理 
 | 
    void DispalyWorkMgr() 
 | 
    { 
 | 
        workMgrRect.SetActive(true); 
 | 
        workersRect.SetActive(false); 
 | 
  
 | 
        int workingCnt = GoldRushManager.Instance.GetWarehouseCnt(); 
 | 
        if (workingCnt == 0) 
 | 
        { 
 | 
            workMgrScroller.SetActive(false); 
 | 
            workMgrEmpty.SetActive(true); 
 | 
            getAllAwardBtn.SetActive(false); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            workMgrScroller.SetActive(true); 
 | 
            workMgrEmpty.SetActive(false); 
 | 
            getAllAwardBtn.SetActive(true); 
 | 
        } 
 | 
        lazyWorkerCntText.text = Language.Get("GoldRush20") + GoldRushManager.Instance.GetEmptyWorkerCount() + "/" + GoldRushManager.Instance.maxWorkerCount; 
 | 
        warehouseCntText.text = Language.Get("GoldRush21") + workingCnt + "/" + GoldRushManager.Instance.warehouseMaxCnt; 
 | 
  
 | 
        workMgrScroller.m_Scorller.RefreshActiveCellViews(); 
 | 
    } 
 | 
  
 | 
  
 | 
    //派遣中的队列 + 完成的队列,动态变化的 
 | 
    void CreateManagerScroller() 
 | 
    { 
 | 
        if (workMgrScroller.GetNumberOfCells(workMgrScroller.m_Scorller) == goldRushMissionList.Count) 
 | 
            return; 
 | 
         
 | 
        workMgrScroller.Refresh(); 
 | 
        for (int i = 0; i < goldRushMissionList.Count; ++i) 
 | 
        { 
 | 
            workMgrScroller.AddCell(ScrollerDataType.Header, i); 
 | 
        } 
 | 
        workMgrScroller.Restart(); 
 | 
    } 
 | 
  
 | 
  
 | 
     
 | 
    //派遣中的队列 + 完成的队列,动态变化的 
 | 
    //ID组成 
 | 
    // 派遣中类型1*100000 + campid*100 + 0 
 | 
    // 完成类型2*100000 + goldid*100 + 索引 
 | 
    void RefreshWorkingList() 
 | 
    { 
 | 
        goldRushMissionList.Clear(); 
 | 
        var keys = GoldRushManager.Instance.campInfoDict.Keys.ToList(); 
 | 
  
 | 
        for (int i = 0; i < keys.Count; i++) 
 | 
        { 
 | 
            var campInfo = GoldRushManager.Instance.campInfoDict[keys[i]]; 
 | 
            if (campInfo.GoldID == 0 || campInfo.EndTime == 0) 
 | 
            { 
 | 
                continue; 
 | 
            } 
 | 
  
 | 
            goldRushMissionList.Add(100000 * 1 + campInfo.CampID * 100 + 0); 
 | 
        } 
 | 
  
 | 
        for (int i = 0; i < GoldRushManager.Instance.warehouseIDList.Length; i++) 
 | 
        { 
 | 
            if (GoldRushManager.Instance.warehouseIDList[i] == 0) 
 | 
            { 
 | 
                continue; 
 | 
            } 
 | 
            goldRushMissionList.Add(100000 * 2 + GoldRushManager.Instance.warehouseIDList[i] * 100 + i); 
 | 
        } 
 | 
         
 | 
    } 
 | 
  
 | 
  
 | 
    void OnRefreshWorkMgrCell(ScrollerDataType type, CellView cell) 
 | 
    { 
 | 
        var _cell = cell as GoldRushWorkCell; 
 | 
  
 | 
        if (cell.index >= goldRushMissionList.Count) 
 | 
        { 
 | 
            _cell.Display(-1); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            _cell.Display(goldRushMissionList[cell.index]); 
 | 
        } 
 | 
  
 | 
    } 
 | 
  
 | 
    void OnSecondEvent() 
 | 
    { 
 | 
        if (functionOrder == 0) 
 | 
        {  
 | 
            workMgrScroller.m_Scorller.RefreshActiveCellViews(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    void DispalyWorkers() 
 | 
    { 
 | 
        workMgrRect.SetActive(false); 
 | 
        workersRect.SetActive(true); 
 | 
  
 | 
        unlockWorkerCntText.text = Language.Get("GoldRush39") + GoldRushManager.Instance.maxWorkerCount + "/" + GoldRushManager.Instance.m_MaxWorkerCount; 
 | 
        totalWorkFinishCount.text = Language.Get("GoldRush40") + GoldRushManager.Instance.panningCnt; 
 | 
        workersScroller.m_Scorller.RefreshActiveCellViews(); 
 | 
    } 
 | 
  
 | 
  
 | 
    void CreateWorkersScroller() 
 | 
    { 
 | 
        workersScroller.Refresh(); 
 | 
        var keys = GoldRushWorkerConfig.GetKeys().ToList(); 
 | 
        for (int i = 0; i < keys.Count; ++i) 
 | 
        { 
 | 
            workersScroller.AddCell(ScrollerDataType.Header, keys[i]); 
 | 
        } 
 | 
        workersScroller.Restart(); 
 | 
    } 
 | 
  
 | 
    void OnRefreshWorkersCell(ScrollerDataType type, CellView cell) 
 | 
    { 
 | 
        var _cell = cell as GoldRushWorkerCell; 
 | 
        _cell.Display(cell.index); 
 | 
    } 
 | 
  
 | 
    void OnWorkMgrBtnClick() 
 | 
    { 
 | 
        functionOrder = 0; 
 | 
        Display(); 
 | 
    } 
 | 
  
 | 
    void OnWorkerBtnClick() 
 | 
    { 
 | 
        functionOrder = 1; 
 | 
        Display(); 
 | 
    } 
 | 
  
 | 
    void GetAllAward() 
 | 
    { 
 | 
        if (GoldRushManager.Instance.GetFinishGoldRushCount() == 0) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
        GoldRushManager.Instance.SendGoldRushWarehouseAward(0, 1); 
 | 
    } 
 | 
  
 | 
    void OnGoldRushCampEvent(int campID) 
 | 
    { 
 | 
        Display(); 
 | 
    } 
 | 
  
 | 
    void OnGoldRushInfoEvent() 
 | 
    { 
 | 
        Display(); 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |