local UIGoldenHeroAnecdote = UIViewClass() local EventSystem = require('Event/EventSystem') function UIGoldenHeroAnecdote:OnOpened(context) self.activityId = context.activityId self.heroType = context.heroType self.activityType = MDL.OperationActivity.ActivityType.GoldenHero --标题 local heroTypeData = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(self.heroType) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS[heroTypeData.LevelName]) UIUtils.SetLocalizationImage(self.img_New, "zr_msz_new.png") self.img_New:SetNativeSize() self:RegistSystemEvent(EventID.UI_GoldenHero_RefreshCurrency, self.RefreshConsumeItem) self:RegistSystemEvent(EventID.UI_GoldenHeroAnecdote_RefreshInfo, self.RefreshAnecdoteLevel) self:RegistSystemEvent(CTL.GoldenHeroMain.RpEventId[self.activityId].Boss, self.RefreshGoldenHeroBossRp) -- 协同入口红点 self:RegistSystemEvent(CTL.GoldenHeroMain.RpEventId[self.activityId].BossNewOne, self.RefreshGoldenHeroBossRp) -- 协同入口红点 self:RegistSystemEvent(CTL.GoldenHeroMain.RpEventId[self.activityId].AnecdoteNew, self.RefreshAnecdoteDetailRp) -- 协同入口红点 self:RegistSystemEvent(CTL.GoldenHeroMain.RpEventId[self.activityId].AnecdoteReward, self.RefreshAnecdoteDetailRp) -- 协同入口红点 self:RegistSystemEvent(EventID.UI_OperationActivity_CloseView, self.OnCloseActivitySelf) self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.HeroShowScene) self:RefreshGoldenHeroBossRp(MDL.RedPoint.GetNodeStateByMultiKey(CTL.GoldenHeroMain.RpEventId[self.activityId].TownHome, CTL.GoldenHeroMain.RpEventId[self.activityId].Boss)) -- 协同入口红点 self:RefreshAnecdoteDetailRp() CTL.GoldenHeroMain.OpenCurrencyPanel(self.heroType, self.__viewClassPath, self.currency_Info, {activityType = self.activityType, activityId = self.activityId, energyType = MDL.GoldenHeroMain.EnergyType.Story, title = "IDS_DrawCard_Title_QuickBuy"}) CTL.GoldenHeroStory.SetStoryViewBossButtonNode(self.btn_Fight) UIUtils.SetActive(self.group_GsHint, false) self:RefreshAnecdoteLevel(self.activityId) UIManager.ActiveUIModle(false, "UIGoldenHeroAnecdote") end function UIGoldenHeroAnecdote:OnClosed() UIManager.ActiveUIModle(true, "UIGoldenHeroAnecdote") UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) CTL.GoldenHeroStory.SetStoryViewBossButtonNode(nil) end function UIGoldenHeroAnecdote:RefreshLevelInfo() local anecdoteData = DataSheetManager.GoldHeroActivityAnecdoteLevel:GetDataByID(self.selectId) UIUtils.SetLabelText(self.txt_AnecdoteTitle, Const_IDS[anecdoteData.BarrierTitle]) UIUtils.SetLabelText(self.txt_AnecdoteName, Const_IDS[anecdoteData.BarrierName]) self:SetAnecdoteGs() local rewardData = DataSheetManager.RewardClientShow:GetDataByClientShowID(anecdoteData.RewardClientShowID) local rewardTable = DataSheetUtil.GetRewardClientShowItemTable(rewardData) self.rewardId = {} local isPassed = CTL.GoldenHeroAnecdote.IsLevelPassed(self.activityId, anecdoteData.ID) for i, v in ipairs(self.group_Reward) do local reward = rewardTable[i] if reward then if isPassed and reward.FristGothrough then UIUtils.SetActive(v.gameObject.transform.parent, false) else local itemId = reward.ItemID UIUtils.SetActive(v.gameObject.transform.parent, true) UTL.Item.SetItemCell(v, itemId, reward.ItemNum, reward.FristGothrough) self.rewardId[i] = itemId end else UIUtils.SetActive(v.gameObject.transform.parent, false) end end UIUtils.SetActive(self.btn_Sweep, isPassed) self:RefreshConsumeItem() self.btn_Sweep:SetRedPoint(CTL.GoldenHeroAnecdote.IsLevelCanSweep(self.activityId, anecdoteData.ID)) local heroId = anecdoteData.HeroID local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) UTL.Item.SetLocalizationImage(self.loc_HeroName, self.img_HeroName, "UI_HeroName/"..heroData.HeadImage..".png") UIUtils.SetLabelText(self.txt_HeroName, Const_IDS[heroData.NameIDS]) self:ShowHeroModel(heroId) end local timeHintText = UIUtils.GetLocalizedTxt(Const_IDS.IDS_GoldHeroActivity_AnecdotalHint3) local function StringFormat(ids) return string.format(timeHintText, UIUtils.GetLocalizedTxt(Const_IDS[ids])) end function UIGoldenHeroAnecdote:SetAnecdoteGs() local percent, isMax, leftTime = MDL.GoldenHeroAnecdote.GetDampPercentAndTime(self.activityId, self.selectId) if isMax then self.txt_Time:EndTimer() self:StopRepeatFunc(self.SetAnecdoteGs) else self.txt_Time:SetDHMSStr(StringFormat("IDS_PreviewTime1"), StringFormat("IDS_PreviewTime2"), StringFormat("IDS_PreviewTime3"), StringFormat("IDS_PreviewTime4")) self.txt_Time:ResetAndBeginCustomTimer(false, leftTime, 0, nil) self:StartRepeatFunc(self.SetAnecdoteGs, leftTime, 1) end local percentText = UTL.Attr.FormatNumberToPercentage(1 - percent, 0) self.txt_Tip.text = string.FormatByIdsKey("IDS_GoldHeroActivity_AnecdotalHint6", UTL.Color.FormatGreenColor(percentText)) local recommendGs = MDL.GoldenHeroAnecdote.GetRecommendGs(self.activityId, self.selectId) if 1 - percent > 0 then self.txt_Gs.text = CTL.GoldenHeroBoss.GetSubjugateGsText(recommendGs) .. UTL.Color.FormatGreenColor("(-".. percentText ..")") else self.txt_Gs.text = CTL.GoldenHeroBoss.GetSubjugateGsText(recommendGs) end end function UIGoldenHeroAnecdote:RefreshConsumeItem() --解锁未通关显示首通不消耗体力 if CTL.GoldenHeroAnecdote.IsLevelFirstPass(self.activityId, self.selectId) then self.state_Buttons:SetState(1) else -- 消耗道具数量 self.state_Buttons:SetState(0) UTL.Item.ItemIconWithoutBg(self.img_Icon, DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(self.heroType).LevelEnergyType) local anecdoteData = DataSheetManager.GoldHeroActivityAnecdoteLevel:GetDataByID(self.selectId) local energyNum = anecdoteData.EnergyNum if CTL.GoldenHeroAnecdote.IsEnergyEnough(self.activityId, self.selectId) then energyNum = UTL.Color.FormatWhiteColor(energyNum) else energyNum = UTL.Color.FormatRedColor(energyNum) end UIUtils.SetLabel(self.txt_Num, energyNum) end self.btn_Sweep:SetRedPoint(CTL.GoldenHeroAnecdote.IsLevelCanSweep(self.activityId, self.selectId)) end function UIGoldenHeroAnecdote:ShowHeroModel(heroId) UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) local bgTexturePath = ConstAssetPathConfig.bgTexturePath1 UTL.UIRender.Create2DTextureBgScene(self.modelComponentDataHandle, bgTexturePath, nil, nil) local modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroLightEffects = UTL.UIRender.LoadShowHero(heroId, true, nil, false) UTL.UIRender.CreatePlayerModel(self.modelComponentDataHandle, heroId, modelPath, lightPath, true, "", heroId) UTL.UIRender.SetHeroParentPos(self.modelComponentDataHandle, 0.45, -1.2, 1) UTL.UIRender.SetHeroParentRot(self.modelComponentDataHandle, 0, -10, 0) end function UIGoldenHeroAnecdote:RefreshAnecdoteLevel(activityId) if activityId ~= self.activityId then return end if self.loop_Anecdote.Count > 0 then self.loop_Anecdote:RefreshCells() else for i, v in DataSheetManager.GoldHeroActivityAnecdoteLevel:GetEnumerator() do if self.heroType == v.HeroType then self.loop_Anecdote:AddData(v, 0) self.loop_Anecdote:AddData(nil, 1) end end self.loop_Anecdote:RemoveIndex(self.loop_Anecdote.Count - 1) --移除最后一个箭头cell end --默认选中逻辑 local index = MDL.GoldenHeroAnecdote.GetDefaultIndex(activityId) --cell是一个头像一个箭头穿插的,所以获得的index需要再处理state_Buttons index = (index - 1) * 2 if index > 1 then self.loop_Anecdote:MoveIndex(math.max(self.selectIndex and self.selectIndex - 2 or index - 2, 0)) end self.loop_Anecdote:SelectIndex(self.selectIndex or index) end function UIGoldenHeroAnecdote:OnCloseActivitySelf(viewClassPath, activityId) if viewClassPath == self.__viewClassPath then if self.activityId and activityId == self.activityId then self:CloseView(true) end end end function UIGoldenHeroAnecdote:RefreshAnecdoteDetailRp() self.state_Tips:SetState(0) self.btn_Detail:SetRedPoint(false) if CTL.GoldenHeroAnecdote.IsActivityHasReward(self.activityId) then self.state_Tips:SetState(1) self.btn_Detail:SetRedPoint(true) else if CTL.GoldenHeroAnecdote.IsHasNewAnecdote(self.activityId) then self.state_Tips:SetState(2) self.btn_Detail:SetRedPoint(true) end end end ---@public 协同讨伐入口红点 function UIGoldenHeroAnecdote:RefreshGoldenHeroBossRp(active) if CTL.GoldenHeroBoss.CheckIfHasNewBoss(self.activityId) then UIUtils.SetActive(self.img_New, true) self.btn_Fight:SetRedPoint(false) else UIUtils.SetActive(self.img_New, false) self.btn_Fight:SetRedPoint(active) end end function UIGoldenHeroAnecdote:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then local params = {} local levelEnergyType = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(self.heroType).LevelEnergyType local itemName = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.ItemData:GetDataByID(levelEnergyType).Name]) table.insert(params, itemName) for k,v in DataSheetManager.GoldHeroEnergyGet:GetEnumerator() do if v.Type == 1 then local _,timeStr = UTL.Time.GetDateDescAndTime({v.Time}) table.insert(params, timeStr) end end UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.GoldHeroExperienceLite, params = params}) elseif comp == self.btn_Detail then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldenHeroAnecdoteDetail, {activityId = self.activityId, heroType = self.heroType, selectIndex = self.selectIndex}) elseif comp == self.btn_Fight then -- 协同讨伐 UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGoldenHeroBossMain, {activityId = self.activityId, heroType = self.heroType}) elseif comp == self.btn_Enter or comp == self.btn_Enter2 then if CTL.GoldenHeroAnecdote.IsEnergyEnough(self.activityId, self.selectId) or CTL.GoldenHeroAnecdote.IsLevelFirstPass(self.activityId, self.selectId) then local timeId = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(self.heroType).DailyRankEndTime local anecdoteData = DataSheetManager.GoldHeroActivityAnecdoteLevel:GetDataByID(self.selectId) if UTL.Time.IsServerInOpeningTime(1, timeId) then MDL.GoldenHeroAnecdote.EnterGoldenHeroAnecdoteRequest(self.selectId, anecdoteData.MissonDataID[1], self.activityId) -- 进副本 else -- 23点~隔日5点 扫荡不会发现讨伐boss UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_GoldHeroActivity_NewHint_1, function() MDL.GoldenHeroAnecdote.EnterGoldenHeroAnecdoteRequest(self.selectId, anecdoteData.MissonDataID[1], self.activityId) -- 进副本 end) end else if not CTL.GoldenHeroMain.OpenEnergyBuyViewByAttack(self.activityId, MDL.GoldenHeroMain.EnergyType.Story) then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_GoldHeroActivity_ActivityLevel_WrongHint1, UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.ItemData:GetDataByID(DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(self.heroType).LevelEnergyType).Name]))) end end elseif comp == self.btn_Sweep then self:OnClickSweep() elseif comp == self.group_GsHint then UIUtils.SetActive(self.group_GsHint, false) elseif comp == self.btn_GsInfo then UIUtils.SetActive(self.group_GsHint, not self.group_GsHint.gameObject.activeInHierarchy) else for i, v in ipairs(self.group_Reward) do if comp == v.event_Click then UTL.ItemTips.ShowCommonTipsById(self.rewardId[i]) return end end end end -- 扫荡 function UIGoldenHeroAnecdote:OnClickSweep() if self.levelState == MDL.GoldenHeroStory.LevelState.Lock then CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldHeroActivity_ActivityLevel_LockHint3) -- 请先完成前置任务 elseif self.levelState == MDL.GoldenHeroStory.LevelState.UnLock then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Sweep_NoCondition) -- 通关关卡后可扫荡 else if CTL.GoldenHeroAnecdote.IsEnergyEnough(self.activityId, self.selectId) then local timeId = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(self.heroType).DailyRankEndTime if UTL.Time.IsServerInOpeningTime(1, timeId) then CTL.Sweep.OpenSweepGoldHeroAnecdoteView(self.selectId, self.activityId, self.heroType) else -- 23点~隔日5点 扫荡不会发现讨伐boss UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_GoldHeroActivity_NewHint_1, function() CTL.Sweep.OpenSweepGoldHeroAnecdoteView(self.selectId, self.activityId, self.heroType) end) end else if not CTL.GoldenHeroMain.OpenEnergyBuyViewByAttack(self.activityId, MDL.GoldenHeroMain.EnergyType.Story) then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_GoldHeroActivity_ActivityLevel_WrongHint1, UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.ItemData:GetDataByID(DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(self.heroType).LevelEnergyType).Name]))) end end end end function UIGoldenHeroAnecdote:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Anecdote and data then UTL.Item.SetHeroIconByHeroId(cellTable.img_HeroHead, data.HeroID) local anecdoteId = data.ID UIUtils.SetActive(cellTable.img_Selected, self.selectId == anecdoteId) UIUtils.SetActive(cellTable.img_LockCover, not CTL.GoldenHeroAnecdote.IsLevelUnlock(self.activityId, anecdoteId)) if MDL.GoldenHeroAnecdote.GetAnecdoteUnlockFlag(self.activityId, anecdoteId) then cellTable.effect_Unlock:PlayUIEffect() end end end function UIGoldenHeroAnecdote:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Anecdote then local anecdoteId = data.ID if self.selectId ~= anecdoteId then if CTL.GoldenHeroAnecdote.IsLevelUnlock(self.activityId, anecdoteId) then self.selectId = anecdoteId if self.selectIndex then self.loop_Anecdote:UpdateIndex(self.selectIndex) end self.selectIndex = index UIUtils.SetActive(cellTable.img_Selected, self.selectId == anecdoteId) self:RefreshLevelInfo() else CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldHeroActivity_AnecdotalHint8) end end end end function UIGoldenHeroAnecdote:OnFocusChanged(isFocus) if isFocus then CTL.GoldenHeroMain.SetGoldenHeroFocusTarget(Const_UI_Lua.UIEnum.UIGoldenHeroStory, self.activityId) EventSystem.Dispatch(EventID.UI_GoldenHero_FocusOnGoldenHeroView, Const_UI_Lua.UIEnum.UIGoldenHeroStory, self.activityId) else CTL.GoldenHeroMain.SetGoldenHeroFocusTarget(nil, nil) end end function UIGoldenHeroAnecdote:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end return UIGoldenHeroAnecdote