require("Base/BasePanel") PowerCenterPanel = Inherit(BasePanel) local this = PowerCenterPanel local PowerCenterConfig = ConfigManager.GetConfig(ConfigName.PowerCenterConfig) local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local upHeros, downHeros, equips = {}, {}, {} local liveObj, liveData = nil, {} local lastSelect = nil local timer, timeList = nil, {} --初始化组件(用于子类重写) function PowerCenterPanel:InitComponent() this.btnBack = Util.GetGameObject(this.gameObject, "btnBack") this.btnHelp = Util.GetGameObject(this.gameObject, "btnHelp") this.helpPosition = this.btnHelp:GetComponent("RectTransform").localPosition local scroll = Util.GetGameObject(this.gameObject, "Panel/up/heroGrid").transform local pre = Util.GetGameObject(scroll, "hero") local v = scroll:GetComponent("RectTransform").rect this.upScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, scroll, pre, nil, Vector2.New(v.width, v.height), 1, 1, Vector2.New(0, 0)) this.upScrollView.moveTween.MomentumAmount = 1 this.upScrollView.moveTween.Strength = 1 -- local scroll = Util.GetGameObject(this.gameObject, "Panel/down/scroll").transform -- local pre = Util.GetGameObject(scroll, "pre") -- local v = scroll:GetComponent("RectTransform").rect -- this.downScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, scroll, -- pre, nil, Vector2.New(v.width, v.height), 1, 4, Vector2.New(5, 5)) -- this.downScrollView.moveTween.MomentumAmount = 1 -- this.downScrollView.moveTween.Strength = 1 this.scroll = Util.GetGameObject(this.gameObject, "Panel/down/scrollrect/mask").transform this.pre = Util.GetGameObject(this.gameObject, "Panel/down/scroll/pre") this.PlayerHeadFrameView = SubUIManager.Open(SubUIConfig.PlayerHeadFrameView, this.gameObject.transform) this.UpView = SubUIManager.Open(SubUIConfig.UpView, this.transform) this.livePos = Util.GetGameObject(this.gameObject, "Panel/live") this.btnUnlock = Util.GetGameObject(this.gameObject, "Panel/down/unlock/btnUnlock") this.btnAdd = Util.GetGameObject(this.gameObject, "Panel/down/unlock/btnAdd") end --绑定事件(用于子类重写) function PowerCenterPanel:BindEvent() Util.AddClick(this.btnHelp,function() UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.PowerCenter, this.helpPosition.x, this.helpPosition.y) end) Util.AddClick(this.btnBack, function() this:ClosePanel() end) Util.AddClick(this.btnUnlock, function () UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.PowerCenter, 2, function() PowerCenterManager.GetPowerCenterUnlockPos(function () this.SetDownScroll() -- this.SetInfo() end) end) end) Util.AddClick(this.btnAdd, function() local cost = PowerCenterManager.GetUnlockCost() UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, cost[1][1]) end) end --添加事件监听(用于子类重写) function PowerCenterPanel:AddListener() Game.GlobalEvent:AddEvent(GameEvent.PowerCenter.RefreshLinkList, this.SetDownScroll) Game.GlobalEvent:AddEvent(GameEvent.PowerCenter.RefreshCost, this.SetInfo) end --移除事件监听(用于子类重写) function PowerCenterPanel:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.PowerCenter.RefreshLinkList, this.SetDownScroll) Game.GlobalEvent:RemoveEvent(GameEvent.PowerCenter.RefreshCost, this.SetInfo) end --界面打开时调用(用于子类重写) function PowerCenterPanel:OnOpen() end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function PowerCenterPanel:OnShow() this.PlayerHeadFrameView:OnShow() this.UpView:OnOpen({ showType = UpViewOpenType.ShowRight, panelType = PanelType.Main }) -- PowerCenterManager.GetPowerCenterInfo(function (msg) this.SetInfo() this.SetUpScroll() this.SetDownScroll() this.TimeDown() -- end) end --界面关闭时调用(用于子类重写) function PowerCenterPanel:OnClose() end local scrollItems = {} --界面销毁时调用(用于子类重写) function PowerCenterPanel:OnDestroy() SubUIManager.Close(this.UpView) SubUIManager.Close(this.PlayerHeadFrameView) if liveObj and liveData then UnLoadHerolive(liveData, liveObj) Util.ClearChild(this.livePos.transform) liveObj = nil liveData = nil end Util.ClearChild(this.scroll) scrollItems = {} upHeros, downHeros, equips = {}, {}, {} lastSelect = nil end function this.SetHeroLive(data) if liveObj and liveData then UnLoadHerolive(liveData, liveObj) Util.ClearChild(this.livePos.transform) liveObj = nil liveData = nil end liveObj = LoadHerolive(data, this.livePos,true) liveData = data end function this.SetInfo() local allData = PowerCenterManager.allData local down = Util.GetGameObject(this.gameObject, "Panel/down") local lv = Util.GetGameObject(down, "Level/lv"):GetComponent("Text") local icon = Util.GetGameObject(down, "unlock/cost/icon"):GetComponent("Image") local num = Util.GetGameObject(down, "unlock/cost/num"):GetComponent("Text") local slider = Util.GetGameObject(down, "unlock/slider/Fill"):GetComponent("Image") for i = 1, 4 do if not equips[i] then local parent = Util.GetGameObject(down, "equip/equip"..i) equips[i] = SubUIManager.Open(SubUIConfig.ItemView, parent.transform) end if allData.equip[i] and allData.equip[i].equipId > 0 then equips[i]:OnOpen(false, {allData.equip[i].equipId, 0}, 0.7) equips[i].gameObject:SetActive(true) else equips[i].gameObject:SetActive(false) end end lv.text = allData.level local index = 0 for i = 1, #allData.linkPos do if allData.linkPos[i].state == 2 or allData.linkPos[i].state == 3 then index = i break end end local state = PowerCenterManager.powerCenterIsActivate and index < PowerCenterManager.maxField+1 Util.GetGameObject(down, "unlock/slider"):SetActive(state) Util.GetGameObject(down, "unlock/cost"):SetActive(state) this.btnAdd:SetActive(state) this.btnUnlock:SetActive(state) if state then local cost = PowerCenterConfig[index].Cost icon.sprite = Util.LoadSprite(GetResourcePath(ItemConfig[cost[1][1]].ResourceID)) num.text = CompareNum(BagManager.GetItemCountById(cost[1][1]), cost[1][2]) slider.fillAmount = BagManager.GetItemCountById(cost[1][1])/cost[1][2] end end function this.SetUpScroll() local allData = PowerCenterManager.allData.hero table.sort(allData, function (a, b) if a.lv ~= b.lv then return a.lv > b.lv else if a.warPower ~= b.warPower then return a.warPower > b.warPower else return a.id < b.id end end end) this.upScrollView:SetData(allData, function (index, go) this.SetUpPre(go, allData[index]) end) end function this.SetUpPre(go, data) local select = Util.GetGameObject(go, "select") local pos = Util.GetGameObject(go, "pos") local equips = Util.GetGameObject(go, "equips") if not upHeros[go] then upHeros[go] = SubUIManager.Open(SubUIConfig.ItemView, pos.transform) end upHeros[go]:OnOpen(false, {data.id, 0}, 1) upHeros[go]:SetCorner(6, true, {lv = data.lv, star = data.star}) upHeros[go]:ClickEnable(false) if not lastSelect then lastSelect = select this.SetHeroLive(data.heroConfig) else if select == lastSelect then this.SetHeroLive(data.heroConfig) end end select:SetActive(select == lastSelect) for i = 1, 4 do Util.GetGameObject(equips, "equip"..i):SetActive(this.GetCurHeroShareEquip(data.dynamicId, i)) end Util.AddOnceClick(go, function () if lastSelect then lastSelect:SetActive(false) end lastSelect = select select:SetActive(true) this.SetHeroLive(data.heroConfig) end) end --获取当前英雄分享的装备位置 function this.GetCurHeroShareEquip(onlyId, pos) local allData = PowerCenterManager.allData.equip for i = 1, #allData do if allData[i].equipId > 0 then if allData[i].heroId == onlyId then if allData[i].position == pos then return true end end end end return false end function this.SetDownScroll() timeList = {} local allData = PowerCenterManager.allData.linkPos -- this.downScrollView:SetData(allData, function (index, go) -- this.SetDownPre(go, allData[index]) -- end) for i = 1, #allData do if not scrollItems[i] then scrollItems[i] = newObjToParent(this.pre, this.scroll) end this.SetDownPre(scrollItems[i], allData[i]) end end local stateImg = { "X1_tongyong_daojishi", "X1_tongyong_suo", "X1_tongyong_jiesuo", } --0可共享 1倒计时 2锁 3可解锁 function this.SetDownPre(go, data) local pos = Util.GetGameObject(go, "pos") local state = Util.GetGameObject(go, "state"):GetComponent("Image") local timeTxt = Util.GetGameObject(go, "time"):GetComponent("Text") local redpoint = Util.GetGameObject(go, "redpoint") local add = Util.GetGameObject(go, "add") if not downHeros[go] then downHeros[go] = SubUIManager.Open(SubUIConfig.ItemView, pos.transform) end if data.heroId ~= "" then local hero = HeroManager.GetSingleHeroData(data.heroId) downHeros[go]:OnOpen(false, {hero.id, 0}, 0.85) downHeros[go]:ClickEnable(false) downHeros[go]:SetCorner(6, false, {lv = hero.lv, star = hero.star}) downHeros[go].gameObject:SetActive(true) else downHeros[go].gameObject:SetActive(false) end add:SetActive(data.state == 0 and data.heroId == "") if data.state > 0 then state.sprite = Util.LoadSprite(stateImg[data.state]) end state.gameObject:SetActive(data.state > 0) redpoint:SetActive(data.state == 3) if data.readyTime > 0 and (data.readyTime/1000 - GetTimeStamp()) > 0 then timeTxt.text = TimeToHMS(data.readyTime/1000 - GetTimeStamp()) if not timeList[data.position] then timeList[data.position] = { txt = timeTxt, time = data.readyTime/1000, timedown = true, icon = state, add = add } end else timeTxt.text = "" end Util.AddOnceClick(go, function () if data.heroId ~= "" then local hero = HeroManager.GetSingleHeroData(data.heroId) UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.PowerCenter, 1, function() PowerCenterManager.GetPowerCenterLinkHero(data.position, data.heroId, 0, function () this.SetDownScroll() this.TimeDown() end) end, {{lv = hero.lv, star = hero.star, id = hero.id}, {lv = data.heroLevel, star = hero.star, id = hero.id}}) return end if data.state == 0 then UIManager.OpenPanel(UIName.PowerCenteSelectrLinkPanel, function (heroId) PowerCenterManager.GetPowerCenterLinkHero(data.position, heroId, 1, function () this.SetDownScroll() -- this.TimeDown() end) end) elseif data.state == 1 then UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.PowerCenter, 3, function(costType) PowerCenterManager.GetPowerCenterSpeedUpLinkPos(data.position, costType, function () this.SetDownScroll() -- this.SetInfo() this.TimeDown() end) end) elseif data.state == 3 then UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.PowerCenter, 2, function() PowerCenterManager.GetPowerCenterUnlockPos(function () this.SetDownScroll() -- this.SetInfo() -- this.TimeDown() end) end) end end) end function this.TimeDown() if timer then timer:Stop() timer = nil end timer = Timer.New(function() for i, v in pairs(timeList) do if v and v.timedown then local time = v.time - GetTimeStamp() v.txt.text = TimeToHMS(time) if time <= 0 then v.txt.text = "" v.timedown = false v.icon.gameObject:SetActive(false) v.add:SetActive(true) end end end local isOn = false for i, v in pairs(timeList) do if v.timedown then isOn = true end end if not isOn then if timer then timer:Stop() timer = nil end end end, 1, -1, true) timer:Start() end return PowerCenterPanel