local SummonMainUI = class("SummonMainUI", BaseUI) -- function SummonMainUI:getPreLoadList() -- return { -- [GConst.TYPEOF_UNITY_CLASS.GAME_OBJECT] = { -- "assets/prefabs/effects/ui/vfx_b13_ui_chouka_bg_b02.prefab", -- "assets/prefabs/effects/ui/vfx_b13_ui_chouka_bg_b03.prefab", -- } -- } -- end function SummonMainUI:ctor(params) self.page = params.summonId or 1 end function SummonMainUI:getPrefabPath() return "assets/prefabs/ui/summon/summon_main_ui.prefab" end function SummonMainUI:getCurrencyParams() local ItemConst = require "app/module/item/item_const" local params = {} params.showType = GConst.CURRENCY_TYPE.HORIZONTAL if self.page == 1 then params.itemIds = { ItemConst.ITEM_ID_GOLD, ItemConst.ITEM_ID_GEM, ItemConst.ITEM_ID_SUMMON_1, } else params.itemIds = { ItemConst.ITEM_ID_GOLD, ItemConst.ITEM_ID_GEM, ItemConst.ITEM_ID_SUMMON_2, } end return params end function SummonMainUI:onClose() self.heroNode:removeAllChildren() -- EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.MAIN_UI_CHECK_POP) end function SummonMainUI:onLoadRootComplete() local uiMap = self.root:genAllChildren() uiMap["summon_main_ui.bottom.close_btn"]:addClickListener(function() self:closeUI() end) self.btnSummonFree = uiMap["summon_main_ui.node.btn_summon_free"] self.btnSummonFreeTx = uiMap["summon_main_ui.node.btn_summon_free.text_free"] self.btnSummonAd = uiMap["summon_main_ui.node.btn_summon_ad"] self.btnSummonAdTx = uiMap["summon_main_ui.node.btn_summon_ad.desc_tx"] --两个抽奖按钮 self.btnSummonOne = uiMap["summon_main_ui.node.btn_summon_one"] self.txSummonOneName = uiMap["summon_main_ui.node.btn_summon_one.text"] self.imgSummonOneIcon = uiMap["summon_main_ui.node.btn_summon_one.cost.img_icon_1"] self.txNumOne = uiMap["summon_main_ui.node.btn_summon_one.cost.tx_num_one"] self.btnSummonTen = uiMap["summon_main_ui.node.btn_summon_ten"] self.txSummonTenName = uiMap["summon_main_ui.node.btn_summon_ten.text"] self.imgSummonTenIcon = uiMap["summon_main_ui.node.btn_summon_ten.cost.img_icon_1"] self.txNumTen = uiMap["summon_main_ui.node.btn_summon_ten.cost.tx_num_ten"] self.txFreeTime = uiMap["summon_main_ui.node.tx_free_time"] self.btnWish = uiMap["summon_main_ui.node.btn_wish"] --心愿 self.btnWishTx = uiMap["summon_main_ui.node.btn_wish.tx_guarantee"] --心愿 self.btnWishIcon = uiMap["summon_main_ui.node.btn_wish.img_wish_icon"] --心愿 self.btnWishAddImg = uiMap["summon_main_ui.node.btn_wish.add_img"] self.heroNode = uiMap["summon_main_ui.summon_node.hero_node"] self.uiNode = uiMap["summon_main_ui.node"] self.touchNode = uiMap["summon_main_ui.touch_node"] self.touchNode:setActive(false) self.btnSummonFree:addClickListener(function() self:onSummon(1) end) self.btnSummonOne:addClickListener(function() self:onSummon(1) end) self.btnSummonTen:addClickListener(function() self:onSummon(10) end) self.btnSummonAd:addClickListener(function() SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.SUMMON_AD, function() self:onSummon(1, true) end) end) self.vfxBg = uiMap["summon_main_ui.summon_node.vfx_c1_chouka_bg_01"] self.vfxs = {} self.vfx01s = {} self.vfx02s = {} for i = 1, 4 do self.vfxs[i] = uiMap["summon_main_ui.summon_node.vfx_c1_chouka_0" .. i] self.vfx01s[i] = uiMap["summon_main_ui.summon_node.vfx_c1_chouka_0" .. i .. "_1"] self.vfx02s[i] = uiMap["summon_main_ui.summon_node.vfx_c1_chouka_0" .. i .. "_2"] self.vfxs[i]:setActive(false) self.vfx01s[i]:setActive(false) self.vfx02s[i]:setActive(false) end uiMap["summon_main_ui.node.btn_info"]:addClickListener(function() ModuleManager.SummonManager:showSummonOddsUI(self.page) end) self.txTitle = uiMap["summon_main_ui.node.tx_title"] self.summonBg = uiMap['summon_main_ui.bg'] uiMap["summon_main_ui.node.btn_summon_one.text_one"]:setText(I18N:getGlobalText(I18N.GlobalConst.SUMMON_ONE)) uiMap["summon_main_ui.node.btn_summon_ten.text_ten"]:setText(I18N:getGlobalText(I18N.GlobalConst.SUMMON_TEN)) uiMap["summon_main_ui.node.btn_summon_free.text_free"]:setText(I18N:getGlobalText(I18N.GlobalConst.FREE_DESC_1)) uiMap["summon_main_ui.node.btn_summon_ad.desc_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.SUMMON_DESC_1)) uiMap["summon_main_ui.node.btn_info.desc_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.SUMMON_FORCE_3)) self.descBg = uiMap["summon_main_ui.node.desc_bg"] self.descTx = uiMap["summon_main_ui.node.desc_bg.desc_tx"] self.btnTxs = { I18N:getGlobalText(I18N.GlobalConst.SUMMON_DESC_6), I18N:getGlobalText(I18N.GlobalConst.SUMMON_DESC_7), } self.pageBtns = {} self.pageBtnTxs = {} for i = 1, 2 do self.pageBtns[i] = uiMap['summon_main_ui.bottom.btn_'.. i] self.pageBtnTxs[i] = uiMap['summon_main_ui.bottom.btn_'.. i ..'.tx_desc'] self.pageBtnTxs[i]:setText(self.btnTxs[i]) self.pageBtns[i]:addClickListener(function() if self.page == i then return end self.page = i self:onRefresh() UIManager:updateBarsState(self) end) end -------------抽奖相关--------- self:addEventListener(EventManager.CUSTOM_EVENT.FORCE_SUMMON, function(result, newHero) self:refreshWishBtn() self:onSummonRsp(result, newHero) end) self:addEventListener(EventManager.CUSTOM_EVENT.FORCE_SUMMON_WISH_CLAIM, function(result, newHero) self:refreshWishBtn() ModuleManager.SummonManager:showSummonRewardUI({ rewards = result.rewards, isWish = true, newHero = newHero, page = self.page }) end) self:addEventListener(EventManager.CUSTOM_EVENT.FORCE_SUMMON_WISH_HERO_ID, function() if self:isClosed() then return end self:refreshWishBtn() end) self.btnWish:addClickListener(function() if self.isUnlock then local wishHeroId = DataManager.SummonData:getSummonWishHeroId(self.page) local wishGuarantee = DataManager.SummonData:getSummonWishGuarantee2(self.page) local wishCount = DataManager.SummonData:getSummonWishCount(self.page) if wishCount >= wishGuarantee and wishHeroId ~= 0 then --发送领取奖励的协议 ModuleManager.SummonManager:onSummonWishClaimReq(self.page) else --打开设置心愿界面 ModuleManager.SummonManager:showSummonWishUI(self.page) end else GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.SUMMON_WISH_LOCK)) end end) self:bind(DataManager.SummonData, "isDirty", function() self:onRefresh() end) -- self:bind(DataManager.ActTimeData, "isDirty", function() -- self:onRefresh() -- end) self:scheduleGlobal(function() self:updateTime() end, 1) self:updateTime() end --每秒刷新单抽红点 function SummonMainUI:updateTime() local isFree = DataManager.SummonData:hasSummonFree(self.page) if self.isFree ~= isFree then self.isFree = isFree self:onRefresh() end if not self.isFree then self.remain_time = Time:getTodaySurplusTime() self.txFreeTime:setText(I18N:getGlobalText(I18N.GlobalConst.SUMMON_FREE_TIME, Time:formatNumTime(self.remain_time))) else self.txFreeTime:setText("") end end --刷新 function SummonMainUI:onRefresh() self:refreshSummonBtn() self:refreshWishBtn() -- self:refreshBtnRedPoint() self:refreshPageBtn() self:updateTime() end function SummonMainUI:refreshPageBtn() for i = 1, 2 do if self.page == i then self.pageBtns[i]:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_btn_" .. i .."_1") else self.pageBtns[i]:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_btn_" .. i .."_2") end end end --刷新抽奖按钮 function SummonMainUI:refreshSummonBtn() local freeCount = DataManager.SummonData:getSummonFreeCount(self.page) local adCount = DataManager.SummonData:getSummonAdCount(self.page) self.btnSummonAd:setActive(adCount > 0) self.btnSummonFree:setActive(freeCount > 0) self.btnSummonOne:setActive(freeCount <= 0) local itemCost = DataManager.SummonData:getSummonItemCost(self.page) local costId = itemCost.id local hadNum = DataManager.BagData.ItemData:getItemNumById(costId) if freeCount <= 0 then if hadNum >= 1 then self.txNumOne:setText(1) self.btnSummonOne:addRedPoint(124, 32, 1) self.imgSummonOneIcon:setSprite(ModuleManager.ItemManager:getItemIcon(costId)) else self.btnSummonOne:removeRedPoint() local cost = DataManager.SummonData:getSummonGemCost(self.page) if cost and hadNum == 0 and GFunc.checkCost(GConst.ItemConst.ITEM_ID_GEM, cost.num, false) then self.txNumOne:setText(cost.num) self.imgSummonOneIcon:setSprite(ModuleManager.ItemManager:getItemIcon(GConst.ItemConst.ITEM_ID_GEM)) -- obj = DataManager.BagData.ItemData:getItemById(GConst.ItemConst.ITEM_ID_GEM) else self.txNumOne:setText("1") self.imgSummonOneIcon:setSprite(ModuleManager.ItemManager:getItemIcon(costId)) end end end if hadNum >= 10 then self.txNumTen:setText(10) self.imgSummonTenIcon:setSprite(ModuleManager.ItemManager:getItemIcon(costId)) self.btnSummonTen:addRedPoint(124, 32, 1) else self.btnSummonTen:removeRedPoint() local cost = DataManager.SummonData:getSummonGemCost(self.page) if cost and hadNum == 0 and GFunc.checkCost(GConst.ItemConst.ITEM_ID_GEM, cost.num * 10, false) then self.txNumTen:setText(cost.num * 10) self.imgSummonTenIcon:setSprite(ModuleManager.ItemManager:getItemIcon(GConst.ItemConst.ITEM_ID_GEM)) -- obj = DataManager.BagData.ItemData:getItemById(GConst.ItemConst.ITEM_ID_GEM) else self.txNumTen:setText("10") self.imgSummonTenIcon:setSprite(ModuleManager.ItemManager:getItemIcon(costId)) end end end --刷新心愿按钮 function SummonMainUI:refreshWishBtn() local guarantee1 = DataManager.SummonData:getSummonConfig(self.page).guarantee1 if not guarantee1 then self.descBg:setActive(false) else self.descBg:setActive(true) local count = guarantee1 - DataManager.SummonData:getSummonTriggerCount(self.page) self.descTx:setText(I18N:getGlobalText(I18N.GlobalConst.SUMMON_FORCE_4, count)) end local love = DataManager.SummonData:getSummonWishConfig(self.page) if not love then self.btnWish:setActive(false) return end self.btnWish:setActive(true) local summonCount = DataManager.SummonData:getSummonCount(self.page) local unlockCount = DataManager.SummonData:getSummonWishUnlock(self.page) self.isUnlock = summonCount >= unlockCount local wishCount = DataManager.SummonData:getSummonWishCount(self.page) local needCount = DataManager.SummonData:getSummonWishGuarantee2(self.page) self.btnWishTx:setText(wishCount .. "/" .. needCount) local wishHeroId = DataManager.SummonData:getSummonWishHeroId(self.page) local cfg = DataManager.HeroData:getHeroConfig(wishHeroId) if cfg then self.btnWishIcon:setSprite(GFunc.getHeroIcon(cfg.icon)) self.btnWish:setSprite(GConst.ATLAS_PATH.ICON_ITEM, GConst.FRAME_QLT[cfg.qlt]) self.btnWishAddImg:setActive(false) else self.btnWishIcon:setSprite(GConst.ATLAS_PATH.COMMON, "common_alpha") self.btnWishAddImg:setActive(true) end end --检查单抽红点 function SummonMainUI:refreshBtnRedPoint() if DataManager.SummonData:hasSummonFree(self.page) then self.btnSummonFree:addRedPoint(124, 33, 1) else self.btnSummonFree:removeRedPoint() end end function SummonMainUI:onSummon(count, isAd) self.heroNode:removeAllChildren() if isAd then AudioManager:playEffect(AudioManager.EFFECT_ID.UI_SUMMON_START) self:disableTouch() self.uiNode:setActive(false) ModuleManager.SummonManager:onForceSummonReq(count, 1, self.page) else local freeCount = DataManager.SummonData:getSummonFreeCount(self.page) if freeCount > 0 and count == 1 then self:disableTouch() self.uiNode:setActive(false) ModuleManager.SummonManager:onForceSummonReq(count, 2, self.page) return end local costs = DataManager.SummonData:getSummonCosts(self.page, count) local hasGemCost = false for i, cost in ipairs(costs) do if cost.id == GConst.ItemConst.ITEM_ID_GEM then hasGemCost = true end end if hasGemCost then local params = {} local itemCost = DataManager.SummonData:getSummonItemCost(self.page) local costId = itemCost.id local costNum = (count - DataManager.BagData.ItemData:getItemNumById(costId)) local gemCost = DataManager.SummonData:getSummonGemCost(self.page) local costGemNum = gemCost.num * costNum params.content = I18N:getGlobalText(I18N.GlobalConst.ITEM_NOT_ENOUGH_DESC, costGemNum, GFunc.getRewardName(GConst.REWARD_TYPE.ITEM, costId), costNum) params.boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL params.showToday = GConst.MESSAGE_BOX_SHOW_TODAY.SUMMON_FORCE params.okFunc = function() for i, cost in ipairs(costs) do if not GFunc.checkCost(cost.id, GFunc.getRewardNum(cost), true) then return end end AudioManager:playEffect(AudioManager.EFFECT_ID.UI_SUMMON_START) self:disableTouch() self.uiNode:setActive(false) ModuleManager.SummonManager:onForceSummonReq(count, 0, self.page) end GFunc.showMessageBox(params) return else for i, cost in ipairs(costs) do if not GFunc.checkCost(cost.id, GFunc.getRewardNum(cost), true) then return end end end AudioManager:playEffect(AudioManager.EFFECT_ID.UI_SUMMON_START) self:disableTouch() self.uiNode:setActive(false) ModuleManager.SummonManager:onForceSummonReq(count, 0, self.page) end end function SummonMainUI:onSummonRsp(result, newHero) self:refreshSummonBtn() if not result.rewards or not result.rewards[1] then self:enableTouch() self.uiNode:setActive(true) return end if self.aniSeq then self.aniSeq:Kill() self.aniSeq = nil end for i = 1, 4 do self.vfxs[i]:setActive(false) self.vfx01s[i]:setActive(false) self.vfx02s[i]:setActive(false) end local qlt = 3 for i, v in ipairs(result.rewards) do local id = v.item.id local q = DataManager.HeroData:getHeroQlt(id) qlt = math.max(qlt, q) end qlt = qlt - 2 self.summonResult = result.rewards self.aniSeq = self.root:createBindTweenSequence() if self.vfxs[qlt] then self.vfxs[qlt]:setActive(true) end self.aniSeq:AppendInterval(2) self.aniSeq:AppendCallback(function() self:showHero(1, newHero) end) end function SummonMainUI:showHero(idx, newHero) if not self.summonResult[idx] then self:enableTouch() self.uiNode:setActive(true) for i = 1, 4 do self.vfxs[i]:setActive(false) self.vfx01s[i]:setActive(false) self.vfx02s[i]:setActive(false) end ModuleManager.SummonManager:showSummonRewardUI({ rewards = self.summonResult, callback = function(count, isAd) self:onSummon(count, isAd) end, newHero = newHero, page = self.page }) return end for i = 1, 4 do self.vfx01s[i]:setActive(false) self.vfx02s[i]:setActive(false) end local id = self.summonResult[idx].item.id local cfg = DataManager.HeroData:getHeroConfig(id) local qlt = cfg.qlt - 2 self.heroNode:removeAllChildren() SpineManager:loadHeroAsync(cfg.model_id, self.heroNode, function(spineObject) spineObject:setActive(false) spineObject:playAnimation("idle", true) spineObject:setLocalScale(0.7, 0.7, 0.7) self.vfxBg:setActive(true) if self.vfx01s[qlt] then self.vfx01s[qlt]:setActive(true) end if self.vfx02s[qlt] then self.vfx02s[qlt]:setActive(true) end self:performWithDelayGlobal(function() spineObject:setActive(true) end, 0.25) self:performWithDelayGlobal(function() self:showHero(idx + 1, newHero) end, 1) end) end function SummonMainUI:disableTouch() self.touchNode:setActive(true) end function SummonMainUI:enableTouch() self.touchNode:setActive(false) end return SummonMainUI