local UIMonopolyMainPanel = UIViewClass() local RewardMaxShowCount = 5 local DICESWING_DURATION = 1 local MOVE_DURATION = 0.2 local DICE_RESULT_ANI = "StepNum" local ROUND_ANI = "Point" local IsNextRound = false -- 解决奖励跨圈动画卡死的问题,10圈-20圈奖励,60-80圈奖励的时候会用到。 local PreviousLoopID = -1 local SecondRoundFirstLoopID = 6 local ThirdRoundFirstLoopID = 11 local math_ceil = math.ceil local math_floor = math.floor local DiceResultEftPath = { ConstAssetPathConfig.AssetPath146, ConstAssetPathConfig.AssetPath147, ConstAssetPathConfig.AssetPath148, ConstAssetPathConfig.AssetPath149, ConstAssetPathConfig.AssetPath150, ConstAssetPathConfig.Path34 } ----------------------------- 系统函数 ----------------------------- function UIMonopolyMainPanel:OnCreated() self.roundIndex = 0 self.optResult = nil self.playResultAni = nil self.isPlaying = false self.playMoveAni = nil self.moveNum = 0 self.roundAnis = LuaExt.CreateTable(RewardMaxShowCount) self.toggle_Skip.isOn = PersistentData.PlayerData:Get(LuaConst.SettingKeyEnum.MonopolySkipSingleEffect) or false end function UIMonopolyMainPanel:OnOpened() self:RegistSystemEvent(EventID.Monopoly_Point_Refresh, self.InitMapPoints) self:RegistSystemEvent(EventID.UI_Monopoly_RefreshMain, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_Monopoly_ShowSwingDiceResult, self.ShowSwingDiceResult) self:RegistSystemEvent(EventID.UI_Monopoly_PlayNewRoundRewardEffect, self.PlayNewRoundRewardEffect) self:RegistSystemEvent(EventID.UI_Monopoly_RefreshRp, self.RefreshRp) self:RegistSystemEvent(EventID.UI_DirectGift_GiftInfoUpdate, self.RefreshRp) self:RegistSystemEvent(EventID.UI_Monopoly_OnCloseActivity, self.OnCloseActivity) self:RegistSystemEvent(EventID.UI_Monopoly_ChooseTreasure, self.ShowTreasureChooseInfo) local activityId = self.context.activityId self.activityId = activityId self.mapItemBtns = LuaExt.CreateTable(CTL.Monopoly:GetMapPointCount(activityId)) --设置货币跳转activityId self.currency_Info:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UICurrencyPanel), { viewClassPath = self.__viewClassPath, currencyTypeIds = CTL.Currency.GetCurrentTypeIds(self.__viewClassPath), param = { activityType = MDL.OperationActivity.ActivityType.Monopoly, activityId = activityId } }) if CTL.Monopoly.IsSuperGold(activityId) then UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_Monopoly_High_Title"]) else UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_Monopoly_Title"]) end UIUtils.SetLabelText(self.txt_NumOne, Const_IDS.IDS_Monopoly_1Time) UIUtils.SetLabelText(self.txt_NumTen, Const_IDS.IDS_Monopoly_10Times) UIUtils.SetLabelText(self.txt_NumMore, Const_IDS.IDS_Monopoly_50Times) self:InitMapPoints() self:RefreshRp() self:RefreshActivityTime(true) self:StartRepeatFunc(self.RefreshActivityTime, 1, -1) MDL.Monopoly.MonopolyOpenRequest(activityId) end function UIMonopolyMainPanel:SetMoneyAndItemShow() if CTL.Monopoly.IsSuperGold(self.activityId) then local moneyId,itemId = MDL.Monopoly.GetMoneyAndItemShow(self.activityId) CTL.Currency.OpenCurrencyPanel(nil, self.currency_Info,{MDL.Currency.CurrencyType.GoldIngot,moneyId,itemId}) end end function UIMonopolyMainPanel:OnFocusChanged(isFocus) UIUtils.SetActive(self.group_Role, isFocus) end function UIMonopolyMainPanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIMonopolyMainPanel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then if not self.isPlaying then self:CloseView() end elseif comp == self.UITemplateTitlePanel.btn_Home then if not self.isPlaying then CTL.HomeMain.CloseViewBackHomeMain() end elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.Monopoly,activityId = self.activityId}) elseif comp == self.btn_StartOnce then self:StartDice(1) elseif comp == self.btn_StartTen then self:StartDice(10) elseif comp == self.btn_StartMore then self:StartDice(50) elseif comp == self.btn_Mission then -- 活跃任务 UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyTasks, { selectedTypeID = 0, activityId = self.activityId }) elseif comp == self.btn_Store then -- 商店 UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyStore, { activityId = self.activityId }) elseif comp == self.btn_Gift then -- 超级豪礼 UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyPackageWindow, { activityId = self.activityId }) elseif comp == self.btn_RewardRec then -- 获奖记录 UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyRecords, { activityId = self.activityId }) elseif comp == self.btn_RewardView then -- 圈数奖励预览 UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyRewardRecord, { activityId = self.activityId }) elseif comp == self.btn_Switch then UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyTreasureOptional, { activityId = self.activityId, id = LuaConst.NoteID.Monopoly }, Const_UI_Lua.UIEnum.UIGoldHeroOptional) else for k, rewardBtn in pairs (self.mapItemBtns) do if comp == rewardBtn then local pointInfo = CTL.Monopoly.GetMapPointInfo(self.activityId, k) if pointInfo and pointInfo.PassReward then UTL.ItemTips.ShowCommonTipsById(pointInfo.PassReward.ItemID) break end end end end end function UIMonopolyMainPanel:OnUIAnimationStoped(playingID) if self.playMoveAni == playingID then self:PlayRoleMoveEffect() UIUtils.SetActive(self.toggle_Skip, true) elseif self.playResultAni == playingID then UIUtils.SetActive(self.group_StepNum, false) if self.toggle_Skip.isOn or self.optResult.diceNum > 6 then CTL.Monopoly.ShowPassAndStepRewardTips(self.optResult) end UIUtils.SetActive(self.toggle_Skip, true) else for _, v in pairs (self.roundAnis) do if v == playingID then self:RoundRewardEffectOver() break end end end end function UIMonopolyMainPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.RewardScroll then UTL.Item.SetItemCell(cellTable.UIItemBase, data.LoopRewardID, data.LoopRewardNum) UIUtils.SetLabel(cellTable.lab_CircleNum, string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_Monopoly_LoopNum"]), data.LoopNum)) UIUtils.SetActive(cellTable.group_Got, MDL.Monopoly.GetCurMapRound() >= data.LoopNum) end end function UIMonopolyMainPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.RewardScroll then if target == cellTable.UIItemBase.event_Click then UTL.ItemTips.ShowCommonTipsById(data.LoopRewardID) end end end function UIMonopolyMainPanel:OnClosed() -- 开启奖励提示 MDL.Reward.SetCloseRewardTipShow(false) PersistentData.PlayerData:Set(LuaConst.SettingKeyEnum.MonopolySkipSingleEffect, self.toggle_Skip.isOn, true) end ------------------------------------------------------------------- function UIMonopolyMainPanel:InitMapPoints(activityId) if activityId and activityId ~= self.activityId then return end table.clear(self.mapItemBtns) for i = 1, #self.group_Map do local mapPoint = self.group_Map[i] local pointInfo = CTL.Monopoly.GetMapPointInfo(self.activityId, i) if pointInfo then if pointInfo.type == CTL.Monopoly.PointType.ZeroPoint then mapPoint.PointStateSwitch:SetState(3) elseif pointInfo.type == CTL.Monopoly.PointType.TopRewardPoint then mapPoint.PointStateSwitch:SetState(2) elseif pointInfo.type == CTL.Monopoly.PointType.NormalRewardPoint then mapPoint.PointStateSwitch:SetState(1) elseif pointInfo.type == CTL.Monopoly.PointType.LowerRewardPoint then mapPoint.PointStateSwitch:SetState(0) end -- 设置奖励图标和数量 UIUtils.SetActive(mapPoint.group_Reward, pointInfo.PassReward ~= nil) if pointInfo.PassReward then self.mapItemBtns[i] = mapPoint.group_Reward UTL.Item.ItemIconWithoutBg(mapPoint.img_Icon, pointInfo.PassReward.ItemID) UIUtils.SetLabel(mapPoint.lab_Count, pointInfo.PassReward.ItemNum) end else UIUtils.SetActive(mapPoint.gameObject, false) end end self:SetRoleEffectState(true) end function UIMonopolyMainPanel:RefreshActivityTime(isFromOpen) local activityId = self.activityId if not MDL.Monopoly.IsOpenMonopolyActivity(activityId) then UIUtils.SetLabel(self.txt_Time, UTL.Color.FormatRedColor(UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildBoss_AlreadyClosed"]))) if not isFromOpen and Manager.IsFocus(Const_UI_Lua.UIEnum.UIMonopolyMainPanel) then self:StopRepeatFunc(self.RefreshActivityTime) CTL.Monopoly.CloseAllFuncPanel() end else local duration = MDL.Monopoly.GetActivityInfo(activityId).endTime - UTL.Time.GetServerTimestamp() -- 超过24小时 if duration >= UTL.Time.TotalSecondsOneDay then UIUtils.SetLabel(self.txt_Time, string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_Monopoly_LastTime"]), UTL.Time.FormatTimeForTitle(duration))) else UIUtils.SetLabel(self.txt_Time, string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_Monopoly_LastTime"]), UTL.Time.FormatTimeClockBySeconds(duration))) end end end function UIMonopolyMainPanel:RefreshPanel(activityId) if activityId and activityId ~= self.activityId then return end self:RefreshRolePosition() self:RefreshRound() self:RefreshRoundReward() self:SetRoleEffectState(true) self:SetMoneyAndItemShow() self:RefreshRp() self:ShowTreasureChooseInfo() end function UIMonopolyMainPanel:RefreshRolePosition() local mapId = MDL.Monopoly.GetCurMapPointId() local mapPoint = self.group_Map[mapId] if mapPoint then local anchorPosX, anchorPosY = mapPoint.gameObject.transform.parent:GetAnchoredPosition() self.group_Role.transform:SetAnchoredPosition(anchorPosX, anchorPosY) end end function UIMonopolyMainPanel:RefreshRound() local nextRoundRewardCfg = CTL.Monopoly.GetNextLoopRewardCfg(self.activityId) UIUtils.SetLabel(self.lab_DescReward, string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_Monopoly_LoopReward"]),MDL.Monopoly.GetCurMapRound(), nextRoundRewardCfg.LoopNum)) end function UIMonopolyMainPanel:RefreshRoundReward() -- 填充奖励滑动列表 local nextRoundRewardCfg = CTL.Monopoly.GetNextLoopRewardCfg(self.activityId) local roundIndex = math_ceil(nextRoundRewardCfg.LoopID / RewardMaxShowCount) -- 当从第一圈跨到第二圈、第二圈跨到第三圈的时候,这里 roundIndex 已经刷新而导致前一圈的圈奖励逻辑卡死。 if nextRoundRewardCfg.LoopID - PreviousLoopID == 1 then if (nextRoundRewardCfg.LoopID == SecondRoundFirstLoopID or nextRoundRewardCfg.LoopID == ThirdRoundFirstLoopID) and not IsNextRound then IsNextRound = true end end PreviousLoopID = nextRoundRewardCfg.LoopID if self.roundIndex ~= roundIndex then if self.RewardScroll.Count > 0 then self.RewardScroll:ClearCells() end for i = roundIndex * RewardMaxShowCount - (RewardMaxShowCount - 1), roundIndex * RewardMaxShowCount do self.RewardScroll:AddData(CTL.Monopoly:GetLoopRewardCfg(i, self.activityId), 0) end self.roundIndex = roundIndex else self.RewardScroll:RefreshCells(false) end end function UIMonopolyMainPanel:RefreshRp() local aid = self.activityId self.btn_StartOnce:SetRedPoint(UTL.Item.GetItemStockCount(CTL.Monopoly.GetDiceItemID(aid)) > 0) self.btn_StartTen:SetRedPoint(UTL.Item.GetItemStockCount(CTL.Monopoly.GetDiceItemID(aid)) >= 10) self.btn_Mission:SetRedPoint(MDL.Monopoly.IsShowRpByType(aid, MDL.Monopoly.RedPointType.Task) == true) self.btn_Gift:SetRedPoint(CTL.Monopoly.HasGiftRp(aid)) self:CheckShowStartFifty() end function UIMonopolyMainPanel:ShowTreasureChooseInfo() --自选宝物 local isCanChoose = MDL.Monopoly.GetTreasureIsCanChoose(self.activityId) UIUtils.SetActive(self.btn_Switch, isCanChoose) if isCanChoose and not MDL.Monopoly.IsTreasureChoosePopUpAutoOpened(self.activityId) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIMonopolyTreasureOptional, { activityId = self.activityId, id = LuaConst.NoteID.Monopoly }, Const_UI_Lua.UIEnum.UIGoldHeroOptional) MDL.Monopoly.SetTreasureChoosePopUpAutoOpened(self.activityId) end end function UIMonopolyMainPanel:StartDice(num) if not self.isPlaying then local aid = self.activityId if not MDL.Monopoly.IsOpenMonopolyActivity(aid) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_RebelStrike_NotAtActivityTime"]) return end if UTL.Item.GetItemStockCount(CTL.Monopoly.GetDiceItemID(aid)) >= num then if MDL.Monopoly.GetTreasureIsCanChoose(self.activityId) then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_COMMON_PROMPT, Const_IDS.IDS_OptionalHorseAndTreasure_Hint9, function () self:MonopolyDiceRequest(num, aid) end) return end self:MonopolyDiceRequest(num, aid) else CTL.OperationActivity.OpenGetActivityItemPanel(CTL.Monopoly.GetDiceItemID(aid), aid, MDL.OperationActivity.ActivityType.Monopoly) end end end function UIMonopolyMainPanel:MonopolyDiceRequest(num, aid) if not self.toggle_Skip.isOn and num == 1 then self.isPlaying = true end -- 关闭奖励提示 MDL.Reward.SetCloseRewardTipShow(true) MDL.Monopoly.MonopolyDiceRequest(num,aid) end -- 相关播放效果 -- 扔筛子结果展示 function UIMonopolyMainPanel:ShowSwingDiceResult(monopolyDiceOptResult) -- 关闭操作按钮 UIUtils.SetActive(self.btn_StartOnce, false) UIUtils.SetActive(self.btn_StartTen, false) UIUtils.SetActive(self.btn_StartMore, false) UIUtils.SetActive(self.toggle_Skip, false) self.optResult = monopolyDiceOptResult -- 跳过或者10次 if self.toggle_Skip.isOn or self.optResult.diceNum > 6 then self:ShowDiceStepInfo() self:RefreshRolePosition() self:RefreshRound() return end self.moveNum = self.optResult.diceNum -- 根据骰子数播放对应特效 self.effect_Dice:PlayUIEffect(DiceResultEftPath[self.optResult.diceNum], 2) self:StartRepeatFunc(self.SwingDiceEffectOver, DICESWING_DURATION, 1) end function UIMonopolyMainPanel:SwingDiceEffectOver() -- 特效解锁播放角色跳动效果 self:PlayRoleMoveEffect(true) end -- 显示投掷步数信息 仅限跳过和10连投显示 function UIMonopolyMainPanel:ShowDiceStepInfo() -- 显示跳跃步数信息 CTL.Sound.PlayGameSound("UI_treasures_roll") UIUtils.SetActive(self.group_StepNum, true) self.number.text = self.optResult.diceNum if not self.playResultAni then self.playResultAni = self:PlayUIAnimation(DICE_RESULT_ANI, true) else self:PlayUIAnimation(self.playResultAni) end end -- 播放人物移动动画 function UIMonopolyMainPanel:PlayRoleMoveEffect(isFirstPlay) if self.moveNum == 0 then self:RefreshPanel() CTL.Monopoly.ShowPassAndStepRewardTips(self.optResult) return end -- 播放特效 if isFirstPlay then self:SetRoleEffectState(false) else self.effect_Jump:PlayUIEffect() end -- 播放移动曲线 local targetMapId = MDL.Monopoly.GetCurMapPointId() - self.moveNum + 1 targetMapId = targetMapId > 0 and targetMapId or CTL.Monopoly:GetMapPointCount(self.activityId) + targetMapId local targetX, targetY = self.group_Map[targetMapId].gameObject.transform.parent:GetAnchoredPosition() self.playMoveAni = self:MoveToPos(self.group_Role, targetX, targetY, MOVE_DURATION, true) self.moveNum = self.moveNum - 1 end -- 圈数奖励 function UIMonopolyMainPanel:PlayNewRoundRewardEffect() if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIMonopolyRewardTip) then UIManager.CloseView(Const_UI_Lua.UIEnum.UIMonopolyRewardTip) end self:RoundRewardEffectOver() end function UIMonopolyMainPanel:RoundRewardEffectOver() CTL.Monopoly.ShowRoundRewardEft(self.optResult) self:StopMonopolyEffect() end function UIMonopolyMainPanel:StopMonopolyEffect() self.optResult = nil self.moveNum = 0 self.isPlaying = false -- 开启奖励提示 MDL.Reward.SetCloseRewardTipShow(false) UIUtils.SetActive(self.btn_StartOnce, true) UIUtils.SetActive(self.btn_StartTen, true) self:CheckShowStartFifty() self:RefreshRoundReward() end function UIMonopolyMainPanel:SetRoleEffectState(isIdle) UIUtils.SetActive(self.effect_Breathe.gameObject, isIdle) UIUtils.SetActive(self.effect_Jump.gameObject, not isIdle) if isIdle then self.effect_Breathe:PlayUIEffect() else self.effect_Jump:PlayUIEffect() end end --是否显示投掷 50次 function UIMonopolyMainPanel:CheckShowStartFifty() local isShowFifty = UTL.Item.GetItemStockCount(CTL.Monopoly.GetDiceItemID(self.activityId)) >= 50 UIUtils.SetActive(self.btn_StartMore,isShowFifty) self.btn_StartMore:SetRedPoint(isShowFifty) end function UIMonopolyMainPanel:OnCloseActivity() self:CloseView(true) end return UIMonopolyMainPanel