local UIHorseRearMain = 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 UIHorseRearMain:OnOpened(context) self.activityType = MDL.OperationActivity.ActivityType.HorseRear self:RegistSystemEvent(EventID.UI_HorseRear_InfoUpdate, self.RefreshRearLevelInfo) self:RegistSystemEvent(EventID.UI_HorseRear_PlayEventPerform, self.PlayEventPerform) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshFeedItemCount) self:RegistSystemEvent(EventID.UI_HorseRear_ChooseHorse, self.ShowBasicInfo) UIUtils.SetLabel(self.lab_FeedOne2, "X1") --喂养1次 UIUtils.SetLabel(self.lab_FeedTen2, "X10") --喂养10次 UIUtils.SetLabel(self.lab_FeedFifty2, "X50") --喂养50次 self.activityId = context.activityId self.activityType = MDL.OperationActivity.ActivityType.HorseRear self:RegistTriggerEvent(self.btn_Drag, UIEventTriggerType.Drag) self.sliderAni = self.slider_Exp.transform:GetComponent(typeof(SliderAnimation)) self.sliderAni.enabled = false self.isInit = true 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:RegistSystemEvent(CTL.HorseRear.RpEventId[self.activityId].Task, self.RefreshTaskRp) self:RegistSystemEvent(CTL.HorseRear.RpEventId[self.activityId].Gift, self.RefreshGiftRp) self:RegistSystemEvent(CTL.HorseRear.RpEventId[self.activityId].FeedItemEnough, self.RefreshFeedRedPoint) self:RefreshTaskRp() self:RefreshGiftRp() self:RefreshFeedRedPoint() --彩金的读取运营活动里的 hud配置 local currencyTypeIds = CTL.Currency.GetCurrentTypeIds(self.__viewClassPath) if CTL.HorseRear.IsSuperGold(self.activityId) then local superGoldCoin = 234 --彩金的货币 local basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) currencyTypeIds = { MDL.Currency.CurrencyType.GoldIngot, superGoldCoin, basicData.ItemID } UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_HorseActivity_High_Title"]) else UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_HorseActivity_Title"]) end CTL.Currency.OpenCurrencyPanel(self.__viewClassPath, self.currency_Info, currencyTypeIds, { activityType = self.activityType, activityId = self.activityId }) UIManager.ActiveUIModle(false, "UIHorseRearMain") end function UIHorseRearMain:OnClosed() UIManager.ActiveUIModle(true, "UIHorseRearMain") end function UIHorseRearMain:ClickFeed(times) local basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) local feedItemId = basicData.ItemID local feedItemCount = UTL.Item.GetItemStockCount(feedItemId) if feedItemCount >= times then if MDL.HorseRear.GetRearHorseIsCanChoose(self.activityId) then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_COMMON_PROMPT, Const_IDS.IDS_OptionalHorseAndTreasure_Hint10, function () self:HorseRearReq(times) end) return end self:HorseRearReq(times) else CTL.OperationActivity.OpenGetActivityItemPanel(feedItemId, self.activityId, self.activityType) end end function UIHorseRearMain:HorseRearReq(times) UIUtils.SetActive(self.btn_Block, true) MDL.HorseRear.HorseRearReq(self.activityId, times) end function UIHorseRearMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIHorseRearMain:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { activityId = self.activityId, id = LuaConst.NoteID.HorseRear }) elseif comp == self.btn_FeedInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseRearReward, { activityId = self.activityId }) elseif comp == self.btn_Task then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseRearTasks, { activityType = self.activityType, activityId = self.activityId }) elseif comp == self.btn_Store then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseRearStore, { activityType = self.activityType, activityId = self.activityId }) elseif comp == self.btn_Gift then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseRearPackageWindow, { 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.item_Feed.event_Click then local basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) UTL.ItemTips.ShowCommonTipsById(basicData.ItemID) elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Switch then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseOptional, { activityId = self.activityId, id = LuaConst.NoteID.HorseRear }, Const_UI_Lua.UIEnum.UIGoldHeroOptional) end end function UIHorseRearMain:PlayEventPerform(msgResp, oldLevel, newLevel) local horseId = MDL.HorseRear.GetRearHorseChooseId(self.activityId) self:PlayExpAnimation(oldLevel, newLevel) --通知界面播放养马的特效和动作 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.HorseRearEvent:GetDataByActivityID_EventID(self.activityId, highEventId) local horseData = DataSheetManager.HorseData:GetDataByHorseID(horseId) self.effect_HorseEvent:PlayUIEffect(eventData.EventEffect, EffectDuration) CTL.Sound.PlayGameSound(RearEffectSound[highEventId]) local animPath = horseData[eventData.EventAction] if animPath then self.renderModel:PlayHorseAnim(horseData[eventData.EventAction]) end local voicePath = horseData[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.UIHorseRearLevelUp, { oldLevel = oldLevel, newLevel = newLevel }) end end self:StartRepeatFunc(function() UIUtils.SetActive(self.btn_Block, false) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseRearGetReward, { rearEventData = msgResp, closeViewCB = levelUpPerform }) end, WaitEffectTime, 1) end function UIHorseRearMain:PlayExpAnimation(oldLevel, newLevel) local curLevelNum = MDL.HorseRear.GetCurExpNum(self.activityId) local newLevelData = MDL.OperationActivity.HorseRearLevel:GetDataByActivityID_Level(self.activityId, newLevel + 1) self.sliderAni.enabled = true if newLevelData then self.sliderAni:Init(self.slider_Exp.value, newLevel - oldLevel, curLevelNum / newLevelData.RearEXP) else self.sliderAni:Init(self.slider_Exp.value, newLevel - oldLevel, 1) end end function UIHorseRearMain:RefreshRearLevelInfo() local rearLevel = MDL.HorseRear.GetRearLevel(self.activityId) local curLevelNum = MDL.HorseRear.GetCurExpNum(self.activityId) self.txt_Lv.text = string.FormatByIdsKey("IDS_BreakThrough_Lv", rearLevel) local curLevelData = MDL.OperationActivity.HorseRearLevel:GetDataByActivityID_Level(self.activityId, rearLevel) local nextLevelData = MDL.OperationActivity.HorseRearLevel:GetDataByActivityID_Level(self.activityId, rearLevel + 1) if nextLevelData then self.txt_LvNum.text = curLevelNum .. "/" .. nextLevelData.RearEXP if self.isInit then self.slider_Exp.value = curLevelNum / nextLevelData.RearEXP self.isInit = false end else --没有下一级数据,证明满级了 local levelNum = curLevelData.RearEXP self.txt_LvNum.text = levelNum .. "/" .. levelNum if self.isInit then self.slider_Exp.value = 1 self.isInit = false end end if self.loop_LevelReward.Count > 0 then self.loop_LevelReward:ClearCells() end local visibleLevel = curLevelData and curLevelData.RewardVisibleLevel or nextLevelData.RewardVisibleLevel for i, v in MDL.OperationActivity.HorseRearLevel:GetEnumeratorByActivityID(self.activityId) do if v.Level > visibleLevel then self.loop_LevelReward:AddData(nil, 1) break end self.loop_LevelReward:AddData(v, 0) end self.loop_LevelReward:MoveIndex(rearLevel - 1) self:RefreshLeftTime() self:ShowHorseChooseInfo() end function UIHorseRearMain:RefreshFeedItemCount() local basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) local feedItemId = basicData.ItemID local feedItemCount = UTL.Item.GetItemStockCount(feedItemId) UTL.Item.SetItemCell(self.item_Feed, feedItemId, feedItemCount > 0 and feedItemCount or nil) self:RefreshFeedRedPoint() end function UIHorseRearMain: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 UIHorseRearMain:ShowBasicInfo() local horseId = MDL.HorseRear.GetRearHorseChooseId(self.activityId) local horseData = DataSheetManager.HorseData:GetDataByHorseID(horseId) local renderId = DataSheetManager.HorseActivityData:GetDataByHorseID(horseId).RenderID --展示模型 local horseModeData = DataSheetManager.HorseModelData:GetDataByHorseModelID(horseData.HorseModelID) self.renderModel:ShowHorse(horseModeData.HorseModel, renderId, horseData.HorsePreviewModelLight, horseData.ActivationModelRot, "", horseModeData.HorseShowEffect) --名字 UIUtils.SetLabelText(self.txt_HorseName, Const_IDS[horseData.HorseName]) --饲料信息 local basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) local feedItemData = DataSheetManager.ItemData:GetDataByID(basicData.ItemID) UIUtils.SetLabelText(self.txt_FeedName, Const_IDS[feedItemData.Name]) UIUtils.SetLabelText(self.lab_FeedDes, Const_IDS[feedItemData.Des]) self:RefreshFeedItemCount() self:ShowHorseChooseInfo() end function UIHorseRearMain:ShowHorseChooseInfo() --自选马 local isCanChoose = MDL.HorseRear.GetRearHorseIsCanChoose(self.activityId) UIUtils.SetActive(self.btn_Switch, isCanChoose) if isCanChoose and not MDL.HorseRear.IsHorseChoosePopUpAutoOpened(self.activityId) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseOptional, { activityId = self.activityId, id = LuaConst.NoteID.HorseRear }, Const_UI_Lua.UIEnum.UIGoldHeroOptional) MDL.HorseRear.SetHorseChoosePopUpAutoOpened(self.activityId) end end function UIHorseRearMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_LevelReward then if data then UTL.Item.SetItemCell(cellTable.Item, data.RewardItem, data.RewardNum) local curLevel = data.Level cellTable.lab_Lv.text = string.FormatByIdsKey("IDS_BreakThrough_Lv", curLevel) UIUtils.SetActive(cellTable.group_Got, CTL.HorseRear.IsGotLevelReward(self.activityId, curLevel)) if CTL.HorseRear.IsCanGetLevelReward(self.activityId, curLevel) then cellTable.effect_Available:PlayUIEffect() else cellTable.effect_Available:StopUIEffect() end end end end function UIHorseRearMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_LevelReward then if data then if target == cellTable.Item.event_Click then if CTL.HorseRear.IsCanGetLevelReward(self.activityId, data.Level) then MDL.HorseRear.HorseLevelRewardReq(self.activityId) else UTL.ItemTips.ShowCommonTipsById(data.RewardItem) end end else if target == cellTable.btn_Lock then local rearLevel = MDL.HorseRear.GetRearLevel(self.activityId) local curLevelData = MDL.OperationActivity.HorseRearLevel:GetDataByActivityID_Level(self.activityId, rearLevel > 0 and rearLevel or 1) local curVisibleLevel = curLevelData.RewardVisibleLevel local nextUnlockVisibleLevel for i, v in MDL.OperationActivity.HorseRearLevel:GetEnumeratorByActivityID(self.activityId) do if v.Level >= rearLevel then if v.RewardVisibleLevel ~= curVisibleLevel then nextUnlockVisibleLevel = v.Level break end end end CTL.Tips.AddTipsMsg(Const_IDS.IDS_HorseActivity_LockHint, nextUnlockVisibleLevel) end end end end function UIHorseRearMain:OnDrag(comp, eventdata) if comp == self.btn_Drag then self.renderModel:RotatingByManual(eventdata) end end --region *********************** 红点 ******************************** --是否显示喂养50次 function UIHorseRearMain:CheckShowFeedFifty() local basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) local feedItemId = basicData.ItemID local feedItemCount = UTL.Item.GetItemStockCount(feedItemId) UIUtils.SetActive(self.btn_FeedFifty, feedItemCount >= 50) self.btn_FeedFifty:SetRedPoint(feedItemCount >= 50) end function UIHorseRearMain:RefreshFeedRedPoint() local basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) local feedItemId = basicData.ItemID local feedItemCount = UTL.Item.GetItemStockCount(feedItemId) self.btn_FeedTen:SetRedPoint(feedItemCount >= 10) self.btn_FeedOne:SetRedPoint(feedItemCount >= 1) self:CheckShowFeedFifty() end function UIHorseRearMain:RefreshTaskRp(active) self.btn_Task:SetRedPoint(CTL.OACommon.IsHasTaskRedPoint(self.activityId)) end function UIHorseRearMain:RefreshGiftRp(active) self.btn_Gift:SetRedPoint(CTL.OACommon.IsHasGiftRedPoint(self.activityId)) end --endregion *********************** 红点 ******************************** return UIHorseRearMain