| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- local UIWalletShopGoldBuyTipsView = require("UIRuneShop/UIRuneShopGoldBuyTipsView_Generate")
- function UIWalletShopGoldBuyTipsView:OnAwake(data)
- self.controller = require("UIRuneShop/UIWalletShopGoldBuyTipsCtr"):new()
- self.controller:Init(self)
- self.controller:SetData(data)
- end
- function UIWalletShopGoldBuyTipsView:AddEventListener()
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
- end
- function UIWalletShopGoldBuyTipsView: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 UIWalletShopGoldBuyTipsView:Init()
- self.controller:InitData()
- local goodsData = self.controller:GetCurGoodsData()
- self.presentPrice.currency:SetActive(false)
- if not goodsData then
- self.textTitle.text.text = ''
- self.buyLimitTxt.text.text = ''
- self.presentPrice.number.text.text = ''
- self.image.image.enabled = false
- self.image.image.sprite = nil
- return
- end
- local price = goodsData.price
- if price <= 0 then
- self.presentPrice.number.text.text = string.formatbykey('Free')
- else
- self.presentPrice.number.text.text = string.formatbykey('WalletGold',price)--tostring(price)
- end
- local cfgData = goodsData.cfgData
- if cfgData then
- CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite)
- if sprite then
- self.image.image.sprite = sprite
- self.image.image.enabled = true
- end
- end)
- local rewards = cfgData.Reward
- local reward
- local goldNum = 0
- if rewards then
- for i = 1, #rewards do
- reward = rewards[i]
- if reward[1] == Enum.ItemType.Diamond then
- if reward[2] then
- goldNum = goldNum + reward[2]
- end
- end
- end
- end
- local extraGoldNum = 0
- local isFirstBuy = goodsData.first_buy
- if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and isFirstBuy then
- self.textTitle.text.text = I18N.T(tostring(cfgData.Name)) .. string.formatbykey('RuneShopGoldTitle1')
- rewards = cfgData.FirstBuyReward
- for i = 1, #rewards do
- reward = rewards[i]
- if reward[1] == Enum.ItemType.Diamond then
- if reward[2] then
- extraGoldNum = extraGoldNum + reward[2]
- end
- end
- end
- elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then
- self.textTitle.text.text = I18N.T(tostring(cfgData.Name)) .. string.formatbykey('RuneShopGoldTitle2')
- rewards = cfgData.ExtraBuyReward
- for i = 1, #rewards do
- reward = rewards[i]
- if reward[1] == Enum.ItemType.Diamond then
- if reward[2] then
- extraGoldNum = extraGoldNum + reward[2]
- end
- end
- end
- else
- self.textTitle.text.text = I18N.T(tostring(cfgData.Name))
- end
- local contentStr = '+' .. tostring((goldNum + extraGoldNum))
- local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemType.Diamond)
- if itemCfgData then
- contentStr = contentStr .. tostring(itemCfgData.Name)
- end
- self.buyLimitTxt.text.text = string.formatbykey('RuneShopGoldDsc2', tostring(price))
- self.goldText.text.text = string.formatbykey('RuneShopGoldDsc3', tostring((goldNum + extraGoldNum)),tostring(goldNum), tostring(extraGoldNum))
- else
- self.image.image.enabled = false
- self.image.image.sprite = nil
- self.textTitle.text.text = ''
- self.goldText.text.text = ''
- self.buyLimitTxt.text.text = ''
- end
- end
- function UIWalletShopGoldBuyTipsView:RemoveEventListener()
- ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
- end
- function UIWalletShopGoldBuyTipsView:AddUIEventListener()
- self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnBuy.button, self, self.OnClickBuyBtn)
- end
- function UIWalletShopGoldBuyTipsView:OnHide()
- end
- function UIWalletShopGoldBuyTipsView:OnShow(data)
- self.controller:SetData(data)
- end
- function UIWalletShopGoldBuyTipsView:OnClose()
- end
- function UIWalletShopGoldBuyTipsView:OnDispose()
- self.controller:OnDispose()
- end
- function UIWalletShopGoldBuyTipsView:OnClickCloseBtn()
- self:UIClose()
- end
- function UIWalletShopGoldBuyTipsView:OnClickBuyBtn()
- --钱包儲值
- local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.WalletNum)
- local goodsData = self.controller:GetCurGoodsData()
- if not goodsData then
- self:UIClose()
- return
- end
- local cfgData = goodsData.cfgData
- if cfgData then
- if count >= cfgData.RMB then
- local creditLimit = ManagerContainer.DataMgr.WalletShopData:GetCreditLimit()
- if creditLimit then
- ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(cfgData.Id)
- else
- local max_credit = ManagerContainer.DataMgr.WalletShopData:GetMaxUseCredit()
- local use_credit = ManagerContainer.DataMgr.WalletShopData:GetCurUseCredit()
- local credit = max_credit - use_credit
- if credit >= cfgData.RMB then
- ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(cfgData.Id)
- else
- ManagerContainer.LuaUIMgr:ShowMessageBox("Insufficient",nil,nil,self,self.OnClickGetCredit)
- --ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("InsufficientLimit")
- end
- end
- else
- CommonUtil.ItemNotEnoughHandle(Enum.ItemType.WalletNum)
- end
- end
- self:UIClose()
- end
- function UIWalletShopGoldBuyTipsView:OnClickGetCredit()
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, nil)
- end
- return UIWalletShopGoldBuyTipsView
|