| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- local UIBoliShopBuyTipsView = require("UIShop/UIShopBuyTipsView_Generate")
- function UIBoliShopBuyTipsView:OnAwake(data)
- self.controller = require("UIShop/UIBoliShopBuyTipsCtr"):new()
- self.controller:Init(self)
- self.controller:SetData(data)
- end
- function UIBoliShopBuyTipsView:AddEventListener()
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
- end
- function UIBoliShopBuyTipsView: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 UIBoliShopBuyTipsView:Init()
- if not self.controller:IsValidData() then
- self.iconItem:SetActive(false)
- self.limitBox:SetActive(false)
- self.itemName.text.text = ''
- self.desTxt.text.text = ''
- self.buyNumTxt.text.text = ''
- self.presentPrice.number.text.text = ''
- if self.timer then
- self.timer:Stop()
- self.timer = nil
- end
- return
- end
- self.iconItem:SetActive(true)
- local goodsData = self.controller:GetCurGoodsData()
- local goodsCfgData = goodsData:GetGoodsCfgData()
- local data = {cfgId = goodsCfgData.GoodsItem}
- CommonUtil.UpdateItemPrefab(self, self.iconItem, data, nil, self, self.ShowItemTips, data)
- local havenum = CommonUtil.GetOwnResCountByItemId(goodsCfgData.GoodsItem)
- self.itemnum.text.text = tostring(havenum)
- self.itemName.text.text = goodsCfgData.GoodsName
- self.desTxt.text.text = goodsCfgData.GoodsDesc
- self:RefreshCost()
- local itemCfgData = ManagerContainer.CfgMgr:GetItemById(goodsCfgData.PayForType)
- CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
- self.presentPrice.icon.image.sprite = sprite
- end)
- local limitType = goodsData.limitType
- if limitType == Enum.LimitBuyType.NoLimit then
- self.limitBox:SetActive(false)
- elseif limitType == Enum.LimitBuyType.Forever then
- self.limitBox:SetActive(false)
- elseif limitType == Enum.LimitBuyType.Daily then
- self.limitBox:SetActive(true)
- self.timeLimit.text.text = goodsData:CalculateLimitTime()
- self.timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
- elseif limitType == Enum.LimitBuyType.Week then
- self.limitBox:SetActive(true)
- self.timeLimit.text.text = goodsData:CalculateLimitTime()
- self.timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
- elseif limitType == Enum.LimitBuyType.Time then
- self.limitBox:SetActive(true)
- self.timeLimit.text.text = goodsData:CalculateLimitTime()
- self.timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
- elseif limitType == Enum.LimitBuyType.Special then
- self.limitBox:SetActive(false)
- else
- self.limitBox:SetActive(false)
- end
- if self.timer then
- self.timer:Start()
- end
- end
- function UIBoliShopBuyTipsView:RemoveEventListener()
- ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
- self.btnMinus.repeatButton:AddRepeatClickEventListener(nil, nil)
- self.btnAdd.repeatButton:AddRepeatClickEventListener(nil, nil)
- end
- function UIBoliShopBuyTipsView:AddUIEventListener()
- self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonEventListener(self.btnMax.button, self, self.OnClickMaxBtn)
- self.uiBase:AddButtonEventListener(self.btnBuy.button, self, self.OnClickBuyBtn)
- self.btnMinus.repeatButton:AddRepeatClickEventListener(self, self.OnClickMinusBuyNum)
- self.btnAdd.repeatButton:AddRepeatClickEventListener(self, self.OnClickAddBuyNum)
- end
- function UIBoliShopBuyTipsView:OnHide()
- end
- function UIBoliShopBuyTipsView:OnShow(data)
- self.controller:SetData(data)
- end
- function UIBoliShopBuyTipsView:OnClose()
- end
- function UIBoliShopBuyTipsView:OnDispose()
- if self.timer then
- self.timer:Stop()
- self.timer = nil
- end
- self.controller:OnDispose()
- end
- function UIBoliShopBuyTipsView:OnClickCloseBtn()
- self:UIClose()
- end
- function UIBoliShopBuyTipsView:OnClickMaxBtn()
- if self.controller:SetBuyNum(self.controller:GetMaxBuyNumOnce()) then
- self:RefreshCost()
- end
- end
- function UIBoliShopBuyTipsView:OnClickBuyBtn()
- local errorCode, itemCfgId = self.controller:SendShopBuyItemReq()
- if errorCode ~= 0 then
- if errorCode == 391 then
- CommonUtil.ItemNotEnoughHandle(itemCfgId, Enum.UIPageName.UIShop)
- else
- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
- end
- end
- self:UIClose()
- end
- function UIBoliShopBuyTipsView:OnClickMinusBuyNum()
- if self.controller:ChangeDeltaBuyNum(-1) then
- self:RefreshCost()
- end
- end
- function UIBoliShopBuyTipsView:OnClickAddBuyNum()
- if self.controller:ChangeDeltaBuyNum(1) then
- self:RefreshCost()
- end
- end
- function UIBoliShopBuyTipsView:RefreshCost()
- if not self.controller:IsValidData() then return end
- self.buyNumTxt.text.text = tostring(self.controller:GetBuyNum())
- self.presentPrice.number.text.text = tostring(self.controller:GetBuyNum() * self.controller:GetCurPrice())
- end
- function UIBoliShopBuyTipsView:RefreshTimer()
- local goodsData = self.controller:GetCurGoodsData()
- if not goodsData then return end
- self.limitBox:SetActive(true)
- self.timeLimit.text.text = goodsData:CalculateLimitTime()
- end
- return UIBoliShopBuyTipsView
|