InvadeMonsterView = {} local this = InvadeMonsterView local StoreConfig = ConfigManager.GetConfig(ConfigName.StoreConfig) local orginLayer = 0 -- 上一个宝箱的状态 local lastBoxState = 0 -- 是否已经点击了宝箱 local hadClicked = false --初始化组件(用于子类重写) function InvadeMonsterView:InitComponent(gameObject, fightPointPassMainPanel) self.gameObject = gameObject this.adventureMainPanel = fightPointPassMainPanel --极速探险 this.expeditionsBtn = Util.GetGameObject(self.gameObject, "Bg/invadeBtn/expeditionsBtn") -- 宝箱的根节点 this.rewardBox = Util.GetGameObject(self.gameObject, "Bg/getBoxReward") -- 宝箱的4个动画 this.rewardBox1 = Util.GetGameObject(self.gameObject, "boxRoot/UI_effect_GuaJi_Box_01") this.rewardBox2 = Util.GetGameObject(self.gameObject, "boxRoot/UI_effect_GuaJi_Box_02") this.rewardBox3 = Util.GetGameObject(self.gameObject, "boxRoot/UI_effect_GuaJi_Box_03") this.btnFastExplore = Util.GetGameObject(self.gameObject, "Bg/btnDown/btnFastExplore") --红点 this.expeditionRedPoint = Util.GetGameObject(self.gameObject, "Bg/btnDown/btnFastExplore/redPoint") this.rewardBoxRedPoint = Util.GetGameObject(self.gameObject, "Bg/getBoxReward/rewardBoxRedPoint") this.chapterRedPoint = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRewrdChapter/redPoint") this.btnRewrdChapter = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRewrdChapter") this.btnRewardOnline = Util.GetGameObject(self.gameObject, "Bg/LeftUp/box/btnRewrdOnline") this.onlineRedPoint = Util.GetGameObject(this.btnRewardOnline, "redPoint") this.onlineRewardQuality = Util.GetGameObject(this.btnRewardOnline, "quality"):GetComponent("Image") this.onlineRewardIcon = Util.GetGameObject(this.btnRewardOnline, "icon"):GetComponent("Image") this.onlineRewardNum = Util.GetGameObject(this.btnRewardOnline, "num"):GetComponent("Text") this.onlineRewardTime = Util.GetGameObject(this.btnRewardOnline, "time"):GetComponent("Text") this.onlineRewardEffect = Util.GetGameObject(this.btnRewardOnline, "effect") effectAdapte(Util.GetGameObject(this.onlineRewardEffect, "ziti mask (1)")) this.onlineRewardData = nil this.onlineRewardState = nil end --绑定事件(用于子类重写) function InvadeMonsterView:BindEvent() --点击宝箱领取奖励 Util.AddClick(this.rewardBox, function() if not hadClicked then hadClicked = true FightPointPassManager.oldLevel = PlayerManager.level local boxState = this.GetBoxShowState(AdventureManager.stateTime) if boxState > 0 then local isPopUp = RedPointManager.PlayerPrefsGetStr(PlayerManager.uid .. "mazeTreasureMax") local currentTime = os.date("%Y%m%d", PlayerManager.serverTime) local mazeTreasureMax = ConfigManager.GetConfigData(ConfigName.PlayerLevelConfig,PlayerManager.level).MazeTreasureMax local str = "当前拥有"..BagManager.GetItemCountById(FindTreasureManager.materialItemId).."/"..mazeTreasureMax.. "的"..ConfigManager.GetConfigData(ConfigName.ItemConfig,FindTreasureManager.materialItemId).Name.. ",收宝箱奖励后数量溢出的部分将会丢失,是否继续?" if BagManager.GetItemCountById(FindTreasureManager.materialItemId) >= mazeTreasureMax and isPopUp ~= currentTime then MsgPanel.ShowTwo(str, nil, function(isShow) if (isShow) then local currentTime = os.date("%Y%m%d", PlayerManager.serverTime) RedPointManager.PlayerPrefsSetStr(PlayerManager.uid .."mazeTreasureMax", currentTime) end FightPointPassManager.isBeginFight = true AdventureManager.GetAventureRewardRequest(2, false, false) this.InitBoxShow() end,nil,nil,nil,true) else FightPointPassManager.isBeginFight = true AdventureManager.GetAventureRewardRequest(2, false, false) this.InitBoxShow() end else PopupTipPanel.ShowTip("奖励正在积攒中!") end hadClicked = false end end) --点击极速探险 Util.AddClick(this.btnFastExplore, function() FightPointPassManager.isBeginFight = true UIManager.OpenPanel(UIName.FastExploreInfoPopup) end) -- 在线奖励 Util.AddClick(this.btnRewardOnline, function() --UIManager.OpenPanel(UIName.CourtesyDressPanel, ActivityTypeDef.OnlineGift, true) UIManager.OpenPanel(UIName.OnlineRewardPanel, ActivityTypeDef.OnlineGift, true) end) -- 通关奖励 Util.AddClick(this.btnRewrdChapter, function() UIManager.OpenPanel(UIName.CourtesyDressPanel, ActivityTypeDef.ChapterAward, true) end) end --更新宝箱状态 function InvadeMonsterView.UpdataBoxStateShow() -- 避免频繁使用SetActive -- 判断当前挂机使用,发出冲击状态发生改变时,设置一下宝箱状态 local state = this.GetBoxShowState(AdventureManager.stateTime) this.SetBoxShow(state) end ----@param hangupTime 已经挂机时长 ---@return 0 -- 无奖励 1 -- 第一个奖励 2 -- 第二个奖励 3 -- 满奖励 没有奖励也显示这个该死的宝箱 function this.GetBoxShowState(hangupTime) --Log("挂机时长 hangupTime " .. hangupTime) local state = 0 if hangupTime < AdventureManager.adventureRefresh then state = 0 elseif hangupTime >= AdventureManager.adventureRefresh and hangupTime < AdventureManager.adventureBoxShow[1] then state = 1 elseif hangupTime >= AdventureManager.adventureRefresh and hangupTime < AdventureManager.adventureBoxShow[2] then state = 2 else state = 3 end FightPointPassManager.SetBoxState(state) return state end function this.SetBoxShow(curState) if curState ~= lastBoxState then -- 设置一次宝箱状态 --Log("更新一次宝箱状态 state == " .. curState) this.rewardBox:SetActive(true) if curState == 0 or curState == 1 then this.rewardBox1:SetActive(true) else this.rewardBox1:SetActive(false) end this.rewardBox2:SetActive(curState == 2) this.rewardBox3:SetActive(curState == 3) this.rewardBoxRedPoint:SetActive(curState == 3) end lastBoxState = curState end -- 初始化宝箱状态 function this.InitBoxShow() this.rewardBox:SetActive(true) this.rewardBox1:SetActive(true) this.rewardBox2:SetActive(false) this.rewardBox3:SetActive(false) this.rewardBoxRedPoint:SetActive(false) end function InvadeMonsterView:OnSortingOrderChange() Util.AddParticleSortLayer(self.rewardBox1, this.adventureMainPanel.sortingOrder - orginLayer) Util.AddParticleSortLayer(self.rewardBox2, this.adventureMainPanel.sortingOrder - orginLayer) Util.AddParticleSortLayer(self.rewardBox3, this.adventureMainPanel.sortingOrder - orginLayer) Util.AddParticleSortLayer(this.onlineRewardEffect, this.adventureMainPanel.sortingOrder - orginLayer) orginLayer = this.adventureMainPanel.sortingOrder end --添加事件监听(用于子类重写) function InvadeMonsterView:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Adventure.OnRefeshBoxRewardShow, this.UpdataBoxStateShow) Game.GlobalEvent:AddEvent(GameEvent.Adventure.OnRefreshRedShow, this.OnRefreshRedPoint) Game.GlobalEvent:AddEvent(GameEvent.Adventure.OnFastBattleChanged, this.OnRefreshRedPoint) Game.GlobalEvent:AddEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess, this.RefreshOnlineRewardShow) Game.GlobalEvent:AddEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess, this.OnRefreshRedPoint) end --移除事件监听(用于子类重写) function InvadeMonsterView:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Adventure.OnRefeshBoxRewardShow, this.UpdataBoxStateShow) Game.GlobalEvent:RemoveEvent(GameEvent.Adventure.OnRefreshRedShow, this.OnRefreshRedPoint) Game.GlobalEvent:RemoveEvent(GameEvent.Adventure.OnFastBattleChanged, this.OnRefreshRedPoint) Game.GlobalEvent:RemoveEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess, this.RefreshOnlineRewardShow) Game.GlobalEvent:RemoveEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess, this.OnRefreshRedPoint) end --界面打开时调用(用于子类重写) function InvadeMonsterView:OnShow(...) lastBoxState = 0 this:OnRefreshRedPoint() this.SetBoxShow(1) this:UpdataBoxStateShow() -- 在线奖励 this.RefreshOnlineRewardShow() --判断章节奖励是全部领完 if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.Chapter_Reward) then if not ActivityGiftManager.chapterOpen or ActivityGiftManager.ActivityIsHaveGetFinally(ActivityGiftManager.chapterGetRewardState) then this.btnRewrdChapter:SetActive(false) else this.btnRewrdChapter:SetActive(true) end else this.btnRewrdChapter:SetActive(false) end end -- 刷新在线奖励显示 function this.RefreshOnlineRewardShow() --判断在线礼包是全部领完 if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.Online_Reward) then if not ActivityGiftManager.onlineOpen or ActivityGiftManager.ActivityIsHaveGetFinally(ActivityGiftManager.onlineGetRewardState) then this.btnRewardOnline:SetActive(false) else this.btnRewardOnline:SetActive(true) CheckRedPointStatus(RedPointType.CourtesyDress_Online) end else this.btnRewardOnline:SetActive(false) end -- 获取在线奖励状态 this.onlineRewardData, this.onlineRewardState = ActivityGiftManager.GetNextOnlineRewardData() this.CheckOnlineRewardShow() end --倒计时时间格式化 function this.ForamtionCountDownTime(remainTime) local hour = 0 local min = 0 local sec = 0 sec = math.floor(remainTime % 60) hour = math.floor(remainTime / 3600) min = 0 if (hour >= 1) then min = math.floor((remainTime - hour * 3600) / 60) else min = math.floor(remainTime / 60) end return string.format("%02d:%02d:%02d", hour, min, sec) end -----============================ 外敌相关 ============================== --刷新红点 function this:OnRefreshRedPoint() -- 探索红点 local hadExplore = AdventureManager.GetSandFastBattleCount() ~= 0 -- 在线红点 local hadOnline = ActivityGiftManager.CheckOnlineRed() -- 章节红点 local hadChpater = ActivityGiftManager.CheckChapterRed() this.expeditionRedPoint:SetActive(hadExplore) this.onlineRedPoint:SetActive(hadOnline) this.chapterRedPoint:SetActive(hadChpater) end -- 检测在线奖励状态 function this.CheckOnlineRewardShow() if not this.onlineRewardData then this.onlineRewardEffect:SetActive(false) this.onlineRewardTime.text = "已完成" if this.timer then this.timer:Stop() this.timer = nil end else local itemId = this.onlineRewardData.Reward[1][1] this.onlineRewardQuality.sprite = SetFrame(itemId) this.onlineRewardIcon.sprite = SetIcon(itemId) this.onlineRewardNum.text = this.onlineRewardData.Reward[1][2] if this.onlineRewardState == 0 then this.onlineRewardEffect:SetActive(true) this.OnRefreshRedPoint() this.onlineRewardTime.text = "可领取" if this.timer then this.timer:Stop() this.timer = nil end elseif this.onlineRewardState == -1 then this.onlineRewardEffect:SetActive(false) if not this.timer then this.TimeUpdate() this.timer = Timer.New(this.TimeUpdate, 1, -1, true) this.timer:Start() end end end end -- 定时器回调 function this.TimeUpdate() if this.onlineRewardState == -1 then local curOnlineTime = GetTimeStamp() - ActivityGiftManager.cuOnLineTimestamp local needTime = this.onlineRewardData.Values[1][1]*60 local remainTime = needTime - curOnlineTime if remainTime >= 0 then this.onlineRewardTime.text = TimeToMS(remainTime) else this.RefreshOnlineRewardShow() end else if this.timer then this.timer:Stop() this.timer = nil end end end --界面关闭时调用(用于子类重写) function InvadeMonsterView:OnClose() if this.timerEffect then this.timerEffect:Stop() end this.timerEffect = nil if this.timer then this.timer:Stop() this.timer = nil end end --界面销毁时调用(用于子类重写) function InvadeMonsterView:OnDestroy() end return InvadeMonsterView