using System.Collections.Generic; 
 | 
using UnityEngine; 
 | 
using UnityEngine.UI; 
 | 
  
 | 
  
 | 
//淘金中信息列表显示 
 | 
public class GoldRushWorkCell : CellView 
 | 
{ 
 | 
    [SerializeField] Transform _cell; 
 | 
    [SerializeField] ItemCell itemCell; 
 | 
    [SerializeField] Text nameText; 
 | 
    [SerializeField] Text timeText; 
 | 
    [SerializeField] Slider slider; 
 | 
    [SerializeField] UIHeroController[] heroModels; 
 | 
    [SerializeField] CountControler countControler; 
 | 
    [SerializeField] Button awardBtn; 
 | 
  
 | 
    GoldRushItemConfig config; 
 | 
    int campID; 
 | 
    //派遣中的队列 + 完成的队列,动态变化的 
 | 
    //ID组成 
 | 
    // 派遣中类型1*100000 + campid*100 + 0 
 | 
    // 完成类型2*100000 + goldid*100 + 索引 
 | 
    public void Display(int missionID) 
 | 
    { 
 | 
        if (missionID == -1) 
 | 
        {  
 | 
            _cell.SetActive(false); 
 | 
            return; 
 | 
        } 
 | 
        _cell.SetActive(true); 
 | 
        int type = missionID / 100000; 
 | 
        int targetID = missionID / 100 % 1000; 
 | 
        int index = missionID % 100; 
 | 
  
 | 
        campID = 0; 
 | 
        int goldID = targetID; 
 | 
  
 | 
        if (type == 1) 
 | 
        { 
 | 
            campID = targetID; 
 | 
            goldID = GoldRushManager.Instance.GetCampGoldID(campID); 
 | 
        } 
 | 
        if (goldID == 0) 
 | 
        { 
 | 
            this.SetActive(false); 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        config = GoldRushItemConfig.Get(goldID); 
 | 
        int itemID = config.ItemID; 
 | 
        itemCell.Init(new ItemCellModel(itemID, false, config.ItemCount)); 
 | 
        itemCell.button.AddListener(()=> 
 | 
        { 
 | 
            ItemTipUtility.Show(itemID); 
 | 
        }); 
 | 
  
 | 
        nameText.text = GoldRushManager.Instance.GetCampItemName(config); 
 | 
        var endTime = GoldRushManager.Instance.GetCampEndTime(campID); 
 | 
  
 | 
        if (type == 1) 
 | 
        { 
 | 
            if (endTime != 0) 
 | 
            { 
 | 
                timeText.text = TimeUtility.SecondsToHMS(endTime - TimeUtility.AllSeconds); 
 | 
                //按原总时长当进度条 
 | 
                slider.value = (config.NeedSeconds - (endTime - TimeUtility.AllSeconds)) / (float)config.NeedSeconds; 
 | 
            } 
 | 
            countControler.SetActive(true);//此处调整+/-会实时发包 
 | 
            countControler.Init(ChangeWorkerCount, config.WorkerMax, GoldRushManager.Instance.GetCampWorkerCnt(campID), AddWorker, DecWorker); 
 | 
            awardBtn.SetActive(false); 
 | 
            var workCnt = GoldRushManager.Instance.GetCampWorkerCnt(campID); 
 | 
            int skinCnt = GoldRushManager.Instance.skinIDs.Count; 
 | 
            for (int i = 0; i < heroModels.Length; i++) 
 | 
            { 
 | 
                if (i < workCnt) 
 | 
                { 
 | 
                    heroModels[i].SetActive(true); 
 | 
                    var skinID = GoldRushManager.Instance.GetWorkerSkinID(campID, i); 
 | 
                    heroModels[i].Create(skinID, 0.6f, motionName:"run"); 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    heroModels[i].SetActive(false); 
 | 
                } 
 | 
            } 
 | 
  
 | 
        } 
 | 
        else if (type == 2) 
 | 
        { 
 | 
            countControler.SetActive(false); 
 | 
            awardBtn.SetActive(true); 
 | 
            timeText.text = Language.Get("L1036"); 
 | 
            slider.value = slider.maxValue; 
 | 
  
 | 
            awardBtn.AddListener(() => 
 | 
            { 
 | 
                GoldRushManager.Instance.SendGoldRushWarehouseAward(index, 0); 
 | 
            }); 
 | 
        } 
 | 
             
 | 
  
 | 
    } 
 | 
  
 | 
  
 | 
    void ChangeWorkerCount(int count) 
 | 
    { 
 | 
        //重新调整监工 
 | 
        AssignWorker(count); 
 | 
    } 
 | 
  
 | 
    bool AddWorker(int count) 
 | 
    { 
 | 
        if (count >= config.WorkerMax) 
 | 
        { 
 | 
            return false; 
 | 
        } 
 | 
  
 | 
        //可派遣的监工: 空闲监工数+当前监工数 
 | 
        if (count + 1 > GoldRushManager.Instance.GetEmptyWorkerCount() + GoldRushManager.Instance.GetCampWorkerCnt(campID)) 
 | 
        {  
 | 
            SysNotifyMgr.Instance.ShowTip("GoldRush2"); 
 | 
            return false; 
 | 
        } 
 | 
  
 | 
        return true; 
 | 
    } 
 | 
  
 | 
    bool DecWorker(int count) 
 | 
    { 
 | 
        if (count <= 1) 
 | 
        {  
 | 
            ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), 
 | 
            Language.Get("GoldRush38"), (bool isOK) => 
 | 
                { 
 | 
                    if (isOK) 
 | 
                    { 
 | 
                        //撤回监工 
 | 
                        GoldRushManager.Instance.SendGoldRushOP(3, campID, 0); 
 | 
                    } 
 | 
                }); 
 | 
            return false; 
 | 
        } 
 | 
        return true; 
 | 
    } 
 | 
  
 | 
    void AssignWorker(int workerCount) 
 | 
    { 
 | 
        if (workerCount == 0) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        if (workerCount > config.WorkerMax) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        if (workerCount == GoldRushManager.Instance.GetCampWorkerCnt(campID)) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        GoldRushManager.Instance.SendGoldRushOP(2, campID, workerCount); 
 | 
        SysNotifyMgr.Instance.ShowTip("GoldRush1"); 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |