local UIThreeTeamFightSelectOfficer = UIViewClass() local Effect_Drag_Event = ConstAssetPathConfig.Effect_Drag_Event local Effect_Replace_Event = ConstAssetPathConfig.Effect_Replace_Event function UIThreeTeamFightSelectOfficer:OnOpened(context) self.event_TeamArray = { [1] = self.event_Team1, [2] = self.event_Team2, [3] = self.event_Team3, } self.dragParentObj = self.drag_Parent.gameObject self.dragParentTrans = self.drag_Parent.transform self:InitEvents() self:RegistSystemEvent(EventID.UI_FreeLineUp_RefreshUI, self.OnRefreshSelectOfficer) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.CheckIfFuncUnlock) -- GMS UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, context.titleIDS) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, context.noteFunc ~= nil) self.selectHeroIndex = -1 --当前的阵容lineNumber self.curSelectLineNumber = 0 --当前阵容的6个武将 self.curLineUpHeroIds = { -1, -1, -1, -1, -1, -1 } self.curLineUpHeroInfos = {} self.curTabIndex = 1 MDL.FreeLineUp.FreeLineUpGetInfoRequest(context.freeLineupFuncType, context.lineNumbers, context.tempLineNumbers) end --如果tempLineNumbers不为空,则布阵过程都用temp来交互,直到最后才将temp置换到真正的lineNumber function UIThreeTeamFightSelectOfficer:GetLineNumbers() if self.context.tempLineNumbers then return self.context.tempLineNumbers end return self.context.lineNumbers end function UIThreeTeamFightSelectOfficer:OnRefreshSelectOfficer(funcType) if funcType == self.context.freeLineupFuncType then if CTL.ThreeTeamFight.IsSavingLineUp then CTL.ThreeTeamFight.IsSavingLineUp = false CTL.Tips.AddTipsMsg(Const_IDS.IDS_HeroBiography_Sweep10) self:CloseView() return end local allInfo = MDL.FreeLineUp.GetLineUpInfoByFunctionType(funcType) self.allLineUpInfo = {} local lineNumbers = self:GetLineNumbers() for _, lineNumber in ipairs(lineNumbers) do for i, v in ipairs(allInfo) do if v.lineNumber == lineNumber then self.allLineUpInfo[lineNumber] = v break end end end self:UpdatePickHero() self:SelectTabItem(self.curTabIndex) end end function UIThreeTeamFightSelectOfficer:UpdateLineUpHeroIds() if self.allLineUpInfo == nil then return end table.clear(self.curLineUpHeroInfos) for i, v in ipairs(self.curLineUpHeroIds) do self.curLineUpHeroIds[i] = -1 end local heroInfos if self.allLineUpInfo[self.curSelectLineNumber] then heroInfos = self.allLineUpInfo[self.curSelectLineNumber].heroInfos end if heroInfos then for i, v in ipairs(heroInfos) do if v.heroId > 0 then self.curLineUpHeroIds[v.posNumber] = v.heroId self.curLineUpHeroInfos[v.posNumber] = v end end end end function UIThreeTeamFightSelectOfficer:UpdatePickHero() local heroList = MDL.FreeLineUp.GetLineUpSpareHeroInfoList() if self.context.sortFunc then table.sort(heroList, self.context.sortFunc) end self.loop_AvailableHero:ReloadAll(heroList) end function UIThreeTeamFightSelectOfficer:UpdateLineUpHeroShow() if self.allLineUpInfo == nil then for i, v in ipairs(self.group_Heros) do v.empty_State:SetState(1) end return end for i, v in ipairs(self.group_Heros) do local heroInfo = self.curLineUpHeroInfos[i] if heroInfo then v.empty_State:SetState(0) self:SetLineUpHeroInfo(v, heroInfo) else v.empty_State:SetState(1) end end self:UpdateLineUpPower() end function UIThreeTeamFightSelectOfficer:UpdateLineUpPower() if self.allLineUpInfo == nil then return end local lineNumbers = self:GetLineNumbers() local power1 = MDL.FreeLineUp.GetTotalGs(self.context.freeLineupFuncType, lineNumbers[1]) local power2 = MDL.FreeLineUp.GetTotalGs(self.context.freeLineupFuncType, lineNumbers[2]) local power3 = MDL.FreeLineUp.GetTotalGs(self.context.freeLineupFuncType, lineNumbers[3]) if self.curTabIndex == 1 then UIUtils.SetLabelText(self.txt_Score01, Const_IDS.IDS_3TeamsPK_Team1Power) UIUtils.SetLabelText(self.txt_Score02, Const_IDS.IDS_3TeamsPK_Team2Power) UIUtils.SetLabelText(self.txt_Score03, Const_IDS.IDS_3TeamsPK_Team3Power) self.txt_Num01.text = power1 self.txt_Num02.text = power2 self.txt_Num03.text = power3 elseif self.curTabIndex == 2 then UIUtils.SetLabelText(self.txt_Score01, Const_IDS.IDS_3TeamsPK_Team2Power) UIUtils.SetLabelText(self.txt_Score02, Const_IDS.IDS_3TeamsPK_Team1Power) UIUtils.SetLabelText(self.txt_Score03, Const_IDS.IDS_3TeamsPK_Team3Power) self.txt_Num01.text = power2 self.txt_Num02.text = power1 self.txt_Num03.text = power3 elseif self.curTabIndex == 3 then UIUtils.SetLabelText(self.txt_Score01, Const_IDS.IDS_3TeamsPK_Team3Power) UIUtils.SetLabelText(self.txt_Score02, Const_IDS.IDS_3TeamsPK_Team1Power) UIUtils.SetLabelText(self.txt_Score03, Const_IDS.IDS_3TeamsPK_Team2Power) self.txt_Num01.text = power3 self.txt_Num02.text = power1 self.txt_Num03.text = power2 end self.txt_TotalScore.text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_Jade_Power) .. "\n" .. (power1 + power2 + power3) end function UIThreeTeamFightSelectOfficer:SetLineUpHeroInfo(comp, heroInfo) UTL.Item.SetHeroIconByHeroId(comp.img_SelectedHero, heroInfo.heroId, heroInfo.heroAwaken) local quality = CTL.HeroAwaken.GetHeroQuality(heroInfo.heroId, heroInfo.heroAwaken) UTL.Color.SetQualityImageByType(comp.img_QualityFrame, quality, UTL.Color.QualityType.HeroSelectFrame) UTL.Color.SetQualityImageByType(comp.img_QualityHead, quality, UTL.Color.QualityType.HeroSelectBg) UIUtils.SetLabel(comp.txt_Basic, heroInfo.heroBaseGs) UIUtils.SetLabel(comp.txt_Heritaged, heroInfo.lineUpGs) end function UIThreeTeamFightSelectOfficer:SelectTabItem(tabIndex) local lineNumbers = self:GetLineNumbers() self.curSelectLineNumber = lineNumbers[tabIndex] self.curTabIndex = tabIndex for i, v in ipairs(self.event_TeamArray) do self:UpdateTabItem(v, tabIndex == i) end self:UpdateLineUpHeroIds() self:UpdateLineUpHeroShow() self:UpdatePickHero() end function UIThreeTeamFightSelectOfficer:UpdateTabItem(comp, isSelect) if isSelect then comp.state_Button:SetState(1) else comp.state_Button:SetState(0) end end function UIThreeTeamFightSelectOfficer:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIThreeTeamFightSelectOfficer:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:OnCloseBtnClick() elseif comp == self.UITemplateTitlePanel.btn_Home then self:OnCloseBtnClick(true) elseif comp == self.btn_Save then self:OnSaveBtnClick() elseif comp == self.UITemplateTitlePanel.btn_Info then self.context.noteFunc() elseif comp == self.btn_Formation then MDL.ThreeTeamFight.CurEditLineNumber = self.curSelectLineNumber UIManager.OpenView(Const_UI_Lua.UIEnum.UIFreeLineupDetailPanel, { id = self.context.freeLineupFuncType, heroList = self.curLineUpHeroIds }) else for i, v in ipairs(self.group_Heros) do if v.rect_Click == comp then if self.curLineUpHeroIds[i] > 0 then self:ChangeLineUpHero(i, -1) break end end end end end function UIThreeTeamFightSelectOfficer:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_AvailableHero then UTL.Item.SetHeroIconByHeroId(cellTable.img_SelectedHero, data.heroId, data.heroAwaken) local quality = CTL.HeroAwaken.GetHeroQuality(data.heroId, data.heroAwaken) UTL.Color.SetQualityImageByType(cellTable.img_QualityFrame, quality, UTL.Color.QualityType.HeroSelectFrame) UTL.Color.SetQualityImageByType(cellTable.img_QualityHead, quality, UTL.Color.QualityType.HeroSelectBg) UIUtils.SetLabel(cellTable.txt_BR, data.heroBaseGs) local lineNumber = self:GetHeroLinePosNumber(data.heroId) if lineNumber > 0 then UIUtils.SetActive(cellTable.img_BlackCover, true) UIUtils.SetActive(cellTable.group_Team, true) self:FormatLineNumber(cellTable, lineNumber) else UIUtils.SetActive(cellTable.img_BlackCover, false) UIUtils.SetActive(cellTable.group_Team, false) end end end function UIThreeTeamFightSelectOfficer:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_AvailableHero then local lineNumber, posNumber = self:GetHeroLinePosNumber(data.heroId) if lineNumber > 0 then if lineNumber ~= self.curSelectLineNumber then CTL.Tips.AddTipsMsg(Const_IDS.IDS_3TeamsPK_AdjustTips) else self:ChangeLineUpHero(posNumber, -1) end else local unLineUpPos = self:GetUnLineUpPos() if unLineUpPos == 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_BossChallenge_ChooseHero_FullHero) else self:ChangeLineUpHero(unLineUpPos, data.heroId) end end end end function UIThreeTeamFightSelectOfficer:ChangeLineUpHero(pos, heroId) self.curLineUpHeroIds[pos] = heroId MDL.FreeLineUp.FreeLineUpSetRequest(self.context.freeLineupFuncType, self.curSelectLineNumber, MDL.FreeLineUp.SetType.Official, self.curLineUpHeroIds) end function UIThreeTeamFightSelectOfficer:GetUnLineUpPos() for i, v in ipairs(self.curLineUpHeroIds) do if v <= 0 then return i end end return 0 end --返回武将的阵容以及位置 function UIThreeTeamFightSelectOfficer:GetHeroLinePosNumber(heroId) if self.allLineUpInfo then for lineNumber, info in pairs(self.allLineUpInfo) do for i, v in ipairs(info.heroInfos) do if v.heroId == heroId then return lineNumber, v.posNumber end end end end return 0, 0 end function UIThreeTeamFightSelectOfficer:FormatLineNumber(cellTable, lineNumber) local lineNumbers = self:GetLineNumbers() cellTable.state_Team:SetState(lineNumber == self.curSelectLineNumber and 0 or 1) if lineNumbers[1] == lineNumber then UIUtils.SetLabelText(cellTable.labLocal_Team, Const_IDS.IDS_3TeamsPK_Team1) elseif lineNumbers[2] == lineNumber then UIUtils.SetLabelText(cellTable.labLocal_Team, Const_IDS.IDS_3TeamsPK_Team2) elseif lineNumbers[3] == lineNumber then UIUtils.SetLabelText(cellTable.labLocal_Team, Const_IDS.IDS_3TeamsPK_Team3) end end function UIThreeTeamFightSelectOfficer:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) end function UIThreeTeamFightSelectOfficer:InitEvents() self.dropGroup = { self.event_Team1.rect_Event.gameObject, self.event_Team2.rect_Event.gameObject, self.event_Team3.rect_Event.gameObject, } --注册事件 for i, v in ipairs(self.event_TeamArray) do self:RegistAllEvent(v.rect_Event) end end function UIThreeTeamFightSelectOfficer:RegistAllEvent(comp) self:RegistTriggerEvent(comp, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(comp, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(comp, UIEventTriggerType.Drag) self:RegistTriggerEvent(comp, UIEventTriggerType.EndDrag) self:RegistDropEvent(comp, self.dropGroup) end function UIThreeTeamFightSelectOfficer:OnBeginDrag(comp, eventData) UIUtils.ScreenPointToWorldPointInRectangle(self.dragParentObj, eventData) self.draggingTrans = comp.transform.parent self.originParent = self.draggingTrans.parent self.originX, self.originY = self.draggingTrans:GetLocalPosition() self.draggingTrans:SetParent(self.dragParentTrans, true) self:PlayDragEffect(comp) end function UIThreeTeamFightSelectOfficer:OnDrag(comp, eventData) UIUtils.ScreenPointToWorldPointInRectangle(self.dragParentObj, eventData) if eventData.pointerEnter then self:PlayReplaceEffect(comp, eventData.pointerEnter.transform) end end function UIThreeTeamFightSelectOfficer:OnDrop(comp, eventData) self:StopAllEffect() self:TryExchangeLineUp(comp, eventData.pointerDrag.transform) --实际不更换拖拽与释放的位置,只更换数据,因此最终都放回原来的位置即可 self.draggingTrans:SetParent(self.originParent, true) self.draggingTrans:SetLocalPosition(self.originX, self.originY, 0) end function UIThreeTeamFightSelectOfficer:OnEndDrag() --可以不写逻辑 但是必须有 ondrop 在 OnEndDrag 之后 end function UIThreeTeamFightSelectOfficer:PlayDragEffect(rect) local tagEffect = self:GetEffectNode(rect) if tagEffect then tagEffect:StopUIEffect() tagEffect:PlayUIEffect(Effect_Drag_Event, -1) end end function UIThreeTeamFightSelectOfficer:PlayReplaceEffect(dragTrans, targetTrans) self:StopAllEffect(dragTrans) local tagEffect = self:GetEffectNode(targetTrans) if tagEffect then tagEffect:StopUIEffect() tagEffect:PlayUIEffect(Effect_Replace_Event, -1) end end function UIThreeTeamFightSelectOfficer:StopAllEffect(exceptRect) for i, v in ipairs(self.event_TeamArray) do if exceptRect and exceptRect == v.rect_Event then else v.tag_Effect:StopUIEffect() end end end function UIThreeTeamFightSelectOfficer:GetEffectNode(rect) for i, v in ipairs(self.event_TeamArray) do if rect == v.rect_Event then return v.tag_Effect end end return nil end function UIThreeTeamFightSelectOfficer:GetRectIndex(rect) for i, v in ipairs(self.event_TeamArray) do if rect == v.rect_Event then return i end end return nil end function UIThreeTeamFightSelectOfficer:TryExchangeLineUp(targetObj, dragObj) if targetObj == nil then return end local curIndex = self:GetRectIndex(dragObj) local targetIndex = self:GetRectIndex(targetObj) if curIndex and targetIndex then local lineNumbers = self:GetLineNumbers() local lineNumber1 = lineNumbers[curIndex] local lineNumber2 = lineNumbers[targetIndex] self.curTabIndex = targetIndex MDL.FreeLineUp.FreeLineUpExchangeReq(self.context.freeLineupFuncType, lineNumber1, lineNumber2) end end function UIThreeTeamFightSelectOfficer:OnPointerDown(comp, eventdata) local index = self:GetRectIndex(comp) if index then if self.curTabIndex == index then return end self:SelectTabItem(index) end end function UIThreeTeamFightSelectOfficer:OnCloseBtnClick(isHome) if self.context.tempLineNumbers then if MDL.FreeLineUp.CheckLineNumbersDiff(self.context.freeLineupFuncType, self.context.tempLineNumbers, self.context.lineNumbers) then local saveFunc = function() self:OnSaveBtnClick() end local closeFunc = function() if isHome then CTL.HomeMain.CloseViewBackHomeMain() else self:CloseView() end end UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_3TeamsPK_SaveTips, saveFunc, closeFunc, Const_IDS.IDS_Btn_Save) else --没啥变化,直接关闭即可 if isHome then CTL.HomeMain.CloseViewBackHomeMain() else self:CloseView() end end else if isHome then CTL.HomeMain.CloseViewBackHomeMain() else self:CloseView() end end end function UIThreeTeamFightSelectOfficer:OnSaveBtnClick() local lineNumbers = self:GetLineNumbers() for i, lineNumber in ipairs(lineNumbers) do local illegal, tips = MDL.FreeLineUp.CheckLineNumberIllegal(self.context.freeLineupFuncType, lineNumber) if illegal then CTL.Tips.AddTipsMsg(tips) --跳转到对应的阵容 self:SelectTabItem(i) return end end CTL.ThreeTeamFight.IsSavingLineUp = true MDL.FreeLineUp.FreeLineUpGetInfoRequest(self.context.freeLineupFuncType, self.context.tempLineNumbers, self.context.lineNumbers) end function UIThreeTeamFightSelectOfficer:CheckIfFuncUnlock(funcId, isUnlock) if funcId == MDL.Unlock.FunctionType.ThreeTeamFight and not MDL.Unlock.IsUnlock(funcId) then self:CloseView() end end return UIThreeTeamFightSelectOfficer