From b6936a2c4a7d59d55ba889ebb93b1a22dcba590c Mon Sep 17 00:00:00 2001 From: Fang Date: Fri, 2 Jun 2023 15:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E8=A7=A3=E9=94=81=E9=A3=9E?= =?UTF-8?q?=E8=A1=8C=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/bf/unity/base_object.lua | 5 + lua/app/module/maincity/maincity_manager.lua | 57 +++++++++ .../ui/main_city/cell/side_bar_base_cell.lua | 19 +++ .../cell/side_bar_beginner_gift_cell.lua | 4 + .../cell/side_bar_first_recharge_cell.lua | 4 + .../main_city/cell/side_bar_gold_pig_cell.lua | 4 + .../cell/side_bar_growth_fund_cell.lua | 4 + .../ui/main_city/cell/side_bar_idle_cell.lua | 4 + .../cell/side_bar_seven_days_cell.lua | 4 + lua/app/ui/main_city/component/main_comp.lua | 37 ++++-- lua/app/ui/main_city/main_city_ui.lua | 61 ++++++++- lua/app/ui/main_city/module_unlock_ui.lua | 118 +++++++++++++----- lua/app/userdata/activity/activity_data.lua | 1 - 13 files changed, 278 insertions(+), 44 deletions(-) diff --git a/lua/app/bf/unity/base_object.lua b/lua/app/bf/unity/base_object.lua index a1d055bd..6af513ca 100644 --- a/lua/app/bf/unity/base_object.lua +++ b/lua/app/bf/unity/base_object.lua @@ -259,6 +259,11 @@ function BaseObject:addPosition(x, y, z) transform.position = Vector3 end +function BaseObject:getPosition() + local transform = self:getTransform() + return transform.position +end + function BaseObject:getLocalPosition() local transform = self:getTransform() return transform.localPosition diff --git a/lua/app/module/maincity/maincity_manager.lua b/lua/app/module/maincity/maincity_manager.lua index 8276f98f..f4ab3c67 100644 --- a/lua/app/module/maincity/maincity_manager.lua +++ b/lua/app/module/maincity/maincity_manager.lua @@ -26,7 +26,13 @@ function MaincityManager:firstEnterMainCity() end function MaincityManager:changeMainCityLeftSideBarOpenOrClose() + local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI) + if not mainUI then + return nil + end + self.isLeftSideBarClose = not self.isLeftSideBarClose + mainUI:refreshLeftBtns() end function MaincityManager:getIsMainCityLeftSideBarClose() @@ -34,11 +40,62 @@ function MaincityManager:getIsMainCityLeftSideBarClose() end function MaincityManager:changeMainCityRightSideBarOpenOrClose() + local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI) + if not mainUI then + return nil + end + self.isRightSideBarClose = not self.isRightSideBarClose + mainUI:refreshRightBtns() end function MaincityManager:getIsMainCityRightSideBarClose() return self.isRightSideBarClose end +-- 获取主界面各个模块的入口坐标 +function MaincityManager:getModuleEntrancePos(moduleKey) + local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI) + if not mainUI then + return nil + end + + if moduleKey == ModuleManager.MODULE_KEY.TASK then + return mainUI:getTaskIconPos() + elseif moduleKey == ModuleManager.MODULE_KEY.MALL_DAILY then + return mainUI:getMallIconPos() + elseif moduleKey == ModuleManager.MODULE_KEY.DAILY_CHALLENGE then + return mainUI:getDailyChallengeIconPos() + elseif moduleKey == ModuleManager.MODULE_KEY.FUND or + moduleKey == ModuleManager.MODULE_KEY.IDLE_DROP or + moduleKey == ModuleManager.MODULE_KEY.SEVEN_DAY then + return mainUI:getSideBarActIconPos(moduleKey) + end +end + +-- 模块在侧边栏,-1:左,0:不在侧边栏,1:右 +function MaincityManager:getModuleInSideBarWhere(moduleKey) + local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI) + if not mainUI then + return nil + end + + if self.mainCityUI:isInSideBarLeft(moduleKey) then + return -1 + elseif self.mainCityUI:isInSideBarRight(moduleKey) then + return 1 + else + return 0 + end +end + +function MaincityManager:isActivSideBarModule(moduleKey) + local mainUI = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI) + if not mainUI then + return nil + end + + return self.mainCityUI:isActivSideBarModule(moduleKey) +end + return MaincityManager \ No newline at end of file diff --git a/lua/app/ui/main_city/cell/side_bar_base_cell.lua b/lua/app/ui/main_city/cell/side_bar_base_cell.lua index 6a5ea157..2d254b78 100644 --- a/lua/app/ui/main_city/cell/side_bar_base_cell.lua +++ b/lua/app/ui/main_city/cell/side_bar_base_cell.lua @@ -5,6 +5,12 @@ local DEFAULT_RED_POINT_POS_Y = 30 local DEFAULT_RED_POINT_SCALE = 0.6 -- 需要继承重写的部分 *********************************************************** + +-- 模块key值,对应ModuleManager.MODULE_KEY +function SideBarBaseCellComp:getModuleKey() + return nil +end + function SideBarBaseCellComp:getIsOpen() return false end @@ -142,6 +148,19 @@ function SideBarBaseCellComp:setVisible(visible) end end +function SideBarBaseCellComp:getIsVisible() + return self.visible +end + +function SideBarBaseCellComp:getEntrancePos() + if self:getIconRes() then + return self.icon:getPosition() + elseif self:getSpineName() then + return self.spine:getPosition() + end + return nil +end + function SideBarBaseCellComp:getCellPath() return self.cellPath end diff --git a/lua/app/ui/main_city/cell/side_bar_beginner_gift_cell.lua b/lua/app/ui/main_city/cell/side_bar_beginner_gift_cell.lua index 5fcfbc4f..6738e77a 100644 --- a/lua/app/ui/main_city/cell/side_bar_beginner_gift_cell.lua +++ b/lua/app/ui/main_city/cell/side_bar_beginner_gift_cell.lua @@ -1,6 +1,10 @@ local SideBarBaseCellComp = require "app/ui/main_city/cell/side_bar_base_cell" local SideBarBeginnerGiftCell = class("SideBarBeginnerGiftCell", SideBarBaseCellComp) +function SideBarBeginnerGiftCell:getModuleKey() + return ModuleManager.MODULE_KEY.BEGINNER_GIFT +end + function SideBarBeginnerGiftCell:getIsOpen() return DataManager.ShopData:getBeginnerGiftShowSideBar() end diff --git a/lua/app/ui/main_city/cell/side_bar_first_recharge_cell.lua b/lua/app/ui/main_city/cell/side_bar_first_recharge_cell.lua index ec4da44b..b952199a 100644 --- a/lua/app/ui/main_city/cell/side_bar_first_recharge_cell.lua +++ b/lua/app/ui/main_city/cell/side_bar_first_recharge_cell.lua @@ -1,6 +1,10 @@ local SideBarBaseCellComp = require "app/ui/main_city/cell/side_bar_base_cell" local SideBarFirstRechargeCell = class("SideBarFirstRechargeCell", SideBarBaseCellComp) +function SideBarFirstRechargeCell:getModuleKey() + return ModuleManager.MODULE_KEY.FIRST_RECHARGE +end + function SideBarFirstRechargeCell:getIsOpen() return DataManager.ShopData:getShowFirstRechargeSideBar() end diff --git a/lua/app/ui/main_city/cell/side_bar_gold_pig_cell.lua b/lua/app/ui/main_city/cell/side_bar_gold_pig_cell.lua index eadb6a0a..1d8e9446 100644 --- a/lua/app/ui/main_city/cell/side_bar_gold_pig_cell.lua +++ b/lua/app/ui/main_city/cell/side_bar_gold_pig_cell.lua @@ -1,6 +1,10 @@ local SideBarBaseCellComp = require "app/ui/main_city/cell/side_bar_base_cell" local SideBarGoldPigCell = class("SideBarGoldPigCell", SideBarBaseCellComp) +function SideBarGoldPigCell:getModuleKey() + return ModuleManager.MODULE_KEY.GOLD_PIG +end + function SideBarGoldPigCell:getIsOpen() return DataManager.GoldPigData:getIsOpen() end diff --git a/lua/app/ui/main_city/cell/side_bar_growth_fund_cell.lua b/lua/app/ui/main_city/cell/side_bar_growth_fund_cell.lua index 6bf5f779..9e8d4ad6 100644 --- a/lua/app/ui/main_city/cell/side_bar_growth_fund_cell.lua +++ b/lua/app/ui/main_city/cell/side_bar_growth_fund_cell.lua @@ -1,6 +1,10 @@ local SideBarBaseCellComp = require "app/ui/main_city/cell/side_bar_base_cell" local SideBarGrowthFundCell = class("SideBarGrowthFundCell", SideBarBaseCellComp) +function SideBarGrowthFundCell:getModuleKey() + return ModuleManager.MODULE_KEY.FUND +end + function SideBarGrowthFundCell:getIsOpen() return DataManager.GrowthFundData:getIsOpen() end diff --git a/lua/app/ui/main_city/cell/side_bar_idle_cell.lua b/lua/app/ui/main_city/cell/side_bar_idle_cell.lua index c3c2e277..6b659715 100644 --- a/lua/app/ui/main_city/cell/side_bar_idle_cell.lua +++ b/lua/app/ui/main_city/cell/side_bar_idle_cell.lua @@ -1,6 +1,10 @@ local SideBarBaseCellComp = require "app/ui/main_city/cell/side_bar_base_cell" local SideBarIdleCell = class("SideBarIdleCell", SideBarBaseCellComp) +function SideBarIdleCell:getModuleKey() + return ModuleManager.MODULE_KEY.IDLE_DROP +end + function SideBarIdleCell:getIsOpen() return DataManager.IdleData:getIsOpen() end diff --git a/lua/app/ui/main_city/cell/side_bar_seven_days_cell.lua b/lua/app/ui/main_city/cell/side_bar_seven_days_cell.lua index ab2ef947..fb1dbc22 100644 --- a/lua/app/ui/main_city/cell/side_bar_seven_days_cell.lua +++ b/lua/app/ui/main_city/cell/side_bar_seven_days_cell.lua @@ -1,6 +1,10 @@ local SideBarBaseCellComp = require "app/ui/main_city/cell/side_bar_base_cell" local SideBarSevenDaysCell = class("SideBarSevenDaysCell", SideBarBaseCellComp) +function SideBarSevenDaysCell:getModuleKey() + return ModuleManager.MODULE_KEY.SEVEN_DAY +end + function SideBarSevenDaysCell:getIsOpen() return DataManager.SevenDayData:getIsOpen() end diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index 59d1bed1..9ce7880c 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -71,8 +71,10 @@ function MainComp:refreshFightBtn() end function MainComp:refreshLeftBtn() - local leftBtn = self.uiMap["main_comp.left_btn"] - leftBtn:setActive(false) + if self.leftBtn == nil then + self.leftBtn = self.uiMap["main_comp.left_btn"] + end + self.leftBtn:setActive(false) local leftIdx = self:getCurLeftModuleIdx() if leftIdx == nil then @@ -83,23 +85,25 @@ function MainComp:refreshLeftBtn() return end - leftBtn:setActive(true) + self.leftBtn:setActive(true) local iconAtlas, iconName = moduleCell:getEntranceIcon() self.uiMap["main_comp.left_btn.desc"]:setText(moduleCell:getEntranceName()) self.uiMap["main_comp.left_btn.icon"]:setSprite(iconAtlas, iconName) - leftBtn:addClickListener(function() + self.leftBtn:addClickListener(function() self:refreshModule(leftIdx) end) if moduleCell:getShowEntranceRedPoint() then - leftBtn:addRedPoint(65, 35, 0.6) + self.leftBtn:addRedPoint(65, 35, 0.6) else - leftBtn:removeRedPoint() + self.leftBtn:removeRedPoint() end end function MainComp:refreshRightBtn() - local rightBtn = self.uiMap["main_comp.right_btn"] - rightBtn:setActive(false) + if self.rightBtn == nil then + self.rightBtn = self.uiMap["main_comp.right_btn"] + end + self.rightBtn:setActive(false) local rightIdx = self:getCurRightModuleIdx() if rightIdx == nil then @@ -110,17 +114,17 @@ function MainComp:refreshRightBtn() return end - rightBtn:setActive(true) + self.rightBtn:setActive(true) local iconAtlas, iconName = moduleCell:getEntranceIcon() self.uiMap["main_comp.right_btn.desc"]:setText(moduleCell:getEntranceName()) self.uiMap["main_comp.right_btn.icon"]:setSprite(iconAtlas, iconName) - rightBtn:addClickListener(function() + self.rightBtn:addClickListener(function() self:refreshModule(rightIdx) end) if moduleCell:getShowEntranceRedPoint() then - rightBtn:addRedPoint(-65, 35, 0.6) + self.rightBtn:addRedPoint(-65, 35, 0.6) else - rightBtn:removeRedPoint() + self.rightBtn:removeRedPoint() end end @@ -188,4 +192,13 @@ function MainComp:refreshStageFormaion() end end +function MainComp:getDailyChallengeIconPos() + if self:getCurLeftModuleIdx() == GConst.MainCityConst.MAIN_MODULE.DAILY_CHALLENGE then + return self.leftBtn:getPosition() + end + if self:getCurRightModuleIdx() == GConst.MainCityConst.MAIN_MODULE.DAILY_CHALLENGE then + return self.rightBtn:getPosition() + end +end + return MainComp \ No newline at end of file diff --git a/lua/app/ui/main_city/main_city_ui.lua b/lua/app/ui/main_city/main_city_ui.lua index fa188a81..1f3a3615 100644 --- a/lua/app/ui/main_city/main_city_ui.lua +++ b/lua/app/ui/main_city/main_city_ui.lua @@ -403,7 +403,6 @@ end function MainCityUI:openOrCloseLeftSideBar() ModuleManager.MaincityManager:changeMainCityLeftSideBarOpenOrClose() - self:refreshLeftBtns() if self.isShowLeftSideBarArrowRedPoint ~= nil then local isShowLeftSideBarArrowRedPoint = self.isShowLeftSideBarArrowRedPoint self.isShowLeftSideBarArrowRedPoint = nil @@ -470,7 +469,6 @@ end function MainCityUI:openOrCloseRightSideBar() ModuleManager.MaincityManager:changeMainCityRightSideBarOpenOrClose() - self:refreshRightBtns() if self.isShowRightSideBarArrowRedPoint ~= nil then local isShowRightSideBarArrowRedPoint = self.isShowRightSideBarArrowRedPoint self.isShowRightSideBarArrowRedPoint = nil @@ -969,4 +967,63 @@ function MainCityUI:checkGift() end end +function MainCityUI:getTaskIconPos() + return self.taskBtn:getPosition() +end + +function MainCityUI:getMallIconPos() + return self.bottomBtnSpines[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:getPosition() +end + +function MainCityUI:getDailyChallengeIconPos() + return self.subComps[GConst.MainCityConst.BOTTOM_PAGE.MAIN]:getDailyChallengeIconPos() +end + +function MainCityUI:getSideBarActIconPos(moduleKey) + for name, cell in pairs(self.leftBarList) do + if moduleKey == cell:getModuleKey() then + return cell:getBaseObject():getPosition() + end + end + for name, cell in pairs(self.rightBarList) do + if moduleKey == cell:getModuleKey() then + return cell:getBaseObject():getPosition() + end + end + return nil +end + +function MainCityUI:isInSideBarLeft(moduleKey) + for name, cell in pairs(self.leftBarList) do + if moduleKey == cell:getModuleKey() then + return true + end + end + return false +end + +function MainCityUI:isInSideBarRight(moduleKey) + for name, cell in pairs(self.rightBarList) do + if moduleKey == cell:getModuleKey() then + return true + end + end + return false +end + +function MainCityUI:isActivSideBarModule(moduleKey) + for name, cell in pairs(self.leftBarList) do + if moduleKey == cell:getModuleKey() then + return cell:getIsActive() and cell:getIsVisible() + end + end + for name, cell in pairs(self.rightBarList) do + if moduleKey == cell:getModuleKey() then + return cell:getIsActive() and cell:getIsVisible() + end + end + return nil +end + + return MainCityUI \ No newline at end of file diff --git a/lua/app/ui/main_city/module_unlock_ui.lua b/lua/app/ui/main_city/module_unlock_ui.lua index 5fc5ed30..4be18147 100644 --- a/lua/app/ui/main_city/module_unlock_ui.lua +++ b/lua/app/ui/main_city/module_unlock_ui.lua @@ -29,54 +29,114 @@ end function ModuleUnlockUI:onLoadRootComplete() self.uiMap = self.root:genAllChildren() - self.uiMap["module_unlock_ui.bg"]:addClickListener(function() - self:showNextModuleUnlockAnimation() + + self.bg = self.uiMap["module_unlock_ui.bg"] + self.bg:addClickListener(function() + if not self.canClick then + return + end + self:showModuleUnlockVanishAnim() end) - - self.moduleNameTx = self.uiMap["module_unlock_ui.name_tx"] + self.moduleNameTx = self.uiMap["module_unlock_ui.bg.name_tx"] self.moduleIcon = self.uiMap["module_unlock_ui.icon"] - self.uiMap["module_unlock_ui.continue"]:setText(I18N:getGlobalText(I18N.GlobalConst.CLICK_TO_CONTINUE)) - self.uiMap["module_unlock_ui.title_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.FUNC_UNLOCK)) + self.titleTx = self.uiMap["module_unlock_ui.bg.spine_title.title_tx"] + self.spineTitle = self.uiMap["module_unlock_ui.bg.spine_title"] + self.spineCircle = self.uiMap["module_unlock_ui.icon.spine_circle"] + self.spineStar = self.uiMap["module_unlock_ui.spine_star"] + self.uiMap["module_unlock_ui.bg.continue"]:setText(I18N:getGlobalText(I18N.GlobalConst.CLICK_TO_CONTINUE)) + self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.FUNC_UNLOCK)) - self:showModuleUnlockAnimation() + self.initIconPos = self.uiMap["module_unlock_ui.init_pos"]:getPosition() + self.canvasGroupBg = self.bg:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP) + self.canvasGroupTitleTx = self.titleTx:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP) + self.canvasGroupIcon = self.moduleIcon:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP) + + self:checkShowNext() end -function ModuleUnlockUI:showNextModuleUnlockAnimation() - if self:showModuleUnlockAnimation() then - self:playUnlockAnimation() - end -end - -function ModuleUnlockUI:showModuleUnlockAnimation() +-- 检查是否展示 +function ModuleUnlockUI:checkShowNext() if #self.unlockList <= 0 then self:closeUI() - return false + return end - local moduleKey = table.remove(self.unlockList, 1) - local info = ConfigManager:getConfig("func_open")[moduleKey] - local i18nInfo = I18N:getConfig("func_open")[moduleKey] + self.moduleKey = table.remove(self.unlockList, 1) + local info = ConfigManager:getConfig("func_open")[self.moduleKey] + local i18nInfo = I18N:getConfig("func_open")[self.moduleKey] if info == nil or i18nInfo == nil then self:closeUI() - return false + return end self.moduleNameTx:setText(i18nInfo.name) if info.icon then self.moduleIcon:setSprite(GConst.ATLAS_PATH.MODULE, info.icon) end - return true + + -- 侧边栏功能,检查处理侧边栏打开 + if not ModuleManager.MaincityManager:isActivSideBarModule(self.moduleKey) then + if ModuleManager.MaincityManager:getModuleInSideBarWhere(self.moduleKey) == -1 then + ModuleManager.MaincityManager:changeMainCityLeftSideBarOpenOrClose() + elseif ModuleManager.MaincityManager:getModuleInSideBarWhere(self.moduleKey) == 1 then + ModuleManager.MaincityManager:changeMainCityRightSideBarOpenOrClose() + end + end + self:showModuleUnlockAppearAnim() end -function ModuleUnlockUI:playUnlockAnimation() - if self.unlockAnimationSeq == nil then - self.unlockAnimationSeq = self.root:createBindTweenSequence() - local scaleTween1 = self.root:getTransform():DOScale(1.05, 0.15) - self.unlockAnimationSeq:Append(scaleTween1) +-- 出现 +function ModuleUnlockUI:showModuleUnlockAppearAnim() + self.canClick = false + self.canvasGroupBg.alpha = 0 + self.canvasGroupTitleTx.alpha = 0 + self.canvasGroupIcon.alpha = 0 + self.titleTx:setLocalScale(0,0,0) + self.moduleIcon:setLocalScale(1,1,1) + self.moduleIcon:setPosition(self.initIconPos.x, self.initIconPos.y, self.initIconPos.z) - local scaleTween2 = self.root:getTransform():DOScale(1, 0.2) - self.unlockAnimationSeq:Append(scaleTween2) - self.unlockAnimationSeq:SetAutoKill(false) + self.spineTitle:playAnim("idle", false, true, true) + self:performWithDelayGlobal(function() + self.spineCircle:playAnim("idle", false, true, true) + end, 0.17) + if self.animAppear == nil then + self.animAppear = self.root:createBindTweenSequence() + self.animAppear:Insert(0, self.canvasGroupBg:DOFade(1, 0.14)) + self.animAppear:Insert(0.13, self.canvasGroupIcon:DOFade(1, 0.07)) + self.animAppear:Insert(0.13, self.moduleIcon:getTransform():DOScale(1.2, 0.07)) + self.animAppear:Insert(0.17, self.canvasGroupTitleTx:DOFade(1, 0.1)) + self.animAppear:Insert(0.17, self.titleTx:getTransform():DOScale(1.2, 0.1)) + self.animAppear:Insert(0.2, self.moduleIcon:getTransform():DOScale(1, 0.13)) + self.animAppear:SetAutoKill(false) + self.animAppear:OnComplete(function() + self.canClick = true + end) else - self.unlockAnimationSeq:Restart() + self.animAppear:Restart() + end +end + +-- 消失 +function ModuleUnlockUI:showModuleUnlockVanishAnim() + self.canClick = false + self.animVanish = self.root:createBindTweenSequence() + self.animVanish:Insert(0, self.canvasGroupBg:DOFade(0, 0.1)) + self.animVanish:Insert(0, self.titleTx:getTransform():DOScale(1, 0.16)) + self.animVanish:Insert(0, self.moduleIcon:getTransform():DOScale(0.46, 0.1)) + self.animVanish:Insert(0.33, self.canvasGroupIcon:DOFade(0, 0.07)) + local targetPos = ModuleManager.MaincityManager:getModuleEntrancePos(self.moduleKey) + if targetPos then + self.spineStar:setPosition(targetPos.x, targetPos.y, targetPos.z) + self.animVanish:Insert(0.17, self.moduleIcon:getTransform():DOMove(CS.UnityEngine.Vector3(targetPos.x, targetPos.y, targetPos.z), 0.16)) + self.animVanish:OnComplete(function() + self.animVanish = nil + self.spineStar:playAnimComplete("idle", false, true, function() + self:checkShowNext() + end) + end) + else + self.animVanish:OnComplete(function() + self.animVanish = nil + self:checkShowNext() + end) end end diff --git a/lua/app/userdata/activity/activity_data.lua b/lua/app/userdata/activity/activity_data.lua index 11f31d14..12aeaef6 100644 --- a/lua/app/userdata/activity/activity_data.lua +++ b/lua/app/userdata/activity/activity_data.lua @@ -1,7 +1,6 @@ local ActivityData = class("ActivityData", BaseData) function ActivityData:init(data) - end return ActivityData \ No newline at end of file