local UIThreeTeamFightPopUp = UIViewClass() local Effect_Drag_Event = ConstAssetPathConfig.Effect_Drag_Event1 local Effect_Replace_Event = ConstAssetPathConfig.Effect_Replace_Event2 function UIThreeTeamFightPopUp:OnOpened(context) self:InitEvents() UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Fomation_Fomation) self:RegistSystemEvent(EventID.UI_ThreeTeamFight_RefreshChallengePopUpInfo, self.UpdateInfo) self:RegistSystemEvent(EventID.UI_FreeLineUp_RefreshUI, self.UpdateMyLineUp) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.CheckIfFuncUnlock) -- GMS self:RegistSystemEvent(EventID.UI_ThreeTeamFight_OnSeasonFinish, self.OnSeasonFinish) -- GMS self:InitMyInfo() MDL.ThreeTeamFight.ThreeTeamsPKFightInfoReq(self.context.acid) end function UIThreeTeamFightPopUp:InitMyInfo() local lev = MDL.Player.GetRoleInfo() self:SetPlayerInfo(self.group_LeftHero, BattleDataGetter.GetPlayerName(), MDL.Character.GetCurWearPortrait(), MDL.Character.GetCurWearFrame(), lev, MDL.Player.GetSelfGender(), MDL.Login.GetServerShowId()) end function UIThreeTeamFightPopUp:UpdateInfo(info) --我方阵容 self:SetMyLineUp(info.lineUpInfo.lineUps) --对方阵容 self:SetTargetLineUpHeroArray(self.group_Right[1], info.lineUpHeroIds1, info.gs[1], CTL.ThreeTeamFight.CheckIfHideByIndex(self.context.rank, 1)) self:SetTargetLineUpHeroArray(self.group_Right[2], info.lineUpHeroIds2, info.gs[2], CTL.ThreeTeamFight.CheckIfHideByIndex(self.context.rank, 2)) self:SetTargetLineUpHeroArray(self.group_Right[3], info.lineUpHeroIds3, info.gs[3], CTL.ThreeTeamFight.CheckIfHideByIndex(self.context.rank, 3)) self:SetPlayerInfo(self.group_RightHero, info.ShowInfo.name, info.ShowInfo.PortraitId, info.ShowInfo.FrameId, info.ShowInfo.level, info.ShowInfo.sex, info.ShowInfo.ShowServerId) end function UIThreeTeamFightPopUp:UpdateMyLineUp() local lineUps = MDL.FreeLineUp.GetLineUpInfoByFunctionType(MDL.FreeLineUp.FuncType.ThreeTeamFight) if lineUps then self:SetMyLineUp(lineUps) end end function UIThreeTeamFightPopUp:SetMyLineUp(lineUps) if lineUps and #lineUps > 0 then for i, v in ipairs(lineUps) do if v.lineNumber == CTL.ThreeTeamFight.LineNumberType.Attack_1 then self:SetMyLineUpHeroArray(self.group_Left[1], v.heroInfos, v.TotalGs) elseif v.lineNumber == CTL.ThreeTeamFight.LineNumberType.Attack_2 then self:SetMyLineUpHeroArray(self.group_Left[2], v.heroInfos, v.TotalGs) elseif v.lineNumber == CTL.ThreeTeamFight.LineNumberType.Attack_3 then self:SetMyLineUpHeroArray(self.group_Left[3], v.heroInfos, v.TotalGs) end end else for i, v in ipairs(self.group_Left) do self:SetMyLineUpHeroArray(v, nil, 0) end end end function UIThreeTeamFightPopUp:SetPlayerInfo(comp, name, portraitId, frameId, level, sex, serverId) comp.txt_Name.text = name CTL.Character.SetPortraitAndFrame(comp.UIHeroHead150, portraitId, frameId, level) CTL.Player.OperateGenderImage(comp.image_Gender, sex) comp.txt_Num.text = "S." .. serverId end function UIThreeTeamFightPopUp:SetMyLineUpHeroArray(comp, heroInfos, gs) if heroInfos then for i, v in ipairs(comp.group_Team) do local heroInfoMain = heroInfos[i * 2 - 1] self:SetHeroItem(true, v.template_HeroMain, heroInfoMain) local heroInfoAssistant = heroInfos[i * 2] self:SetHeroItem(true, v.template_HeroAssistant, heroInfoAssistant) end else for i, v in ipairs(comp.group_Team) do self:SetHeroItem(true, v.template_HeroMain, nil) self:SetHeroItem(true, v.template_HeroAssistant, nil) end end comp.txt_BR.text = gs end function UIThreeTeamFightPopUp:SetTargetLineUpHeroArray(comp, heroInfoArray, gs, isHide) if heroInfoArray then for i, v in ipairs(comp.group_Team) do local heroInfoMain = heroInfoArray[i * 2 - 1] self:SetHeroItem(false, v.template_HeroMain, heroInfoMain, isHide) local heroInfoAssistant = heroInfoArray[i * 2] self:SetHeroItem(false, v.template_HeroAssistant, heroInfoAssistant, isHide) end else for i, v in ipairs(comp.group_Team) do self:SetHeroItem(false, v.template_HeroMain, nil, isHide) self:SetHeroItem(false, v.template_HeroAssistant, nil, isHide) end end if isHide then comp.txt_BR.text = "???" else comp.txt_BR.text = gs end end function UIThreeTeamFightPopUp:SetHeroItem(isMy, template, heroInfo, isHide) local heroId = heroInfo and heroInfo.heroId or 0 UIUtils.SetActive(template.group_Level, false) if isHide then UIUtils.SetActive(template.img_Hide, true) UIUtils.SetActive(template.img_Empty, false) UIUtils.SetActive(template.img_HeroHead, false) else UIUtils.SetActive(template.img_Hide, false) if heroId and heroId > 0 then UIUtils.SetActive(template.img_Empty, false) UIUtils.SetActive(template.img_HeroHead, true) if isMy then UTL.Item.SetHeroIconByHeroId(template.img_HeroHead, heroId, heroInfo.heroAwaken) else UTL.Item.SetHeroIconByHeroId(template.img_HeroHead, heroId, heroInfo.isAwaken) end else UIUtils.SetActive(template.img_Empty, true) UIUtils.SetActive(template.img_HeroHead, false) end end end function UIThreeTeamFightPopUp:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIThreeTeamFightPopUp:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Formation then CTL.ThreeTeamFight.OpenFormation(true) elseif comp == self.btn_Challenge then MDL.ThreeTeamFight.EnterFightReq(self.context.acid, self.context.rank) end end function UIThreeTeamFightPopUp:OnClosed() --防止模板被污染,关闭时将新增的节点给隐藏掉 for _, group in ipairs(self.group_Left) do for _, v in ipairs(group.group_Team) do UIUtils.SetActive(v.template_HeroMain.img_Hide, false) UIUtils.SetActive(v.template_HeroAssistant.img_Hide, false) end end for _, group in ipairs(self.group_Right) do for _, v in ipairs(group.group_Team) do UIUtils.SetActive(v.template_HeroMain.img_Hide, false) UIUtils.SetActive(v.template_HeroAssistant.img_Hide, false) end end end function UIThreeTeamFightPopUp:InitEvents() self.dragParentObj = self.drag_Parent.gameObject self.dragParentTrans = self.drag_Parent.transform self.dropGroup = { self.group_Left[1].img_drag.gameObject, self.group_Left[2].img_drag.gameObject, self.group_Left[3].img_drag.gameObject, } --注册事件 for i, v in ipairs(self.group_Left) do self:RegistAllEvent(v.img_drag) end end function UIThreeTeamFightPopUp:RegistAllEvent(comp) self:RegistTriggerEvent(comp, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(comp, UIEventTriggerType.Drag) self:RegistTriggerEvent(comp, UIEventTriggerType.EndDrag) self:RegistDropEvent(comp, self.dropGroup) end function UIThreeTeamFightPopUp: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 UIThreeTeamFightPopUp:OnDrag(comp, eventData) UIUtils.ScreenPointToWorldPointInRectangle(self.dragParentObj, eventData) if eventData.pointerEnter then self:PlayReplaceEffect(comp, eventData.pointerEnter.transform) end end function UIThreeTeamFightPopUp: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 UIThreeTeamFightPopUp:OnEndDrag() --可以不写逻辑 但是必须有 ondrop 在 OnEndDrag 之后 end function UIThreeTeamFightPopUp:PlayDragEffect(rect) local tagEffect = self:GetEffectNode(rect) if tagEffect then tagEffect:StopUIEffect() tagEffect:PlayUIEffect(Effect_Drag_Event, -1) end end function UIThreeTeamFightPopUp: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 UIThreeTeamFightPopUp:StopAllEffect(exceptRect) for i, v in ipairs(self.group_Left) do if exceptRect and exceptRect == v.img_drag then else v.tag_Effect:StopUIEffect() end end end function UIThreeTeamFightPopUp:GetEffectNode(rect) for i, v in ipairs(self.group_Left) do if rect == v.img_drag then return v.tag_Effect end end return nil end function UIThreeTeamFightPopUp:GetRectLineNumber(rect) if rect == self.group_Left[1].img_drag then return CTL.ThreeTeamFight.LineNumberType.Attack_1 elseif rect == self.group_Left[2].img_drag then return CTL.ThreeTeamFight.LineNumberType.Attack_2 elseif rect == self.group_Left[3].img_drag then return CTL.ThreeTeamFight.LineNumberType.Attack_3 end return nil end function UIThreeTeamFightPopUp:TryExchangeLineUp(targetObj, dragObj) if targetObj == nil then return end local curLineNumber = self:GetRectLineNumber(dragObj) local targetLineNumber = self:GetRectLineNumber(targetObj) if curLineNumber and targetLineNumber then MDL.FreeLineUp.FreeLineUpExchangeReq(MDL.FreeLineUp.FuncType.ThreeTeamFight, curLineNumber, targetLineNumber) end end function UIThreeTeamFightPopUp:CheckIfFuncUnlock(funcId, isUnlock) if funcId == MDL.Unlock.FunctionType.ThreeTeamFight and not MDL.Unlock.IsUnlock(funcId) then self:OnButtonClicked(self.UICommonPopUp.btn_Close) end end function UIThreeTeamFightPopUp:OnSeasonFinish() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end return UIThreeTeamFightPopUp