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 self._bgVfxMap = {} end function SummonMainUI:getPrefabPath() return "assets/prefabs/ui/summon/summon_main_ui.prefab" end function SummonMainUI:currencyParams() 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_QLT_5_FRAGMENT, } else params.itemIds = { ItemConst.ITEM_ID_GOLD, ItemConst.ITEM_ID_GEM, ItemConst.SUMMON_ACT_STONE, } end return params, true end function SummonMainUI:onClose() if self._bgVfxMap then for k, v in pairs(self._bgVfxMap) do v:destroy() end self._bgVfxMap = nil end 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.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.toggleJump = uiMap["summon_main_ui.jump_tween"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TOGGLE) -- self.isJumpTween = self.toggleJump.isOn -- self.toggleJump.onValueChanged:AddListener(function(isOn) self.isJumpTween = isOn end) self.touchNode = uiMap["summon_main_ui.node.touch_node"] self.touchNode:setActive(false) -- uiMap["summon_main_ui.jump_tween"]:setActive(false) -- self.vfx_b13_ui_chouka_bg_b01 = uiMap["summon_main_ui.vfx_b13_ui_chouka_bg_b01"] -- self.wishMask = uiMap["summon_main_ui.node.btn_wish.unlock.mask"] -- self.wishQlt = uiMap["summon_main_ui.node.btn_wish.unlock.qlt"] -- self.wishMaskSlider = uiMap["summon_main_ui.node.btn_wish.unlock.mask"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE) -- self.descTx = uiMap["summon_main_ui.btn_wish.desc_tx"] -- self.descTx = uiMap["summon_main_ui.btn_info.desc_tx"] -- self.descTx = uiMap["summon_main_ui.jump_tween.desc_tx"] self.btnSummonFree:addClickListener(function() self:onSummon(1) end) self.btnSummonOne:addClickListener(function() self:onSummon(1) end) self.btnSummonTen:addClickListener(function() self:onSummon(10) end) uiMap["summon_main_ui.node.btn_info"]:addClickListener(function() ModuleManager.SummonManager:showSummonOddsUI() 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_THIS_TIME_DESC)) uiMap["summon_main_ui.node.btn_summon_free.desc_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.SUMMON_DESC_22)) 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.spineHero = {} -- for i = 1, 3 do -- self.spineHero[i] = uiMap['summon_main_ui.ui_spine_obj_'..i] -- if i ~= 1 then -- self.spineHero[i]:setDefaultMix(0) -- end -- end -- self.heroTips = {} -- for i = 1, 2 do -- self.heroTips[i] = {} -- self.heroTips[i].tips = uiMap['summon_main_ui.node.hero_'..i] -- self.heroTips[i].txName = uiMap['summon_main_ui.node.hero_'..i..'.tx_hero_name'] -- self.heroTips[i].txDesc = uiMap['summon_main_ui.node.hero_'..i..'.tx_hero_desc'] -- end self.btnTxs = { I18N:getGlobalText(I18N.GlobalConst.TASK_DAILY), I18N:getGlobalText(I18N.GlobalConst.TASK_CHALLENGE), } 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, newForce) self:refreshWishBtn() self:onSummonRsp(result, newForce) end) self:addEventListener(EventManager.CUSTOM_EVENT.FORCE_SUMMON_WISH_CLAIM, function(result, newForce) self:refreshWishBtn() ModuleManager.SummonManager:showSummonRewardUI({ rewards = result.rewards, isWish = true, newForce = newForce, 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:getSummonWishGuarantee(self.page) local wishCount = DataManager.SummonData:getSummonWishCount(self.page) if wishCount >= wishGuarantee and wishHeroId ~= 0 then --发送领取奖励的协议 ModuleManager.SummonManager:onSummonWishClaimReq() 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:refreshWishBtn() 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))) end end --刷新 function SummonMainUI:onRefresh() self:refreshSummonBtn() self:refreshWishBtn() -- self:refreshBtnRedPoint() self:refreshPageBtn() 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") -- self.pageBtnTxs[i]:setText(self.btnTxs[i]) else self.pageBtns[i]:setSprite(GConst.ATLAS_PATH.ACT_COMMON, "act_common_btn_" .. i .."_2") -- self.pageBtnTxs[i]:setText("" .. self.btnTxs[i] .. "") end end -- for i, v in ipairs(self.pageBtns) do -- if i <= table.nums(summonList) then -- local isRedPoint = false -- if i == 1 then -- if DataManager.SummonData:hasSummonFree(1) or GFunc.checkCost(GConst.ItemConst.ITEM_ID_QLT_5_FRAGMENT, 1, false) then -- isRedPoint = true -- end -- else -- local itemCost = DataManager.SummonData:getSummonItemCost(summonList[i]) -- if itemCost then -- local costId = GFunc.getRewardId(itemCost) -- local costNum = GFunc.getRewardNum(itemCost) -- if GFunc.checkCost(costId, costNum, false) then -- isRedPoint = true -- end -- end -- end -- if isRedPoint then -- v.btn:addRedPoint(33, 33, 1) -- else -- v.btn:removeRedPoint() -- end -- else -- v.btn:setActive(false) -- end -- end end --刷新抽奖按钮 function SummonMainUI:refreshSummonBtn() local isFree = DataManager.SummonData:hasSummonFree(self.page) self.btnSummonFree:setActive(isFree) self.btnSummonOne:setActive(not isFree) -- self.txFreeTime:setActive(not isFree and not DataManager.SummonData:getIsActivity()) local itemCost = DataManager.SummonData:getSummonItemCost(self.page) local costId = itemCost.id local costNum = itemCost.num local hadNum = DataManager.BagData.ItemData:getItemNumById(costId) local obj = DataManager.BagData.ItemData:getItemById(costId) if hadNum >= 1 then self.txNumOne:setText(1) self.btnSummonOne:addRedPoint(124, 33, 1) self.imgSummonOneIcon:setSprite(ModuleManager.ItemManager:getItemIcon(costId)) else self.btnSummonOne:removeRedPoint() -- if DataManager.SummonData:getIsActivity() then -- --是活动 -- self.txNumOne:setText("1") -- self.imgSummonOneIcon:setSprite(ModuleManager.ItemManager:getItemIcon(costId)) -- else 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 obj = DataManager.BagData.ItemData:getItemById(costId) if hadNum >= 10 then self.txNumTen:setText(10) self.imgSummonTenIcon:setSprite(ModuleManager.ItemManager:getItemIcon(costId)) self.btnSummonTen:addRedPoint(124, 33, 1) else self.btnSummonTen:removeRedPoint() -- if DataManager.SummonData:getIsActivity() then -- --是活动 -- self.txNumTen:setText("10") -- self.imgSummonTenIcon:setSprite(ModuleManager.ItemManager:getItemIcon(costId)) -- else 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 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 -- self.wishUnlock:setActive(self.isUnlock) -- self.wishLock:setActive(not self.isUnlock) -- if self.isUnlock then -- local wishHeroId = DataManager.SummonData:getSummonWishHeroId() -- if wishHeroId ~= 0 then -- local modelId = DataManager.ForceData:getForceModelId(wishHeroId) -- local qlt = DataManager.ForceData:getForceQlt(wishHeroId) -- self.wishQlt:setActive(true) -- self.wishQlt:setSprite(GConst.ATLAS_PATH.ICON_ITEM, DataManager.ForceData:getForceQltItem(qlt)) -- if self.wishModelId ~= modelId then -- self.wishModelId = modelId -- end -- if self.wishModelId ~= nil then -- self.imgWishIcon:setActive(true) -- self.imgWishIcon:setSprite(GConst.ATLAS_PATH.ICON_ITEM, DataManager.ForceData:getForceFightIcon(wishHeroId)) -- else -- self.imgWishIcon:setActive(false) -- end -- isAddRedPoint = false -- else -- self.wishQlt:setActive(false) -- self.imgWishIcon:setActive(false) -- isAddRedPoint = true -- end -- local wishGuarantee = DataManager.SummonData:getSummonWishGuarantee() -- local wishCount = DataManager.SummonData:getSummonWishCount() -- if wishCount >= wishGuarantee then -- self.btnWish:addRedPoint(124, 33, 1) -- self.txGuarantee:setText(I18N:getGlobalText(I18N.GlobalConst.SUMMON_GET)) -- isAddRedPoint = true -- self.wishMask:setActive(false) -- else -- if wishHeroId ~= 0 then -- self.wishMask:setActive(true) -- else -- self.wishMask:setActive(false) -- end -- self.txGuarantee:setText(wishCount .. "/" .. wishGuarantee) -- self.wishMaskSlider.fillAmount = 1 - (wishCount / wishGuarantee) -- end -- else -- isAddRedPoint = false -- self.btnWish:removeRedPoint() -- self.txUnlock:setText(summonCount .. "/" .. unlockCount .. I18N:getGlobalText(I18N.GlobalConst.MAGIC_BOOK_DESC_4)) -- end -- if isAddRedPoint then -- self.btnWish:addRedPoint(33, 33, 1) -- else -- self.btnWish:removeRedPoint() -- 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) local isFree = DataManager.SummonData:hasSummonFree(self.page) if isFree and count == 1 then AudioManager:playEffect(AudioManager.EFFECT_ID.UI_SUMMON_START) ModuleManager.SummonManager:onForceSummonReq(count, true) else 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, 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) ModuleManager.SummonManager:onForceSummonReq(count, false, 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) ModuleManager.SummonManager:onForceSummonReq(count, false, self.page) end end function SummonMainUI:onSummonRsp(result, newForce) self:refreshSummonBtn() self.summonResult = result if self.isJumpTween or self.selectSpineId ~= 1 then ModuleManager.SummonManager:showSummonRewardUI({ rewards = self.summonResult.rewards, callback = function(count) self:onSummon(count) end, newForce = newForce, page = self.page }) else self:disableTouch() self.selectSpine:playAnimComplete("open01", false, true, function() self.selectSpine:playAnim("idle02", true, false) end, false, 0.4, function() ModuleManager.SummonManager:showSummonRewardUI({ rewards = self.summonResult.rewards, callback = function(count) self:onSummon(count) end, tweenEnd = function() self:enableTouch() self.selectSpine:playAnim("idle01", true, false) end, newForce = newForce, page = self.page }) end) end end function SummonMainUI:disableTouch() self.touchNode:setActive(true) end function SummonMainUI:enableTouch() self.touchNode:setActive(false) end return SummonMainUI