local UIGodBeastActivityMain = UIViewClass() local WaitEffectTime = 0.6 local EffectDuration = 2 local RearEffectSound = { [1] = "UI_feed_blue", [2] = "UI_feed_violet", [3] = "UI_feed_orange", [4] = "UI_feed_red", } function UIGodBeastActivityMain:OnCreated() self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.renderModel) end function UIGodBeastActivityMain:OnOpened(context) self:RegistSystemEvent(EventID.UI_OperationActivity_CloseView, self.OnCloseActivitySelf) self:RegistSystemEvent(EventID.UI_GodBeastActivity_InfoUpdate, self.RefreshRearLevelInfo) self:RegistSystemEvent(EventID.UI_GodBeastActivity_PlayEventPerform, self.PlayEventPerform) self:RegistSystemEvent(EventID.UI_GodBeastActivity_RefreshRp, self.RefreshRedPoint) self:RegistSystemEvent(EventID.UI_GodBeastActivity_ChooseGodBeast, self.ShowBasicInfo) self.activityType = MDL.OperationActivity.ActivityType.GodBeastActivity self.activityId = context.activityId self.basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) self.feedItemId = self.basicData.ItemID self.maxLevel = MDL.OperationActivity.GodBeastLevel:GetDataLengthByActivityID(self.activityId) self.MaxShowIndex = math.modf(self.maxLevel / 10) - 1 self.curMaxShowIndex = 0 self.curShowIndex = 0 self.isInit = true UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_GodBeastActivity_Title"]) UIUtils.SetLabel(self.lab_FeedOne2, "X1") --喂养1次 UIUtils.SetLabel(self.lab_FeedTen2, "X10") --喂养10次 UIUtils.SetLabel(self.lab_FeedFifty2, "X50") --喂养50次 UTL.Item.SetItemIcon(self.img_FeedOne2, self.feedItemId) UTL.Item.SetItemIcon(self.img_FeedTen2, self.feedItemId) UTL.Item.SetItemIcon(self.img_FeedFifty2, self.feedItemId) self.currency_Info:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UICurrencyPanel), { viewClassPath = self.__viewClassPath, currencyTypeIds = CTL.Currency.GetCurrentTypeIds(self.__viewClassPath), param = { activityType = self.activityType, activityId = self.activityId } }) UIUtils.SetActive(self.btn_Block, false) self.group_Time:SetDHMSStr(UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_BuffShow), "{0}:{1}:{2}", "{0}:{1}", "{0}:{1}") self:ShowBasicInfo() self:RefreshRearLevelInfo() self:RefreshRedPoint() UIManager.ActiveUIModle(false, "UIGodBeastActivityMain") end function UIGodBeastActivityMain:OnClosed() UIManager.ActiveUIModle(true, "UIGodBeastActivityMain") UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) end function UIGodBeastActivityMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIGodBeastActivityMain:ClickFeed(times) local feedItemCount = UTL.Item.GetItemStockCount(self.feedItemId) if feedItemCount >= times then if MDL.GodBeastActivity.GetGodBeastIsCanChoose(self.activityId) then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_COMMON_PROMPT, Const_IDS.IDS_OptionalHorseAndTreasure_Title20, function () self:GodBeastRearReq(times) end) return end self:GodBeastRearReq(times) else CTL.OperationActivity.OpenGetActivityItemPanel(self.feedItemId, self.activityId, self.activityType) end end function UIGodBeastActivityMain:GodBeastRearReq(times) UIUtils.SetActive(self.btn_Block, true) MDL.GodBeastActivity.BeastRearRequest(self.activityId, times) end function UIGodBeastActivityMain:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.GodBeastActivity }) elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_FeedInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastActivityReward, { activityId = self.activityId }) elseif comp == self.btn_Task then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastActivityTasks, { activityType = self.activityType, activityId = self.activityId }) elseif comp == self.btn_Store then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastActivityStore, { activityType = self.activityType, activityId = self.activityId }) elseif comp == self.btn_Gift then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastActivityPackageWindow, { activityType = self.activityType, activityId = self.activityId }) elseif comp == self.btn_FeedOne then self:ClickFeed(1) elseif comp == self.btn_FeedTen then self:ClickFeed(10) elseif comp == self.btn_FeedFifty then self:ClickFeed(50) elseif comp == self.btn_ArrowLeft then self.curShowIndex = self.curShowIndex - 1 if self.curShowIndex < 0 then self.curShowIndex = 0 else self:RefreshRewardList() end elseif comp == self.btn_ArrowRight then self.curShowIndex = self.curShowIndex + 1 if self.curShowIndex > self.curMaxShowIndex then self.curShowIndex = self.curMaxShowIndex local curLevelData = MDL.OperationActivity.GodBeastLevel:GetDataByActivityID_Level(self.activityId, self.rearLevel > 0 and self.rearLevel or 1) local curVisibleLevel = curLevelData.RewardVisibleLevel local nextUnlockVisibleLevel for i, v in MDL.OperationActivity.GodBeastLevel:GetEnumeratorByActivityID(self.activityId) do if v.Level >= self.rearLevel then if v.RewardVisibleLevel ~= curVisibleLevel then nextUnlockVisibleLevel = v.Level break end end end CTL.Tips.AddTipsMsg(Const_IDS.IDS_GodBeastActivity_LockHint, nextUnlockVisibleLevel) else self:RefreshRewardList() end elseif comp == self.btn_Switch then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastActivityOptional, { activityId = self.activityId, id = LuaConst.NoteID.OptionalGodBeast }, Const_UI_Lua.UIEnum.UIGoldHeroOptional) else self:ClickReward(comp) end end function UIGodBeastActivityMain:OnCloseActivitySelf(viewClassPath, activityId) if viewClassPath == self.__viewClassPath then if self.activityId and activityId == self.activityId then self:CloseView(true) end end end function UIGodBeastActivityMain:PlayEventPerform(msgResp, oldLevel, newLevel) self.curLevelNum = MDL.GodBeastActivity.GetGodBeastCurExpNum(self.activityId) local newLevelData = MDL.OperationActivity.GodBeastLevel:GetDataByActivityID_Level(self.activityId, newLevel + 1) if newLevelData then self:SetSliderAnimation(self.bg_Process.fillAmount, newLevel - oldLevel, self.curLevelNum / newLevelData.RearEXP, 1.5) else self:SetSliderAnimation(self.bg_Process.fillAmount, newLevel - oldLevel, 1, 1.5) end --通知界面播放养马的特效和动作 local highEventId = 0 for i, v in ipairs(msgResp.eventTimes) do if v.eventId > highEventId then highEventId = v.eventId end end if highEventId > 0 then local eventData = MDL.OperationActivity.GodBeastEvent:GetDataByActivityID_EventID(self.activityId, highEventId) self.effect_GodBeastEvent:PlayUIEffect(eventData.EventEffect, EffectDuration) UIUtils.SetParticleRenderSortingOrder(self.effect_GodBeastEvent, self.panel_GDActivity, 20) CTL.Sound.PlayGameSound(RearEffectSound[highEventId]) local voicePath = self.godBeastData[eventData.EventActionVoice] if voicePath then CTL.Sound.PlayGameSound(voicePath) end else logging.error(LTAG.ERROR, "本次喂养Resp中的最高事件ID为0,请检查!!!") end local levelUpPerform if newLevel ~= oldLevel then --是否播放升级表现 levelUpPerform = function() UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastActivityLevelUp, { oldLevel = oldLevel, newLevel = newLevel }) end end self:StartRepeatFunc(function() UIUtils.SetActive(self.btn_Block, false) UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastActivityGetReward, { rearEventData = msgResp, closeViewCB = levelUpPerform }) end, WaitEffectTime, 1) end function UIGodBeastActivityMain:RefreshRewardList() self.startIndex = self.curShowIndex * 10 if self.startIndex >= self.maxLevel then self.startIndex = self.startIndex - 10 end UIUtils.SetActive(self.btn_ArrowLeft, self.curShowIndex ~= 0) UIUtils.SetActive(self.btn_ArrowRight, self.curShowIndex < self.MaxShowIndex) for k, reward_Cell in ipairs(self.group_Reward) do local data = MDL.OperationActivity.GodBeastLevel:GetDataByActivityID_Level(self.activityId, self.startIndex + k) UTL.Item.SetItemCell(reward_Cell.Item, data.RewardItem, data.RewardNum) local curLevel = data.Level reward_Cell.lab_Lv.text = string.FormatByIdsKey("IDS_BreakThrough_Lv", curLevel) UIUtils.SetActive(reward_Cell.group_Got, CTL.GodBeastActivity.IsGotLevelReward(self.activityId, curLevel)) if CTL.GodBeastActivity.IsCanGetLevelReward(self.activityId, curLevel) then reward_Cell.effect_Available:PlayUIEffect() else reward_Cell.effect_Available:StopUIEffect() end end end function UIGodBeastActivityMain:ClickReward(comp) for k, reward_Cell in ipairs(self.group_Reward) do local data = MDL.OperationActivity.GodBeastLevel:GetDataByActivityID_Level(self.activityId, self.startIndex + k) if comp == reward_Cell.Item.event_Click then if CTL.GodBeastActivity.IsCanGetLevelReward(self.activityId, data.Level) then MDL.GodBeastActivity.BeastLevelRewardRequest(self.activityId) else UTL.ItemTips.ShowCommonTipsById(data.RewardItem) end end end end function UIGodBeastActivityMain:ShowBasicInfo() local godBeastID = MDL.GodBeastActivity.GetGodBeastChooseId(self.activityId) self.godBeastData = DataSheetManager.GodBeastData:GetDataByID(godBeastID) local renderID = DataSheetManager.GodBeastActivityData:GetDataByGodBeastID(godBeastID).RenderID -- 释放之前的模型 UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) --展示模型 local godBeastModelData = DataSheetManager.MonsterModelData:GetDataByID(self.godBeastData.GodBeastModelID) UTL.UIRender.CreateRTSceneTrans(self.modelComponentDataHandle, self.godBeastData.GodBeastPreviewModelLight) UTL.UIRender.CreateRTRenderModel( self.modelComponentDataHandle, godBeastModelData.Path, self.godBeastData.ModelScale, nil, renderID, self.godBeastData.ModelIdleAnim ) --名字 UIUtils.SetLabelText(self.txt_GDName, Const_IDS[self.godBeastData.GodBeastName]) self:ShowGodBeastChooseInfo() end function UIGodBeastActivityMain:ShowGodBeastChooseInfo() --自选神兽 local isCanChoose = MDL.GodBeastActivity.GetGodBeastIsCanChoose(self.activityId) UIUtils.SetActive(self.btn_Switch, isCanChoose) if isCanChoose and not MDL.GodBeastActivity.IsGodBeastChoosePopUpAutoOpened(self.activityId) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastActivityOptional, { activityId = self.activityId, id = LuaConst.NoteID.OptionalGodBeast }, Const_UI_Lua.UIEnum.UIGoldHeroOptional) MDL.GodBeastActivity.SetGodBeastChoosePopUpAutoOpened(self.activityId) end end function UIGodBeastActivityMain:RefreshLeftTime() local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) local leftTimes = activityInfo.endTime - UTL.Time.GetServerTimestamp() self.group_Time:ResetAndBeginCustomTimer(false, leftTimes, 0, nil) end function UIGodBeastActivityMain:RefreshRearLevelInfo() self.rearLevel = MDL.GodBeastActivity.GetGodBeastRearLevel(self.activityId) self.curLevelNum = MDL.GodBeastActivity.GetGodBeastCurExpNum(self.activityId) self.txt_Lv.text = string.FormatByIdsKey("IDS_BreakThrough_Lv", self.rearLevel) local curLevelData = MDL.OperationActivity.GodBeastLevel:GetDataByActivityID_Level(self.activityId, self.rearLevel) local nextLevelData = MDL.OperationActivity.GodBeastLevel:GetDataByActivityID_Level(self.activityId, self.rearLevel + 1) self.curRewardVisibleLevel = curLevelData and curLevelData.RewardVisibleLevel or nextLevelData.RewardVisibleLevel self.curMaxShowIndex = math.modf(self.curRewardVisibleLevel / 10) - 1 self.curShowIndex = math.modf(self.rearLevel / 10) if self.rearLevel == self.maxLevel or (self.rearLevel > 0 and self.curShowIndex * 10 == self.rearLevel) then self.curShowIndex = self.curShowIndex - 1 end if nextLevelData then self.txt_LvNum.text = self.curLevelNum .. "/" .. nextLevelData.RearEXP if self.isInit then self.bg_Process.fillAmount = self.curLevelNum / nextLevelData.RearEXP self.isInit = false end else --没有下一级数据,证明满级了 local levelNum = curLevelData.RearEXP self.txt_LvNum.text = levelNum .. "/" .. levelNum UIUtils.SetLabelText(self.txt_LvNum, Const_IDS.IDS_GodBeastActivity_ChildTitle_7) if self.isInit then self.bg_Process.fillAmount = 1 self.isInit = false end end self:RefreshRewardList() self:RefreshLeftTime() self:ShowGodBeastChooseInfo() end --是否显示喂养50次 function UIGodBeastActivityMain:CheckShowFeedFifty() local feedItemCount = UTL.Item.GetItemStockCount(self.feedItemId) UIUtils.SetActive(self.btn_FeedFifty, feedItemCount >= 50) self.btn_FeedFifty:SetRedPoint(feedItemCount >= 50) end function UIGodBeastActivityMain:RefreshRedPoint() self.btn_Task:SetRedPoint(CTL.OACommon.IsHasTaskRedPoint(self.activityId)) self.btn_Gift:SetRedPoint(CTL.OACommon.IsHasGiftRedPoint(self.activityId)) local feedItemCount = UTL.Item.GetItemStockCount(self.feedItemId) self.btn_FeedTen:SetRedPoint(feedItemCount >= 10) self.btn_FeedOne:SetRedPoint(feedItemCount >= 1) self:CheckShowFeedFifty() end function UIGodBeastActivityMain:SetSliderAnimation(startValue, diffLeveL, lastValue, baseSpeed) self:StopRepeatFunc(self.RefreshSliderRepeatFunc) self._tempEndValue = -1 self.bg_Process.fillAmount = startValue local _endValue = diffLeveL + lastValue self._lastValue = lastValue self._showEndValues = {} self._totalTime = 0 if _endValue > 1 then local times, diff = math.modf(_endValue) for i = 1, times do table.insert(self._showEndValues, 1) end if diff > 0 then table.insert(self._showEndValues, diff) end else table.insert(self._showEndValues, _endValue) end self._speed = baseSpeed * #self._showEndValues self:PopEndValues() self:StartRepeatFunc(self.RefreshSliderRepeatFunc, 0.02) end function UIGodBeastActivityMain:PopEndValues() if #self._showEndValues > 0 then local pop = self._showEndValues[1] self._showEndValues[1] = nil table.remove(self._showEndValues, 1) self._tempEndValue = pop else self._tempEndValue = 0 end end function UIGodBeastActivityMain:RefreshSliderRepeatFunc(deltaTime, timeSinceUpdate) if self._tempEndValue < 0 then self.bg_Process.fillAmount = self._lastValue self:StopRepeatFunc(self.RefreshSliderRepeatFunc) end self._totalTime = self._totalTime + deltaTime if self._tempEndValue - self.bg_Process.fillAmount > 0.001 then self.bg_Process.fillAmount = UTL.UIRender.GetLerpValue(self.bg_Process.fillAmount, self._tempEndValue, self._speed * self._totalTime) else self:PopEndValues() if self._tempEndValue > 0 then self.bg_Process.fillAmount = 0 self._totalTime = 0 end end end return UIGodBeastActivityMain