local Common2DScenePrefab = ConstAssetPathConfig.Common2DScenePrefab --- 公平竞技-1v1(谁与争锋) 选择武将界面 local UISyncSoloFormation = UIViewClass() function UISyncSoloFormation:OnOpened(context) self:InitEvent() self:Init() end function UISyncSoloFormation:InitEvent() self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.OnCloseGamePlay) self:RegistSystemEvent(EventID.UI_FairPlay_RefreshHeroFixedInfo, self.RefreshHeroFixedInfo) self:RegistDragEvent() end function UISyncSoloFormation:Init() --优化加载武将界面,防止名称信息面板穿透 UIManager.ActiveUIModle(false, "UISyncSoloFormation") UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_BossChallenge_ChooseHero_Title) self.currentSkillGroupIndex = 1 --当前显示的技能组索引 -- 初始化可选武将列表 self:InitAllHeroList() --1. 初始化阵容 self:InitFormationHeroList() --2. 首次打开界面加载武将优化策略 self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.BossFormation) self:LoadHeroModelOnEnter() self.btn_Challenge:SetText(Const_IDS.IDS_1v1Sync_Button_Save) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_1v1Sync_Button_ChooseHero) self:RefreshRightFormationHeroes() self:RefreshLeftHeroScroll() local experienceCardNum = UTL.Item.GetItemStockCount(CTL.FairPlayCard.experienceCardId) UIUtils.SetLabel(self.txt_card, experienceCardNum > 0 and "x "..experienceCardNum or "x "..UTL.Color.FormatRedColor(experienceCardNum)) UIUtils.SetLabel(self.txt_cardname, UTL.Item.GetItemDataSpliceByType(CTL.FairPlayCard.experienceCardId).Name) self.toggle_UseCard.isOn = MDL.FairPlayCard.GetIs1V1ContinuousUseExperienceCard() MDL.SyncSolo.ResetSyncSoloExperienceFormationKey() UIUtils.SetActive(self.buff_btn, CTL.KingChallenge.IsHasSeasonBuff()) end function UISyncSoloFormation:InitAllHeroList() self.heroList = {} -- 测试武将 local testHeroArray = MDL.SyncSolo.GetTestHeroArray() if #testHeroArray > 0 then for i, v in ipairs(testHeroArray) do local itemData = DataSheetManager.ItemData:GetDataByID(v) table.insert(self.heroList, {heroId = itemData.BelongToHero, itemID = v, isFree = false}) end end -- 限免武将 local freeHeroList = MDL.SyncSolo.GetSyncSoloSeasonInfo().freeHeroes for i, v in ipairs(freeHeroList) do --将武将的道具ID转换成武将ID local itemData = DataSheetManager.ItemData:GetDataByID(v) local isTestHeroAndOpen, isTestHero, isOpen = MDL.SyncSolo.CheckIsTestHero(v) if not isTestHeroAndOpen then table.insert(self.heroList, {heroId = itemData.BelongToHero, isFree = true}) end end -- 排序后的已解锁武将(包括体验卡武将) local heroList = MDL.Replay.GetSortedAvailableSelectHeroList(MDL.Replay.FairPlayType.Solo, true) for i, v in ipairs(heroList) do if not self:ContainHeroId(self.heroList, v.heroId) then local isTestHeroAndOpen, isTestHero, isOpen = MDL.SyncSolo.CheckIsTestHero(v, true) if not isTestHeroAndOpen then table.insert(self.heroList, { heroId = v.heroId, isFree = false }) end end end CTL.HeroAwaken.TryFillAwakenHeroData(self.heroList, false) end function UISyncSoloFormation:InitFormationHeroList() self.formationHeroIdList = MDL.SyncSolo.LoadSyncSoloFormation() for index, heroId in ipairs(self.formationHeroIdList) do if heroId > 0 and CTL.FairPlayCard.IsUsedExperienceCard(heroId) then self.hasExperienceHeroLineup = true end end end function UISyncSoloFormation: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_1v1Sync_Button_Save) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_1v1Sync_Button_ChooseHero) self:RefreshRightFormationHeroes() end function UISyncSoloFormation:ContainHeroId(list, id) for i, v in ipairs(list) do if v.heroId == id then return true end end return false end function UISyncSoloFormation:OnClosed() UIManager.ActiveUIModle(true, "UISyncSoloFormation") UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) self:CloseSaveLineup() MDL.Replay.ClearWinRateCacheData(MDL.FairPlay.FairPlayType.Solo) end function UISyncSoloFormation:CloseSaveLineup() MDL.SyncSolo.SaveSyncSoloFormation(self.formationHeroIdList) if self.effectResult then self.effectResult:Dispose() self.effectResult = nil end end function UISyncSoloFormation:OnBackButtonPressed() self:OnButtonClicked(self.btn_Challenge) end function UISyncSoloFormation:OnClickSaveOrQuit() self:CloseView(true) end function UISyncSoloFormation:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close or comp == self.btn_Challenge then self:OnClickSaveOrQuit() 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.BattleGround_1V1, params = {MDL.SyncSolo.GetSoloLevelRank()}}) 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) 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_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.FairPlayCard}) elseif comp == self.btn_card then UTL.ItemTips.ShowCommonTipsById(CTL.FairPlayCard.experienceCardId) elseif comp == self.buff_btn then UIManager.OpenView(Const_UI_Lua.UIEnum.UIKingChallengeSeasonBuffPopUp) 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) if CTL.FairPlayCard.IsUsedExperienceCard(self.formationHeroIdList[i]) then self.hasExperienceHeroLineup = false end 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 end end function UISyncSoloFormation: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 UISyncSoloFormation: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 UISyncSoloFormation: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 UISyncSoloFormation: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) for i, v in ipairs(self.group_BuffInfos) do UIUtils.SetActive(v.gameObject, false) end end function UISyncSoloFormation: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 UISyncSoloFormation:RefreshRightFormationHeroes() for i, v in ipairs(self.group_RightHero) do self:RefreshSingleHeroCell(i) end end function UISyncSoloFormation: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 UISyncSoloFormation:SetBasicHeroCell(cell, heroId) UTL.Item.SetHeroIconByHeroId(cell.img_HeroHead, CTL.HeroAwaken.DecodeHeroId(heroId)) for i, v in ipairs(cell.group_Buffs) do UIUtils.SetActive(v, false) end end function UISyncSoloFormation: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 UISyncSoloFormation:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_BossFormationHero then local heroId = data.heroId self:SetBasicHeroCell(cellTable, heroId) local isAwaken heroId, isAwaken = CTL.HeroAwaken.DecodeHeroId(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 local isTestHeroAndOpen, isTestHero, isOpen = MDL.SyncSolo.CheckIsTestHero(data.itemID) if isTestHeroAndOpen then UIUtils.SetActive(cellTable.img_TestBg, true) UIUtils.SetActive(cellTable.img_Free, false) else UIUtils.SetActive(cellTable.img_TestBg, false) UIUtils.SetActive(cellTable.img_Free, data.isFree) end UIUtils.SetActive(cellTable.img_experience, CTL.FairPlayCard.IsUsedExperienceCard(heroId)) end end function UISyncSoloFormation:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopScroll_BossFormationHero then local index = CTL.BossChallenge.GetIndexByHeroId(self.formationHeroIdList, data.heroId) if index then if CTL.FairPlayCard.IsUsedExperienceCard(data.heroId) then self.hasExperienceHeroLineup = false end 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 if self.hasExperienceHeroLineup and CTL.FairPlayCard.IsUsedExperienceCard(data.heroId) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_KingChallenge_Hint17"]) return end if CTL.FairPlayCard.IsUsedExperienceCard(data.heroId) then self.hasExperienceHeroLineup = true end 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 UISyncSoloFormation: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 UISyncSoloFormation: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 UISyncSoloFormation: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 UISyncSoloFormation:OnDrag(comp, eventData) if self.dragItem then UIUtils.ScreenPointToWorldPointInRectangle(self.dragItem, eventData) end end function UISyncSoloFormation:OnEndDrag(comp, eventData) self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end end function UISyncSoloFormation: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 UISyncSoloFormation:OnCloseGamePlay() if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.SyncSolo) then self:CloseView(true) end end function UISyncSoloFormation:RefreshHeroFixedInfo() if self.curHeroId then self:ShowHeroFixedInfo(self.curHeroId) end end --显示武将校正信息 function UISyncSoloFormation:ShowHeroFixedInfo(heroId) local hasData, atkContent,defContent,hpContent = CTL.FairPlay.GetFixedContent(MDL.FairPlay.FairPlayType.Solo,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 function UISyncSoloFormation:OnValueChanged(comp, value) if comp == self.toggle_UseCard then if UTL.Item.GetItemStockCount(CTL.FairPlayCard.experienceCardId) <= 0 then if self.toggle_UseCard.isOn then self.toggle_UseCard.isOn = false CTL.Tips.AddTipsMsg(Const_IDS.IDS_KingChallenge_Hint16) end else MDL.FairPlayCard.ChangeFairPlayCardInfoReq(MDL.FairPlay.FairPlayType.Solo, MDL.FairPlayCard.GetIs1V1UseProtectCard(), value) end end end return UISyncSoloFormation