local UIRuneShopBTView = require("UIRuneShop/UIRuneShopBTView_Generate") local ConditionJudge = require("Common/ConditionJudge") local FirstBuyBgIconPath = 'ShopIcons/txt_club_first' local ExtraBuyBgIconPath = 'ShopIcons/txt_club_free_extra_cn' function UIRuneShopBTView:OnAwake(data) self.controller = require("UIRuneShop/UIRuneShopBTCtr"):new() self.controller:Init(self) self.controller:SetData(data) end function UIRuneShopBTView: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_DATA_CHANGED, self, self.OnRuneShopDataChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.RED_POINT_MGR_NOTICE, self, self.OnRPNotify) end function UIRuneShopBTView: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 UIRuneShopBTView:Init() self.controller:InitData() self.privilegeCardItem.privilegeScrollView.loopListView:InitListView(0, function (loopListView, itemIdx) return self:GetItemByIndexPrivilege(loopListView, itemIdx) end, nil, nil) self.privilegeCardItem.rewardScrollView.loopGridView:InitGridView(0, function (loopGridView, itemIdx, row, column) return self:GetItemByRowColumnPrivilege(loopGridView, itemIdx, row, column) end, nil, nil) self.giftsBox.scrollView.loopGridView:InitGridView(0, function(loopGridView, itemIdx, row, column) return self:GetItemByRowColumnGifts(loopGridView, itemIdx, row, column) end, nil, nil) self.rOPassport.scrollView.loopListView:InitListView(0, function(loopListView, itemIdx) return self:GetItemByIndexROPass(loopListView, itemIdx) end) self.limitedBox.scrollView.loopGridView:InitGridView(0, function(loopGridView, itemIdx, row, column) return self:GetItemByRowColumnLimited(loopGridView, itemIdx, row, column) end, nil, nil) self:RefreshRoCoinView() self:RefreshCoinView() self:RefreshGoldView() self:RefreshVipView() self:RefreshToggleGroupView() self:RefreshShopView(true) end function UIRuneShopBTView:RemoveEventListener() ManagerContainer.LuaEventMgr:Unregister(self.uiData.name) end function UIRuneShopBTView:AddUIEventListener() self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn) self.uiBase:AddButtonUniqueEventListener(self.btnVIP.button, self, self.OnClickVipBtn) self.uiBase:AddToggleUniqueEventListener(self.privilegeCardToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.SpecialPrivilege) self.uiBase:AddToggleUniqueEventListener(self.weekToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.MonthCard) self.uiBase:AddToggleUniqueEventListener(self.passportToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.PassCheck) self.uiBase:AddToggleUniqueEventListener(self.giftsToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.Gifts) self.uiBase:AddToggleUniqueEventListener(self.limitedToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.LimitTime) self.uiBase:AddButtonUniqueEventListener(self.dailyBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Daily) self.uiBase:AddButtonUniqueEventListener(self.weekBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Week) self.uiBase:AddButtonUniqueEventListener(self.roCoinBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.ROCoin) self.uiBase:AddButtonUniqueEventListener(self.goldBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Gold) self.uiBase:AddButtonUniqueEventListener(self.monthBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Month) end function UIRuneShopBTView:OnHide() end function UIRuneShopBTView:OnShow(data) if data then self.controller:SetData(data) self.controller:InitData() end self:RefreshCoinView() self:RefreshGoldView() self:RefreshVipView() self:RefreshToggleGroupView() self:RefreshShopView(true) end function UIRuneShopBTView:OnClose() end function UIRuneShopBTView:OnDispose() self.privilegeUnlockDess = nil self.privilegeRewards = nil self.roPassUnlockDess = nil self:DisposeRefreshTimer() self.privilegeCardItem.privilegeScrollView.loopListView:Dispose() self.privilegeCardItem.rewardScrollView.loopGridView:Dispose() self.giftsBox.scrollView.loopGridView:Dispose() self.rOPassport.scrollView.loopListView:Dispose() self.limitedBox.scrollView.loopGridView:Dispose() self.controller:OnDispose() end function UIRuneShopBTView:OnClickCloseBtn() ManagerContainer.LuaUIMgr:OpenSourceUI(self) end function UIRuneShopBTView:OnClickVipBtn() ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIVip) end function UIRuneShopBTView:OnClickOneToggle(tog, params, b) if not b then return end local shopType = params[0] if self.controller:ChangeShopType(shopType) then self:RefreshShopView(true) end end function UIRuneShopBTView:OnClickShopSubBtn(btn, params) local shopSubType = params[0] if self.controller:ChangeShopSubType(shopSubType) then self:RefreshGiftsView(true) end end function UIRuneShopBTView:OnClickMonthCardPrice(_, params) local id = params[0] local errorCodeKey = self.controller:SendPay(id) if not errorCodeKey then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey) end end function UIRuneShopBTView:OnClickRoPassBuy(_, params) local id = params[0] local errorCodeKey = self.controller:SendPay(id) if not errorCodeKey then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey) end end function UIRuneShopBTView:OnClickShopGoodsItem(_, params) local data = params[0] if not data then return end if data:IsSoldout() then return end local id = data:GetId() local runeShopType = self.controller:GetShopType() local runeShopSubType = self.controller:GetShopSubType() if runeShopType == Enum.RuneShopType.Gifts then if runeShopSubType == Enum.RuneShopSubType.Gold then ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopGoldBuyTips, {runeShopType, runeShopSubType, id}) return end end ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBuyTips, {runeShopType, runeShopSubType, id}) end function UIRuneShopBTView:OnClickGiftItem(button, params) local id = params[0] local runeShopType = self.controller:GetShopType() local runeShopSubType = self.controller:GetShopSubType() ManagerContainer.SDKEventReportMgr:SendClickGoods() if runeShopType == Enum.RuneShopType.Gifts then if runeShopSubType == Enum.RuneShopSubType.Gold then ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopGoldBuyTips, {runeShopType, runeShopSubType, id}) return end end ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBuyTips, {runeShopType, runeShopSubType, id}) end function UIRuneShopBTView:OnClickGiftPrice(button, params) -- 直接发起支付 ManagerContainer.SDKEventReportMgr:SendClickGoods() local id = params[0] local errorCodeKey = self.controller:SendPay(id) if not errorCodeKey then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey) end end function UIRuneShopBTView:OnClickLimitedItem(button, params) local id = params[0] local itemIdx = params[1] local runeShopType = self.controller:GetShopType() local runeShopSubType = self.controller:GetShopSubType() ManagerContainer.SDKEventReportMgr:SendClickGoods() if runeShopType == Enum.RuneShopType.Gifts then if runeShopSubType == Enum.RuneShopSubType.Gold then ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopGoldBuyTips, {runeShopType, runeShopSubType, id}) return end end ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBuyTips, {runeShopType, runeShopSubType, id}) ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:CancelRedPointStatusById(id) self.limitedBox.scrollView.loopGridView:RefreshItemByItemIndex(itemIdx) end function UIRuneShopBTView:OnClickLimitedPrice(button, params) -- 直接发起支付 local id = params[0] local itemIdx = params[1] ManagerContainer.SDKEventReportMgr:SendClickGoods() local errorCodeKey = self.controller:SendPay(id) if not errorCodeKey then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey) end ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:CancelRedPointStatusById(id) self.limitedBox.scrollView.loopGridView:RefreshItemByItemIndex(itemIdx) end function UIRuneShopBTView:OnRoCoinChanged() self:RefreshRoCoinView() end function UIRuneShopBTView:OnCoinChanged() self:RefreshCoinView() end function UIRuneShopBTView:OnDiamondChanged() self:RefreshGoldView() end function UIRuneShopBTView:OnVipLvChanged() self:RefreshVipView() end function UIRuneShopBTView:OnRuneShopDataChanged(runeShopType, runeShopSubType) if runeShopType ~= self.controller:GetShopType() then return end local curRuneShopSubType = self.controller:GetShopSubType() if curRuneShopSubType and runeShopSubType ~= curRuneShopSubType then return end self.controller:RefreshCurShopData() self:RefreshShopView() end function UIRuneShopBTView:OnRPNotify(rpType) if rpType ~= Enum.RPNotifyType.RuneShopLimitGift then return end if Enum.RuneShopType.LimitTime ~= self.controller:GetShopType() then return end local curRuneShopSubType = self.controller:GetShopSubType() if curRuneShopSubType and nil ~= curRuneShopSubType then return end self:RefreshShopView() end function UIRuneShopBTView:RefreshRoCoinView() self.ro.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.ROCoin)) end function UIRuneShopBTView:RefreshCoinView() self.coin.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.Coin)) end function UIRuneShopBTView:RefreshGoldView() self.gold.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.Diamond)) end function UIRuneShopBTView: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 UIRuneShopBTView:RefreshToggleGroupView() self:SetHideLB() local shopType = self.controller:GetShopType() local toggleGroup = self.content.toggleGroup local oldAllowSwitchOff = toggleGroup.allowSwitchOff toggleGroup.allowSwitchOff = true self.weekToggle.toggle.isOn = (shopType == Enum.RuneShopType.MonthCard) self.giftsToggle.toggle.isOn = (shopType == Enum.RuneShopType.Gifts) self.limitedToggle.toggle.isOn = (shopType == Enum.RuneShopType.LimitTime) toggleGroup.allowSwitchOff = oldAllowSwitchOff end function UIRuneShopBTView:RefreshShopView(resetPos) self.privilegeUnlockDess = nil self.privilegeRewards = nil self.roPassUnlockDess = nil self:StopAndClearRefreshTimer() local shopType = self.controller:GetShopType() if shopType == Enum.RuneShopType.SpecialPrivilege then self.privilegeBox:SetActive(true) self.weekBox:SetActive(false) self.passportBox:SetActive(false) self.giftsBox:SetActive(false) self.limitedBox:SetActive(false) self:RefreshSpecialPrivilegeView() self.textBox.text.text = string.formatbykey('DscClub05') elseif shopType == Enum.RuneShopType.MonthCard then self.privilegeBox:SetActive(false) self.weekBox:SetActive(true) self.passportBox:SetActive(false) self.giftsBox:SetActive(false) self.limitedBox:SetActive(false) self:RefreshMonthCardView() self.textBox.text.text = string.formatbykey('DscClub06') elseif shopType == Enum.RuneShopType.PassCheck then self.privilegeBox:SetActive(false) self.weekBox:SetActive(false) self.passportBox:SetActive(true) self.giftsBox:SetActive(false) self.limitedBox:SetActive(false) self:RefreshRoPassView() self.textBox.text.text = string.formatbykey('DscClub07') elseif shopType == Enum.RuneShopType.Gifts then self.privilegeBox:SetActive(false) self.weekBox:SetActive(false) self.passportBox:SetActive(false) self.giftsBox:SetActive(true) self.limitedBox:SetActive(false) self:RefreshGiftsView(resetPos) self.textBox.text.text = string.formatbykey('DscClub02') elseif shopType == Enum.RuneShopType.LimitTime then self.privilegeBox:SetActive(false) self.weekBox:SetActive(false) self.passportBox:SetActive(false) self.giftsBox:SetActive(false) self.limitedBox:SetActive(true) self:RefreshLimitedView(resetPos) self.textBox.text.text = string.formatbykey('DscClub03') else self.privilegeBox:SetActive(false) self.weekBox:SetActive(false) self.passportBox:SetActive(false) self.giftsBox:SetActive(false) self.limitedBox:SetActive(false) self.textBox.text.text = '' end end function UIRuneShopBTView:RefreshSpecialPrivilegeView() local id = self.controller:GetSpecialPrivilegeId() local cfgData = nil local unlock = true if id then cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(id) if not cfgData then id = 1 cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(1) unlock = false end else id = 1 cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(1) unlock = false end if not cfgData then self.privilegeBox:SetActive(false) return end local privilegeCardItem = self.privilegeCardItem privilegeCardItem.privilegeLv1:SetActive(id == 1) privilegeCardItem.privilegeLv2:SetActive(id == 2) local buyRewards = cfgData.BuyReward if buyRewards then local buyReward = buyRewards[1] if buyReward then self:RefreshCurrenyItem(privilegeCardItem.buyReward1, buyReward[1], buyReward[2], true) else self:RefreshCurrenyItem(privilegeCardItem.buyReward1) end buyReward = buyRewards[2] if buyReward then self:RefreshCurrenyItem(privilegeCardItem.buyReward2, buyReward[1], buyReward[2], true) else self:RefreshCurrenyItem(privilegeCardItem.buyReward2) end else self:RefreshCurrenyItem(privilegeCardItem.buyReward1) self:RefreshCurrenyItem(privilegeCardItem.buyReward2) end privilegeCardItem.privilegeScrollView.loopListView:SetListItemCount(0, true) self.privilegeUnlockDess = unlock and cfgData.Activation or cfgData.UnlockDes if self.privilegeUnlockDess then privilegeCardItem.privilegeScrollView.loopListView:SetListItemCount(#self.privilegeUnlockDess, true) end privilegeCardItem.rewardScrollView.loopGridView:SetListItemCount(0, true) self.privilegeRewards = nil if cfgData.Reward then self.privilegeRewards = {} for i = 1, #cfgData.Reward do local reward = cfgData.Reward[i] self.privilegeRewards[#self.privilegeRewards+1] = {cfgId = reward[1], num = reward[2]} end end if self.privilegeRewards then privilegeCardItem.rewardScrollView.loopGridView:SetListItemCount(#self.privilegeRewards, true) end privilegeCardItem.active:SetActive(unlock) privilegeCardItem.unActive:SetActive(not unlock) if unlock then local nextCfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(id + 1) if nextCfgData then local canUpgrade = false if nextCfgData.UnlockCond then canUpgrade = ConditionJudge:ConditionPassResult1(nextCfgData.UnlockCond) end privilegeCardItem.btnUpgrade:SetActive(canUpgrade) privilegeCardItem.btnBuyPrivilege:SetActive(false) self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnUpgrade.button, self, self.OnClickPrivlegeActiveBtn) else privilegeCardItem.btnUpgrade:SetActive(false) privilegeCardItem.btnBuyPrivilege:SetActive(false) end if self.controller:CanGetSpecialPrivilegeReward() then privilegeCardItem.btnReceive:SetActive(true) privilegeCardItem.labelReceived:SetActive(false) else privilegeCardItem.btnReceive:SetActive(false) privilegeCardItem.labelReceived:SetActive(true) end self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnReceive.button, self, self.OnClickPrivlegeReceiveBtn) else privilegeCardItem.btnUpgrade:SetActive(false) privilegeCardItem.btnBuyPrivilege:SetActive(true) privilegeCardItem.btnReceive:SetActive(true) privilegeCardItem.labelReceived:SetActive(false) self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnBuyPrivilege.button, self, self.OnClickPrivlegeActiveBtn) self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnReceive.button, self, self.OnClickPrivlegeActiveBtn) end end function UIRuneShopBTView:OnClickPrivlegeReceiveBtn() local errorCode = self.controller:SendRuneSpecialPrvilegeRewardReq() if errorCode ~= 0 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) end end function UIRuneShopBTView:OnClickPrivlegeActiveBtn() ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPrivilegeCardTips) end function UIRuneShopBTView:GetItemByIndexPrivilege(loopListView, itemIdx) local unlockDess = self.privilegeUnlockDess if not unlockDess then return nil end local unlockDes = unlockDess[itemIdx + 1] if not unlockDes then return nil end local item = loopListView:NewListViewItem('EntryUnlockDscItem') local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'EntryUnlockDscItem', item.gameObject) if itemLua then local idx = unlockDes[1] or 0 itemLua.icon.uIImageSwitchSprite:ChangeSprite(idx) local params = {} local langKey = unlockDes[2] for i = 3, #unlockDes do params[#params + 1] = tostring(unlockDes[i]) end itemLua.desTxt.text.text = string.formatbykey(langKey, unpack(params)) end ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform) return item end function UIRuneShopBTView:GetItemByRowColumnPrivilege(loopGridView, itemIdx, row, column) if not self.privilegeRewards then return nil end local reward = self.privilegeRewards[itemIdx + 1] if not reward then return nil end local item = loopGridView:NewListViewItem('Item') local iconItem = item.transform:Find('IconItem') local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', iconItem.gameObject) CommonUtil.UpdateItemPrefab(self, itemLua, reward, nil, self, self.ShowItemTips, reward) return item end function UIRuneShopBTView:ShowItemTips(button, params) local data = params[0] ManagerContainer.LuaUIMgr:OpenTips(data) end function UIRuneShopBTView:RefreshMonthCardView() self:RefreshOneMonthCardView(self.weekCard1, 1) end function UIRuneShopBTView:RefreshOneMonthCardView(itemLua, idx) local showGoodsDatas = self.controller:GetShowGoodsDatas() if not showGoodsDatas then itemLua:SetActive(false) return end local showGoodsData = showGoodsDatas[idx] if not showGoodsData then itemLua:SetActive(false) return end itemLua:SetActive(true) local cfgData = showGoodsData:GetCfgData() local buyRewards = cfgData.BuyReward if buyRewards then local buyReward = buyRewards[1] if buyReward then self:RefreshCurrenyItem(itemLua.buyReward1, buyReward[1], buyReward[2], true) else self:RefreshCurrenyItem(itemLua.buyReward1) end buyReward = buyRewards[2] if buyReward then self:RefreshCurrenyItem(itemLua.buyReward2, buyReward[1], buyReward[2], true) else self:RefreshCurrenyItem(itemLua.buyReward2) end else self:RefreshCurrenyItem(itemLua.buyReward1) self:RefreshCurrenyItem(itemLua.buyReward2) end local dayRewards = cfgData.DayReward if dayRewards then local dayReward = dayRewards[1] if dayReward then self:RefreshCurrenyItem(itemLua.dailyReward, dayReward[1], dayReward[2], true) else self:RefreshCurrenyItem(itemLua.dailyReward) end else self:RefreshCurrenyItem(itemLua.dailyReward) end local totalRewards = cfgData.TotalReward if totalRewards then local totalReward = totalRewards[1] if totalReward then self:RefreshCurrenyItem(itemLua.totalReward, totalReward[1], totalReward[2], true) else self:RefreshCurrenyItem(itemLua.totalReward) end else self:RefreshCurrenyItem(itemLua.totalReward) end local price = showGoodsData:GetPrice() if price <= 0 then itemLua.presentPrice.number.text.text = string.formatbykey('Free') else itemLua.presentPrice.number.text.text = FloatToPrice(price) end local timerStr, outTime = showGoodsData:CalculateLimitTime() if not outTime then self:StartRefreshTimer(itemLua, showGoodsData) itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr) itemLua.active:SetActive(true) itemLua.unActive:SetActive(false) else self:StopRefreshTimer(itemLua) local mdec = cfgData.Monthdec if mdec then itemLua.textDsc.text.text = string.formatbykey(cfgData.Monthdec) else itemLua.textDsc.text.text = "" end itemLua.active:SetActive(false) itemLua.unActive:SetActive(true) end self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickMonthCardPrice, showGoodsData:GetId()) end function UIRuneShopBTView: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 UIRuneShopBTView:RefreshRoPassView() local cfgData = ManagerContainer.CfgMgr:GetPassCheckCfgById(1) local isActive = self.controller:GetRoPassStatus() if isActive then self.rOPassport.active:SetActive(true) self.rOPassport.presentPrice:SetActive(false) else self.rOPassport.active:SetActive(false) self.rOPassport.presentPrice:SetActive(true) self.rOPassport.presentPrice.number.text.text = FloatToPrice(cfgData and cfgData.RMB or 999) self.uiBase:AddButtonUniqueEventListener(self.rOPassport.presentPrice.button, self, self.OnClickRoPassBuy, 1) end self.rOPassport.scrollView.loopListView:SetListItemCount(0, true) if not cfgData then return end self.roPassUnlockDess = isActive and cfgData.Activation or cfgData.UnlockDes if not self.roPassUnlockDess then return end self.rOPassport.scrollView.loopListView:SetListItemCount(#self.roPassUnlockDess, true) end function UIRuneShopBTView:GetItemByIndexROPass(loopListView, itemIdx) local unlockDess = self.roPassUnlockDess if not unlockDess then return nil end local unlockDes = unlockDess[itemIdx + 1] if not unlockDes then return nil end local item = loopListView:NewListViewItem('EntryUnlockDscItem') local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'EntryUnlockDscItem', item.gameObject) if itemLua then local idx = unlockDes[1] or 0 itemLua.icon.uIImageSwitchSprite:ChangeSprite(idx) local params = {} local langKey = unlockDes[2] for i = 3, #unlockDes do params[#params + 1] = tostring(unlockDes[i]) end itemLua.desTxt.text.text = string.formatbykey(langKey, unpack(params)) end ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform) return item end function UIRuneShopBTView:RefreshGiftsView(resetPos) local shopSubType = self.controller:GetShopSubType() if shopSubType == Enum.RuneShopSubType.Week then self:RefreshShopSubBtnState(self.dailyBtn, false) self:RefreshShopSubBtnState(self.weekBtn, true) self:RefreshShopSubBtnState(self.roCoinBtn, false) self:RefreshShopSubBtnState(self.goldBtn, false) self:RefreshShopSubBtnState(self.monthBtn, false) elseif shopSubType == Enum.RuneShopSubType.ROCoin then self:RefreshShopSubBtnState(self.dailyBtn, false) self:RefreshShopSubBtnState(self.weekBtn, false) self:RefreshShopSubBtnState(self.roCoinBtn, true) self:RefreshShopSubBtnState(self.goldBtn, false) self:RefreshShopSubBtnState(self.monthBtn, false) elseif shopSubType == Enum.RuneShopSubType.Gold then self:RefreshShopSubBtnState(self.dailyBtn, false) self:RefreshShopSubBtnState(self.weekBtn, false) self:RefreshShopSubBtnState(self.roCoinBtn, false) self:RefreshShopSubBtnState(self.goldBtn, true) self:RefreshShopSubBtnState(self.monthBtn, false) elseif shopSubType == Enum.RuneShopSubType.Daily then self:RefreshShopSubBtnState(self.dailyBtn, true) self:RefreshShopSubBtnState(self.weekBtn, false) self:RefreshShopSubBtnState(self.roCoinBtn, false) self:RefreshShopSubBtnState(self.goldBtn, false) self:RefreshShopSubBtnState(self.monthBtn, false) else self:RefreshShopSubBtnState(self.dailyBtn, false) self:RefreshShopSubBtnState(self.weekBtn, false) self:RefreshShopSubBtnState(self.roCoinBtn, false) self:RefreshShopSubBtnState(self.goldBtn, false) self:RefreshShopSubBtnState(self.monthBtn, true) end local endTime = self.controller:GetRemainTime() if endTime then self:StartRefreshTimer(self, true) if endTime < 0 then endTime = 0 end self.timeBox:SetActive(true) self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false)) else self:StopRefreshTimer(self) self.timeBox:SetActive(false) end local showGoodsDatas = self.controller:GetShowGoodsDatas() local length = (showGoodsDatas and #showGoodsDatas or 0) if resetPos then self.giftsBox.scrollView.loopGridView:RefreshListByIndex(length, 0) else self.giftsBox.scrollView.loopGridView:RefreshListByIndex(length) end end function UIRuneShopBTView:RefreshShopSubBtnState(itemLua, isOn) itemLua.off:SetActive(not isOn) itemLua.on:SetActive(isOn) itemLua.button.interactable = (not isOn) end function UIRuneShopBTView:GetItemByRowColumnGifts(loopGridView, itemIdx, row, column) local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1) if not data then return nil end local shopSubType = self.controller:GetShopSubType() if shopSubType == Enum.RuneShopSubType.ROCoin then return self:RefreshRoCoinShopGoodsItem(loopGridView, data) else return self:RefreshMoneyShopGoodsItem(loopGridView, data) end end function UIRuneShopBTView:RefreshMoneyShopGoodsItem(loopGridView, data) local item = loopGridView:NewListViewItem('RuneShopGoodsItem') local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopGoodsItem', item.gameObject) if itemLua then itemLua.itemIcon.image.sprite = nil itemLua.itemIcon.image.enabled = false itemLua.presentPrice.icon:SetActive(false) itemLua.presentPrice.currency:SetActive(true) local cfgData = data.cfgData if cfgData then CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite) if sprite then itemLua.itemIcon.image.sprite = sprite itemLua.itemIcon.image.enabled = true end end, itemLua, 'ItemIcon') itemLua.itemName.text.text = string.formatbykey(cfgData.Name) if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and data:IsFirstBuy() then itemLua.discount:SetActive(true) itemLua.discount.text.text.text = string.formatbykey('LabelFirst') self:RefreshGiftsItem(itemLua, FirstBuyBgIconPath, cfgData.FirstBuyPic, cfgData.Reward) elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then itemLua.discount:SetActive(true) itemLua.discount.text.text.text = string.formatbykey('LabelExtra') self:RefreshGiftsItem(itemLua, ExtraBuyBgIconPath, cfgData.ExtraBuyPic, cfgData.Reward) else itemLua.discount:SetActive(false) self:RefreshGiftsItem(itemLua, nil, nil, cfgData.Reward) end else itemLua.discount:SetActive(false) itemLua.itemName.text.text = '' itemLua.specialReward:SetActive(false) itemLua.goodsItems:SetActive(false) end local remainBuyNum = data:GetRemainBuyNum() if remainBuyNum >= 0 then itemLua.purchaseLimit:SetActive(true) itemLua.purchaseLimit.text.text = string.formatbykey('RuneShopLimitBuy', tostring(remainBuyNum)) else itemLua.purchaseLimit:SetActive(false) end local price = data:GetPrice() if price <= 0 then itemLua.presentPrice.number.text.text = string.formatbykey('Free') else itemLua.presentPrice.number.text.text = FloatToPrice(price) end if data:IsSoldout() then itemLua.soldout:SetActive(true) itemLua.button.onClick:RemoveAllListeners() itemLua.presentPrice.button.onClick:RemoveAllListeners() else itemLua.soldout:SetActive(false) self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickGiftItem, data:GetId()) self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickGiftPrice, data:GetId()) end end return item end function UIRuneShopBTView:RefreshRoCoinShopGoodsItem(gridView, data) local item = gridView:NewListViewItem('ShopGoodsItem') local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'ShopGoodsItem', item.gameObject) local cfgData = data:GetCfgData() local rewards = cfgData.Reward local cfgId = rewards[1][1] CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, {cfgId = cfgId}, nil) local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemIds.ROCoin) CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite) itemLua.presentPrice.icon.image.sprite = sprite itemLua.originalPrice.icon.image.sprite = sprite end, itemLua, 'CurrenyIcon') itemLua.itemName.text.text = string.formatbykey(cfgData.Name) local price = data:GetPrice() if price <= 0 then itemLua.presentPrice.number.text.text = string.formatbykey('Free') else itemLua.presentPrice.number.text.text = FloatToPrice(price) end itemLua.discount:SetActive(false) itemLua.originalPrice:SetActive(false) local remainBuyNum = data:GetRemainBuyNum() if remainBuyNum >= 0 then itemLua.purchaseLimit:SetActive(true) itemLua.purchaseLimit.text.text = string.formatbykey("RuneShopLimitBuy", remainBuyNum) itemLua.limitBox:SetActive(false) else itemLua.purchaseLimit:SetActive(false) itemLua.limitBox:SetActive(false) end itemLua.soldout:SetActive(data:IsSoldout()) self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickShopGoodsItem, data) self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickShopGoodsItem, data) return item end function UIRuneShopBTView:RefreshGiftsItem(itemLua, bgPic, numPic, rewards) if numPic and numPic ~= '' then itemLua.specialReward.bg.image.sprite = nil itemLua.specialReward.bg.image.enabled = false CommonUtil.LoadIcon(self, bgPic, function(sprite) if sprite then itemLua.specialReward.bg.image.sprite = sprite itemLua.specialReward.bg.image.enabled = true end end, itemLua, 'SpecialRewardBgIcon') itemLua.specialReward.num.image.sprite = nil itemLua.specialReward.num.image.enabled = false CommonUtil.LoadIcon(self, numPic, function(sprite) if sprite then itemLua.specialReward.num.image.sprite = sprite itemLua.specialReward.num.image.enabled = true end end, itemLua, 'SpecialRewardNumIcon') itemLua.specialReward:SetActive(true) itemLua.goodsItems:SetActive(false) else itemLua.specialReward:SetActive(false) if rewards then itemLua.goodsItems:SetActive(true) local reward = rewards[1] if reward then itemLua.iconSmallItem1:SetActive(true) CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem1, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag) else itemLua.iconSmallItem1:SetActive(false) end reward = rewards[2] if reward then itemLua.iconSmallItem2:SetActive(true) CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem2, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag) else itemLua.iconSmallItem2:SetActive(false) end reward = rewards[3] if reward then itemLua.iconSmallItem3:SetActive(true) CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem3, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag) else itemLua.iconSmallItem3:SetActive(false) end else itemLua.goodsItems:SetActive(false) end end end function UIRuneShopBTView:GetItemByRowColumnLimited(loopGridView, itemIdx, row, column) local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1) if not data then return nil end local item = loopGridView:NewListViewItem('RuneShopLimitedItem') local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopLimitedItem', item.gameObject) if itemLua then itemLua.itemIcon.image.sprite = nil itemLua.itemIcon.image.enabled = false local cfgData = data.cfgData if cfgData then CommonUtil.LoadIcon(self, cfgData.Banner, function(sprite) if sprite then itemLua.itemIcon.image.sprite = sprite itemLua.itemIcon.image.enabled = true end end, itemLua, 'ItemIcon') end if data:HasEndTime() then local timerStr = data:CalculateLimitTime() itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr) itemLua.timerLab:SetActive(true) self:StartRefreshTimer(itemLua, data) else self:StopRefreshTimer(itemLua) itemLua.timerLab:SetActive(false) end local price = data:GetPrice() if price <= 0 then itemLua.presentPrice.number.text.text = string.formatbykey('Free') else itemLua.presentPrice.number.text.text = FloatToPrice(price) end if data:IsSoldout() then itemLua.soldout:SetActive(true) itemLua.button.onClick:RemoveAllListeners() itemLua.presentPrice.button.onClick:RemoveAllListeners() else itemLua.soldout:SetActive(false) self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickLimitedItem, data:GetId(), itemIdx) self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickLimitedPrice, data:GetId(), itemIdx) end itemLua.redPoint:SetActive(ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:GetRedPointStatusById(data:GetId())) end return item end function UIRuneShopBTView:RefreshLimitedView(resetPos) local showGoodsDatas = self.controller:GetShowGoodsDatas() local length = (showGoodsDatas and #showGoodsDatas or 0) if resetPos then self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length, 0) else self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length) end end function UIRuneShopBTView: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 UIRuneShopBTView: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 UIRuneShopBTView:StopAndClearRefreshTimer() if self.refreshTimer then self.refreshTimer:Stop() self.refreshTimer.time = 1 self.refreshTimer.duration = 1 self.refreshTimer.updateItemMap = nil end end function UIRuneShopBTView:DisposeRefreshTimer() self:StopAndClearRefreshTimer() self.refreshTimer = nil end function UIRuneShopBTView: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 runeShopType = self.controller:GetShopType() if runeShopType == Enum.RuneShopType.MonthCard then for itemLua, goodsData in pairs(updateItemMap) do local timerStr, outTime, remainTime = goodsData:CalculateLimitTime() if not outTime then itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr) itemLua.active:SetActive(true) itemLua.unActive:SetActive(false) else updateItemMap[itemLua] = nil itemLua.textDsc.text.text = string.formatbykey('DscClubMonth1') itemLua.active:SetActive(false) itemLua.unActive:SetActive(true) end if remainTime and remainTime > 0 then if not minRemainTime or minRemainTime > remainTime then minRemainTime = remainTime end end end if minRemainTime and minRemainTime > 0 then minRemainTime = 1 end elseif runeShopType == Enum.RuneShopType.Gifts then local endTime = self.controller:GetRemainTime() if endTime then if endTime < 0 then endTime = 0 end if endTime <= 0 then timer.updateItemMap = nil end self.timeBox:SetActive(true) self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false)) else self.timeBox:SetActive(false) timer.updateItemMap = nil end if endTime and endTime > 0 then if not minRemainTime or minRemainTime > endTime then minRemainTime = endTime end end elseif runeShopType == Enum.RuneShopType.LimitTime then for itemLua, goodsData in pairs(updateItemMap) do if goodsData:HasEndTime() then local timerStr, outTime, remainTime = goodsData:CalculateLimitTime() if outTime then updateItemMap[itemLua] = nil end itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr) itemLua.timerLab:SetActive(true) if remainTime and remainTime > 0 then if not minRemainTime or minRemainTime > remainTime then minRemainTime = remainTime end end else updateItemMap[itemLua] = nil itemLua.timerLab:SetActive(false) end if minRemainTime and minRemainTime > 0 then minRemainTime = 1 end 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 function UIRuneShopBTView:SetHideLB() if IShServer() then self.controller:SetData({Enum.RuneShopType.Gifts,Enum.RuneShopSubType.ROCoin}) self.controller:InitData() self.privilegeCardToggle:SetActive(false) self.weekToggle:SetActive(false) self.passportToggle:SetActive(false) self.limitedToggle:SetActive(false) self.weekBtn:SetActive(false) self.monthBtn:SetActive(false) end end return UIRuneShopBTView