| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- local UIVipView = require("UIVip/UIVipView_Generate")
- function UIVipView:OnAwake(data)
- self.controller = require("UIVip/UIVipCtr"):new()
- self.controller:Init(self)
- self.controller:SetData(data)
- end
- function UIVipView:AddEventListener()
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_EXP_CHANGED, self, self.OnVipExpChanged)
- end
- function UIVipView: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 UIVipView:Init()
- self.customerServiceData = nil
- self.gainList.loopListView:InitListView(0, function(loopListView, itemIndex)
- return self:GetItemByIndex(loopListView, itemIndex)
- end)
- self.gainList.loopListView.ScrollRect.enabled = false
- self.expSlider.slider.interactable = false
- self:RefreshTopView()
- self:RefreshBottomView()
- self:RefreshSwitchButton()
- self:StartCheckCustomerService()
- end
- function UIVipView:RemoveEventListener()
- ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
- end
- function UIVipView:AddUIEventListener()
- -- self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnBack.button, self, self.OnClickCloseBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnUpLv.button, self, self.OnClickUpLvBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnInfo.button, self, self.OnClickInfoBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnLeft.button, self, self.OnClickLeftBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnRight.button, self, self.OnClickRightBtn)
- self.uiBase:AddButtonUniqueEventListener(self.btnCustomerService.button, self, self.OnClickCustomerServiceBtn)
- end
- function UIVipView:OnHide()
- end
- function UIVipView:OnShow(data)
- self.controller:SetData(data)
- end
- function UIVipView:OnClose()
- end
- function UIVipView:OnDispose()
- self.customerServiceData = nil
- self:DisposeCheckCustomerService()
- self.gainList.loopListView:Dispose()
- self.rewardList.loopHorizontalScrollRect:ClearCells()
- self.controller:OnDispose()
- end
- function UIVipView:OnPageInEnd()
- self.super.OnPageInEnd(self)
- self.gainList.loopListView.ScrollRect.enabled = true
- end
- function UIVipView:OnVipLvChanged()
- self:RefreshLvView()
- self:StartCheckCustomerService()
- end
- function UIVipView:OnVipExpChanged()
- self:RefreshExpView()
- end
- function UIVipView:OnClickCloseBtn()
- self:UIClose()
- end
- function UIVipView:OnClickUpLvBtn()
- if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIRuneShopBT) then
- local uibase = ManagerContainer.LuaUIMgr:GetPage(Enum.UIPageName.UIRuneShopBT)
- if uibase then
- local luaTable = uibase.MLuaTable
- if luaTable then
- if luaTable.OnShow then
- luaTable:OnShow({Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold})
- end
- end
- end
- else
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold})
- end
- self:UIClose()
- end
- function UIVipView:OnClickInfoBtn()
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'VipExplain'})
- end
- function UIVipView:OnClickLeftBtn()
- if not self.controller:ChangeCurShowVipLv(false) then
- return
- end
- self:RefreshBottomView()
- self:RefreshSwitchButton()
- end
- function UIVipView:OnClickRightBtn()
- if not self.controller:ChangeCurShowVipLv(true) then
- return
- end
- self:RefreshBottomView()
- self:RefreshSwitchButton()
- end
- function UIVipView:OnClickCustomerServiceBtn()
- local infos = self:GetCustomerServiceInfos()
- if not infos then
- return
- end
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UICustomerServiceTips, infos)
- end
- function UIVipView:RefreshTopView()
- self:RefreshLvView()
- self:RefreshExpView()
- end
- function UIVipView:RefreshLvView()
- 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.curVipNameTxt.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.curVipNameTxt.text.text = string.formatbykey(vipCfg.Name)
- self.expTxt.sealIcon.image.sprite = nil
- self.expTxt.sealIcon.image.enabled = false
- local nextVipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv + 1)
- if nextVipCfg then
- CommonUtil.LoadIcon(self, nextVipCfg.SmallIcon, function(sprite)
- if sprite then
- self.expTxt.sealIcon.image.sprite = sprite
- self.expTxt.sealIcon.image.enabled = true
- end
- end)
- end
- end
- function UIVipView:RefreshExpView()
- local curVipLv = self.controller:GetCurVipLv()
- local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv)
- if not vipCfg then
- self.expTxt:SetActive(false)
- self.expSlider:SetActive(false)
- return
- end
- local curVipExp = self.controller:GetCurVipExp()
- self.expTxt:SetActive(true)
- self.expSlider:SetActive(true)
- local nextVipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv + 1)
- if nextVipCfg then
- self.expTxt.text.text = string.formatbykey('VipUpLv', tostring(vipCfg.VipExp - curVipExp), string.formatbykey(nextVipCfg.Name))
- self.expSlider.slider.value = Mathf.Clamp01(curVipExp / vipCfg.VipExp)
- else
- self.expTxt.text.text = string.formatbykey('VipUpLvMax')
- self.expSlider.slider.value = 1
- end
- self.number.text.text = tostring(curVipExp) .. '/' .. tostring(vipCfg.VipExp)
- end
- function UIVipView:RefreshBottomView()
- local vipLv = self.controller:GetCurShowVipLv()
- local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
- if not vipCfg then
- self.vipNameTxt.text.text = ''
- self.gainList.loopListView:SetListItemCount(0)
- CommonUtil.LoopGridViewEleCreateNew(self, self.rewardList.loopHorizontalScrollRect, nil, {}, 0, self, self.UpdateRewardItem)
- return
- end
- self.vipNameTxt.text.text = string.formatbykey(vipCfg.Name)
- self.gainList.loopListView:SetListItemCount(vipCfg.UnlockDes and #vipCfg.UnlockDes or 0)
- self.gainList.loopListView:RefreshAllShownItem()
- CommonUtil.LoopGridViewEleCreateNew(self, self.rewardList.loopHorizontalScrollRect, nil, vipCfg.Reward and vipCfg.Reward or {}, 0, self, self.UpdateRewardItem)
- end
- function UIVipView:RefreshSwitchButton()
- self.btnLeft:SetActive(self.controller:HasPrev())
- self.btnRight:SetActive(self.controller:HasNext())
- end
- function UIVipView:UpdateRewardItem(itemLua, itemIdx, itemData)
- if not itemLua or not itemData then return end
- CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, {cfgId = itemData[1], num = itemData[2]}, Enum.ItemIEnterType.Bag, self, self.ShowItemTips)
- itemLua.check:SetActive(self.controller:IsReachLv())
- end
- function UIVipView:ShowItemTips(button, params)
- ManagerContainer.LuaUIMgr:OpenTips(params[0])
- end
- function UIVipView:GetItemByIndex(loopListView, itemIndex)
- local vipLv = self.controller:GetCurShowVipLv()
- local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
- if not vipCfg then return nil end
- if not vipCfg.UnlockDes then return nil end
- local unlockDes = vipCfg.UnlockDes[itemIndex + 1]
- if not unlockDes then return nil end
- local item = loopListView:NewListViewItem('VipUnlockDesItem')
- local isNew = unlockDes[1] or 0
- local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'VipUnlockDesItem', item.gameObject)
- if itemLua then
- itemLua.exist:SetActive(isNew ~= 1)
- itemLua.new:SetActive(isNew == 1)
- 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 UIVipView:StartCheckCustomerService()
- self.btnCustomerService.gameObject:SetActive(false)
- local isShow = self.controller:IsShowCustomerVipLv()
- if not isShow then
- self:StopCheckCustomerService()
- return
- end
- if self.reqWWW then
- return
- end
- local url = PlatformPack.CUSTOMER_SERVICE_INFO_URL .. '?timesamp=' .. tostring(os.time())
- local platform = ManagerContainer.LuaGameMgr.platform
- if platform and platform ~= '' then
- url = url .. '&platform=' .. tostring(platform)
- end
- local subplatform = ManagerContainer.LuaGameMgr.channelName
- if subplatform and subplatform ~= '' then
- url = url .. '&sub_platform=' .. tostring(subplatform)
- end
- self.reqWWW = UnityEngine.WWW(url)
- if not self.checkReqWWWTimer then
- self.checkReqWWWTimer = FrameTimer.New(slot(self.CheckCustomerService, self), 1, -1)
- end
- if not self.checkReqWWWTimer.running then
- self.checkReqWWWTimer:Start()
- end
- end
- function UIVipView:StopCheckCustomerService()
- if self.reqWWW then
- self.reqWWW:Dispose()
- self.reqWWW = nil
- end
- if self.checkReqWWWTimer and self.checkReqWWWTimer.running then
- self.checkReqWWWTimer:Stop()
- end
- end
- function UIVipView:DisposeCheckCustomerService()
- self:StopCheckCustomerService()
- self.checkReqWWWTimer = nil
- end
- function UIVipView:CheckCustomerService()
- if not self.checkReqWWWTimer then
- self:StopCheckCustomerService()
- return
- end
- if self.reqWWW.isDone then
- local content = nil
- if not self.reqWWW.error or self.reqWWW.error == '' then
- content = self.reqWWW.text
- end
- self:StopCheckCustomerService()
- if content then
- local ok, result = RO_XPCALL(JSON.decode, debug.traceback, JSON, content)
- if ok then
- self.customerServiceData = result
- local infos = self:GetCustomerServiceInfos()
- self.btnCustomerService.gameObject:SetActive((infos ~= nil))
- else
- LogError('[wboy] CheckCustomerService Fail ' .. tostring(result))
- end
- end
- end
- end
- function UIVipView:GetCustomerServiceInfos()
- if not self.customerServiceData then
- return nil
- end
- if not self.customerServiceData.open then
- return nil
- end
- local datas = self.customerServiceData.infos
- if not datas or #datas <= 0 then
- return nil
- end
- return datas
- end
- return UIVipView
|