require("Base/BasePanel") local XiaoYaoEventPanel = Inherit(BasePanel) local this = XiaoYaoEventPanel local triggertype=0 --0:游历成功 大于0:触发仙缘 --初始化组件(用于子类重写) function this:InitComponent() this.spLoader = SpriteLoader.New() this.btnBack = Util.GetGameObject(self.transform, "closeBtn") this.title=Util.GetGameObject(self.transform, "bg/title"):GetComponent("Image") this.grid=Util.GetGameObject(self.transform, "bg/grid") this.grid2=Util.GetGameObject(self.transform, "bg/grid2") -- this.eventName=Util.GetGameObject(self.transform, "bg/xianyuan/name"):GetComponent("Text") --this.eventIcon=Util.GetGameObject(self.transform, "bg/xianyuan/icon"):GetComponent("Image") this.preList={} for i = 1, 3 do local item=Util.GetGameObject(self.transform, "bg/grid2/xianyuan"..i) table.insert(this.preList,item) end this.rewardItemViewList = {} end --绑定事件(用于子类重写) function this:BindEvent() Util.AddClick(this.btnBack, function() this:ClosePanel() if triggertype==0 then XiaoYaoManager.OpenMapList() end end) end --界面打开时调用(用于子类重写) function this:OnOpen(_type,_data,curindex,list,num) triggertype=_type if _type>0 then this.title.sprite=this.spLoader:LoadSprite("x_xiaoyaoyou_chufaxianyuan_zh") this.grid:SetActive(false) for i = 1, #this.preList do this.preList[i]:SetActive(false) end local index=0 for i = curindex-num+1, curindex do -- LogError("list[i].eventData.Style=="..list[i].eventData.Style) if list[i].eventData and (list[i].eventData.Style==24 or list[i].eventData.Style==25 or list[i].eventData.Style==26) then index=index+1 if this.preList[index] then this.preList[index]:SetActive(true) Util.GetGameObject(this.preList[index], "name"):GetComponent("Text").text=string.format("★%s★",GetLanguageStrById(list[i].eventData.Desc)) --LogError("_data.Desc==".._data.Desc.." _data.EventPointBg==".._data.EventPointBg) Util.GetGameObject(this.preList[index], "icon"):GetComponent("Image").sprite=this.spLoader:LoadSprite(list[i].eventData.EventPointBg) end end end -- if _data~=nil then -- this.eventName.text=string.format("★%s★",GetLanguageStrById(_data.Desc)) -- LogError("_data.Desc==".._data.Desc.." _data.EventPointBg==".._data.EventPointBg) -- this.eventIcon.sprite=this.spLoader:LoadSprite(_data.EventPointBg) -- end else this.grid2:SetActive(false) this.title.sprite=this.spLoader:LoadSprite("x_xiaoyaoyou_youlichenggong_zh") this.grid:SetActive(true) local showItemdata=this.GetDropReward(_data) local starItemDataList=BagManager.GetItemListFromTempBag(_data) for i = 1, #starItemDataList do this.SetItemData2(starItemDataList[i]) end -- Log("终极大奖:"..#_data.itemlist) -- Log("终极大奖:"..#showItemdata) if showItemdata and #showItemdata>0 then for i = 1, math.max(#showItemdata,#this.rewardItemViewList) do if not showItemdata[i] then this.rewardItemViewList[i].gameObject:SetActive(false) else if not this.rewardItemViewList[i] then this.rewardItemViewList[i] = SubUIManager.Open(SubUIConfig.ItemView, this.grid.transform) end end this.rewardItemViewList[i]:OnOpen(false,showItemdata[i],1) end end end end --存储本地 function this.SetItemData2(itemdata) if itemdata.itemType==1 then --后端更新 elseif itemdata.itemType==2 then EquipManager.UpdateEquipData(itemdata.backData) elseif itemdata.itemType==3 then HeroManager.UpdateHeroDatas(itemdata.backData) elseif itemdata.itemType==4 then TalismanManager.InitUpdateSingleTalismanData(itemdata.backData) elseif itemdata.itemType==5 then EquipTreasureManager.InitSingleTreasureData(itemdata.backData) elseif itemdata.itemType==6 then PokemonManager.UpdatePokemonDatas(itemdata.backData,true) elseif itemdata.itemType==51 then FaXiangManager.InitSingleTreasureData(itemdata.backData) end end function this.GetDropReward(_drop) local _rewardList={} if _drop.itemlist then for i = 1, #_drop.itemlist do Log("list有奖励") local _rewardData={} _rewardData[1]=_drop.itemlist[i].itemId _rewardData[2]=_drop.itemlist[i].itemNum table.insert(_rewardList,_rewardData) end end if _drop.equipId then for i = 1, #_drop.equipId do local _rewardData={} _rewardData[1]=_drop.equipId[i].equipId--id _rewardData[2]=1 table.insert(_rewardList,_rewardData) end end if _drop.Hero then for i = 1, #_drop.Hero do local _rewardData={} _rewardData[1]=_drop.Hero[i].heroId--id _rewardData[2]=1 table.insert(_rewardList,_rewardData) end end if _drop.soulEquip then for i = 1, #_drop.soulEquip do local _rewardData={} _rewardData[1]=_drop.soulEquip[i].equipId--id _rewardData[2]=1 table.insert(_rewardList,_rewardData) end end return _rewardList end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function this:OnShow() end --界面关闭时调用(用于子类重写) function this:OnClose() if triggertype>0 then Game.GlobalEvent:DispatchEvent(GameEvent.XiaoYao.PlayEventEffect) end end --界面销毁时调用(用于子类重写) function this:OnDestroy() for i = 1, #this.rewardItemViewList do SubUIManager.Close(this.rewardItemViewList[i]) end this.rewardItemViewList = {} this.spLoader:Destroy() end return XiaoYaoEventPanel