require("Base/BasePanel") EnergyDetails = Inherit(BasePanel) local this = EnergyDetails local BaseResourceConfig = ConfigManager.GetConfig(ConfigName.BaseResourceConfig) local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local selectNum = 0 local timer = nil local selectPos, curData, curPlayerId, changeData function this:InitComponent() this.mask = Util.GetGameObject(this.gameObject, "mask") this.btnBack = Util.GetGameObject(this.gameObject, "btnBack") this.btnReduce = Util.GetGameObject(this.gameObject, "btnReduce") this.btnAdd = Util.GetGameObject(this.gameObject, "btnAdd") this.btnMax = Util.GetGameObject(this.gameObject, "btnMax") this.fight = Util.GetGameObject(this.gameObject, "fight") this.limit = Util.GetGameObject(this.gameObject, "limit"):GetComponent("Text") this.obtain = Util.GetGameObject(this.gameObject, "obtain"):GetComponent("Text") this.reward = Util.GetGameObject(this.gameObject, "reward"):GetComponent("Image") this.btnDispatch = Util.GetGameObject(this.gameObject, "btnDispatch") this.changeTime = Util.GetGameObject(this.gameObject, "time"):GetComponent("Text") this.time = Util.GetGameObject(this.fight, "obtain/time"):GetComponent("Text") end function this:BindEvent() Util.AddClick(this.mask, function() self:ClosePanel() end) Util.AddClick(this.btnBack, function() self:ClosePanel() end) Util.AddClick(this.btnDispatch, function() EnergyBaseManager.BaseCoolieDispatch(selectPos, curPlayerId, selectNum, function () self:ClosePanel() end, {itemID = this.itemID, itemNum = this.itemNum, itemTime = this.itemTime}) end) Util.AddClick(this.btnReduce, function() selectNum = selectNum - 1 if selectNum < 0 then selectNum = 0 end this.SetTime() this.SetCount() end) Util.AddClick(this.btnAdd, function() selectNum = selectNum + 1 local baseInfo = EnergyBaseManager.GetBaseInfo() local config = BaseResourceConfig[curData.resourceId] local num = 0 if curPlayerId == PlayerManager.uid then num = curData.collieCount else num = curData.snatchCollieCount end if selectNum > baseInfo.freeCoolieCount + num then selectNum = baseInfo.freeCoolieCount + num end if selectNum > config.DispatchMax then selectNum = config.DispatchMax end this.SetTime() this.SetCount() end) Util.AddClick(this.btnMax, function() local baseInfo = EnergyBaseManager.GetBaseInfo() local num = 0 if curPlayerId == PlayerManager.uid then num = curData.collieCount else num = curData.snatchCollieCount end selectNum = baseInfo.freeCoolieCount + num local config = BaseResourceConfig[curData.resourceId] if selectNum > config.DispatchMax then selectNum = config.DispatchMax end this.SetTime() this.SetCount() end) end function this:AddListener() end function this:RemoveListener() end function this:OnOpen(args) selectPos, curData, curPlayerId = args.pos, args.resource, args.playerId if curPlayerId == PlayerManager.uid then selectNum = curData.collieCount else selectNum = curData.snatchCollieCount end if selectNum == 0 then local baseInfo = EnergyBaseManager.GetBaseInfo() if baseInfo.freeCoolieCount > 0 then selectNum = 1 end end local config = BaseResourceConfig[curData.resourceId] this.limit.text = GetLanguageStrById(50476)..config.DispatchMax this.reward.sprite = Util.LoadSprite(GetResourcePath(ItemConfig[config.Reward[1]].ResourceID)) this.obtain.text = config.Reward[2] Util.GetGameObject(this.fight, "obtain/icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(ItemConfig[config.Reward[1]].ResourceID)) Util.GetGameObject(this.fight, "obtain/lv"):GetComponent("Text").text = "Lv."..config.Level.."" Util.GetGameObject(this.fight, "left/num"):GetComponent("Text").text = curData.collieCount Util.GetGameObject(this.fight, "right/num"):GetComponent("Text").text = curData.snatchCollieCount Util.GetGameObject(this.fight, "left/arrow"):SetActive(curData.collieCount >= curData.snatchCollieCount) Util.GetGameObject(this.fight, "right/arrow"):SetActive(curData.collieCount < curData.snatchCollieCount) Util.GetGameObject(this.fight, "left"):SetActive(not not curData and curData.collieCount > 0) Util.GetGameObject(this.fight, "right"):SetActive(not not curData and curData.snatchCollieCount > 0) this.noCompetitionTime = 0 if curPlayerId == PlayerManager.uid then this.noCompetitionTime = BaseResourceConfig[curData.resourceId].CollectTime*(1-curData.progress) else this.noCompetitionTime = BaseResourceConfig[curData.resourceId].CollectTime*(1+curData.progress) end this.time.text = TimeToHMS(this.noCompetitionTime) this.SetTime() this.SetCount() this.TimeDown() --数据上报用 this.itemID = config.Reward[1] this.itemNum = config.Reward[2] end function this:OnShow() end function this:OnSortingOrderChange() -- local sortingOrder = self.sortingOrder -- Util.GetGameObject(this.fight, "obtain/GameObject/RobotEffect"):GetComponent("SortingGroup").sortingOrder = sortingOrder + 10 end function this:OnClose() if timer then timer:Stop() timer = nil end end function this:OnDestroy() selectPos = 0 if timer then timer:Stop() timer = nil end end function this.SetTime() local fatigue = EnergyBaseManager.GetFatigue() changeData = {} if curPlayerId == PlayerManager.uid then changeData = { collieCount = selectNum, snatchCollieCount = curData.snatchCollieCount, progress = curData.progress, redSpeed = fatigue[2].CollectSpeed, blueSpeed = curData.blueSpeed, resourceId = curData.resourceId, startTime = curData.startTime or 0 } else changeData = { collieCount = curData.collieCount, snatchCollieCount = selectNum, progress = curData.progress, redSpeed = curData.redSpeed, blueSpeed = fatigue[2].CollectSpeed, resourceId = curData.resourceId, startTime = curData.startTime or 0 } end local finalTime = EnergyBaseManager.ComputingTime(changeData) if curData.startTime > 0 then finalTime = finalTime - GetTimeStamp() end if changeData.collieCount == 0 and changeData.snatchCollieCount == 0 then finalTime = this.noCompetitionTime end this.changeTime.text = TimeToHMS(finalTime) --数据上报用 this.itemTime = finalTime end function this.SetCount() local baseInfo = EnergyBaseManager.GetBaseInfo() local num = 0 if curPlayerId == PlayerManager.uid then num = curData.collieCount else num = curData.snatchCollieCount end local max = BaseResourceConfig[curData.resourceId].DispatchMax if baseInfo.freeCoolieCount+num > max then num = max else num = baseInfo.freeCoolieCount+num end Util.GetGameObject(this.gameObject, "count"):GetComponent("Text").text = selectNum.." / "..num end function this.TimeDown() if timer then timer:Stop() timer = nil end timer = Timer.New(function() if curData.collieCount > 0 or curData.snatchCollieCount > 0 then local finalTime = EnergyBaseManager.ComputingTime(curData) finalTime = finalTime - GetTimeStamp() if finalTime < 0 then finalTime = 0 end if finalTime >= 0 then this.time.text = TimeToHMS(finalTime) end end if selectNum > 0 then if changeData.collieCount > 0 or changeData.snatchCollieCount > 0 then local finalTime = EnergyBaseManager.ComputingTime(changeData) if curData.startTime > 0 then finalTime = finalTime - GetTimeStamp() end if finalTime < 0 then finalTime = 0 end if finalTime >= 0 then this.changeTime.text = TimeToHMS(finalTime) --数据上报用 this.itemTime = finalTime end end end end, 1, -1, true) timer:Start() end return EnergyDetails