2023-04-07 15:24:55 +08:00

507 lines
15 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local MainComp = class("MainComp", LuaComponent)
local BG_PREFIX = "assets/arts/textures/background/chapter/%s.png"
local PATTERN_ICON = {
[GConst.StageConst.CHAPTER_PATTERN.HARD] = {"common_menu_6", "common_decoration_16"},
[GConst.StageConst.CHAPTER_PATTERN.NORMAL] = {"common_menu_7", "common_decoration_15"}
}
function MainComp:refresh(childPage)
self.childPage = childPage
self.showLeftRed = false
self.showRightRed = false
self.showLeftSideBar = true
self.showRightSideBar = true
-- self:_display()
self:_addListeners()
end
function MainComp:_display()
local uiMap = self:getBaseObject():genAllChildren()
self.rightSideBarBg = uiMap["main_comp.right_node"]
self.leftSideBarBg = uiMap["main_comp.left_node"]
self.leftArrow = uiMap["main_comp.left_node.arrow"]
self.rightArrow = uiMap["main_comp.right_node.arrow"]
-- 宝箱相关
self.boxImg = uiMap["main_comp.box_touch_1"]
self.boxImgShadow = uiMap["main_comp.box_touch_1_shadow"]
self.boxShakeImg = uiMap["main_comp.box_touch_1.box_shakeImg"]
self.boxTx = uiMap["main_comp.box_tx"]
self.boxImgShadow:setActive(false)
self.boxImgShadow:setLocalScale(0.8,0.8,0.8)
self:refreshBoxShakeEff(true)
self.btnGM = uiMap["main_comp.gm_btn"]
self.btnGM:setVisible(not Platform:getIsPublishChannel(),2)
self.btnGM:addClickListener(function()
ModuleManager.DevToolManager:showOrHideDevListUI()
end)
-- self:refreshChapter()
-- self:refreshRedPoint()
end
function MainComp:_addListeners()
local uiMap = self:getBaseObject():genAllChildren()
-- 战斗按钮
uiMap["main_comp.hang_up_node.fight_btn"]:addClickListener(function()
self:onFightBtnClick()
end)
end
function MainComp:onFightBtnClick()
ModuleManager.BattleManager:playBattle(nil, GConst.BattleConst.BATTLE_TYPE.STAGE)
end
function MainComp:onClickPattern()
local chapterId = DataManager.StageData:getChapterId()
local pattern = DataManager.StageData:getChapterPattern(chapterId)
if self.childPage then
pattern = self.childPage
self.childPage = nil
elseif pattern == GConst.StageConst.CHAPTER_PATTERN.HARD then
pattern = GConst.StageConst.CHAPTER_PATTERN.NORMAL
else
pattern = GConst.StageConst.CHAPTER_PATTERN.HARD
end
local maxId = DataManager.StageData:getMaxChapterId(pattern)
local maxCfg = ConfigManager:getConfig("chapter")[maxId]
if maxCfg and maxCfg.next_chapter then
maxId = maxCfg.next_chapter
elseif not maxCfg and pattern == GConst.StageConst.CHAPTER_PATTERN.HARD then
maxId = DataManager.StageData:getDefaultHardId()
elseif not maxCfg then
maxId = DataManager.StageData:getDefaultId()
end
DataManager.StageData:changeChapterId(maxId)
self:_display()
end
function MainComp:refreshChapter()
local curId = DataManager.StageData:getChapterId()
local pattern = DataManager.StageData:getChapterPattern(curId)
local cfg = ConfigManager:getConfig("chapter")[curId]
local uiMap = self:getBaseObject():genAllChildren()
self:initHardChapterUI(uiMap, pattern, cfg)
self:initFightBtn(uiMap, cfg.cost)
self:setChapterTxtUI(uiMap, curId)
uiMap["main_comp.box_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.CHAPTER_BOX_TITLE))
uiMap["main_comp.chapter_img"]:setTexture(string.format(BG_PREFIX, cfg.scenes.."_main"))
self:refreshBoxShakeEff()
end
--endregion
--region UI初始化
function MainComp:refreshBoxShakeEff(onlyKill)
self.boxShakeImg:setLocalRotation(0,0,0)
-- GFunc.getShakeSeqRotate(self.boxShakeImg,nil)
end
function MainComp:initFightBtn(uiMap,cost)
local btnTx = I18N:getGlobalText(I18N.GlobalConst.CONTINUE_DESC)
uiMap["main_comp.hang_up_node.fight_btn.desc"]:setText(btnTx)
uiMap["main_comp.hang_up_node.fight_btn.desc_2"]:setText(cost)
end
function MainComp:initHardChapterUI(uiMap, pattern, cfg)
--暂时屏蔽困难按钮
if true then
uiMap["main_comp.hard_btn"]:setVisible(false)
return
end
local hardBtn = uiMap["main_comp.hard_btn"]
local atmosphereNode = uiMap["main_comp.atmosphere_node"]
atmosphereNode:setVisible(false)
if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.HARD_STAGE, true) then
hardBtn:setVisible(true)
local text = uiMap["main_comp.hard_btn.desc"]
local kulou = uiMap["main_comp.hard_btn.kulo_img"]
if pattern == GConst.StageConst.CHAPTER_PATTERN.NORMAL then
atmosphereNode:setVisible(false)
text:setText(I18N:getGlobalText(I18N.GlobalConst.HARD_DESC))
elseif pattern == GConst.StageConst.CHAPTER_PATTERN.HARD then
atmosphereNode:setVisible(true)
text:setText(I18N:getGlobalText(I18N.GlobalConst.SIMPLY_DESC))
if cfg and cfg.scenes_a then
uiMap["main_comp.atmosphere_node.top"]:setTexture("assets/arts/textures/background/main/" .. cfg.scenes_a .. ".png")
end
end
if PATTERN_ICON[pattern] then
hardBtn:setSprite(GConst.ATLAS_PATH.COMMON, PATTERN_ICON[pattern][1])
kulou:setSprite(GConst.ATLAS_PATH.COMMON, PATTERN_ICON[pattern][2])
end
else
hardBtn:setVisible(false)
end
end
function MainComp:setChapterTxtUI(uiMap,curChapterId)
uiMap["main_comp.chapter_name"]:setText(I18N:getConfig("chapter")[curChapterId].name)
local chapterPassedTx = uiMap["main_comp.chapter_passed"]
local info = DataManager.StageData:getChapterInfo(curChapterId)
local content = ""
if info.passed then
content = I18N:getGlobalText(I18N.GlobalConst.ALREADY_PASS_DESC)
else
local wave = info.bestWave or 0
content = I18N:getGlobalText(I18N.GlobalConst.PASS_DESC_2, wave.."/"..self:getMaxWave())
end
chapterPassedTx:setText(content)
end
function MainComp:getMaxWave()
local chapterId = DataManager.StageData:getChapterId()
self.generateSteps = DataManager.StageData:getChapterGenMonsterSteps(chapterId) or GConst.EMPTY_TABLE
self.generateChapterCfg = ConfigManager:getConfig("chapter")[chapterId]
self.generateStageCfg = ConfigManager:getConfig("story_stage")
local maxWave = 0
for i,v in ipairs(self.generateChapterCfg.stage) do
local stageCfg = self.generateStageCfg[v]
if stageCfg and stageCfg.wave_type ~= GConst.BattleConst.STEP_TYPE.ROUGE and not stageCfg.is_tutorial then
maxWave = maxWave + 1
end
end
return maxWave
end
function MainComp:calcLeftBarIconPos(leftNum)
local maxColumnNum = self:getMaxColumnNum()
local w = 104
local h = 0
local showArrow = false--leftNum > 2
if leftNum <= maxColumnNum then
if showArrow then
h = 104 * leftNum + 84
else
h = 104 * leftNum + 28
end
else
w = 208
h = 104 * maxColumnNum
end
self.leftArrow:removeRedPoint()
if not self.showLeftSideBar then
if leftNum > 2 then
h = 104 + 84
else
h = 104 + 28
end
if self.showLeftRed then
self.leftArrow:addRedPoint(12, 8, 0.5)
end
end
self.leftArrow:setAnchoredPositionX(47)
if leftNum <= maxColumnNum or not self.showLeftSideBar then
self.leftArrow:setAnchoredPositionX(0)
end
self.leftArrow:setActive(showArrow)
self.leftSideBarBg:setSizeDelta(w, h)
if leftNum <= 0 then
self.leftSideBarBg:setVisible(false)
else
self.leftSideBarBg:setVisible(true)
end
end
function MainComp:calcRightBarIconPos(rightNum)
local maxColumnNum = self:getMaxColumnNum()
local w = 104
local h = 0
local showArrow = false--rightNum > 2
if rightNum <= maxColumnNum then
if showArrow then
h = 104 * rightNum + 84
else
h = 104 * rightNum + 28
end
else
w = 208
h = 104 * maxColumnNum
end
self.rightArrow:removeRedPoint()
if not self.showRightSideBar then
w = 104
if rightNum > 2 then
h = 104 + 84
else
h = 104 + 28
end
if self.showRightRed then
self.rightArrow:addRedPoint(12, 8, 0.5)
end
end
self.rightArrow:setAnchoredPositionX(-47)
if rightNum <= maxColumnNum or not self.showRightSideBar then
self.rightArrow:setAnchoredPositionX(0)
end
self.rightArrow:setVisible(showArrow)
self.rightSideBarBg:setSizeDelta(w, h)
if rightNum <= 0 then
self.rightSideBarBg:setVisible(false)
else
self.rightSideBarBg:setVisible(true)
end
end
function MainComp:getMaxColumnNum()
if not self.maxColumnNum then
local screenOffsetY = GFunc.calculateFitSizeY()
self.maxColumnNum = 5 + screenOffsetY // 104
end
return self.maxColumnNum
end
function MainComp:getSideBtnPos(btnNum, offsetY, isRight)
local x = 0
local y = offsetY
local maxColumnNum = self:getMaxColumnNum()
btnNum = btnNum + 1
if btnNum < maxColumnNum then
offsetY = offsetY - 104
else
local num = btnNum - maxColumnNum
if num > 0 then
if not isRight then
x = 99
else
x = -99
end
end
offsetY = -47.5 - num * 104
end
return offsetY, btnNum, x, y
end
function MainComp:initFirstRechargeUI(offsetLy, leftNum, x, y)
-- 首充礼包
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.FIRST_CHARGE, true) or DataManager.ActivityGiftData:isFirstGiftClaimed() then
GFunc.getShakeSeq(self.firstRechargeBtn, true)
self.firstRechargeBtn:setVisible(false)
else
if (not DataManager.ActivityGiftData:getCheckUI(GConst.ActivityConst.CHECK_UI.firstRecharge)) and self.showLeftSideBar then
GFunc.getShakeSeq(self.firstRechargeBtn, nil, 1, true)
else
GFunc.getShakeSeq(self.firstRechargeBtn, true)
end
offsetLy, leftNum, x, y = self:getSideBtnPos(leftNum, offsetLy)
self.firstRechargeBtn:setVisible(true)
if (not self.showLeftSideBar) and leftNum > 1 then
self.firstRechargeBtn:setVisible(false)
end
self.firstRechargeBtn:setAnchoredPosition(x, y)
end
return offsetLy, leftNum, x, y
end
function MainComp:initDcBtnUI(offsetLy, leftNum, x, y)
if CS.BF.BFMain.IsShenhe then
return offsetLy, leftNum, x, y
end
offsetLy, leftNum, x, y = self:getSideBtnPos(leftNum, offsetLy)
self.dcBtn:setVisible(true)
if (not self.showLeftSideBar) and leftNum > 1 then
GFunc.getShakeSeqRotate(self.dcIcon,true)
self.dcBtn:setVisible(false)
else
GFunc.getShakeSeqRotate(self.dcIcon,nil, true)
end
self.dcBtn:setAnchoredPosition(x, y)
return offsetLy, leftNum, x, y
end
--endregion
--region 右侧按钮排版
function MainComp:initLvCardUI(offsetY, rightNum, x, y)
-- 成长基金
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.ACT_LEVEL_GIFT, true) or DataManager.ActivityGiftData:isLvGiftFinish() then
GFunc.getShakeSeq(self.lvGiftBtn, true)
self.lvGiftBtn:setVisible(false)
else
if (not DataManager.ActivityGiftData:isLvGiftOpen()) and self.showRightSideBar then
if not DataManager.ActivityGiftData:getCheckUI(GConst.ActivityConst.CHECK_UI.lvGift) then
GFunc.getShakeSeq(self.lvGiftBtn, nil, 1, true)
else
GFunc.getShakeSeq(self.lvGiftBtn, true)
end
else
if DataManager.ActivityGiftData:showLvGiftRedPoint() and self.showRightSideBar then
GFunc.getShakeSeq(self.lvGiftBtn, nil, 1, true)
else
GFunc.getShakeSeq(self.lvGiftBtn, true)
end
end
offsetY, rightNum, x, y = self:getSideBtnPos(rightNum, offsetY, true)
self.lvGiftBtn:setVisible(true)
if (not self.showRightSideBar) and rightNum > 1 then
self.lvGiftBtn:setVisible(false)
end
self.lvGiftBtn:setAnchoredPosition(x, y)
end
return offsetY, rightNum, x, y
end
function MainComp:initTaskUI(offsetY, rightNum, x, y)
if CS.BF.BFMain.IsShenhe then
self.taskBtn:setActive(false)
self.boxImg:setAnchoredPositionX(0)
self.boxTx:setAnchoredPositionX(0)
self.boxImgShadow:setAnchoredPositionX(0)
return offsetY, rightNum, x, y
end
-- 任务 开启后常驻
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.TASK, true) then
GFunc.getShakeSeq(self.taskBtn, true)
self.taskBtn:setVisible(false)
else
if DataManager.TaskData:showRedPoint() and self.showRightSideBar then
GFunc.getShakeSeq(self.taskBtn, nil, 1, true)
else
GFunc.getShakeSeq(self.taskBtn, true)
end
offsetY, rightNum, x, y = self:getSideBtnPos(rightNum, offsetY, true)
self.taskBtn:setVisible(true)
if (not self.showRightSideBar) and rightNum > 1 then
self.taskBtn:setVisible(false)
end
self.taskBtn:setAnchoredPosition(x, y)
end
return offsetY, rightNum, x, y
end
function MainComp:initPopGiftUI(offsetY, rightNum, x, y)
if #self.popData <= 0 then
GFunc.getShakeSeq(self.popGiftBtn, true)
self.popGiftBtn:setVisible(false)
else
self.popGiftBtn:setVisible(true)
self.popGiftBtn:setAnchoredPositionY(offsetY)
if #self.popData > 0 then
GFunc.getShakeSeq(self.popGiftBtn, nil, 1, true)
else
GFunc.getShakeSeq(self.popGiftBtn, true)
end
offsetY, rightNum, x, y = self:getSideBtnPos(rightNum, offsetY, true)
end
return offsetY, rightNum, x, y
end
function MainComp:updateTime()
self:refreshPopUI()
self:refreshRedPoint()
end
function MainComp:refreshPopUI()
if self.popData and #self.popData > 0 then
local data = self.popData[1]
local nowTime = Time:getServerTime()
local endTime = data.endTime or 0
if nowTime > endTime then
self.popData = DataManager.ActivityGiftData:getPopGiftData()
self.popGiftCd:setText("")
return
end
self.popGiftCd:setText(GFunc.getTimeStrWithHMS(endTime - nowTime))
end
end
--region 红点
function MainComp:refreshRedPoint()
-- self.boxRedPoint = self:chapterBoxRedPoint()
-- -- 两侧按钮
-- self.showLeftRed = self:showLeftRedPoint()
-- self.showRightRed = self:showRightRedPoint()
end
function MainComp:getIsShowRedPoint()
return self.boxRedPoint or self.showLeftRed or self.showRightRed
end
function MainComp:showLeftRedPoint()
local sevenDayRed = self:showSevenDayRedPoint()
local rechargeRed = self:refreshFirstRechargeRedPoint()
return sevenDayRed or rechargeRed
end
function MainComp:showRightRedPoint()
local lvGiftRedPoint = self:refreshLvGiftRedPoint()
local taskRedPoint = self:refreshTaskRedPoint()
return lvGiftRedPoint or taskRedPoint
end
function MainComp:showSevenDayRedPoint()
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.ACT_SEVENDAY, true) then
return false
end
return DataManager.SevenDayData:getRedPoint()
end
function MainComp:chapterBoxRedPoint()
-- local showRedPoint = DataManager.StageData:showMainCompRedPoint()
-- if showRedPoint then
-- self.boxImg:addRedPoint(58, 46, 0.8)
-- GFunc.getShakeSeqRotate(self.boxShakeImg,nil, true)
-- else
-- self.boxImg:removeRedPoint()
-- GFunc.getShakeSeqRotate(self.boxShakeImg,true)
-- end
-- return showRedPoint
end
function MainComp:refreshLvGiftRedPoint()
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.ACT_LEVEL_GIFT, true) then
return false
end
local giftHallNeedRp = false
if DataManager.ActivityGiftData:showLvGiftRedPoint() then
self.lvGiftBtn:addRedPoint(30, 30, 0.6)
giftHallNeedRp = true
else
self.lvGiftBtn:removeRedPoint()
end
return giftHallNeedRp
end
function MainComp:refreshFirstRechargeRedPoint()
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.FIRST_CHARGE, true) then
return false
end
if DataManager.ActivityGiftData:canClaimFirstGift() then
self.firstRechargeBtn:addRedPoint(30, 30, 0.6)
return true
else
self.firstRechargeBtn:removeRedPoint()
end
end
function MainComp:refreshTaskRedPoint()
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.TASK, true) then
return false
end
if DataManager.TaskData:showRedPoint() then
self.taskBtn:addRedPoint(30, 30, 0.6)
return true
else
self.taskBtn:removeRedPoint()
end
return false
end
--endregion
return MainComp