From f13f1f3e3a68050e2126e932bd611cbfca57ebb6 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Wed, 5 Jul 2023 21:58:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=AF=BC=E5=A4=84=E7=90=86=E4=B8=80?= =?UTF-8?q?=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/ui/common/cell/hero_cell.lua | 8 ++++ lua/app/ui/hero/cell/hero_list_cell.lua | 11 +++++ lua/app/ui/hero/hero_comp.lua | 15 +++++++ lua/app/ui/tutorial/tutorial_ui.lua | 47 ++++++++++++++++++--- lua/app/userdata/tutorial/tutorial_data.lua | 4 ++ 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/lua/app/ui/common/cell/hero_cell.lua b/lua/app/ui/common/cell/hero_cell.lua index 3463c135..dbfe2215 100644 --- a/lua/app/ui/common/cell/hero_cell.lua +++ b/lua/app/ui/common/cell/hero_cell.lua @@ -31,6 +31,7 @@ function HeroCell:init() end function HeroCell:refresh(heroEntity, isGray) + self.heroEntity = heroEntity self.selfNode:setVisible(true) self.otherNode:setVisible(false) @@ -80,6 +81,13 @@ function HeroCell:refresh(heroEntity, isGray) end end +function HeroCell:getHeroId() + if not self.heroEntity then + return + end + return self.heroEntity:getCfgId() +end + function HeroCell:refreshBriefInfo(id, level) self.selfNode:setVisible(false) self.otherNode:setVisible(true) diff --git a/lua/app/ui/hero/cell/hero_list_cell.lua b/lua/app/ui/hero/cell/hero_list_cell.lua index 145c88d9..db5d3644 100644 --- a/lua/app/ui/hero/cell/hero_list_cell.lua +++ b/lua/app/ui/hero/cell/hero_list_cell.lua @@ -82,4 +82,15 @@ function HeroListCell:refresh(index, heroList, stageFormation, allHeroCount, act end end +function HeroListCell:getHeroCellByHeroId(heroId) + if not self.heroCells then + return + end + for i, cell in ipairs(self.heroCells) do + if cell:getHeroId() == heroId then + return cell + end + end +end + return HeroListCell \ No newline at end of file diff --git a/lua/app/ui/hero/hero_comp.lua b/lua/app/ui/hero/hero_comp.lua index 37b52d65..afab5ff9 100644 --- a/lua/app/ui/hero/hero_comp.lua +++ b/lua/app/ui/hero/hero_comp.lua @@ -255,4 +255,19 @@ function HeroComp:clearAdapt() viewport:setSizeDelta(self.viewDefaultSize.x, self.viewDefaultSize.y) end +function HeroComp:getHeroCell(heroId) + if not self.scrollRect then + return + end + local targetCell + for index, cell in pairs(self.scrollRect:getListCell()) do + local heroCell = cell:getHeroCellByHeroId(heroId) + if heroCell then + targetCell = heroCell + break + end + end + return targetCell +end + return HeroComp \ No newline at end of file diff --git a/lua/app/ui/tutorial/tutorial_ui.lua b/lua/app/ui/tutorial/tutorial_ui.lua index c3f09074..28054768 100644 --- a/lua/app/ui/tutorial/tutorial_ui.lua +++ b/lua/app/ui/tutorial/tutorial_ui.lua @@ -181,8 +181,13 @@ function TutorialUI:showTutorialText() end self.fingerParentNode:setLocalPosition(fingerOffset[1], fingerOffset[2], 0) - if targetName then - local targetGo = UIManager:getMainCanvasTransform():Find(targetName) + if targetName or DataManager.TutorialData:getTargetHeroId() then + local targetGo + if targetName then + targetGo = UIManager:getMainCanvasTransform():Find(targetName) + else + targetGo = self:getHeroCellByHeroId(DataManager.TutorialData:getTargetHeroId()) + end local anchoredPosition = nil local setGuideFingerPosition = nil setGuideFingerPosition = function(interval) @@ -226,7 +231,11 @@ function TutorialUI:showTutorialText() ModuleManager.TutorialManager:unscheduleGlobal(self._findTargetSid) end self._findTargetSid = ModuleManager.TutorialManager:scheduleGlobal(function() - targetGo = UIManager:getMainCanvasTransform():Find(targetName) + if targetName then + targetGo = UIManager:getMainCanvasTransform():Find(targetName) + else + targetGo = self:getHeroCellByHeroId(DataManager.TutorialData:getTargetHeroId()) + end if targetGo then anchoredPosition = self:getTargetAnchoredPosition(targetGo) ModuleManager.TutorialManager:unscheduleGlobal(self._findTargetSid) @@ -333,18 +342,28 @@ function TutorialUI:registerClickBtnListener(callback, targetName, clickType) if targetName == nil then targetName = DataManager.TutorialData:getTargetName() end - if targetName == nil then + + if targetName == nil and not DataManager.TutorialData:getTargetHeroId() then ModuleManager.TutorialManager:stopTutorial() return end - local targetGo = UIManager:getMainCanvasTransform():Find(targetName) + local targetGo + if targetName then + targetGo = UIManager:getMainCanvasTransform():Find(targetName) + else + targetGo = self:getHeroCellByHeroId(DataManager.TutorialData:getTargetHeroId()) + end if targetGo == nil then -- 没有找到说明需要找的ui还没打开 -- 每隔一定时间在重新找一次 if self._findTargetSid then ModuleManager.TutorialManager:unscheduleGlobal(self._findTargetSid) end self._findTargetSid = ModuleManager.TutorialManager:scheduleGlobal(function() - targetGo = UIManager:getMainCanvasTransform():Find(targetName) + if targetName then + targetGo = UIManager:getMainCanvasTransform():Find(targetName) + else + targetGo = self:getHeroCellByHeroId(DataManager.TutorialData:getTargetHeroId()) + end if targetGo then ModuleManager.TutorialManager:unscheduleGlobal(self._findTargetSid) self._findTargetSid = nil @@ -579,4 +598,20 @@ function TutorialUI:setVisible(visible) self.baseObject:setActive(visible) end +function TutorialUI:getHeroCellByHeroId(heroId) + local uiObj = UIManager:getUIByIndex(UIManager.UI_PATH.MAINCITY_UI) + if not uiObj then + return + end + local heroComp = uiObj:getHeroComp() + if not heroComp then + return + end + local cell = heroComp:getHeroCell(heroId) + if not cell then + return + end + return cell:getBaseObject():getTransform() +end + return TutorialUI \ No newline at end of file diff --git a/lua/app/userdata/tutorial/tutorial_data.lua b/lua/app/userdata/tutorial/tutorial_data.lua index 34439707..c47a17b1 100644 --- a/lua/app/userdata/tutorial/tutorial_data.lua +++ b/lua/app/userdata/tutorial/tutorial_data.lua @@ -191,6 +191,10 @@ function TutorialData:getTargetName() return self.tutorialInfo.target_name end +function TutorialData:getTargetHeroId() + return self.tutorialInfo.heroid +end + function TutorialData:getTutorialTalkRoleId() return self.tutorialInfo.head end