require("Base/BasePanel") HandBookHeroInfoPanel = Inherit(BasePanel) local this = HandBookHeroInfoPanel local tabs = { [1] = {default = "r_hero_xuanze_002", lock = "r_hero_xuanze_002", select = "r_hero_xuanze_001",title = Language[11093], sub = SubUIConfig.HandBookRoleInfoLayout }, [2] = {default = "r_hero_xuanze_002", lock = "r_hero_xuanze_002", select = "r_hero_xuanze_001",title = Language[11095], sub = SubUIConfig.RoleStoryLayout }, [3] = {default = "r_hero_xuanze_002", lock = "r_hero_xuanze_002", select = "r_hero_xuanze_001",title = Language[11816], sub = SubUIConfig.HandBookRoleSkinPanel }, } local index = {1,2,3,4,5,6,9,10,11} local heroConFigData local leftHeroData local rightHeroData local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig) local heroLevelConfig = ConfigManager.GetConfig(ConfigName.HeroLevelConfig) local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig) local isClickLeftOrRightBtn = true local index=0 local leftIndex=0 local rightIndex=0 local _leftStar=0 local _curStar=0 local _rightStar=0 local tabsList = {} local _CurPageIndex = 1 --初始化组件(用于子类重写) function HandBookHeroInfoPanel:InitComponent() this.spLoader = SpriteLoader.New() self.btnBack = Util.GetGameObject(self.transform, "btnBack") this.bgImageList = {} for i = 1, 4 do this.bgImageList[i] = Util.GetGameObject(self.transform, "bg/di ("..i..")") end self.curObj= Util.GetGameObject(self.transform, "curObj") self.leftObj= Util.GetGameObject(self.transform, "leftObj") self.rightObj= Util.GetGameObject(self.transform, "rightObj") self.leftBtn = Util.GetGameObject(self.transform, "leftBtn/GameObject") self.rightBtn = Util.GetGameObject(self.transform, "rightBtn/GameObject") self.dragView = SubUIManager.Open(SubUIConfig.DragView, self.gameObject.transform) self.dragView.transform:SetSiblingIndex(1) self.starGrid = Util.GetGameObject(self.transform, "info/sartAndLvLayout") self.heroName = Util.GetGameObject(self.transform, "info/nameAndPossLayout/heroName"):GetComponent("Text") self.profession = Util.GetGameObject(self.transform, "info/nameAndPossLayout/proImage/proImage"):GetComponent("Image") --定位描述 self.posBgImage=Util.GetGameObject(self.transform,"pos"):GetComponent("Image") self.posImage=Util.GetGameObject(self.transform,"pos/posImage"):GetComponent("Image") self.posText=Util.GetGameObject(self.transform,"pos/posText"):GetComponent("Text") self.layout=Util.GetGameObject(self.transform,"layout") self.PageList = {} this.trigger=Util.GetEventTriggerListener(self.dragView.gameObject) this.trigger.onBeginDrag = this.trigger.onBeginDrag + this.OnBeginDrag this.trigger.onDrag = this.trigger.onDrag + this.OnDrag this.trigger.onEndDrag = this.trigger.onEndDrag + this.OnEndDrag this.posBtn=Util.GetGameObject(self.gameObject,"posBtn")--定位按钮 this.btnList = Util.GetGameObject(self.transform,"btnList") this.btnPre = Util.GetGameObject(self.transform,"btnInfo") this.select = Util.GetGameObject(self.transform, "selectBtn") this.btnMask = Util.GetGameObject(self.transform, "btnMask") this.btnMask.gameObject:SetActive(false) end --绑定事件(用于子类重写) function HandBookHeroInfoPanel:BindEvent() Util.AddClick(self.btnBack, function() self:ClosePanel() end) Util.AddClick(this.leftBtn, function() self:LeftBtnOnClick() end) Util.AddClick(this.rightBtn, function() self:RightBtnOnClick() end) Util.AddClick(this.posBtn, function() UIManager.OpenPanel(UIName.RolePosInfoPopup,heroConFigData,_curStar) end) end local heroDatas = {} --界面打开时调用(用于子类重写) 第一个参数 英雄数据 第二个参数 属性id function HandBookHeroInfoPanel:OnOpen(...) local temp={...} heroDatas = {} heroConFigData = temp[1] if(temp[3]) then _curStar=temp[3] end _CurPageIndex = 1 heroDatas = PlayerManager.heroHandBookListData[_curStar] for i = 1, #heroDatas do if heroConFigData.Id == heroDatas[i].Id then index = i end end end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function HandBookHeroInfoPanel:OnShow() --先清除之前的立绘 if this.leftLiveObj then poolManager:UnLoadLive(this.leftLiveObj.name, this.leftLiveObj) this.leftLiveObj = nil end if this.rightLiveObj then poolManager:UnLoadLive(this.rightLiveObj.name, this.rightLiveObj) this.rightLiveObj = nil end if this.curLiveObj then poolManager:UnLoadLive(this.curLiveObj.name, this.curLiveObj) this.curLiveObj = nil end Util.ClearChild(self.curObj.transform) Util.ClearChild(self.leftObj.transform) Util.ClearChild(self.rightObj.transform) self:RefreshHeroLive() end --刷新英雄界面信息 function HandBookHeroInfoPanel:RefreshHeroLive() self:UpdateLiveList() --加载当前英雄的立绘 this.leftLiveObj = self:LoadHerolive(leftHeroData,self.leftObj) this.rightLiveObj = self:LoadHerolive(rightHeroData,self.rightObj) this.curLiveObj = self:LoadHerolive(heroConFigData,self.curObj) if this.curLiveObj then self.dragView.gameObject:SetActive(true) self.dragView:SetDragGO(this.curLiveObj) else self.dragView.gameObject:SetActive(false) end self:UpdateHeroInfoData() end --刷新左右两边的英雄星级和index function HandBookHeroInfoPanel:UpdateLiveList() local starIndex = ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.RoleAwake) and 11 or 10 if index - 1 > 0 then _leftStar = _curStar leftIndex = index - 1 leftHeroData=heroDatas[leftIndex] else _leftStar = _curStar + 1 while(not PlayerManager.heroHandBookListData[_leftStar] or #PlayerManager.heroHandBookListData[_leftStar] < 1) do if _leftStar >= starIndex then _leftStar = 0 end _leftStar = _leftStar + 1 end leftIndex = #PlayerManager.heroHandBookListData[_leftStar] leftHeroData = PlayerManager.heroHandBookListData[_leftStar][leftIndex] end if index + 1 <= #heroDatas then _rightStar = _curStar rightIndex = index + 1 rightHeroData=heroDatas[rightIndex] else _rightStar = _curStar - 1 while(not PlayerManager.heroHandBookListData[_rightStar] or #PlayerManager.heroHandBookListData[_rightStar] < 1) do if _rightStar < 1 then _rightStar = starIndex + 1 end _rightStar = _rightStar - 1 end rightIndex = 1 rightHeroData=PlayerManager.heroHandBookListData[_rightStar][rightIndex] end end function HandBookHeroInfoPanel:SetPanelBg(heroData) for i = 1, 4 do if heroData.PropertyName == i then this.bgImageList[i]:SetActive(true) else this.bgImageList[i]:SetActive(false) end end end --刷新页签数据 function this:UpdateHeroInfoData() for k,v in pairs(this.PageList) do v:OnHide() end local starSize = Vector2.New(60,60) SetHeroStars(this.spLoader, this.starGrid, _curStar,2,starSize,-10,Vector2.New(0.5,0.5)) this.heroName.text = GetLanguageStrById(heroConFigData.ReadingName) this.profession.sprite =this.spLoader:LoadSprite(GetProStrImageByProNum(heroConFigData.PropertyName)) --定位描述相关 this.posBgImage.sprite=this.spLoader:LoadSprite(GetHeroPosBgStr(heroConFigData.Profession)) this.posImage.sprite=this.spLoader:LoadSprite(GetHeroPosStr(heroConFigData.Profession)) this.posText.text=GetLanguageStrById(heroConFigData.HeroLocation) SetTextVerTial(self.posText,Vector3.New(72,0,0)) if _CurPageIndex == 3 then local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.HeroSkin,"HeroId",heroConFigData.Id) local HeoSkin = {} for i = 1 ,#configs do if not HeoSkin[configs[i].Type] and configs[i].Show == 1 then HeoSkin[configs[i].Type] = configs[i] end end if LengthOfTable(HeoSkin) < 2 then _CurPageIndex = 1 end end self:SetPanelBg(heroConFigData) self:UpdateBtnList() self:SetSelectBtn(_CurPageIndex) self:OnPageTabChange(_CurPageIndex) --角色定位按钮 this.posBtn.gameObject:SetActive(heroConFigData.ShowHeroLocation==1) end --加载页签内容 function HandBookHeroInfoPanel:UpdateBtnList() if not tabsList then tabsList = {} end for k,v in pairs(tabsList) do tabsList[k].gameObject:SetActive(false) end for k,v in ipairs(tabs) do if not tabsList[k] then tabsList[k] = newObjToParent(this.btnPre,this.btnList) end if k == 3 then local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.HeroSkin,"HeroId",heroConFigData.Id) local HeoSkin = {} for i = 1 ,#configs do if not HeoSkin[configs[i].Type] and configs[i].Show then HeoSkin[configs[i].Type] = configs[i] end end if LengthOfTable(HeoSkin) > 1 then tabsList[k].gameObject:SetActive(true) else tabsList[k].gameObject:SetActive(false) end else tabsList[k].gameObject:SetActive(true) end local title = Util.GetGameObject(tabsList[k], "Text"):GetComponent("Text") title.text = GetCurLanguage() == 0 and v.title or ""..v.title.."" Util.AddOnceClick(tabsList[k],function() if k == _CurPageIndex then else self:SetSelectBtn(k) self:OnPageTabChange(k) end end) end end --页签选中效果设置 function HandBookHeroInfoPanel:SetSelectBtn(index) this.select.transform:SetParent(tabsList[index].transform) this.select.transform.localScale = Vector3.one this.select.transform.localPosition=Vector3.zero this.select.transform:SetAsFirstSibling() end -- tab改变事件 function HandBookHeroInfoPanel:OnPageTabChange(index) self:ChangeCurentHeroSkinLive() if this.PageList[_CurPageIndex] then this.PageList[_CurPageIndex]:OnHide() end _CurPageIndex = index if not this.PageList[index] then this.PageList[index] = SubUIManager.Open(tabs[index].sub,self.layout.transform) end this.PageList[index]:OnShow() this.PageList[index]:SetData(this.sortingOrder,self,heroConFigData,_curStar) end function HandBookHeroInfoPanel:ChangeCurentHeroSkinLive(herodata) if this.curLiveObj then poolManager:UnLoadLive(this.curLiveObj.name, this.curLiveObj) this.curLiveObj = nil end if herodata then this.curLiveObj=self:LoadHerolive(herodata,this.curObj) else this.curLiveObj=self:LoadHerolive(heroConFigData,this.curObj) end self:SetDragView() end function HandBookHeroInfoPanel:SetDragView() if this.curLiveObj then this.dragView.gameObject:SetActive(true) this.dragView:SetDragGO(this.curLiveObj) else this.dragView.gameObject:SetActive(false) end end function this:OnSortingOrderChange() this.sortingOrder = this.sortingOrder end --根据界面数据加载动态立绘 function HandBookHeroInfoPanel:LoadHerolive(_heroData, _objPoint) --TODO:动态加载立绘 local testLive = poolManager:LoadLive(GetResourcePath(_heroData.Live), _objPoint.transform, Vector3.one * _heroData.Scale, Vector3.New(_heroData.Position[1], _heroData.Position[2], 0)) local SkeletonGraphic = testLive:GetComponent("SkeletonGraphic") local idle = function() SkeletonGraphic.AnimationState:SetAnimation(0, "idle", true) end SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete + idle poolManager:SetLiveClearCall(_heroData.Live, testLive, function () SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete - idle end) return testLive end --右切换按钮点击 function HandBookHeroInfoPanel:RightBtnOnClick() if isClickLeftOrRightBtn == false then return end this.btnMask.gameObject:SetActive(true) isClickLeftOrRightBtn = false self.rightBtn:GetComponent("Button").enabled = false local oldIndexConfigData = heroDatas[index] index =rightIndex if _curStar ~= _rightStar then _curStar = _rightStar heroDatas = PlayerManager.heroHandBookListData[_curStar] end heroConFigData = heroDatas[index] if this.leftLiveObj then poolManager:UnLoadLive(GetResourcePath(leftHeroData.Live), this.leftLiveObj) this.leftLiveObj = nil end this.curLiveObj.transform:SetParent(self.leftObj.transform) this.curLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(oldIndexConfigData.Position[1],oldIndexConfigData.Position[2]), 0.5, false):SetEase(Ease.Linear) this.rightLiveObj.transform:SetParent(self.curObj.transform) this.rightLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(rightHeroData.Position[1],rightHeroData.Position[2]), 0.5, false):OnComplete(function () this:UpdateLiveList() if this.curLiveObj then poolManager:UnLoadLive(this.curLiveObj.name, this.leftLiveObj) this.curLiveObj = nil end Util.ClearChild(self.leftObj.transform) this.leftLiveObj = this:LoadHerolive(leftHeroData,self.leftObj) this.curLiveObj = this.rightLiveObj this.rightLiveObj = this:LoadHerolive(rightHeroData,self.rightObj) local SkeletonGraphic = this.curLiveObj:GetComponent("SkeletonGraphic") SkeletonGraphic.AnimationState:SetAnimation(0, "touch", false) this.rightBtn:GetComponent("Button").enabled = true isClickLeftOrRightBtn = true this:UpdateHeroInfoData() this.btnMask.gameObject:SetActive(false) end):SetEase(Ease.Linear) end --左切换按钮点击 function HandBookHeroInfoPanel:LeftBtnOnClick() if isClickLeftOrRightBtn == false then return end this.btnMask.gameObject:SetActive(true) isClickLeftOrRightBtn = false self.leftBtn:GetComponent("Button").enabled = false local oldIndexConfigData = heroDatas[index] index =leftIndex if _curStar~= _leftStar then _curStar = _leftStar heroDatas = PlayerManager.heroHandBookListData[_curStar] end heroConFigData = heroDatas[index] if this.rightLiveObj then poolManager:UnLoadLive(GetResourcePath(rightHeroData.Live), this.rightLiveObj) this.rightLiveObj = nil end this.curLiveObj.transform:SetParent(self.rightObj.transform) this.curLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(oldIndexConfigData.Position[1],oldIndexConfigData.Position[2]), 0.5, false):SetEase(Ease.Linear) this.leftLiveObj.transform:SetParent(self.curObj.transform) this.leftLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(leftHeroData.Position[1],leftHeroData.Position[2]), 0.5, false):OnComplete(function () this:UpdateLiveList() if this.curLiveObj then poolManager:UnLoadLive(this.curLiveObj.name, this.rightLiveObj) this.curLiveObj = nil end Util.ClearChild(self.rightObj.transform) this.rightLiveObj = this:LoadHerolive(rightHeroData,self.rightObj) this.curLiveObj = this.leftLiveObj this.leftLiveObj = this:LoadHerolive(leftHeroData,self.leftObj) local SkeletonGraphic = this.curLiveObj:GetComponent("SkeletonGraphic") SkeletonGraphic.AnimationState:SetAnimation(0, "touch", false) this.leftBtn:GetComponent("Button").enabled = true isClickLeftOrRightBtn = true this:UpdateHeroInfoData() this.btnMask.gameObject:SetActive(false) end):SetEase(Ease.Linear) end --手指滑动 local beginV3 local endV3 local distance function HandBookHeroInfoPanel:OnBeginDrag(Pointgo, data) beginV3=this.curLiveObj.transform.anchoredPosition end function HandBookHeroInfoPanel:OnDrag(Pointgo, data) distance=Vector2.Distance(beginV3,this.curLiveObj.transform.anchoredPosition) end function HandBookHeroInfoPanel:OnEndDrag(Pointgo, data) endV3=this.curLiveObj.transform.anchoredPosition if distance>250 and endV3.x<0 then this:RightBtnOnClick() elseif distance>250 and endV3.x>0 then this:LeftBtnOnClick() else this.curLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(heroConFigData.Position[1],heroConFigData.Position[2]), 0.5, false):SetEase(Ease.Linear) end distance=0 end --界面关闭时调用(用于子类重写) function HandBookHeroInfoPanel:OnClose() if this.leftLiveObj then poolManager:UnLoadLive(GetResourcePath(leftHeroData.Live), this.leftLiveObj) this.leftLiveObj = nil end if this.rightLiveObj then poolManager:UnLoadLive(GetResourcePath(rightHeroData.Live), this.rightLiveObj) this.rightLiveObj = nil end if this.curLiveObj then poolManager:UnLoadLive(GetResourcePath(heroConFigData.Live), this.curLiveObj) this.curLiveObj = nil end this.leftBtn:GetComponent("Button").enabled = true this.rightBtn:GetComponent("Button").enabled = true Util.ClearChild(this.curObj.transform) Util.ClearChild(this.leftObj.transform) Util.ClearChild(this.rightObj.transform) for k,v in pairs(this.PageList) do v:OnHide() end end --界面销毁时调用(用于子类重写) function HandBookHeroInfoPanel:OnDestroy() this.spLoader:Destroy() SubUIManager.Close(SubUIConfig.DragView, self.dragView) for k,v in pairs(this.PageList) do SubUIManager.Close(v) end tabsList = {} end return HandBookHeroInfoPanel