| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- local UIRechargeWalletShopView = require("UIRuneShop/UIRechargeWalletShopView_Generate")
- local FirstBuyBgIconPath = 'ShopIcons/txt_club_first'
- local ExtraBuyBgIconPath = 'ShopIcons/txt_club_free_extra_cn'
- function UIRechargeWalletShopView:OnAwake(data)
-
- self.controller = require("UIRuneShop/UIRechargeWalletShopCtr"):new()
- self.controller:Init(self)
- self.controller:SetData(data)
-
- end
- function UIRechargeWalletShopView:AddEventListener()
-
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WALLETSHOP_REFRESH,self,self.RefreshShopItem)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WALLETSHOPCREDIT_REFRESH,self,self.RefreshWalletUI)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WALLETSHOP_ENDTIME_REFRESH,self,self.StartRefreshTimer)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WALLETSHOP_SHOWREWARD,self,self.ShowReward)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.COIN_CHANGED, self, self.RefreshCoins)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.RefreshDiamond)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
- end
- function UIRechargeWalletShopView:StartRefreshTimer()
- local endTime = ManagerContainer.DataMgr.WalletShopData:GetEndTime()
- local remainTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(endTime)
- self.moneytime.text.text = I18N.SetLanguageValue('WalletRefresh', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false))
- local timer = self.refreshTimer
- if not timer then
- timer = Timer.New(slot(self.RefreshTimer,self), 1, -1)
- self.refreshTimer = timer
- end
- if not timer.running then
- timer:Start()
- end
- end
- function UIRechargeWalletShopView:StopRefreshTimer()
- if self.refreshTimer then
- self.refreshTimer:Stop()
- end
- end
- function UIRechargeWalletShopView:DisposeRefreshTimer()
- self:StopRefreshTimer()
- self.refreshTimer = nil
- end
- function UIRechargeWalletShopView:RefreshTimer()
- local endTime = ManagerContainer.DataMgr.WalletShopData:GetEndTime()
- local remainTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(endTime)
- self.moneytime.text.text = I18N.SetLanguageValue('WalletRefresh', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false))
- self.timeSlider.scrollbar.size = remainTime / 86400
- if not remainTime or remainTime <= 0 then
- ManagerContainer.DataMgr.WalletShopData:SendWalletShopInfoReq()
- self:StopRefreshTimer()
- else
- if self.refreshTimer then
- local validTime = nil
- if remainTime >= 86400 then
- validTime = remainTime % 3600
- if validTime == 0 then validTime = 3600 end
- elseif remainTime >= 3600 then
- validTime = remainTime % 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 UIRechargeWalletShopView:RefreshShopItemByIdx(idx,data)
- if not data then return nil end
- local itemLua = self["runeShopGoodsItem"..idx]
- if itemLua then
- itemLua.purchaseLimit:SetActive(false)
- itemLua.itemIcon.image.sprite = nil
- itemLua.itemIcon.image.enabled = false
- itemLua.presentPrice.icon.image.enabled = false
-
- local cfgData = ManagerContainer.CfgMgr:GetPurseShopCfgById(idx)
- 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.first_buy 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.buy_nums
- -- 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.price
-
- if price <= 0 then
- itemLua.presentPrice.number.text.text = string.formatbykey('Free')
- else
- itemLua.presentPrice.number.text.text = string.formatbykey('WalletGold',FloatToPrice(price))--tostring(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.goods_id)
- self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickGiftPrice, data.goods_id)
- --end
- end
- end
- function UIRechargeWalletShopView:OnClickGiftItem(button, params)
- local id = params[0]
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWalletShopGoldBuyTips, id)
- end
- function UIRechargeWalletShopView:OnClickGiftPrice(button, params)
- local id = params[0]
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWalletShopGoldBuyTips, id)
- -- local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.WalletNum)
- -- local id = params[0]
- -- local cfgData = ManagerContainer.CfgMgr:GetPurseShopCfgById(id)
- -- if cfgData then
- -- if count >= cfgData.RMB then
- -- local creditLimit = ManagerContainer.DataMgr.WalletShopData:GetCreditLimit()
- -- if creditLimit then
- -- ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(id)
- -- else
- -- local max_credit = ManagerContainer.DataMgr.WalletShopData:GetMaxUseCredit()
- -- local use_credit = ManagerContainer.DataMgr.WalletShopData:GetCurUseCredit()
- -- local credit = max_credit - use_credit
- -- local cfgData = ManagerContainer.CfgMgr:GetPurseShopCfgById(id)
- -- if credit >= cfgData.RMB then
- -- ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(id)
- -- else
- -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("InsufficientLimit")
- -- end
- -- end
- -- else
- -- CommonUtil.ItemNotEnoughHandle(Enum.ItemType.WalletNum)
- -- end
- -- end
- end
- function UIRechargeWalletShopView: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 UIRechargeWalletShopView:ShowReward(idx)
- local data = ManagerContainer.DataMgr.WalletShopData:GetWalletShopDataById(idx)
- if not data then
- return
- end
- local cfgData = ManagerContainer.CfgMgr:GetPurseShopCfgById(idx)
- if cfgData then
- local rewards = {}
- local reward = cfgData.Reward
- local firstReward = cfgData.FirstBuyReward
- local extraReward = cfgData.ExtraBuyReward
- local num = reward[1][2]
- if data.first_buy then
- num = num + firstReward[1][2]
- else
- num = num + extraReward[1][2]
- end
- table.insert(rewards,{cfgId = reward[1][1], num = num})
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewards})
- end
- end
- function UIRechargeWalletShopView:HideShopItemByIconIdx(idx)
- local itemLua = self["runeShopGoodsItem"..idx]
- if(itemLua) then
- itemLua.presentPrice.icon.image.enabled = false
- end
- end
- function UIRechargeWalletShopView:RefreshShopItem(data)
-
- local walletShopData = ManagerContainer.DataMgr.WalletShopData:GetWalletShopData()
- if not walletShopData then
- for i=1,10,1 do
- self:HideShopItemByIconIdx(i)
- end
- return
- end
-
- if data ~= nil then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRechargeSuccess,FloatToPrice(data.shop_item.price))
- local idx = data.shop_item.goods_id
- local data = walletShopData[idx]
- if data then
- self:RefreshShopItemByIdx(idx,data)
- end
- else
- for k, v in pairs(walletShopData) do
- self:RefreshShopItemByIdx(k,v)
- end
- end
- self:RefreshWalletUI()
- end
- function UIRechargeWalletShopView:RefreshCoins()
- local coin = ManagerContainer.DataMgr.UserData:GetOwnCoin()
- self.coin.number.text.text = CommonUtil.FormatNumber(coin)
- self.curCoin = coin
- local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemType.Coin)
- CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
- self.coin.icon.image.sprite = sprite
- end)
- end
- function UIRechargeWalletShopView:RefreshDiamond()
- local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.Diamond)
- self.gold.number.text.text = CommonUtil.FormatNumber(count)
- local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemType.Diamond)
- CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
- self.gold.icon.image.sprite = sprite
- end)
- end
- function UIRechargeWalletShopView:RefreshWalletUI()
- local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.WalletNum)
- self.moneytoday.text.text = CommonUtil.FormatNumber(count)
- local creditLimit = ManagerContainer.DataMgr.WalletShopData:GetCreditLimit()
- local max_credit = ManagerContainer.DataMgr.WalletShopData:GetMaxUseCredit()
- local use_credit = ManagerContainer.DataMgr.WalletShopData:GetCurUseCredit()
- if creditLimit then
- self.moneylimit.text.text = I18N.T("DscMoneyLimitMax")
- self.textBox.text.text = I18N.T("RemainLimit2")
- else
- self.textBox.text.text = I18N.SetLanguageValue("RemainLimit1",max_credit - use_credit)
- self.moneylimit.text.text = use_credit.."/"..max_credit
- end
- self.btnIncreaseLimit:SetActive(not creditLimit)
- end
- function UIRechargeWalletShopView: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 UIRechargeWalletShopView: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 UIRechargeWalletShopView:Init()
- self:RefreshVipView()
- self:RefreshCoins()
- self:RefreshDiamond()
- self:RefreshWalletUI()
- --self:RefreshShopItem(nil)
- --self:StartRefreshTimer()
- ManagerContainer.DataMgr.WalletShopData:SendWalletShopInfoReq()
- end
- function UIRechargeWalletShopView:RemoveEventListener()
- ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
- end
- function UIRechargeWalletShopView:AddUIEventListener()
- self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnVIP.button, self, self.OnClickVipBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnInfo.button, self, self.OnClickPlayRuleBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnIncreaseLimit.button, self, self.OnClickGetCredit)
- end
- function UIRechargeWalletShopView:OnClickGetCredit()
- local curUIId = ManagerContainer.LuaUIMgr:GetCurUIId()
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, nil, curUIId)
- end
- function UIRechargeWalletShopView:OnClickPlayRuleBtn()
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', "RechargeWalletRule"})
- end
- function UIRechargeWalletShopView:OnClickVipBtn()
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIVip)
- end
- function UIRechargeWalletShopView:OnVipLvChanged()
- self:RefreshVipView()
- end
- function UIRechargeWalletShopView:OnClickCloseBtn()
- self:UIClose()
- local str = GlobalConfig.Instance:GetConfigStrValue(361)
- local data = CommonUtil.DeserializeGlobalStrToNumberTable(str)
- local curlevelId = ManagerContainer.LuaBattleMgr:GetCurLevelUniqueId()
- local forceData = data and data[1]
- if forceData and forceData[1] == curlevelId then
- local forceGuideId = forceData[2]
- if not forceGuideId or forceGuideId <= 0 then
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_OVER)
- return
- end
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_TRIGGER, Enum.ForceGuideTriggerEnum.FGGroupId, forceGuideId, false)
- end
- end
- function UIRechargeWalletShopView:OnHide()
- end
- function UIRechargeWalletShopView:OnShow(data)
- self.controller:SetData(data)
- end
- function UIRechargeWalletShopView:OnClose()
- end
- function UIRechargeWalletShopView:OnDispose()
- self:StopRefreshTimer()
- self.controller:OnDispose()
- end
- return UIRechargeWalletShopView
|