--- 公平竞技-BOOS战(无双挑战) 选择武将界面 local UIBossChallengeFormation = UIViewClass() local Common2DScenePrefab = ConstAssetPathConfig.Common2DScenePrefab function UIBossChallengeFormation:OnOpened(context) self:Init(context) end function UIBossChallengeFormation:Init(context) MDL.FairPlay.FairGetFixAttrReq(MDL.FairPlay.FairPlayType.Boss) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title,Const_IDS.IDS_BossChallenge_ChooseHero_Title) self.bossLevelId = context.bossLevelId self.seasonId = context.seasonId self.currentSkillGroupIndex = 1 --当前显示的技能组索引 self:RegistDragEvent() self:RegistSystemEvent(EventID.UI_FairPlay_RefreshHeroFixedInfo, self.RefreshHeroFixedInfo) self.buffTable = {} self.heroList = {} local heroList = MDL.HeroSelect.GetHasHeroList() for i, v in ipairs(heroList) do table.insert(self.heroList, v) end self.effectResult = nil local sort = function (a, b) local infA = CTL.BossChallenge.GetBossLevelBuffInfluenceNumbers(self.bossLevelId, a.heroId) local infB = CTL.BossChallenge.GetBossLevelBuffInfluenceNumbers(self.bossLevelId, b.heroId) if infA ~= infB then return infA > infB else return a.heroId < b.heroId end end self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.BossFormation) table.sort(self.heroList, sort) CTL.HeroAwaken.TryFillAwakenHeroData(self.heroList, false) --1. 初始化武将出阵 self.formationHeroIdList = MDL.BossChallenge.LoadBossFormation(self.seasonId, self.bossLevelId) or {0, 0, 0, 0, 0, 0} --2. 首次打开界面加载武将优化策略 self:LoadHeroModelOnEnter() self.btn_Challenge:SetText(Const_IDS.IDS_ClimbTower_Start) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Hero_Choose) self:RefreshRightFormationHeroes() self:RefreshLeftHeroScroll() UIUtils.SetActive(self.group_card, false) end function UIBossChallengeFormation:LoadHeroModelOnEnter() local firstHeroId = CTL.BossChallenge.GetFirstSelectedHeroId(self.formationHeroIdList) if firstHeroId then self:RefreshHeroInfo(firstHeroId) else UIUtils.SetActive(self.group_UnHero.gameObject, true) --TODO:华为mate30 卡死 临时解决 进来先加载显示一个武将 但不是选中 self:RefreshHeroInfo(self.heroList[1].heroId) end self.btn_Challenge:SetText(Const_IDS.IDS_ClimbTower_Start) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Hero_Choose) self:RefreshRightFormationHeroes() UIManager.ActiveUIModle(false, "UIBossChallengeFormation") end function UIBossChallengeFormation:OnClosed() self:Closed() end function UIBossChallengeFormation:Closed() UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) MDL.BossChallenge.SaveBossFormation(self.seasonId, self.bossLevelId, self.formationHeroIdList) UIManager.ActiveUIModle(true, "UIBossChallengeFormation") if self.effectResult then self.effectResult:Dispose() self.effectResult = nil end end function UIBossChallengeFormation:SetBasicHeroCell(cell, heroId) local id, isAwaken = CTL.HeroAwaken.DecodeHeroId(heroId) UTL.Item.SetHeroIconByHeroId(cell.img_HeroHead, id, isAwaken) local influenceList = CTL.BossChallenge.GetBossLevelBuffInfluenceList(self.bossLevelId, id) local bossLevelData = DataSheetManager.BossChallengeLevel:GetDataByID(self.bossLevelId) local buffTable = bossLevelData.BuffID for i, v in ipairs(cell.group_Buffs) do if influenceList[i] then UIUtils.SetImageByAssetBundle(v, DataSheetManager.BuffData:GetDataByBuffID(buffTable[i]).BuffIcon) UIUtils.SetActive(v, true) else UIUtils.SetActive(v, false) end end end function UIBossChallengeFormation:RefreshLeftHeroScroll() if self.loopScroll_BossFormationHero.Count > 0 then self.loopScroll_BossFormationHero:ClearCells() end for i, v in ipairs(self.heroList) do self.loopScroll_BossFormationHero:AddData(v, 0) end end function UIBossChallengeFormation:RegistDragEvent() for i, v in ipairs(self.group_RightHero) do self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.Drag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.EndDrag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.Drop) self:RegistTriggerEvent(v.img_Empty, UIEventTriggerType.Drop) end end function UIBossChallengeFormation:RefreshRightFormationHeroes() for i, v in ipairs(self.group_RightHero) do self:RefreshSingleHeroCell(i) end end function UIBossChallengeFormation:RefreshSingleHeroCell(index) if index <= 6 then local heroId = self.formationHeroIdList[index] local cell = self.group_RightHero[index] if heroId and heroId > 0 then self:SetBasicHeroCell(cell, heroId) UIUtils.SetActive(cell.group_FormationHero, true) UIUtils.SetActive(cell.img_Empty, false) else UIUtils.SetActive(cell.group_FormationHero, false) UIUtils.SetActive(cell.img_Empty, true) end else logging.error(LTAG.ERROR, "传入的index: ", index, ", 超过了6,请检查!") end end function UIBossChallengeFormation:RefreshHeroInfo(heroId) self.curHeroId = heroId self.currentSkillGroupIndex = 1 --重置技能组索引 UIUtils.SetActive(self.group_Bottom.gameObject, true) UIUtils.SetActive(self.group_MidInfo.gameObject, true) UIUtils.SetActive(self.group_UnHero.gameObject, false) self:RefreshHeroSkills(heroId) self:RefreshHeroBasicInfos(heroId) self:RefreshHeroModel(heroId) end local SkillPath = ConstAssetPathConfig.SkillImagePath function UIBossChallengeFormation:RefreshHeroSkills(heroId) local id, isAwaken = CTL.HeroAwaken.DecodeHeroId(heroId) self.skillList = MDL.HeroSelect.GetHeroDisplaySkillIdList(id, true) --多套技能显示切换展示按钮 UIUtils.SetActive(self.btn_Change, #self.skillList > 1) for index, cell in ipairs(self.group_Skills) do local skillId = self.skillList[self.currentSkillGroupIndex][index] local skillIcon local skillData = (skillId and skillId>0) and DataSheetManager.SkillTipsData:GetDataByID(skillId) or nil if skillData then skillIcon = skillData.SkillIcon UIUtils.SetActive(cell.gameObject, true) if isAwaken then UIUtils.SetImageByAssetBundle(cell.img_Skill, CTL.HeroAwaken.GetAwakenDisplaySkillIcon(id, skillId)) else UIUtils.SetImageByAssetBundle(cell.img_Skill, string.format(SkillPath, skillIcon)) end else UIUtils.SetActive(cell.gameObject, false) end end end function UIBossChallengeFormation:RefreshHeroBasicInfos(heroId) local isAwaken heroId, isAwaken = CTL.HeroAwaken.DecodeHeroId(heroId) local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) if isAwaken then self.txt_HeroName.text = string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_Awaken, UIUtils.GetLocalizedTxt(Const_IDS[heroData.NameIDS])) else UIUtils.SetLabelText(self.txt_HeroName, Const_IDS[heroData.NameIDS]) end -- 武将国别 CTL.HeroSelect.SetHeroCountry(heroId, self.obj_Country) -- 武将职业 CTL.HeroSelect.SetHeroProfession(heroId, self.obj_Profession, true) local bossLevelData = DataSheetManager.BossChallengeLevel:GetDataByID(self.bossLevelId) local buffTable = bossLevelData.BuffID for i, v in ipairs(buffTable) do local iconPath = DataSheetManager.BuffData:GetDataByBuffID(v).BuffIcon UIUtils.SetImageByAssetBundle(self.group_BuffInfos[i].gameObject:GetComponent(typeof(Image)), iconPath) if CTL.BossChallenge.IsHeroBenefitBuffByBuffId(v, heroId) then self.group_BuffInfos[i]:SetGray(false) else self.group_BuffInfos[i]:SetGray(true, true) end end end function UIBossChallengeFormation:RefreshHeroModel(heroId) heroId = CTL.HeroAwaken.DecodeHeroId(heroId) --加载新模型之前先卸载之前的模型 UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) local bgTexturePath = ConstAssetPathConfig.bgTexturePath UTL.UIRender.Create2DSceneTrans(self.modelComponentDataHandle, Common2DScenePrefab, 1600, 0, 1600, bgTexturePath, false) UTL.UIRender.CreatePlayerModel(self.modelComponentDataHandle, heroId, nil, nil, true) UTL.UIRender.SetHeroParentPos(self.modelComponentDataHandle, 0.16, -1.2, 0) UTL.UIRender.SetHeroParentRot(self.modelComponentDataHandle, 0, -10, 0) if not self.effectResult then self.effectResult = CTL.FairPlay.CreateFogEffectInScene(UTL.UIRender.GetSceneTrans(self.modelComponentDataHandle)) end end function UIBossChallengeFormation:OnClickChallenge() if CTL.Activities.IsOpeningTime(LuaConst.ActivityType.BossChallenge) then for i, v in ipairs(self.formationHeroIdList) do if v == 0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_BossChallenge_ChooseHero_LackHero"]) return end end --进入关卡逻辑 if CTL.BossChallenge.IfBossLevelIdUnlock(self.bossLevelId, self.seasonId) then MDL.BossChallenge.EnterBossChallengeRequest(self.bossLevelId, self.seasonId, self.formationHeroIdList) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_BossChallenge_NotOpen"]) end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairPlay_3v3NotOpen"]) CTL.Sound.PlayGameSound("UI_invalid") end end function UIBossChallengeFormation:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIBossChallengeFormation:OnButtonClicked(comp) if comp == self.btn_Challenge then self:OnClickChallenge() CTL.Sound.PlayGameSound("UI_sound_Attack") elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.BossChallenge}) elseif comp == self.obj_Country.btn_Country then if self.curHeroId then local id, isAwaken = CTL.HeroAwaken.DecodeHeroId(self.curHeroId) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroFilterView, {canJump = false, heroId = id, isCountry = true, heroFilterPos = self.obj_HeroFilterPos}) end elseif comp == self.obj_Profession.btn_Profession then if self.curHeroId then local id, isAwaken = CTL.HeroAwaken.DecodeHeroId(self.curHeroId) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroFilterView, {canJump = false, heroId = id, isCountry = false, heroFilterPos = self.obj_HeroFilterPos}) end elseif comp == self.btn_Change then --切换技能显示 self.currentSkillGroupIndex = self.currentSkillGroupIndex + 1 if self.currentSkillGroupIndex > #self.skillList then self.currentSkillGroupIndex = 1 end self:RefreshHeroSkills(self.curHeroId) else for i, v in ipairs(self.group_RightHero) do if comp == v.btn_FormationHero then if self.dragItemId and self.dragItem then self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end return end local heroId = self.formationHeroIdList[i] local loopIndex = MDL.Array.GetIndexCellByList(self.formationHeroIdList[i], self.heroList) self.formationHeroIdList[i] = 0 self:RefreshSingleHeroCell(i) self.loopScroll_BossFormationHero:UpdateIndex(loopIndex - 1) self:OnClickHeroItem(heroId) return end end for index, cell in ipairs(self.group_Skills) do if comp == cell.btn_Skill then local id, isAwaken = CTL.HeroAwaken.DecodeHeroId(self.curHeroId) CTL.Tips.OpenHeroSkillTipsPreview(true, self.SkillTips, id, self.skillList[self.currentSkillGroupIndex][index], isAwaken) return end end for i, v in ipairs(self.group_BuffInfos) do if comp == v then CTL.Tips.CloseSkillTips(self.SkillTips) local buffId = DataSheetManager.BossChallengeLevel:GetDataByID(self.bossLevelId).BuffID[i] CTL.Tips.OpenSkillTips(buffId, self.SkillTips, CTL.Tips.SkillType.ConstantBuff) end end end end function UIBossChallengeFormation:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_BossFormationHero then self:SetBasicHeroCell(cellTable, data.heroId) local heroId, isAwaken = CTL.HeroAwaken.DecodeHeroId(data.heroId) local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) if isAwaken then cellTable.txt_HeroName.text = string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_Awaken, UIUtils.GetLocalizedTxt(Const_IDS[heroData.NameIDS])) else UIUtils.SetLabelText(cellTable.txt_HeroName, Const_IDS[heroData.NameIDS]) end if table.containValue(self.formationHeroIdList, data.heroId) then UIUtils.SetActive(cellTable.group_select, true) UIUtils.SetActive(cellTable.img_Selected, true) elseif table.containValue(self.formationHeroIdList, CTL.HeroAwaken.TranslateHeroId(data.heroId)) then UIUtils.SetActive(cellTable.group_select, true) UIUtils.SetActive(cellTable.img_Selected, false) else UIUtils.SetActive(cellTable.group_select, false) end UIUtils.SetActive(cellTable.img_Free, false) UIUtils.SetActive(cellTable.img_TestBg, false) end end function UIBossChallengeFormation:OnClickHeroItem(heroId) local id = CTL.HeroAwaken.TranslateHeroId(heroId) if id ~= heroId then local index = MDL.Array.GetIndexCellByList(id, self.heroList) if index and index - 1 >= 0 then self.loopScroll_BossFormationHero:UpdateIndex(index - 1) end end end function UIBossChallengeFormation:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopScroll_BossFormationHero then local index = CTL.BossChallenge.GetIndexByHeroId(self.formationHeroIdList, data.heroId) if index then self.formationHeroIdList[index] = 0 UIUtils.SetActive(cellTable.group_select, false) self:RefreshSingleHeroCell(index) self:OnClickHeroItem(data.heroId) else if CTL.BossChallenge.GetIndexByHeroId(self.formationHeroIdList, CTL.HeroAwaken.TranslateHeroId(data.heroId)) then --点击了同类武将无反馈(觉醒前后) return end local emptyIndex = CTL.BossChallenge.GetFirstNoneSelectIndex(self.formationHeroIdList) if emptyIndex then self.formationHeroIdList[emptyIndex] = data.heroId UIUtils.SetActive(cellTable.group_select, true) UIUtils.SetActive(cellTable.img_Selected, true) self:RefreshSingleHeroCell(emptyIndex) self:OnClickHeroItem(data.heroId) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_BossChallenge_ChooseHero_FullHero"]) return end end self:RefreshHeroInfo(data.heroId) self:ShowHeroFixedInfo(data.heroId) end end function UIBossChallengeFormation:GetIndexByInteractiveItem(comp) for i, v in ipairs(self.group_RightHero) do if comp == v.btn_FormationHero or comp == v.img_Empty then return i end end return nil end ---拖拽相关回调。一个特殊情况需要注意——将一个物体进行拖动,然后再放回原位置时,会触发Click而不是OnDrop和OnEndDrag function UIBossChallengeFormation:OnBeginDrag(comp, eventData) self.dragItem = GameObject.Instantiate(comp.transform.parent.parent.gameObject) self.dragItem.transform:SetParent(self.btn_Challenge.transform, false) self.dragItem.transform:GetChild(0):GetComponentInChildren(typeof(Image)).raycastTarget = false self.dragIndex = self:GetIndexByInteractiveItem(comp) self.dragItemId = self.formationHeroIdList[self.dragIndex] end function UIBossChallengeFormation:OnDrag(comp, eventData) if self.dragItem then UIUtils.ScreenPointToWorldPointInRectangle(self.dragItem, eventData) end end function UIBossChallengeFormation:OnEndDrag(comp, eventData) self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end end function UIBossChallengeFormation:OnDrop(comp, eventData) if not eventData.pointerEnter or not self.dragItemId or self.dragItemId <= 0 then self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end return end local dropIndex = self:GetIndexByInteractiveItem(comp) if dropIndex and dropIndex ~= self.dragIndex then local dragIndex = CTL.BossChallenge.GetIndexByHeroId(self.formationHeroIdList, self.dragItemId) local loopDragIndex = MDL.Array.GetIndexCellByList(self.dragItemId, self.heroList) local loopDropIndex = MDL.Array.GetIndexCellByList(self.formationHeroIdList[dropIndex], self.heroList) self.formationHeroIdList[dragIndex] = self.formationHeroIdList[dropIndex] self.formationHeroIdList[dropIndex] = self.dragItemId self:RefreshSingleHeroCell(dragIndex) self:RefreshSingleHeroCell(dropIndex) self.loopScroll_BossFormationHero:UpdateIndex(loopDragIndex - 1) if loopDropIndex then self.loopScroll_BossFormationHero:UpdateIndex(loopDropIndex - 1) end end self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end end function UIBossChallengeFormation:RefreshHeroFixedInfo() if self.curHeroId then self:ShowHeroFixedInfo(self.curHeroId) end end --显示武将校正信息 function UIBossChallengeFormation:ShowHeroFixedInfo(heroId) local hasData, atkContent,defContent,hpContent = CTL.FairPlay.GetFixedContent(MDL.FairPlay.FairPlayType.Boss,heroId) if hasData then UIUtils.SetActive(self.group_HeroInfo.gameObject,true) --修正属性 if string.isNilOrEmpty(atkContent) then UIUtils.SetActive(self.group_HeroInfo.txt_Info1,false) else UIUtils.SetActive(self.group_HeroInfo.txt_Info1,true) UIUtils.SetLabel(self.group_HeroInfo.txt_Info1,atkContent) end if string.isNilOrEmpty(defContent) then UIUtils.SetActive(self.group_HeroInfo.txt_Info2,false) else UIUtils.SetActive(self.group_HeroInfo.txt_Info2,true) UIUtils.SetLabel(self.group_HeroInfo.txt_Info2,defContent) end if string.isNilOrEmpty(hpContent) then UIUtils.SetActive(self.group_HeroInfo.txt_Info3,false) else UIUtils.SetActive(self.group_HeroInfo.txt_Info3,true) UIUtils.SetLabel(self.group_HeroInfo.txt_Info3,hpContent) end else UIUtils.SetActive(self.group_HeroInfo.gameObject,false) end end return UIBossChallengeFormation