require("Base/BasePanel") local XiaoYaoLuckyBossPopup = Inherit(BasePanel) local this = XiaoYaoLuckyBossPopup local monsterGroup = {} local curMonsterGroup local _LiveName local _LiveNode local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig) local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig) local rewardGroupConfig=ConfigManager.GetConfig(ConfigName.RewardGroup) local MonsterGroup=ConfigManager.GetConfig(ConfigName.MonsterGroup) local MonsterConfig=ConfigManager.GetConfig(ConfigName.MonsterConfig) local ArtConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local monsterGroupPrefabs = {} local rewardPrefabs = {} local costId = 0 local costNum = 0 local cost = {} local fightBossIndex = 0 function XiaoYaoLuckyBossPopup:InitComponent() this.spLoader = SpriteLoader.New() this.root = self.gameObject this.btnBack =Util.GetGameObject(this.root,"Panel/bg/btnBack") this.title =Util.GetGameObject(this.root,"Panel/bg/title"):GetComponent("Text") --this.liveRoot=Util.GetGameObject(this.root,"Panel/EnemyInfo/root") this.e_liveRoot=Util.GetGameObject(this.root,"Panel/EnemyInfo/root/liveRoot") this.e_name=Util.GetGameObject(this.root,"Panel/EnemyInfo/name/text"):GetComponent("Text") this.e_level=Util.GetGameObject(this.root,"Panel/EnemyInfo/name/level/Text"):GetComponent("Text") this.hp = Util.GetGameObject(this.root,"Panel/EnemyInfo/hp/Image"):GetComponent("Image") this.e_fightBtn=Util.GetGameObject(this.root,"Panel/EnemyInfo/fight") this.heroList=Util.GetGameObject(this.root,"Panel/EnemyInfo/Scroll/heroList") this.rewardList=Util.GetGameObject(this.root,"Panel/EnemyInfo/rewardScroll/rewardList") this.iconPre=Util.GetGameObject(this.root,"Panel/EnemyInfo/Scroll/pre") this.timeText = Util.GetGameObject(this.root,"Panel/EnemyInfo/remainTime"):GetComponent("Text") this.selectKuang = Util.GetGameObject(this.root,"Panel/EnemyInfo/Scroll/choosed") end function XiaoYaoLuckyBossPopup:BindEvent() Util.AddClick(this.btnBack,function() self:ClosePanel() end) Util.AddClick(this.e_fightBtn,function() if BagManager.GetItemCountById(costId) < costNum then PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[costId].Name)..Language[10657]) else XiaoYaoManager.ExecuteFightBattle(curMonsterGroup.monsterIndex,function() if _LiveNode then poolManager:UnLoadLive(_LiveName, _LiveNode) _LiveNode = nil end this:ClosePanel() end) end end) end function XiaoYaoLuckyBossPopup:OnOpen() this.title.text = Language[12003] local config = ConfigManager.GetConfigDataByKey(ConfigName.FreeTravel,"MapID",XiaoYaoManager.curMapId) cost = config.BossConsume end function XiaoYaoLuckyBossPopup:OnShow() monsterGroup = XiaoYaoManager.GetMonsterDatas() if not monsterGroup or #monsterGroup < 1 then LogBlue("得到得怪物不存在") this:ClosePanel() return end fightBossIndex = XiaoYaoManager.fightBossIndex LogYellow("fightBossIndex:"..fightBossIndex) if fightBossIndex == 0 then curMonsterGroup = monsterGroup[1] else local isExist = false for i = 1,#monsterGroup do if monsterGroup[i].monsterIndex == fightBossIndex then curMonsterGroup = monsterGroup[i] isExist = true break end end if not isExist then curMonsterGroup = monsterGroup[1] end end LogYellow("curMonsterGroup.monsterInDex:"..curMonsterGroup.monsterIndex) this:InitMonsterList() this:SetSelectHero(curMonsterGroup) end function this:TimerDown() if this.timer then this.timer:Stop() this.timer = nil end local timeDown = curMonsterGroup.remainTime - PlayerManager.serverTime local temp = 0 this.timeText.text = Language[10023]..TimeToHMS(timeDown) this.timer = Timer.New(function() if timeDown < 1 then XiaoYaoManager.fightBossIndex = 0 this:OnShow() return end for i = 1 , #monsterGroup do temp = monsterGroup[i].remainTime - PlayerManager.serverTime if temp < 1 then this:OnShow() return end end timeDown = timeDown - 1 this.timeText.text = Language[10023]..TimeToHMS(timeDown) end, 1, -1, true) this.timer:Start() end function this:InitMonsterList() for i = 1 ,#monsterGroupPrefabs do monsterGroupPrefabs[i].gameObject:SetActive(false) end for i = 1 , #monsterGroup do if not monsterGroupPrefabs[i] then monsterGroupPrefabs[i] = newObjToParent(this.iconPre,this.heroList) end monsterGroupPrefabs[i].gameObject:SetActive(true) this:SetSingleMonster(monsterGroupPrefabs[i],monsterGroup[i]) end end function XiaoYaoLuckyBossPopup:SetSingleMonster(go,data) local frame = Util.GetGameObject(go,"frame"):GetComponent("Image") local icon = Util.GetGameObject(go,"icon"):GetComponent("Image") local lv = Util.GetGameObject(go,"lv/Text"):GetComponent("Text") local choosed = Util.GetGameObject(go,"choosed") --LogGreen("data.monsterId:"..data.monsterId.." "..MonsterGroup[data.monsterId].Contents[1][2]) local id = MonsterGroup[data.monsterId].Contents[1][2] local _data = MonsterConfig[id] frame.sprite = this.spLoader:LoadSprite("r_hero_qingbao-jineng-002") icon.sprite = this.spLoader:LoadSprite(GetResourcePath(heroConfig[_data.MonsterId].Icon)) lv.text = _data.Level if data.monsterIndex == curMonsterGroup.monsterIndex then this.selectKuang.transform:SetParent(go.transform) this.selectKuang:GetComponent("RectTransform").localPosition = Vector3.zero end Util.AddOnceClick(go,function() if curMonsterGroup.monsterIndex == data.monsterIndex then else curMonsterGroup = data XiaoYaoManager.fightBossIndex = curMonsterGroup.monsterIndex this.selectKuang.transform:SetParent(go.transform) this.selectKuang:GetComponent("RectTransform").localPosition = Vector3.zero this:SetSelectHero(data) end end) end function XiaoYaoLuckyBossPopup:SetSelectHero(monsterData) XiaoYaoManager.fightBossIndex = monsterData.monsterIndex local _data = MonsterConfig[MonsterGroup[monsterData.monsterId].Contents[1][2]] local monsterId = _data.MonsterId local paintingId = heroConfig[monsterId].Live local pos = heroConfig[monsterId].Position if _LiveNode then poolManager:UnLoadLive(_LiveName, _LiveNode) _LiveNode = nil end _LiveName = ArtConfig[paintingId].Name _LiveNode = poolManager:LoadLive(_LiveName, this.e_liveRoot.transform, Vector3.one * heroConfig[monsterId].Scale, Vector3.New(pos[1], pos[2], 0)) --this.liveRoot.transform.localScale = Vector3.one*0.7 this.e_level.text = "lv.".. _data.Level this.e_name.text = GetLanguageStrById(_data.ReadingName) this.hp.fillAmount = monsterData.monsterHp/_data.Hp if monsterData.attackNum > 0 then if not cost[monsterData.attackNum+1] then costId = cost[#cost][1] costNum = cost[#cost][2] else costId = cost[monsterData.attackNum+1][1] costNum = cost[monsterData.attackNum+1][2] end --LogGreen("costId:"..costId.." costNum:"..costNum) Util.GetGameObject(this.e_fightBtn,"Text").gameObject:SetActive(false) Util.GetGameObject(this.e_fightBtn,"layout").gameObject:SetActive(true) Util.GetGameObject(this.e_fightBtn,"layout/icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(ArtConfig[itemConfig[costId].ResourceID].Name) if BagManager.GetItemCountById(costId) < costNum then Util.GetGameObject(this.e_fightBtn,"layout/num"):GetComponent("Text").text = "" .. costNum .. "" else Util.GetGameObject(this.e_fightBtn,"layout/num"):GetComponent("Text").text = "" .. costNum .. "" end else costId = 16 costNum = 0 Util.GetGameObject(this.e_fightBtn,"Text").gameObject:SetActive(true) Util.GetGameObject(this.e_fightBtn,"layout").gameObject:SetActive(false) end this:SetSingleReward(monsterData.reward) this:TimerDown() end function XiaoYaoLuckyBossPopup:SetSingleReward(id) for i = 1 ,#rewardPrefabs do rewardPrefabs[i].gameObject:SetActive(false) end local data = rewardGroupConfig[id].ShowItem for i = 1 , #data do if not rewardPrefabs[i] then rewardPrefabs[i] = SubUIManager.Open(SubUIConfig.ItemView,this.rewardList.transform) end rewardPrefabs[i].gameObject:SetActive(true) LogRed("id:"..data[i][1].." data[i][2]:"..data[i][2]) rewardPrefabs[i]:OnOpen(false, {data[i][1],0},0.8,false,false,false) end end function this:OnClose() Game.GlobalEvent:DispatchEvent(GameEvent.XiaoYao.RefreshEventShow) if _LiveNode then poolManager:UnLoadLive(_LiveName, _LiveNode) _LiveNode = nil end if this.timer then this.timer:Stop() this.timer = nil end end function this:OnDestroy() this.spLoader:Destroy() if _LiveNode then poolManager:UnLoadLive(_LiveName, _LiveNode) _LiveNode = nil end monsterGroupPrefabs = {} rewardPrefabs = {} if this.timer then this.timer:Stop() this.timer = nil end end return this