local UILuckyEggView = require("UILuckyEgg/UILuckyEggView_Generate") function UILuckyEggView:OnAwake(data) self.controller = require("UILuckyEgg/UILuckyEggCtr"):new() self.controller:Init(self) self.controller:SetData(data) end function UILuckyEggView:AddEventListener() ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ITEM_CHANGE, self, self.OnItemChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.OnDiamondChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.LUCKYEGG_DATA_CHANGED, self, self.OnSmashDataChanged) ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.LUCKYEGG_RANK_DATA_CHANGED, self, self.OnSmashRankDataChanged) end function UILuckyEggView: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 UILuckyEggView:Init() -- 清除红点信息 self.controller:ReadyData() self.dot:SetActive(false) self.window.animator:Play('UIShow') self.currency:SetActive(false) local initParam = SuperScrollView.LoopListViewInitParam() initParam.mSmoothDumpRate = 0.05 initParam.mSnapVecThreshold = 9999 self.scrollView.loopListView.OffsetSnapCenterPercent = 0.4 self.scrollView.loopListView.ItemSnapEnable = true self.scrollView.loopListView:InitListView(-1, function(loopListView, idx) return self:GetItemByIndex(loopListView, idx) end, nil, initParam) self.scrollView.loopListView:MovePanelToItemIndex(self.controller:GetListIdx(), 0) self:RefreshView() end function UILuckyEggView:RemoveEventListener() ManagerContainer.LuaEventMgr:Unregister(self.uiData.name) self.scrollView.loopListView.mOnSnapItemFinished = nil end function UILuckyEggView:AddUIEventListener() self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn) self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn) self.uiBase:AddToggleEventListener(self.goldenEggToggle.toggle,self,self.OnClickTab,1) self.uiBase:AddToggleEventListener(self.variegationEggToggle.toggle,self,self.OnClickTab,2) self.uiBase:AddButtonUniqueEventListener(self.btnPlayRule.button, self, self.OnClickPlayRuleBtn) self.uiBase:AddButtonUniqueEventListener(self.btnOne.button, self, self.OnClickLuckyEggBtn, 1) self.uiBase:AddButtonUniqueEventListener(self.btnTen.button, self, self.OnClickLuckyEggBtn, 2) self.uiBase:AddButtonUniqueEventListener(self.btnArrowL.button, self, self.OnClickArrowBtn, false) self.uiBase:AddButtonUniqueEventListener(self.btnArrowR.button, self, self.OnClickArrowBtn, true) self.scrollView.loopListView.mOnBeginDragAction = function() return self:OnBeginDragAction() end self.scrollView.loopListView.mOnSnapItemFinished = function(loopListView, loopListViewItem) return self:OnSnapItemFinished(loopListView, loopListViewItem) end --滚动文字 local OnChangeText = function (TextObj) self:ChangeLogText(TextObj) end self.NextTextIndex = 0 if self.viewport.uiLoopAutoMove then self.viewport.uiLoopAutoMove:SetChangeInfoCb(OnChangeText) end self.controller:SendLuckyEggRecordReq() end function UILuckyEggView:OnClickTab(tog,idex) if tog.isOn then -- local cfg = self.controller:GetCfgByIdx(idex) local curSelect = self.controller:GetSelectIdx() if curSelect ~= idex then self:OnClickArrowBtn(nil,{[0]=curSelect < idex}) end end end --添加文字 function UILuckyEggView:ChangeLogText(TextObj) self.NextTextIndex = self.NextTextIndex >= 10 and 1 or self.NextTextIndex + 1 local str = "" local rank_list = self.controller:GetActivityData() --LogError("============ rank_list = "..Inspect(rank_list)); local package = rank_list[self.NextTextIndex] --LogError("============ NextTextIndex = "..self.NextTextIndex); if package then --LogError("============ package = "..Inspect(package)); local itemCfgData = ManagerContainer.CfgMgr:GetItemById(package.itemId) local iname = I18N.T(itemCfgData.Name) local name = nil if package.nickName and package.nickName ~= "" then name = package.nickName else name = ManagerContainer.DataMgr.UserData:GetUserNickname() end str = ManagerContainer.CfgMgr:GetLanguageValueByKey("BTSmashEggsTips1", name.." ",iname) end --LogError("============ Str = "..str); TextObj.text = str end function UILuckyEggView:OnHide() end function UILuckyEggView:OnShow(data) if data then self.controller:SetData(data) end self.scrollView.loopListView:RefreshAllShownItem() self:RefreshLuckyEggBtn() self:RefreshTopCurrency() self:RefreshCostCurrency() self:ResetEggLoopText() --LogError("show") end function UILuckyEggView:OnDispose() self:DisposeCurrency() self:DisposeDot() self.scrollView.loopListView:Dispose() self.controller:OnDispose() end function UILuckyEggView:OnItemChanged() self:RefreshTopCurrency() self:RefreshCostCurrency() end function UILuckyEggView:OnDiamondChanged() self:RefreshTopCurrency() self:RefreshCostCurrency() end function UILuckyEggView:OnSmashDataChanged() if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILuckyEgg) then return end if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILuckyEggAnim) then ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggAnim, nil, self.uiData.id) end end function UILuckyEggView:OnSmashRankDataChanged() self.NextTextIndex = 0 self:ResetEggLoopText() end function UILuckyEggView:OnClickCloseBtn() ManagerContainer.LuaUIMgr:OpenSourceUI(self) end function UILuckyEggView:OnClickPlayRuleBtn() local actId = self.controller:GetActivityId() if actId then ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'LuckyEggPlayExplain_'..actId}) else ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'LuckyEggPlayExplain'}) end end local resType = Enum.RuneShopSubType.Gold function UILuckyEggView:OnClickCurrencyBuyBtn(_, params) local cfgId = params[0] local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId) if not itemCfgData then return end local type if itemCfgData.ResType == Enum.ItemType.Diamond or itemCfgData.ResType == Enum.ItemType.ROCoin then resType = Enum.RuneShopSubType.Gold end ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, resType}, self.uiData.id) end function UILuckyEggView:SureBuy(idx) local errorCode, luckyEggNum, remainLuckyEggNum, vaildCosts = self.controller:GetSendLuckyEggReqErrorCode(idx) if errorCode == 0 then errorCode = self.controller:SendLuckyEggReq(luckyEggNum) if errorCode ~= 0 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) end elseif errorCode == 1 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) elseif errorCode == 2 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) elseif errorCode == 3 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) elseif errorCode == 4 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) else ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) end end function UILuckyEggView:SureJumpBuy(idx) ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold}, self.uiData.id) end --- 发送砸蛋请求 ---@param params Cfg.Method function UILuckyEggView:OnClickLuckyEggBtn(_, params) local idx = params[0] local errorCode, luckyEggNum, remainLuckyEggNum, vaildCosts = self.controller:GetSendLuckyEggReqErrorCode(idx) if errorCode == 0 then local len = #vaildCosts if len > 1 then local vaildCost = vaildCosts[len] local cfgId = vaildCost[1] local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId) if itemCfgData.ResType == Enum.ItemType.Diamond and vaildCost[4] < luckyEggNum then local paramData = {} local vaildCost2 = vaildCosts[1] local cfgId2 = vaildCost2[1] local itemCfgData2 = ManagerContainer.CfgMgr:GetItemById(cfgId2) paramData[1] = itemCfgData2 and string.formatbykey(itemCfgData2.Name) or '' paramData[2] = string.formatbykey('Supplementary', tostring(vaildCost[3] * vaildCost[4]), itemCfgData and string.formatbykey(itemCfgData.Name) or '', tostring(vaildCost[4]), paramData[1]) local data = {"LuckyEggNoItemTip", paramData, idx, self, self.SureBuy} ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data) else errorCode = self.controller:SendLuckyEggReq(luckyEggNum) if errorCode ~= 0 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) end end else errorCode = self.controller:SendLuckyEggReq(luckyEggNum) if errorCode ~= 0 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) end end elseif errorCode == 1 then local len = #vaildCosts if len >= 1 then local vaildCost = vaildCosts[len] if Constant.OpenPay then local cfgId = vaildCost[1] local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId) local showStr = nil if itemCfgData.ResType == Enum.ItemType.Diamond then showStr = "NoDiamondTip" elseif itemCfgData.ResType == Enum.ItemType.ROCoin then showStr = "NoRoDiamondTip" end -- 提示框[1] 提示框的类型 local data = {showStr, nil, idx, self, self.SureJumpBuy} ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data) return end end elseif errorCode == 2 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) elseif errorCode == 3 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) elseif errorCode == 4 then ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) else ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode) end end function UILuckyEggView:OnClickArrowBtn(_, params) local isRight = params[0] local listIdx = self.controller:GetListIdx() if isRight then listIdx = listIdx + 1 else listIdx = listIdx - 1 end self.scrollView.loopListView:SetSnapTargetItemIndex(listIdx) self.window.animator:Play('UIRemove') end function UILuckyEggView:OnClickDetailsBtn(btn, params) local showList = params[0] table.sort(showList,function(a,b) local cfgA = ManagerContainer.CfgMgr:GetItemById(a[1]) local cfgB = ManagerContainer.CfgMgr:GetItemById(b[1]) if cfgA and cfgB then if cfgA.Quality == cfgB.Quality then if cfgA.ResType == Enum.ItemType.SkillEquip or cfgB.ResType == Enum.ItemType.SkillEquip then local artifactA = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(cfgA.Id) local artifactB = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(cfgB.Id) if artifactA and artifactB then if artifactA.ArtifactMaxLevel == artifactB.ArtifactMaxLevel then return cfgA.Id > cfgB.Id else return artifactA.ArtifactMaxLevel > artifactB.ArtifactMaxLevel end end else return cfgA.Id > cfgB.Id end else return cfgA.Quality > cfgB.Quality end end end) local show = { rewards = showList, title = "LuckyEggExtraRewards", type = Enum.ArtifactType.egg } ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIArtifactRewardsList,show) end function UILuckyEggView:OnBeginDragAction() self.window.animator:Play('UIRemove') end function UILuckyEggView:OnSnapItemFinished(loopListView, loopListViewItem) self.window.animator:Play('UIShow') if not self.controller:SetListIdx(loopListViewItem.ItemIndex) then return end self:RefreshView() self:ResetEggLoopText() self.controller:SendLuckyEggRecordReq() end function UILuckyEggView:GetItemByIndex(loopListView, listIdx) local idx = self.controller:GetSelectIdxByListIdx(listIdx) local cfg = self.controller:GetCfgByIdx(idx) if not cfg then return nil end local item = loopListView:NewListViewItem('UILuckyEggItem') local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'UILuckyEggItem', item.gameObject) if itemLua then itemLua.egg.image.enabled = false itemLua.egg.image.sprite = nil CommonUtil.LoadIcon(self, cfg.ShowImg, function(sprite) if sprite then itemLua.egg.image.sprite = sprite itemLua.egg.image.enabled = true end end, itemLua, 'BannerIconAsync') local reward_show = cfg.ClientShow if reward_show and #reward_show > 0 then self.uiBase:AddButtonUniqueEventListener(itemLua.btnMvpPreview.button, self, self.OnClickDetailsBtn, reward_show) end if not cfg.Total or cfg.Total <= 0 then itemLua.extraBox:SetActive(false) else itemLua.extraBox:SetActive(true) local luckyEggNum = self.controller:GetLuckyEggNumByIdx(idx) local percent = luckyEggNum % cfg.Total local per = percent/ cfg.Total itemLua.extraRewardItem.rewardSlider.slider.value = per local validPercent = CommonUtil.GetPreciseDecimal(per * 100) if validPercent <= 0 and luckyEggNum > 0 then validPercent = 1 end itemLua.extraRewardItem.percentTxt.text.text = tostring(validPercent) .. '%' end end item.CachedRectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Horizontal, loopListView.ViewPortWidth) return item end function UILuckyEggView:RefreshView() self:RefreshTopCurrency() self:RefreshLuckyEggBtn() self:RefreshCostCurrency() local selectIdx = self.controller:GetSelectIdx() local length = self.controller:GetCfgLength() local cfg = self.controller:GetCfgByIdx(selectIdx) --LogError("length = "..length) if length <= 1 then self.btnArrowL:SetActive(false) self.btnArrowR:SetActive(false) else self.btnArrowL:SetActive(true) self.btnArrowR:SetActive(true) end if cfg and cfg.Type == 5 then self.goldenEggToggle:SetActive(false) self.variegationEggToggle:SetActive(true) else self.goldenEggToggle:SetActive(true) self.variegationEggToggle:SetActive(false) end if not self.dots then self.dots = {} end local num = #self.dots local dot = nil local parent = self.dotToggleGroup.transform for i = 1, length do if i <= num then dot = self.dots[i] else dot = CommonUtil.Instantiate(self.dot.gameObject, parent) if tolua.getpeer(dot) == nil then tolua.setpeer(dot, {}) end dot.toggle = dot:GetComponent(Enum.TypeInfo.Toggle) self.dots[i] = dot end dot:SetActive(true) dot.toggle.isOn = (i == selectIdx) end for i = length + 1, num do dot = self.dots[i] dot:SetActive(false) end end function UILuckyEggView:RefreshLuckyEggBtn() --- 检测 self.controller:CheckTotalRecharge() local selectIdx = self.controller:GetSelectIdx() local cfg = self.controller:GetCfgByIdx(selectIdx) if cfg == nil then return end if cfg.UnLock and cfg.UnLock > 0 then local result, val, content = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(cfg.UnLock) if not result then self.leftAnim:SetActive(false) self.rightAnim:SetActive(false) return end end self.leftAnim:SetActive(true) self.rightAnim:SetActive(true) local egg_active = self.controller:GetEggActiveByPay() --self.variegationEggToggle.gameObject:SetActive(egg_active) if cfg.Type == 4 then self.goldenEggToggle.toggle.graphic:CrossFadeAlpha(1.0,0.1,true) self.variegationEggToggle.toggle.graphic:CrossFadeAlpha(0.1,0.1,true) elseif cfg.Type == 5 then self.variegationEggToggle.toggle.graphic:CrossFadeAlpha(1.0,0.1,true) self.goldenEggToggle.toggle.graphic:CrossFadeAlpha(0.1,0.1,true) end end function UILuckyEggView:RefreshTopCurrency() local selectIdx = self.controller:GetSelectIdx() local cfg = self.controller:GetCfgByIdx(selectIdx) if cfg == nil then return end local costs = cfg.Cost local num = costs and #costs or 0 local length = 0 if not self.currencys then self.currencys = {} else length = #self.currencys end local parent = self.currency.transform.parent for i = 1, num do local currency = nil if i <= length then currency = self.currencys[i] else currency = CommonUtil.Instantiate(self.currency.gameObject, parent) if tolua.getpeer(currency) == nil then tolua.setpeer(currency, {}) end local icon = currency.transform:Find('Icon').gameObject if tolua.getpeer(icon) == nil then tolua.setpeer(icon, {}) end icon.image = icon:GetComponent(Enum.TypeInfo.Image) currency.icon = icon local number = currency.transform:Find('Number').gameObject if tolua.getpeer(number) == nil then tolua.setpeer(number, {}) end number.text = number:GetComponent(Enum.TypeInfo.Text) currency.number = number local btnBuy = currency.transform:Find('BtnBuy').gameObject if tolua.getpeer(btnBuy) == nil then tolua.setpeer(btnBuy, {}) end btnBuy.button = btnBuy:GetComponent(Enum.TypeInfo.Button) currency.btnBuy = btnBuy self.currencys[i] = currency end currency:SetActive(true) currency.icon.image.enabled = false currency.icon.image.sprite = nil local cfgId = tonumber(costs[i][1]) local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId) if itemCfgData then CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite) if sprite then currency.icon.image.sprite = sprite currency.icon.image.enabled = true end end) if itemCfgData.ResType == Enum.ItemType.ROCoin or itemCfgData.ResType == Enum.ItemType.Diamond then currency.btnBuy:SetActive(Constant.OpenPay) self.uiBase:AddButtonUniqueEventListener(currency.btnBuy.button, self, self.OnClickCurrencyBuyBtn, cfgId) else currency.btnBuy:SetActive(false) currency.btnBuy.button.onClick:RemoveAllListeners() end else currency.btnBuy:SetActive(false) currency.btnBuy.button.onClick:RemoveAllListeners() end currency.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(cfgId)) end for i = num + 1, length do local currency = self.currencys[i] currency:SetActive(false) currency.btnBuy:SetActive(false) currency.btnBuy.button.onClick:RemoveAllListeners() end end function UILuckyEggView:RefreshCostCurrency() local selectIdx = self.controller:GetSelectIdx() local cfg = self.controller:GetCfgByIdx(selectIdx) if cfg == nil then return end local method = cfg.Method local costs = cfg.Cost local costCfgId, costNum local cost = nil if costs then local costLength = #costs for i = 1, costLength do cost = costs[i] if self.controller:GetOwnResCountByItemId(cost[1]) > 0 or i == costLength then costCfgId = tonumber(cost[1]) costNum = tonumber(cost[2]) break end end end self.currencyOne.icon.image.enabled = false self.currencyOne.icon.image.sprite = nil self.currencyTen.icon.image.enabled = false self.currencyTen.icon.image.sprite = nil if not costCfgId or not costNum or not method then self.leftAnim:SetActive(false) self.rightAnim:SetActive(false) else local method1 = method[1] local method2 = method[2] local itemCfgData = ManagerContainer.CfgMgr:GetItemById(costCfgId) CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite) if sprite then self.currencyOne.icon.image.sprite = sprite self.currencyOne.icon.image.enabled = true self.currencyTen.icon.image.sprite = sprite self.currencyTen.icon.image.enabled = true end end) if method1 then self.currencyOne.number.text.text = tostring(tonumber(method1) * costNum) self.leftAnim:SetActive(true) else self.leftAnim:SetActive(false) end if method2 then self.currencyTen.number.text.text = tostring(tonumber(method2) * costNum) self.rightAnim:SetActive(true) else self.rightAnim:SetActive(false) end end end function UILuckyEggView:ResetEggLoopText() if self.viewport and self.viewport.uiLoopAutoMove then self.NextTextIndex = 0 self.viewport.uiLoopAutoMove:Reset() self.viewport.uiLoopAutoMove:RunMove() end end function UILuckyEggView:DisposeCurrency() if not self.currencys then return end for _, currency in pairs(self.currencys) do CommonUtil.DestroyGO(currency) if tolua.getpeer(currency.btnBuy) ~= nil then tolua.setpeer(currency.btnBuy, nil) end if tolua.getpeer(currency.number) ~= nil then tolua.setpeer(currency.number, nil) end if tolua.getpeer(currency.icon) ~= nil then tolua.setpeer(currency.icon, nil) end if tolua.getpeer(currency) ~= nil then tolua.setpeer(currency, nil) end end self.currencys = nil end function UILuckyEggView:OnClose() end function UILuckyEggView:DisposeDot() if not self.dots then return end for _, dot in pairs(self.dots) do CommonUtil.DestroyGO(dot) dot.toggle = nil if tolua.getpeer(dot) ~= nil then tolua.setpeer(dot, nil) end end self.dots = nil end return UILuckyEggView