local UIHeroFilterView = UIViewClass() local EventSystem = require('Event/EventSystem') -- 参数 -- canJump : 是否可以跳转 -- parent {HeroFilterJumpCallBack、CloseSubView} : 如果用subview方式打开 父界面需要支持的函数 -- 如果不是subview打开 需要参数 heroId、isCountry、heroFilterPos or targetCountry or targetProfession function UIHeroFilterView:OnOpened(context) self.parent = context.parent self.canJump = context.canJump if context.heroId then self:InitByHeroID(context.heroId, context.isCountry) end if context.targetCountry then self:InitByCountry(context.targetCountry) end if context.targetProfession then self:InitByProfession(context.targetProfession) end if context.heroFilterPos then self:SetFilterViewPosByTF(context.heroFilterPos) else self:SetFilterViewPosByMouse() end end function UIHeroFilterView:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Filter then UTL.Color.SetQualityImageByType(cellTable.bg_HeroQuality, CTL.HeroAwaken.GetHeroQuality(data, MDL.HeroAwaken.GetIsHeroAwaken(data)), UTL.Color.QualityType.Square) UTL.Item.SetHeroIconByHeroId(cellTable.img_HeroHead, data, MDL.HeroAwaken.GetIsHeroAwaken(data)) UIUtils.SetComponentGray(cellTable.cell, not MDL.HeroSelect.IsHasHero(data)) end end function UIHeroFilterView:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Filter then if not self.canJump then return end if MDL.HeroSelect.IsHasHero(data) then self:OnButtonClicked(self.btn_CloseFilterView) if self.parent and self.parent.HeroFilterJumpCallBack then self.parent:HeroFilterJumpCallBack() end if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIHeroShowPanel) then EventSystem.Dispatch(EventID.UI_HeroShow_SwitchHeroById, data) else MDL.HeroSelect.curSelectHeroID = data UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, { ifBlend = true, isFormation = true, subViewName = MDL.HeroSelect.ToggleViewNameList.Info, isBack = true }) end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Fomation_NotGetTheHero"]) end end end -- TODO 这里因为框架问题,导致子界面的时候 无法用closeView来关闭,暂时先使用父界面的 subView:CloseAll() 来关闭 function UIHeroFilterView:OnButtonClicked(comp) if comp == self.btn_CloseFilterView then if self.parent and self.parent.CloseSubView then self.parent:CloseSubView() else self:CloseView() end end end function UIHeroFilterView:OpenFilterWindowByCountry() if self.loop_Filter.Count > 0 then self.loop_Filter:ClearCells() end UIUtils.SetActive(self.bg2, true) local countryData = DataSheetManager.HeroCountry:GetDataByID(self.targetCountry) UIUtils.SetLabelText(self.txt_Top, Const_IDS[countryData.Name]) UIUtils.SetLabelText(self.txt_Info, Const_IDS[countryData.Des]) for _, v in DataSheetManager.HeroNum:GetEnumerator() do if MDL.HideGolden.IsShowGoldenByID(LuaConst.ShowGoldenType.Hero, v.ID) and v.Kingdom == self.targetCountry then self.loop_Filter:AddData(v.ID, 0) end end end function UIHeroFilterView:OpenFilterWindowByProfession() if self.loop_Filter.Count > 0 then self.loop_Filter:ClearCells() end UIUtils.SetActive(self.bg2, false) local professionData = DataSheetManager.HeroProfession:GetDataByID(self.targetProfession) UIUtils.SetLabelText(self.txt_Top, Const_IDS[professionData.Name]) UIUtils.SetLabelText(self.txt_Info, Const_IDS[professionData.Des]) for _, v in DataSheetManager.HeroNum:GetEnumerator() do if MDL.HideGolden.IsShowGoldenByID(LuaConst.ShowGoldenType.Hero, v.ID) and v.TypeID == self.targetProfession then self.loop_Filter:AddData(v.ID, 0) end end end ------------- 以下方法 暴露给外界使用 ------------- -- 通过transform 设置UI位置 function UIHeroFilterView:SetFilterViewPosByTF(parentRootTF) self.group_FilterView:SetPosition(parentRootTF:GetPosition()) end -- 通过鼠标 设置UI位置 function UIHeroFilterView:SetFilterViewPosByMouse() local pos = UnityEngine.Input.mousePosition local rect = self.gameObject.transform.rect local filterViewRect = self.group_FilterView.rect local minPosX = filterViewRect.width - rect.width / 2 local minPosY = filterViewRect.height - rect.height / 2 self.group_FilterView:SetLocalPosition(math.max(minPosX, pos.x - rect.width / 2), math.max(minPosY, pos.y - rect.height / 2), 0) end -- 通过英雄ID 打开具体展示界面 function UIHeroFilterView:InitByHeroID(heroID, isCountry) if isCountry then self.targetCountry = DataSheetManager.HeroNum:GetDataByID(heroID).Kingdom self:OpenFilterWindowByCountry() else self.targetProfession = DataSheetManager.HeroNum:GetDataByID(heroID).TypeID self:OpenFilterWindowByProfession() end end -- 直接根据国别展示 function UIHeroFilterView:InitByCountry(targetCountry) self.targetCountry = targetCountry self:OpenFilterWindowByCountry() end -- 直接根据职业展示 function UIHeroFilterView:InitByProfession(targetProfession) self.targetProfession = targetProfession self:OpenFilterWindowByProfession() end return UIHeroFilterView