local UIRuneShopExploreView = require("UIRuneShop/UIRuneShopExploreView_Generate") function UIRuneShopExploreView:OnAwake(data) self.controller = require("UIRuneShop/UIRuneShopExploreCtr"):new() self.controller:Init(self) self.controller:SetData(data) end function UIRuneShopExploreView:AddEventListener() ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ROCOIN_CHANGED, self, self.OnRoCoinChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.COIN_CHANGED, self, self.OnCoinChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.OnDiamondChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.RUNE_SHOP_REWARDS_DATA_CHANGED, self, self.OnRuneShopRewardsDataChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_CLOSEED_TASK_PAGE, self, self.OnCloseTask) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_TASK_JUMP, self, self.OnCloseAirShip) end function UIRuneShopExploreView:FillContent(data, uiBase) self.uiBase = uiBase local gameObject = self.uiBase:GetRoot() if gameObject ~= nil then self.gameObject = gameObject self.transform = gameObject.transform end self:InitGenerate(self.transform, data) self:Init() end function UIRuneShopExploreView:Init() self.controller:InitData() self.textBox.text.text = string.formatbykey('DscClub04') self:RefreshRoCoinView() self:RefreshCoinView() self:RefreshGoldView() self:RefreshVipView() self.rewardsBoxItem.scrollView.loopGridView:InitGridView(0, function(loopGridView, itemIdx, row, column) return self:GetItemByRowColumnRewards(loopGridView, itemIdx, row, column) end, nil, nil) self:RefreshRewardsView() end function UIRuneShopExploreView:RemoveEventListener() ManagerContainer.LuaEventMgr:Unregister(self.uiData.name) end function UIRuneShopExploreView:AddUIEventListener() self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn) self.uiBase:AddButtonUniqueEventListener(self.btnVIP.button, self, self.OnClickVipBtn) self.uiBase:AddButtonUniqueEventListener(self.rewardsBoxItem.btnPlayRule.button, self, self.OnClickPlayRuleBtn) self.uiBase:AddButtonUniqueEventListener(self.rewardsBoxItem.btnBuyMore.button, self, self.OnClickBuyAdvancedRewardsBtn) self.uiBase:AddButtonUniqueEventListener(self.btnTaskExp.button, self, self.OnClickTaskExpBtn) end function UIRuneShopExploreView:OnHide() end function UIRuneShopExploreView:OnShow(data) self.controller:SetData(data) end function UIRuneShopExploreView:OnClose() end function UIRuneShopExploreView:OnDispose() self:DisposeRefreshTimer() if self.rewardsBoxItem then self.rewardsBoxItem.scrollView.loopGridView:Dispose() end self.controller:OnDispose() end function UIRuneShopExploreView:OnClickCloseBtn() ManagerContainer.LuaUIMgr:OpenSourceUI(self) end function UIRuneShopExploreView:OnClickVipBtn() ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIVip) end function UIRuneShopExploreView:OnClickPlayRuleBtn() ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'AirshipText'}) end function UIRuneShopExploreView:OnClickTaskExpBtn() ManagerContainer.DataMgr.TaskDataNew:OpenTaskPanel(); end function UIRuneShopExploreView:OnClickBuyAdvancedRewardsBtn() ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRewardsBuyTips) end function UIRuneShopExploreView:OnClickGetAdvancedRewardBtn() if self.rewardsBaseData:GetMaxRewardsNum() > 0 then ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPLORE_EXTRA_REWARD_REQ) end end function UIRuneShopExploreView:OnCloseTask() ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPLORE_INFO_REQ) end function UIRuneShopExploreView:OnCloseAirShip() ManagerContainer.LuaUIMgr:Close(Enum.UIPageName.UIRuneShopExplore) end function UIRuneShopExploreView:OnRoCoinChanged() self:RefreshRoCoinView() end function UIRuneShopExploreView:OnCoinChanged() self:RefreshCoinView() end function UIRuneShopExploreView:OnDiamondChanged() self:RefreshGoldView() end function UIRuneShopExploreView:OnVipLvChanged() self:RefreshVipView() end function UIRuneShopExploreView:OnRuneShopRewardsDataChanged() self:RefreshRewardsView() end function UIRuneShopExploreView:RefreshRoCoinView() self.ro.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.ROCoin)) end function UIRuneShopExploreView:RefreshCoinView() self.coin.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.Coin)) end function UIRuneShopExploreView:RefreshGoldView() self.gold.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.Diamond)) end function UIRuneShopExploreView:RefreshVipView() local curVipLv = self.controller:GetCurVipLv() local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv) self.vipIcon.image.sprite = nil self.vipIcon.image.enabled = false self.vipFrame.image.sprite = nil self.vipFrame.image.enabled = false if not vipCfg then self.vipNameTxt.text.text = '' return end CommonUtil.LoadIcon(self, vipCfg.BigIcon, function(sprite) if sprite then self.vipIcon.image.sprite = sprite self.vipIcon.image.enabled = true end end) CommonUtil.LoadIcon(self, vipCfg.BigFrame, function(sprite) if sprite then self.vipFrame.image.sprite = sprite self.vipFrame.image.enabled = true end end) self.vipNameTxt.text.text = string.formatbykey(vipCfg.Name) end --悬赏战令页面 function UIRuneShopExploreView:RefreshRewardsView() if not self.rewardsBoxItem then return end if ManagerContainer.DataMgr.RuneShopDataMgr.isRewardsDataDirty then self.rewardsBoxItem:SetActive(false) return end self.rewardsBoxItem:SetActive(true) self.rewardsBaseData = self.controller:GetRewardsBaseData() local showGoodsDatas = self.rewardsBaseData:GetShowRewardsData() local curLv = self.rewardsBaseData:GetShowRewardsCurLv() local curExp = self.rewardsBaseData:GetShowRewardsCurExp() local curCfg = self.rewardsBaseData:GetRewardsCurRoundCfg() if not curCfg then self.rewardsBoxItem:SetActive(false) return end self.isShowAirShip = false local length = (showGoodsDatas and #showGoodsDatas or 0) ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.RuneShopRewards, false) --页面下方关于当前等级的信息展示 local nextlv = curLv + 1 if nextlv > length then nextlv = length end if curLv == length then self.rewardsmax:SetActive(true) self.numexp.text.text = tostring(curExp)..'/'.. tostring(curCfg.ExpCost) self.expSlider.slider.value = curExp/curCfg.ExpCost else self.rewardsmax:SetActive(false) self.curLvData = self.controller:GetShowRewardsDataByIdx(nextlv) self.numexp.text.text = tostring(curExp)..'/'.. tostring(self.curLvData.cfgData.Exp) self.expSlider.slider.value = curExp/self.curLvData.cfgData.Exp end self.rewardslv.text.text = tostring(curLv) self.rewardsBoxItem.btnBuyMore.num.text.text = tostring(curCfg.MissonExpUp)..'%' self.expUpBlue.num.text.text = tostring(curCfg.MissonExpUp)..'%' --根据等级经验 刷新小游艇 local newLv =length - curLv --因为多一个开始节点和结束最终奖励节点,所以+2 self.rewardsBoxItem.scrollView.loopGridView:RecycleAllItem() if self.isInited then self.rewardsBoxItem.scrollView.loopGridView:RefreshListByIndex(length+2 ) else self.rewardsBoxItem.scrollView.loopGridView:RefreshListByIndex(length+2 , newLv) end self.rewardsBoxItem.scrollView.loopGridView.mOnBeginDragAction = function(gridView) self:RefreshBigRewardsFloatTips(gridView) end self.rewardsBoxItem.scrollView.loopGridView.mOnDragingAction = function(gridView) self:RefreshBigRewardsFloatTips(gridView) end self.rewardsBoxItem.scrollView.loopGridView.mOnEndDragAction = function(gridView) self:RefreshBigRewardsFloatTips(gridView) end self.isInited = true local isCash = self.rewardsBaseData:GetRewardsIsCash() if isCash == 1 then self.rewardsBoxItem.btnBuyMore:SetActive(false) self.rewardsBoxItem.labelUnLocked:SetActive(true) self.expUpBlue:SetActive(true) else self.rewardsBoxItem.btnBuyMore:SetActive(true) self.rewardsBoxItem.labelUnLocked:SetActive(false) self.expUpBlue:SetActive(false) end local endTime = self.rewardsBaseData:RefreshRewaradsRemainTime() if endTime then self:StartRefreshTimer(self.rewardsBoxItem, true) if endTime < 0 then endTime = 0 end self:RefreshBigRewardsFloatTips(nil) self.rewardsBoxItem.timeBox:SetActive(true) self.rewardsBoxItem.timeBox.textTime.text.text = string.formatbykey('AirshipTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false)) else self:StopRefreshTimer(self.rewardsBoxItem) self.rewardsBoxItem.timeBox:SetActive(false) end end --大奖标签跳转 function UIRuneShopExploreView:JumpToTarget(button , params) local data = clone(params[0]) self.rewardsBoxItem.scrollView.loopGridView:RefreshListByIndex(#self.controller:GetShowRewardsData()+2 , data.targetid) self:RefreshBigRewardsFloatTips() end --设置悬赏单个对象 function UIRuneShopExploreView:UpdateRewardsItem(itemLua, idx, data, isEnd) local curExp = self.rewardsBaseData:GetShowRewardsCurExp() local curLv = self.rewardsBaseData:GetShowRewardsCurLv() --最终奖励宝箱 if isEnd then self.uiBase:AddButtonUniqueEventListener(itemLua.btnBuyMore.button, self, self.OnClickGetAdvancedRewardBtn) local costExp = ManagerContainer.CfgMgr:GetRuneShopExploreCfgByRound(self.rewardsBaseData:GetShowRewardsRoundData()).ExpCost if self.rewardsBaseData:GetMaxRewardsNum() > 0 then itemLua.chestAnim.animator:Play('Open') itemLua.redPoint:SetActive(true) itemLua.btnBuyMore.num.text.text = tostring(self.rewardsBaseData:GetMaxRewardsNum()) ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.RuneShopRewards, true) else itemLua.chestAnim.animator:Play('Close') itemLua.redPoint:SetActive(false) end if self.rewardsBaseData:GetRewardsIsMax() then itemLua.airShip:SetActive(true) itemLua.levelSlider.slider.value = 1 else if curLv == #self.rewardsBaseData:GetShowRewardsData() then itemLua.airShip:SetActive(true) itemLua.levelSlider.slider.value = curExp/costExp else itemLua.airShip:SetActive(false) end end itemLua.dsc.text.text.text = string.formatbykey("DscRewardsMax",tostring(costExp),'1') --通用item else --0级开始 if idx == 0 then itemLua.startItem:SetActive(true) itemLua.rewardsBox2:SetActive(false) itemLua.levelBox2:SetActive(false) if curLv == 0 and curExp/self.curLvData.cfgData.Exp < 0.15 then itemLua.startItem.airShip:SetActive(true) else itemLua.startItem.airShip:SetActive(false) end --常规等级 else CommonUtil.UpdateItemPrefab(self, itemLua, data, Enum.ItemIEnterType.Bag, self, nil) --self.tempItemLua = itemLua itemLua.numlv.text.text = idx itemLua.startItem:SetActive(false) itemLua.rewardsBox2:SetActive(true) itemLua.levelBox2:SetActive(true) itemLua.rewardsBox2.bgyellow:SetActive(false) if data.cfgData.RewardSign > 0 then itemLua.rewardsBox2.bgyellow:SetActive(true) end if data.isReward then --0为 默认状态 if data.isReward == 0 then itemLua.rewardsLeft.arrived:SetActive(false) itemLua.rewardsLeft.received:SetActive(false) --1为已领取 elseif data.isReward == 1 then itemLua.rewardsLeft.arrived:SetActive(false) itemLua.rewardsLeft.received:SetActive(true) --可领取 elseif data.isReward == 2 then itemLua.rewardsLeft.arrived:SetActive(true) itemLua.rewardsLeft.received:SetActive(false) end else itemLua.rewardsLeft.arrived:SetActive(false) itemLua.rewardsLeft.received:SetActive(false) end if data.isCashReward and self.rewardsBaseData:GetRewardsIsCash()==1 then --0为 默认状态 if data.isCashReward == 0 then itemLua.rewardsRight.arrived:SetActive(false) itemLua.rewardsRight.received:SetActive(false) --1为已领取 elseif data.isCashReward == 1 then itemLua.rewardsRight.arrived:SetActive(false) itemLua.rewardsRight.received:SetActive(true) --可领取 elseif data.isCashReward == 2 then itemLua.rewardsRight.arrived:SetActive(true) itemLua.rewardsRight.received:SetActive(false) end else itemLua.rewardsRight.arrived:SetActive(false) itemLua.rewardsRight.received:SetActive(false) end itemLua.activity:SetActive(false) --直接根据等级判断,小于当前等级的直接拉满,大于当前等级的则为空 if curLv+1 > idx then itemLua.levelSlider.slider.value = 1 itemLua.activity:SetActive(true) elseif curLv < idx+1 then itemLua.levelSlider.slider.value = 0 end --左侧经验条slider,因遮挡问题,只有经验超出10%,小飞机才会飞到下一级 if curLv == #self.rewardsBaseData:GetShowRewardsData() then itemLua.airShip:SetActive(false) else if curLv+1 == idx and curExp/self.curLvData.cfgData.Exp > 0.15 then itemLua.airShip:SetActive(true) --LogError('aaacc'..curExp.."aac"..self.curLvData.cfgData.Exp) itemLua.levelSlider.slider.value = curExp/self.curLvData.cfgData.Exp self.isShowAirShip = true else if curLv == idx and not self.isShowAirShip then itemLua.airShip:SetActive(true) --itemLua.levelSlider.slider.value = self.controller:GetShowRewardsCurExp()/self.curLvData.cfgData.Exp else itemLua.airShip:SetActive(false) end end end end end end function UIRuneShopExploreView:RefreshBigRewardsFloatTips(gridView) --通过content高度计算当前处于哪个位置 local py = self.rewardsBoxItem.scrollView.content.transform.localPosition.y local mid = #self.rewardsBaseData:GetShowRewardsData() - self:Toint(py/240) --下方的大奖小图标 local minid = self.controller:GetShowReardsNearMinCashReward(mid -3) if minid then self.rewardsBoxItem.btnGotoDown:SetActive(true) local logicData ={} local rdata=self.controller:GetShowRewardsDataByIdx(minid) if rdata.cfgData.RewardSign == 1 then logicData = {cfgId = rdata.cfgData.Reward[1][1],num = rdata.cfgData.Reward[1][2] , targetid = #self.controller:GetShowRewardsData()-minid} elseif rdata.cfgData.RewardSign == 2 then logicData = {cfgId = rdata.cfgData.CashReward[1][1],num = rdata.cfgData.CashReward[1][2] , targetid = #self.controller:GetShowRewardsData()-minid} end CommonUtil.UpdateItemPrefab(self, self.rewardsBoxItem.btnGotoDown.iconSmallItem, logicData, Enum.ItemIEnterType.Bag, self, self.JumpToTarget) else self.rewardsBoxItem.btnGotoDown:SetActive(false) end --上方的大奖小图标 local maxid = self.controller:GetShowReardsNearMaxCashReward(mid +3) if maxid then self.rewardsBoxItem.btnGotoUp:SetActive(true) local logicData ={} local rdata=self.controller:GetShowRewardsDataByIdx(maxid) if rdata.cfgData.RewardSign == 1 then logicData = {cfgId = rdata.cfgData.Reward[1][1],num = rdata.cfgData.Reward[1][2] , targetid = #self.controller:GetShowRewardsData()-maxid} elseif rdata.cfgData.RewardSign == 2 then logicData = {cfgId = rdata.cfgData.CashReward[1][1],num = rdata.cfgData.CashReward[1][2] , targetid = #self.controller:GetShowRewardsData()-maxid} end CommonUtil.UpdateItemPrefab(self, self.rewardsBoxItem.btnGotoUp.iconSmallItem, logicData, Enum.ItemIEnterType.Bag, self, self.JumpToTarget) else self.rewardsBoxItem.btnGotoUp:SetActive(false) end end function UIRuneShopExploreView:Toint(n) local s = tostring(n) local i,j = s:find('%.') if i then return tonumber(s:sub(1,i-1)) else return n end end function UIRuneShopExploreView:GetItemByRowColumnRewards(loopGridView, itemIdx, row, column) --通用等级奖励 local item if itemIdx == 0 then item = loopGridView:NewListViewItem('CloudTop') local itemEndLua = CommonUtil.BindGridViewItem2Lua(self, 'CloudTop', item.gameObject) self:UpdateRewardsItem(itemEndLua , itemIdx , data ,true) else item = loopGridView:NewListViewItem('RuneShopRewardsItem') local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopRewardsItem', item.gameObject) local data local showGoodsDatas = self.controller:GetShowRewardsData() local length = (showGoodsDatas and #showGoodsDatas or 0) if itemIdx-1 < length then data = self.controller:GetShowRewardsDataByIdx(length-(itemIdx-1)) end self:UpdateRewardsItem(itemLua , length-(itemIdx-1) , data) end return item end function UIRuneShopExploreView:RefreshCurrenyItem(itemLua, itemCfgId, itemNum, ignoreIcon) if not itemCfgId or not itemNum then itemLua:SetActive(false) return end itemLua.number.text.text = CommonUtil.FormatNumber(itemNum) itemLua:SetActive(true) if ignoreIcon then return end itemLua.icon.image.sprite = nil itemLua.icon.image.enabled = false local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemCfgId) if itemCfgData then CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite) if sprite then itemLua.icon.image.sprite = sprite itemLua.icon.image.enabled = true end end) end end function UIRuneShopExploreView:StartRefreshTimer(itemLua, goodsData) local timer = self.refreshTimer if not timer then timer = Timer.New(slot(self.RefreshTimer, self), 1, -1) self.refreshTimer = timer end local updateItemMap = timer.updateItemMap if not updateItemMap then updateItemMap = {} timer.updateItemMap = updateItemMap end updateItemMap[itemLua] = goodsData if not timer.running then timer:Start() end end function UIRuneShopExploreView:StopRefreshTimer(itemLua) local timer = self.refreshTimer if timer then local updateItemMap = timer.updateItemMap if updateItemMap then updateItemMap[itemLua] = nil end if not updateItemMap or table_is_empty(updateItemMap) then timer:Stop() end end end function UIRuneShopExploreView:StopAndClearRefreshTimer() if self.refreshTimer then self.refreshTimer:Stop() self.refreshTimer.time = 1 self.refreshTimer.duration = 1 self.refreshTimer.updateItemMap = nil end end function UIRuneShopExploreView:DisposeRefreshTimer() self:StopAndClearRefreshTimer() self.refreshTimer = nil end function UIRuneShopExploreView:RefreshTimer() local timer = self.refreshTimer if not timer then return end local updateItemMap = timer.updateItemMap if not updateItemMap or table_is_empty(updateItemMap) then timer:Stop() return end local minRemainTime = nil local endTime = self.controller:GetRewardsRemainTime() if endTime then if endTime < 0 then endTime = 0 end if endTime <= 0 then timer.updateItemMap = nil if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIRewardsBuyTips) then ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIRewardsBuyTips) end ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.RuneShopRewards, false) ManagerContainer.CfgMgr.RuneShopExploreRewardCfg =nil ManagerContainer.CfgMgr.RuneShopRoundMap = nil self.rewardsToggle:SetActive(false) end self.rewardsBoxItem.timeBox:SetActive(true) self.rewardsBoxItem.timeBox.textTime.text.text = string.formatbykey('AirshipTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false)) else self.rewardsBoxItem.timeBox:SetActive(false) timer.updateItemMap = nil end if endTime and endTime > 0 then if not minRemainTime or minRemainTime > endTime then minRemainTime = endTime end end if not minRemainTime or minRemainTime <= 0 then self:StopRefreshTimer() else -- 降低刷新频率 if self.refreshTimer then local validTime = nil if minRemainTime >= 86400 then validTime = minRemainTime % 3600 if validTime == 0 then validTime = 3600 end elseif minRemainTime >= 3600 then validTime = minRemainTime % 60 if validTime == 0 then validTime = 60 end else validTime = 1 end if validTime then self.refreshTimer.duration = validTime else self:StopRefreshTimer() end end end end return UIRuneShopExploreView