267 lines
9.4 KiB
Lua
267 lines
9.4 KiB
Lua
require("Base/BasePanel")
|
|
RobotDetails = Inherit(BasePanel)
|
|
local this = RobotDetails
|
|
local BaseAttachmentConfig = ConfigManager.GetConfig(ConfigName.BaseAttachmentConfig)
|
|
local BaseFatigueConfig = ConfigManager.GetAllConfigsData(ConfigName.BaseFatigueConfig)
|
|
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local BaseResourceConfig = ConfigManager.GetConfig(ConfigName.BaseResourceConfig)
|
|
local timer = nil
|
|
local timeList = {}
|
|
local headList = {}
|
|
local itemList = {}
|
|
local cost = nil
|
|
function RobotDetails:InitComponent()
|
|
this.btnBack = Util.GetGameObject(this.gameObject, "bg/btnBack")
|
|
this.prefab = Util.GetGameObject(this.gameObject, "bg/scroll/pre")
|
|
this.btnBuy = Util.GetGameObject(this.gameObject, "bg/info/btnBuy")
|
|
this.btnBuyRp = Util.GetGameObject(this.gameObject, "bg/info/btnBuy/redpoint")
|
|
this.scroll = Util.GetGameObject(this.gameObject, "bg/scroll")
|
|
local v2 = this.scroll.transform.rect
|
|
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
|
|
this.prefab, nil, Vector2.New(v2.width, v2.height), 1, 1, Vector2.New(0, 5))
|
|
this.scrollView.moveTween.MomentumAmount = 1
|
|
this.scrollView.moveTween.Strength = 2
|
|
|
|
-- this.scrollrect = Util.GetGameObject(this.gameObject, "bg/scrollrect/scroll")
|
|
end
|
|
function RobotDetails:BindEvent()
|
|
Util.AddClick(this.btnBack, function()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(this.btnBuy, function()
|
|
EnergyBaseManager.BaseLevelUp(5, function (msg)
|
|
self:OnShow()
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.Energy.BaseOrFacilityUpLv)
|
|
end)
|
|
end)
|
|
end
|
|
|
|
function RobotDetails:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.Energy.RefreshResourceForOtherBase, self.OnShow)
|
|
Game.GlobalEvent:AddEvent(GameEvent.Energy.RefreshResource, self.OnShow)
|
|
end
|
|
|
|
function RobotDetails:RemoveListener()
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Energy.RefreshResourceForOtherBase, self.OnShow)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Energy.RefreshResource, self.OnShow)
|
|
end
|
|
|
|
function RobotDetails:OnOpen()
|
|
end
|
|
|
|
function RobotDetails:OnShow()
|
|
timeList = {}
|
|
EnergyBaseManager.BaseCoolieDetailRequest(function (data)
|
|
this.scrollView:SetData(data, function(index, go)
|
|
this.SetScroll(go, data[index])
|
|
this.TimeDown()
|
|
end)
|
|
end)
|
|
this.SetCoolieInfo()
|
|
end
|
|
|
|
function RobotDetails:OnClose()
|
|
if timer then
|
|
timer:Stop()
|
|
timer = nil
|
|
end
|
|
end
|
|
|
|
function RobotDetails:OnDestroy()
|
|
if timer then
|
|
timer:Stop()
|
|
timer = nil
|
|
end
|
|
timeList = {}
|
|
headList = {}
|
|
itemList = {}
|
|
cost = nil
|
|
end
|
|
|
|
function this.SetScroll(go, data)
|
|
local btnRecall = Util.GetGameObject(go, "btnRecall")
|
|
local btnGo = Util.GetGameObject(go, "btnGo")
|
|
local left = Util.GetGameObject(go, "left")
|
|
local right = Util.GetGameObject(go, "right")
|
|
local resource = Util.GetGameObject(go, "resource")
|
|
local title = Util.GetGameObject(go, "title"):GetComponent("Text")
|
|
local time = Util.GetGameObject(go, "resource/time"):GetComponent("Text")
|
|
if not headList[go] then
|
|
headList[go] = {}
|
|
end
|
|
|
|
local myInfo = {
|
|
parent = nil,
|
|
uid = PlayerManager.uid,
|
|
head = PlayerManager.head,
|
|
level = PlayerManager.level,
|
|
name = PlayerManager.nickName,
|
|
frame = PlayerManager.frame,
|
|
num = data.useCoolieCount,
|
|
}
|
|
local otherInfo = {
|
|
parent = nil,
|
|
uid = data.snatcherInfo.uid,
|
|
head = data.snatcherInfo.head,
|
|
level = data.snatcherInfo.level,
|
|
name = data.snatcherInfo.nickName,
|
|
frame = data.snatcherInfo.headFrame,
|
|
num = data.otherCoolieCount,
|
|
}
|
|
local isMyBase = data.targetUid == PlayerManager.uid
|
|
for i = 1, 2 do
|
|
local cur, parent
|
|
local state = false
|
|
if i == 1 then
|
|
if isMyBase then
|
|
cur = myInfo
|
|
parent = left
|
|
state = myInfo.num >= otherInfo.num
|
|
else
|
|
cur = otherInfo
|
|
parent = left
|
|
state = myInfo.num <= otherInfo.num
|
|
end
|
|
else
|
|
if isMyBase then
|
|
cur = otherInfo
|
|
parent = right
|
|
state = myInfo.num < otherInfo.num
|
|
else
|
|
cur = myInfo
|
|
parent = right
|
|
state = myInfo.num > otherInfo.num
|
|
end
|
|
end
|
|
|
|
if cur.uid > 0 then
|
|
if not headList[go][i] then
|
|
headList[go][i] = SubUIManager.Open(SubUIConfig.PlayerHeadView, parent.transform)
|
|
end
|
|
headList[go][i]:Reset()
|
|
headList[go][i]:SetScale(Vector3.one * 0.45)
|
|
headList[go][i]:SetHead(cur.head)
|
|
headList[go][i]:SetFrame(cur.headFrame)
|
|
headList[go][i]:SetLevel(cur.level)
|
|
end
|
|
Util.GetGameObject(parent, "coolie"):GetComponent("Text").text = cur.num
|
|
parent:SetActive(cur.uid > 0)
|
|
Util.GetGameObject(parent, "arrow"):SetActive(state)
|
|
end
|
|
local resourceData = BaseResourceConfig[data.cfgId]
|
|
if not itemList[go] then
|
|
itemList[go] = SubUIManager.Open(SubUIConfig.ItemView, Util.GetGameObject(resource, "pos").transform)
|
|
end
|
|
itemList[go]:OnOpen(false, resourceData.Reward, 0.7)
|
|
itemList[go]:ShowNum(false)
|
|
Util.GetGameObject(resource, "lv"):GetComponent("Text").text = "Lv."..resourceData.Level
|
|
if isMyBase then
|
|
title.text = GetLanguageStrById(50463)
|
|
else
|
|
title.text = data.snatcherInfo.nickName..GetLanguageStrById(50464)
|
|
end
|
|
|
|
local collieCount, snatchCollieCount
|
|
if isMyBase then
|
|
collieCount = data.useCoolieCount
|
|
snatchCollieCount = data.otherCoolieCount
|
|
else
|
|
collieCount = data.otherCoolieCount
|
|
snatchCollieCount = data.useCoolieCount
|
|
end
|
|
local list = {
|
|
resourceId = data.cfgId,
|
|
collieCount = collieCount,
|
|
snatchCollieCount = snatchCollieCount,
|
|
progress = data.curProgress,
|
|
redSpeed = data.redCollectSpeed,
|
|
blueSpeed = data.blueCollectSpeed,
|
|
startTime = data.startTime
|
|
}
|
|
local finalTime = EnergyBaseManager.ComputingTime(list)
|
|
time.text = TimeToHMS(finalTime-GetTimeStamp())
|
|
timeList[go] = {txt = time, time = finalTime, state = true}
|
|
Util.AddOnceClick(btnRecall, function ()
|
|
EnergyBaseManager.BaseCoolieDispatch(data.resourceNo, data.targetUid, 0, function ()
|
|
this:OnShow()
|
|
end, {itemID = resourceData.Reward[1], resourceData.Reward[2], itemTime = finalTime})
|
|
end)
|
|
Util.AddOnceClick(btnGo, function ()
|
|
if data.targetUid == myInfo.uid then
|
|
this:ClosePanel()
|
|
else
|
|
UIManager.OpenPanel(UIName.EnergyBaseMainPanel, 2, {id = data.targetUid, name = data.snatcherInfo.nickName})
|
|
this:ClosePanel()
|
|
end
|
|
end)
|
|
end
|
|
|
|
function this.TimeDown()
|
|
if timer then
|
|
timer:Stop()
|
|
timer = nil
|
|
end
|
|
timer = Timer.New(function()
|
|
for index, value in pairs(timeList) do
|
|
if value then
|
|
value.txt.text = TimeToHMS(value.time-GetTimeStamp())
|
|
end
|
|
if value.time-GetTimeStamp() <= 0 then
|
|
value.state = false
|
|
end
|
|
|
|
local isOn = false
|
|
for k, v in pairs(timeList) do
|
|
if v.state then
|
|
isOn = true
|
|
end
|
|
end
|
|
if not isOn then
|
|
if timer then
|
|
timer:Stop()
|
|
timer = nil
|
|
end
|
|
end
|
|
end
|
|
end, 1, -1, true)
|
|
timer:Start()
|
|
end
|
|
|
|
function this.SetCoolieInfo()
|
|
local all = Util.GetGameObject(this.gameObject, "bg/info/all/num"):GetComponent("Text")
|
|
local idle = Util.GetGameObject(this.gameObject, "bg/info/idle/num"):GetComponent("Text")
|
|
local pos = Util.GetGameObject(this.gameObject, "bg/info/pos")
|
|
local limit = Util.GetGameObject(this.gameObject, "bg/info/limit")
|
|
local limitTxt = Util.GetGameObject(this.gameObject, "bg/info/limit/Text"):GetComponent("Text")
|
|
local fatigue = Util.GetGameObject(this.gameObject, "bg/info/fatigue"):GetComponent("Text")
|
|
local Slider = Util.GetGameObject(this.gameObject, "bg/info/Slider"):GetComponent("Slider")
|
|
|
|
this.btnBuyRp:SetActive(EnergyBaseManager.RobotBuyRedpoint())
|
|
local baseInfo = EnergyBaseManager.GetBaseInfo()
|
|
all.text = baseInfo.coolieCount
|
|
idle.text = baseInfo.freeCoolieCount
|
|
local fatigueInfo = EnergyBaseManager.GetFatigue()
|
|
fatigue.text = GetLanguageStrById(50465).." "..fatigueInfo[1]
|
|
Slider.value = fatigueInfo[1]/BaseFatigueConfig[#BaseFatigueConfig].LowerLimit
|
|
local facilityInfo = EnergyBaseManager.GetFacilityInfos()
|
|
local curBuildInfo, nextBuildInfo = EnergyBaseManager.GetBuildInfo(facilityInfo[5].type, facilityInfo[5].level)
|
|
if nextBuildInfo then
|
|
if baseInfo.baseLevel >= curBuildInfo.BaseLimit then
|
|
limit:SetActive(false)
|
|
else
|
|
limit:SetActive(true)
|
|
end
|
|
pos:SetActive(true)
|
|
limitTxt.text = curBuildInfo.BaseLimit
|
|
if not cost then
|
|
cost = SubUIManager.Open(SubUIConfig.ItemView, pos.transform)
|
|
end
|
|
cost:OnOpen(false, curBuildInfo.Cost, 0.6)
|
|
cost:CompareNum(BagManager.GetItemCountById(curBuildInfo.Cost[1]), curBuildInfo.Cost[2])
|
|
else
|
|
limit:SetActive(false)
|
|
pos:SetActive(false)
|
|
end
|
|
end
|
|
|
|
return this |