local UIHeroSelectPanel = UIViewClass() local EventSystem = require('Event/EventSystem') local HeroPos = Vector3.New(0, 6, 0) local HeroScale = Vector3.one local Identity = UnityEngine.Quaternion.identity local FontQuality = { "HeroSelectFontBlue","HeroSelectFontYellow","HeroSelectFontRed","HeroSelectFontOrange","HeroSelectFontPurple" } local TIME_RELATION = 1 local ToggleType_All = 0 function UIHeroSelectPanel:OnCreated() self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.heroSelect) self.sortedTypeHeroList = {} end function UIHeroSelectPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_HeroSelect_RefreshAfterActiveHero, self.RefreshAfterActiveHero) self:RegistSystemEvent(EventID.UI_HeroSelect_RefreshHeroOrder, self.RefreshData) self:RegistSystemEvent(EventID.UI_HeroSelect_SelectHero, self.SelectHero) self:RegistSystemEvent(EventID.UI_CheatGreenBg, self.SetCheatGreenBg) self:RegistSystemEvent(CTL.HeroSelect.HeroSelectRpEventId.HeroSelf, self.RefreshCellRp) self:RegistSystemEvent(CTL.HeroSelect.HeroSelectRpEventId.HeroUpgrade, self.RefreshBtnRp) self:InitToggles() local heroID = context and context.heroID or nil self:InitTitle() self.selectedId = heroID self:RefreshData() UIManager.ActiveUIModle(false, "UIHeroSelectPanel") AuxUtil.SetSSSCameraClipParams(true, 0.3, 750) CTL.Setting.Set5SSkin(true) CTL.Setting.SetUIShadowDistance(8) end function UIHeroSelectPanel:InitTitle() UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_Hero"]) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) end function UIHeroSelectPanel:RefreshCellRp(state, userData) local heroId = userData.heroId self.loopScroll_Heads:UpdateIndex(self:GetHeroCellIndex(heroId)) end function UIHeroSelectPanel:RefreshBtnRp(state, userData) local heroId = userData.heroId if heroId == self.selectedId then if userData.type == CTL.HeroSelect.HeroUpgradeType.Break or userData.type == CTL.HeroSelect.HeroUpgradeType.HeroAppearance then self.btn_Enter:SetRedPoint(state) elseif userData.type == CTL.HeroSelect.HeroUpgradeType.Active then self.btn_act:SetRedPoint(state) end end end function UIHeroSelectPanel:OnValueChanged(comp, index) self.selectToggleType = index self:UpdateHeroCells(index) end function UIHeroSelectPanel:UpdateHeroCells(type) table.clearArray(self.sortedTypeHeroList) MDL.HeroSelect.CollectHeroCfgByCountry(self.sortedTypeHeroList, type) if not GameAppInfo.IsVersionGreaterThan115000() then self.loopScroll_Heads:MoveBegin() end self.loopScroll_Heads:ReloadAll(self.sortedTypeHeroList) self.selectedId = self.selectedId or self.sortedTypeHeroList[1].ID --ReloadAll的时候 把之前的都删除了 会从新add 但是下一帧开始的,如果此时moveindex 会导致index不对 if type == ToggleType_All then self:RefreshHeroSelect() else self:StartRepeatFunc(self.RefreshHeroSelect, 0.1, 1) end end function UIHeroSelectPanel:GetHeroCellIndex(id) for i, v in ipairs(self.sortedTypeHeroList) do if v.ID == id then return i - 1 end end return 0 end function UIHeroSelectPanel:RefreshData() self.subToggles:SelectIndex(self.selectToggleType or ToggleType_All) self:RefreshHeroData(self.selectedId) end function UIHeroSelectPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_Heads then self:RefreshHeroCell(cellTable, data, index) elseif scrollRect == self.loop_ItemSources then cellTable.txt_ItemSources.text = data.desc cellTable.state_ItemSources:SetState(data.isUnlock) end end function UIHeroSelectPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopScroll_Heads then self.selectedId = data.ID self:SelectItem(self.selectedId) elseif scrollRect == self.loop_ItemSources then if target == cellTable.btn_ItemSources then if data.isUnlock > 0 then local itemId = DataSheetManager.HeroNum:GetDataByID(self.selectedId).PieceItem if CTL.ItemSources.ExecuteSourceFunctionById(data.sourceId, itemId) then UIUtils.SetActive(self.panel_ItemSources.gameObject, false) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Formation_RelationShip_Closed) end end end end function UIHeroSelectPanel:RefreshHeroCell(cellTable, data, index) cellTable.effect_HeroQuality:StopUIEffect() if MDL.HeroSelect.IsHasHero(data.ID) then --上阵图标显示 if MDL.Player.HeroIsLineUp(data.ID) then UIUtils.SetActive(cellTable.sprite_BgZhen, true) else UIUtils.SetActive(cellTable.sprite_BgZhen, false) end -- 助战图标显示 UIUtils.SetActive(cellTable.img_AssistanceIcon, MDL.AssistanceFight.IsHeroOnAssistancePos(data.ID)) if MDL.HeroAwaken.GetIsHeroAwaken(data.ID) then UIUtils.SetActive(cellTable.txt_BreakNum, true) UIUtils.SetActive(cellTable.img_BreakLevelBg, true) local awakenLevel = MDL.HeroAwaken.GetCurStar(data.ID) cellTable.txt_BreakNum.text = string.FormatByIdsId(Const_IDS["IDS_HeroAwaken_AwakenLevelNum"], awakenLevel) else local heroBreak = MDL.HeroStar.GetHeroStarLevel(data.ID) if heroBreak == 0 then UIUtils.SetActive(cellTable.img_BreakLevelBg, false) UIUtils.SetActive(cellTable.txt_BreakNum, false) else UIUtils.SetActive(cellTable.txt_BreakNum, true) UIUtils.SetActive(cellTable.img_BreakLevelBg, true) cellTable.txt_BreakNum.text = "+" .. heroBreak end end --主将碎片相关 UIUtils.SetActive(cellTable.group_Shards.gameObject, false) local isShowRp = MDL.RedPoint.GetNodeStateByLogicParams(CTL.HeroSelect.HeroSelectRpEventId.TownHome, data.ID, CTL.HeroSelect.HeroUpgradeType.Break) or MDL.RedPoint.GetNodeStateByLogicParams(CTL.HeroSelect.HeroSelectRpEventId.TownHome, data.ID, CTL.HeroSelect.HeroUpgradeType.HeroAppearance) or MDL.RedPoint.GetNodeStateByLogicParams(CTL.HeroSelect.HeroSelectRpEventId.TownHome, data.ID, CTL.HeroSelect.HeroUpgradeType.Strenthen) or CTL.Appearance.IsShowAppearanceRedPoint(data.ID) -- 时装红点 or CTL.LightEffect.IsShowLightEffectRedPoint(data.ID) or CTL.HeroAwaken.CheckHeroSkillRed(data.ID) or CTL.HeroAwaken.CheckAwakenRed(data.ID) if not CTL.HeroSelect.IsSkipHeroRedPoint(data.ID) then cellTable.cell:SetRedPoint(isShowRp) UIUtils.SetActive(cellTable.img_YelPoint, false) else cellTable.cell:SetRedPoint(false) UIUtils.SetActive(cellTable.img_YelPoint, isShowRp) end -- 光效红点 local quality = CTL.HeroAwaken.GetHeroQuality(data.ID, MDL.HeroAwaken.GetIsHeroAwaken(data.ID)) UTL.Color.SetQualityImageByType(cellTable.img_QualityFrame, quality, UTL.Color.QualityType.HeroSelectFrame) UTL.Color.SetQualityImageByType(cellTable.img_QualityHead, quality, UTL.Color.QualityType.HeroSelectBg) cellTable.btn_ClickItem:SetGray(false) --品质特效 CTL.HeroSelect.PlayHeroQualityEffect(cellTable.effect_HeroQuality, data.ID, UTL.Color.EffectType.Main) else UIUtils.SetActive(cellTable.img_BreakLevelBg, false) UIUtils.SetActive(cellTable.img_Rank,false) UIUtils.SetActive(cellTable.group_Shards, true) UIUtils.SetActive(cellTable.sprite_BgZhen, false) UIUtils.SetActive(cellTable.img_AssistanceIcon, false) UIUtils.SetActive(cellTable.img_YelPoint, false) --主将碎片相关显示 local hasCount = MDL.Bag.GetItemCountInOneCell(data.PieceItem) local canActiveCount = DataSheetManager.HeroNum:GetDataByID(data.ID).UnlockPiece UIUtils.SetLabel(cellTable.lab_amount,string.format("%s/%s", hasCount, canActiveCount)) local isCanActive = hasCount >= canActiveCount cellTable.cell:SetRedPoint(isCanActive) if isCanActive then cellTable.effect_Activable:PlayUIEffect() else cellTable.effect_Activable:StopUIEffect() end if isCanActive then UIUtils.SetLabel(cellTable.lab_amount,string.format("%s/%s", hasCount, canActiveCount)) --绿色 else UIUtils.SetLabel(cellTable.lab_amount,string.format("%s/%s", hasCount, canActiveCount)) --红色 end local quality = CTL.HeroAwaken.GetHeroQuality(data.ID, MDL.HeroAwaken.GetIsHeroAwaken(data.ID)) UTL.Color.SetQualityImageByType(cellTable.img_QualityFrame, quality, UTL.Color.QualityType.HeroSelectFrame) UTL.Color.SetQualityImageByType(cellTable.img_QualityHead, quality, UTL.Color.QualityType.HeroSelectBg) cellTable.btn_ClickItem:SetGray(true,true) end UTL.Item.SetHeroIconByHeroId(cellTable.btn_ClickItem, data.ID, MDL.HeroAwaken.GetIsHeroAwaken(data.ID)) end function UIHeroSelectPanel:RefreshHeroData(id) local heroData = DataSheetManager.HeroNum:GetDataByID(id) if not heroData then logging.error(LTAG.ERROR, "not find hero by id", id) return end CTL.HeroSelect.SetHeroName(id, self.loc_Name, self.img_Name, self.txt_Name) if self.effect_name then if MDL.HeroAwaken.GetIsHeroAwaken(id) then self.effect_name:PlayUIEffect() UIUtils.SetActive(self.awaken_name_bg, true) else self.effect_name:StopUIEffect() UIUtils.SetActive(self.awaken_name_bg, false) end end if self.loc_Name.CurState == 0 then UIUtils.SetLocalizationImage(self.img_Country, "country_" .. heroData.Kingdom .. ".png") local heroName = UIUtils.GetLocalizedTxt(Const_IDS[heroData.NameIDS]) local count = UTL.String.GetStrCharCount(heroName, 1) self.uistate:SetState(count - 2) -- 组件从2个字名字开始放位置 else UIUtils.SetLocalizationImage(self.img_CountryEn, "country_" .. heroData.Kingdom .. ".png") self.img_CountryEn:SetNativeSize() end -- 设置职业 CTL.HeroSelect.SetHeroProfession(id, self.obj_Profession, false) if MDL.HeroAwaken.GetIsHeroAwaken(id) == false then UIUtils.SetPolygonVerticesValue(self.img_polygon, heroData.Tendentiousness) else local awakenHeroData = DataSheetManager.AwakenHeroNum:GetDataByID(id) UIUtils.SetPolygonVerticesValue(self.img_polygon, awakenHeroData.Tendentiousness) end CTL.HeroSelect.ShowCV(self.txt_CV, id) UIUtils.SetLabel(self.txt_Intelligence, CTL.HeroSelect.GetHeroIntelligence(id)) end function UIHeroSelectPanel:OnClickEnter() MDL.HeroSelect.curSelectHeroID = self.curSelectHeroID self.context = self.context or {} self.context.heroID = self.curSelectHeroID UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel) end function UIHeroSelectPanel:OnClickBackTown() self:CloseView(true) end function UIHeroSelectPanel:ShowEnterBtn(show) UIUtils.SetActive(self.btn_Enter, show) if CTL.HeroAwaken.IsShowHeroAwakenEntry(self.curSelectHeroID) then self.btn_Enter:SetText(Const_IDS.IDS_HeroAwaken_FunctionName) else self.btn_Enter:SetText(Const_IDS.IDS_HeroDevelop) end end function UIHeroSelectPanel:SelectItem(id) self.context = {heroID = id} self.curSelectHeroID = id self:RefreshHeroData(id) self:CreatHeroObj(id) self.curSelectHeroID = id --self:RefreshHeroSelect(id) if MDL.HeroSelect.IsHasHero(id) then self:ShowEnterBtn(true) self.btn_act.gameObject:SetActive(false) --self.group_GetHero.gameObject:SetActive(false) self.btn_Check.gameObject:SetActive(false) self.group_Sp.gameObject:SetActive(false) if not CTL.HeroSelect.IsSkipHeroRedPoint(id) then self.btn_Enter:SetRedPoint(CTL.HeroSelect.IsHeroCanUpgrade(id)) UIUtils.SetActive(self.img_YelPoint, false) else self.btn_Enter:SetRedPoint(false) UIUtils.SetActive(self.img_YelPoint, CTL.HeroSelect.IsHeroCanUpgrade(id)) end else self:ShowEnterBtn(false) local isCanActive = MDL.HeroSelect.IsHeroCanActive(id) self.btn_act.gameObject:SetActive(isCanActive) self.btn_act:SetRedPoint(isCanActive) self.btn_Check.gameObject:SetActive(not isCanActive) self.group_Sp.gameObject:SetActive(true) --self.group_GetHero.gameObject:SetActive(not isCanActive) --if not isCanActive then -- local heroData = DataSheetManager.HeroNum:GetDataByID(id) -- UIUtils.SetLabelText(self.txt_GetHero, Const_IDS[heroData.GetAccess]) --end local data = DataSheetManager.HeroNum:GetDataByID(id) local needCount = data.UnlockPiece local hasCount = MDL.Bag.GetItemCountInOneCell(data.PieceItem) if hasCount < needCount then hasCount = UTL.Color.FormatRedColor(hasCount) else hasCount = UTL.Color.FormatGreenColor(hasCount) end UIUtils.SetLabel(self.txt_SpNum, string.format("%s/%s", hasCount, needCount)) local sourcesList = CTL.ItemSources.GetHeroSourceList(self.curSelectHeroID) UIUtils.SetActive(self.img_HeroSources, #sourcesList > 0) end end function UIHeroSelectPanel:CreatHeroObj(id) local heroWearAppearanceID = MDL.HeroSelect.GetAppearanceIDByHeroID(id) local tlPath, modelPath, weaponId, isDy = UTL.UIRender.GetHeroTimelineParam(id, heroWearAppearanceID, CTL.HeroSelect.GetWeaponAppearanceId(id, heroWearAppearanceID)) if isDy then UTL.UIRender.CreateDynamicHeroTimeline(self.modelComponentDataHandle, tlPath, modelPath, heroWearAppearanceID, weaponId, 0, 1600, 0) else UTL.UIRender.CreateHeroTimelineTrans(self.modelComponentDataHandle, tlPath, 0, 1600, 0) end local heroAppearanceData = heroWearAppearanceID>0 and DataSheetManager.HeroAppearance:GetDataByID(heroWearAppearanceID) or nil if heroAppearanceData == nil then local data = DataSheetManager.HeroNum:GetDataByID(id) if self.preShowSound ~= data.ShowSound then self.soundId = CTL.Sound.PlayGameSound(data.ShowSound) self.preShowSound = data.ShowSound end else if self.preShowSound ~= heroAppearanceData.ShowSound then self.soundId = CTL.Sound.PlayGameSound(heroAppearanceData.ShowSound) self.preShowSound = heroAppearanceData.ShowSound end end --cheatLogic if self.cheatClearEff and self.cheatBgColor then UTL.UIRender.SetCheatGreenBg(self.modelComponentDataHandle, self.cheatBgColor, self.cheatClearEff) end end function UIHeroSelectPanel:SetCheatGreenBg(color, clearEffect) self:SelectItem(self.selectedId) UTL.UIRender.SetCheatGreenBg(self.modelComponentDataHandle, color,clearEffect) self.cheatBgColor = color self.cheatClearEff = clearEffect end function UIHeroSelectPanel:RefreshHeroSelect() local index = self:GetHeroCellIndex(self.selectedId) self.loopScroll_Heads:SelectIndex(index, true) end --激活主将 function UIHeroSelectPanel:ActiveHero() self.effect_ActiveClick:PlayUIEffect() MDL.HeroSelect.ActiveHeroRequest(self.curSelectHeroID) end function UIHeroSelectPanel:RefreshAfterActiveHero() local heroName=UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.HeroNum:GetDataByID(self.curSelectHeroID).NameIDS]) CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroActivatedNotice"], heroName) self.subToggles:SelectIndex(self.selectToggleType or ToggleType_All) self.loopScroll_Heads:SelectIndex(self:GetHeroCellIndex(self.curSelectHeroID)) --self:RefreshData(self.curSelectHeroID) --开计时器,延时弹出羁绊界面 self:StartRepeatFunc(self.OnUpdateFun, TIME_RELATION, -1, true, false) end function UIHeroSelectPanel:OnUpdateFun(deltaTime, timeSinceUpdate) CTL.HeroSelect.ForceOpenRelationPopup() end function UIHeroSelectPanel:OnClosed() CTL.Setting.SetUIShadowDistance(0) AuxUtil.SetSSSCameraClipParams(false, 1, 750) CTL.Setting.Set5SSkin(false) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) if self.soundId then CTL.Sound.StopById(self.soundId) end UIManager.ActiveUIModle(true, "UIHeroSelectPanel") UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) MDL.HeroAwaken.RemovePlayerInfoCache() end function UIHeroSelectPanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIHeroSelectPanel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:OnClickBackTown() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Enter or comp == self.btn_Check then self:OnClickEnter() elseif comp == self.btn_ShardsGet then --获取碎片 local hero=MDL.HeroSelect.GetHeroDataById(self.curSelectHeroID) elseif comp == self.btn_act then --激活主将 self:ActiveHero() elseif comp == self.add_Sp then self:OnClickGetHeroSourcesButton() elseif comp == self.bg_ItemSources then self:ActiveHeroSourcesPanel(false) end end function UIHeroSelectPanel:OnClickGetHeroSourcesButton() if not self.panel_ItemSources.gameObject.activeSelf then if self.loop_ItemSources.Count > 0 then self.loop_ItemSources:ClearCells() end local sourcesList = CTL.ItemSources.GetHeroSourceList(self.curSelectHeroID) if #sourcesList > 0 then self:ActiveHeroSourcesPanel(true) for i, v in ipairs(sourcesList) do self.loop_ItemSources:AddData(v, 0) end else self:ActiveHeroSourcesPanel(false) CTL.Tips.AddTipsMsg(Const_IDS["IDS_UnactiveHeroOptimize_Hint4"]) end end end function UIHeroSelectPanel:ActiveHeroSourcesPanel(active) UIUtils.SetActive(self.panel_ItemSources.gameObject, active) UIUtils.SetActive(self.bg_ItemSources.gameObject, active) end function UIHeroSelectPanel:InitToggles() self.subToggles:InstaniateToggles(5) for i = 1, 5 do self.subToggles:SetToggleActive(i, true) end self.subToggles:SetToggleCompImage(1, "mark_1", ConstAssetPathConfig.AssetPath138) self.subToggles:SetToggleCompImage(2, "mark_1", ConstAssetPathConfig.AssetPath139) self.subToggles:SetToggleCompImage(3, "mark_1", ConstAssetPathConfig.AssetPath140) self.subToggles:SetToggleCompImage(4, "mark_1", ConstAssetPathConfig.AssetPath141) self.subToggles:SetToggleCompImage(5, "mark_1", ConstAssetPathConfig.Path30) UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(1, "img_NationType"):GetComponent(typeof(UnityEngine.UI.Image)), "sgzz_msz_quan.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(2, "img_NationType"):GetComponent(typeof(UnityEngine.UI.Image)), "sgzz_msz_wei.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(3, "img_NationType"):GetComponent(typeof(UnityEngine.UI.Image)), "sgzz_msz_shu.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(4, "img_NationType"):GetComponent(typeof(UnityEngine.UI.Image)), "sgzz_msz_wu.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(5, "img_NationType"):GetComponent(typeof(UnityEngine.UI.Image)), "sgzz_msz_qun.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(1, "img_markNationType"):GetComponent(typeof(UnityEngine.UI.Image)), "gb_msz_quan.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(2, "img_markNationType"):GetComponent(typeof(UnityEngine.UI.Image)), "gb_msz_wei.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(3, "img_markNationType"):GetComponent(typeof(UnityEngine.UI.Image)), "gb_msz_shu.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(4, "img_markNationType"):GetComponent(typeof(UnityEngine.UI.Image)), "gb_msz_wu.png") UIUtils.SetLocalizationImage(self.subToggles:GetToggleComponent(5, "img_markNationType"):GetComponent(typeof(UnityEngine.UI.Image)), "gb_msz_qun.png") end return UIHeroSelectPanel