BigMapView.lua 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. local BigMapView = class('BigMapView')
  2. local MultiTypeAssetLoadSystem = require("MultiTypeAssetLoadSystem")
  3. local ExecuteSequenceData = require('ExecuteSequenceData')
  4. local PointStartItemPath = 'UIBigMap/PointStartItem'
  5. local PointPlayerItemPath = 'UIBigMap/PointPlayerItem'
  6. local PointIconItemPath = 'UIBigMap/PointIconItem'
  7. local MapAreaIconAsyncIdx = 'MapAreaIconAsyncIdx'
  8. local HeadIconAsyncIdx = 'HeadIconAsyncIdx'
  9. function BigMapView:ctor(uiViewBase)
  10. self.viewBase = uiViewBase
  11. self.view = uiViewBase.bigMap
  12. self.loadSystem = MultiTypeAssetLoadSystem:new()
  13. self.loadSystem:SetCompleteCB(self, self._PreloadedAssets)
  14. self.storyIconLuaCtrs = {}
  15. self.storyGoLuaCtrs = {}
  16. self.executeSequenceData = nil
  17. self.isExecutePlayEffect = false
  18. self:_StartPageOpenFrameTimer()
  19. self:_InitReference()
  20. end
  21. function BigMapView:_StartPageOpenFrameTimer()
  22. self.pageOpenFrameTimer = FrameTimer.New(function()
  23. if self.targetAlginPointPos then
  24. local normalizedPosition = self:_CalcAlginNormalizedPosition(self.targetAlginPointPos)
  25. self.view.scrollRect.normalizedPosition = normalizedPosition
  26. end
  27. end, 1, -1)
  28. self.pageOpenFrameTimer:Start()
  29. end
  30. function BigMapView:_EndPageOpenFrameTimer()
  31. if self.pageOpenFrameTimer then
  32. self.pageOpenFrameTimer:Stop()
  33. end
  34. self.pageOpenFrameTimer = nil
  35. end
  36. function BigMapView:Dispose()
  37. self:_DisposeReference()
  38. self:_DisposeData()
  39. end
  40. function BigMapView:_DisposeData()
  41. self.isExecutePlayEffect = nil
  42. if self.executeSequenceData then
  43. ManagerContainer.ExecuteSequenceMgr:Exit(self.executeSequenceData)
  44. self.executeSequenceData = nil
  45. end
  46. self.loadSystem:Dispose()
  47. self.loadSystem = nil
  48. self.curMapId = nil
  49. self.curLevelId = nil
  50. self.showMapId = nil
  51. self.showRect = nil
  52. self.mapData = nil
  53. self.levelDatas = nil
  54. self.levelPoss = nil
  55. self.storyIconLuaCtrs = nil
  56. self.storyGoLuaCtrs = nil
  57. self.selfPlayerLuaCtr = nil
  58. self.targetAlginPointPos = nil
  59. self:_EndPageOpenFrameTimer()
  60. end
  61. function BigMapView:_InitReference()
  62. local bigPoints = self.view.bigPoints.transform
  63. local go = bigPoints:Find("BigPoint").gameObject
  64. go:SetActive(false)
  65. self.bigPointGo = go
  66. local smallPoints = self.view.smallPoints.transform
  67. go = smallPoints:Find("SmallPoint").gameObject
  68. go:SetActive(false)
  69. self.smallPointGo = go
  70. self.bigPoints = {}
  71. self.smallPoints = {}
  72. end
  73. function BigMapView:_DisposeReference()
  74. CommonUtil.CloseUIClearAsyncSeqIds(self)
  75. self:_DisposeSelfPlayerLuaCtr()
  76. self:_DisposeStoryIconLuaCtrs()
  77. self:_DisposeStoryGoLuaCtrs()
  78. self:_DisposeBigPoints()
  79. self:_DisposeSmallPoints()
  80. self:_DisposeStartPoint()
  81. self.bigPointGo = nil
  82. self.smallPointGo = nil
  83. self.bigPoints = nil
  84. self.smallPoints = nil
  85. end
  86. function BigMapView:InitData(curMapId, curLevelId, showMapId, enterType, showRect)
  87. self.enterType = enterType
  88. self.curMapId = curMapId
  89. self.curLevelId = curLevelId
  90. self.showMapId = showMapId
  91. self.showRect = showRect
  92. local cfgMgr = ManagerContainer.CfgMgr
  93. self.mapData = cfgMgr:GetMapData(showMapId)
  94. local levelDatas = {}
  95. local levelPoss = {}
  96. local levelId = 1
  97. local levelData = cfgMgr:GetLevelDataByMapAndLevel(showMapId, levelId)
  98. while (levelData ~= nil) do
  99. levelDatas[levelId] = levelData
  100. levelPoss[levelId] = CommonUtil.TableToVector2(levelData.LevelPointCoordinate)
  101. levelId = levelId + 1
  102. levelData = cfgMgr:GetLevelDataByMapAndLevel(showMapId, levelId)
  103. end
  104. self.levelDatas = levelDatas
  105. self.levelPoss = levelPoss
  106. self.levelStartPos = CommonUtil.TableToVector2(self.mapData.AreaStartPos)
  107. local isCanScroll = enterType ~= Enum.BigMapEnterType.NextLevel
  108. local scrollRect = self.view.scrollRect
  109. scrollRect.horizontal = isCanScroll
  110. scrollRect.vertical = isCanScroll
  111. self:_RefreshMapBg()
  112. self:_RefreshPoints()
  113. if enterType == Enum.BigMapEnterType.NextLevel then
  114. return
  115. end
  116. if self.curMapId == 1 and self.curLevelId == 1 then
  117. return
  118. end
  119. ManagerContainer.DataMgr.BigMapData:SendGetData()
  120. end
  121. function BigMapView:OnLevelChanged(curMapId, curLevelId, showMapId)
  122. if self.curMapId == curMapId and self.curLevelId == curLevelId and self.showMapId == showMapId then
  123. return
  124. end
  125. if self.enterType and self.enterType ~= Enum.BigMapEnterType.Default then
  126. return
  127. end
  128. self.curMapId = curMapId
  129. self.curLevelId = curLevelId
  130. self:RefreshSelfPos()
  131. self:_DisposeStoryIconLuaCtrs()
  132. self:_DisposeStoryGoLuaCtrs()
  133. self:_DisposeBigPoints()
  134. self:_DisposeSmallPoints()
  135. self:_DisposeStartPoint()
  136. self:_RefreshPoints()
  137. end
  138. function BigMapView:RefreshSelfHead()
  139. local luaCtr = self.selfPlayerLuaCtr
  140. if not luaCtr then return end
  141. local headIcon = ManagerContainer.DataMgr.UserData:GetUserHeadIcon()
  142. local image = luaCtr.iconImage
  143. if not image then return end
  144. image.sprite = nil
  145. if headIcon then
  146. CommonUtil.LoadIcon(self, headIcon, function (sprite)
  147. image.sprite = sprite
  148. end, self, HeadIconAsyncIdx)
  149. end
  150. end
  151. function BigMapView:RefreshSelfRank()
  152. local luaCtr = self.selfPlayerLuaCtr
  153. if not luaCtr then return end
  154. local rank, rankPercent = ManagerContainer.DataMgr.BigMapData:GetSelfRankInfo()
  155. if luaCtr.myRankGo then
  156. luaCtr.myRankGo:SetActive(rank and rank == 1 or false)
  157. end
  158. local contentStr = ''
  159. if rank then
  160. contentStr = I18N.SetLanguageValue('MapRanking', rank)
  161. elseif rankPercent then
  162. contentStr = I18N.SetLanguageValue('MapPercentage', CommonUtil.GetPreciseDecimal(rankPercent, 2))
  163. else
  164. local defaultNum = GlobalConfig.Instance:GetConfigFloatValue(131)
  165. defaultNum = CommonUtil.GetPreciseDecimal(defaultNum, 2)
  166. contentStr = I18N.SetLanguageValue('MapPercentage', tostring(defaultNum))
  167. end
  168. if luaCtr.dscLeftTxt then
  169. luaCtr.dscLeftTxt.text = contentStr
  170. end
  171. if luaCtr.dscRightTxt then
  172. luaCtr.dscRightTxt.text = contentStr
  173. end
  174. end
  175. function BigMapView:RefreshSelfPos()
  176. local luaCtr = self.selfPlayerLuaCtr
  177. if not luaCtr then return end
  178. local mapId = self.showMapId
  179. local curMapId = self.curMapId
  180. local go = luaCtr.go
  181. if mapId ~= curMapId then
  182. if go then
  183. go:SetActive(false)
  184. end
  185. return
  186. end
  187. local curLevelId = self.curLevelId
  188. local pointPos = self.levelPoss[curLevelId]
  189. if not pointPos then
  190. if go then
  191. go:SetActive(false)
  192. end
  193. return
  194. end
  195. if go then
  196. go:SetActive(true)
  197. go.transform.localPosition = pointPos
  198. end
  199. if self:_RectTransformContain(self.view.scrollRect.viewport, luaCtr.dscLeftRect) then
  200. if luaCtr.dscLeftGo then
  201. luaCtr.dscLeftGo:SetActive(true)
  202. -- if ManagerContainer.LuaBattleMgr:IsShowDifficultyTxt() then
  203. -- luaCtr.dscLeftGo:SetActive(false)
  204. -- else
  205. -- luaCtr.dscLeftGo:SetActive(true)
  206. -- end
  207. end
  208. if luaCtr.dscRightGO then
  209. luaCtr.dscRightGO:SetActive(false)
  210. end
  211. else
  212. if luaCtr.dscLeftGo then
  213. luaCtr.dscLeftGo:SetActive(false)
  214. end
  215. if luaCtr.dscRightGO then
  216. luaCtr.dscRightGO:SetActive(true)
  217. -- if ManagerContainer.LuaBattleMgr:IsShowDifficultyTxt() then
  218. -- luaCtr.dscRightGO:SetActive(false)
  219. -- else
  220. -- luaCtr.dscRightGO:SetActive(true)
  221. -- end
  222. end
  223. end
  224. end
  225. function BigMapView:AlginCenter()
  226. if self.showMapId ~= self.curMapId then
  227. return
  228. end
  229. self:_AlginCenterLevelId(self.curLevelId)
  230. end
  231. function BigMapView:OnPageInEnd()
  232. if self.isExecutePlayEffect then return end
  233. if self.targetAlginPointPos then
  234. self.view.scrollRect.normalizedPosition = self:_CalcAlginNormalizedPosition(self.targetAlginPointPos)
  235. if self.pageOpenFrameTimer then
  236. self.pageOpenFrameTimer.duration = 1
  237. self.pageOpenFrameTimer.loop = 1
  238. self.pageOpenFrameTimer.count = Time.frameCount + 1
  239. else
  240. self.pageOpenFrameTimer = FrameTimer.New(function()
  241. if self.targetAlginPointPos then
  242. local normalizedPosition = self:_CalcAlginNormalizedPosition(self.targetAlginPointPos)
  243. self.view.scrollRect.normalizedPosition = normalizedPosition
  244. end
  245. end, 1)
  246. end
  247. else
  248. self:_EndPageOpenFrameTimer()
  249. end
  250. self.isExecutePlayEffect = true
  251. if self.executeSequenceData then
  252. ManagerContainer.ExecuteSequenceMgr:Execute(self.executeSequenceData)
  253. end
  254. end
  255. function BigMapView:_AlginCenterLevelId(levelId, moveTime)
  256. local pointPos = self.levelPoss[levelId]
  257. if not pointPos then
  258. return
  259. end
  260. self:_AlginCenterPos(pointPos, moveTime)
  261. end
  262. function BigMapView:_AlginCenterPos(pointPos, moveTime)
  263. if self.isExecutePlayEffect then
  264. local normalizedPosition = self:_CalcAlginNormalizedPosition(pointPos)
  265. if moveTime and moveTime > 0 then
  266. self.view.scrollRect:DONormalizedPos(normalizedPosition, moveTime)
  267. else
  268. self.view.scrollRect.normalizedPosition = normalizedPosition
  269. end
  270. else
  271. self.targetAlginPointPos = pointPos
  272. end
  273. end
  274. function BigMapView:_CalcAlginNormalizedPosition(pointPos)
  275. local scrollRect = self.view.scrollRect
  276. local viewport = scrollRect.viewport
  277. local content = scrollRect.content
  278. local viewportRect = viewport.rect
  279. local contentRect = content.rect
  280. local viewportW = viewportRect.width
  281. local contentW = contentRect.width
  282. local vaildW = contentW - viewportW
  283. local viewportH = viewportRect.height
  284. local contentH = contentRect.height
  285. local vaildH = contentH - viewportH
  286. local valW = Mathf.Clamp01((pointPos.x / vaildW) + 0.5)
  287. local valH = Mathf.Clamp01((pointPos.y / vaildH) + 0.5)
  288. return Vector2(valW, valH)
  289. end
  290. -- function BigMapView:RefreshTopPlayerRankAndPos(playerList)
  291. -- local oneRank = self.view.oneRank
  292. -- if not playerList then
  293. -- oneRank:SetActive(false)
  294. -- return
  295. -- end
  296. -- local playerInfo = playerList[1]
  297. -- if not playerInfo then
  298. -- oneRank:SetActive(false)
  299. -- return
  300. -- end
  301. -- local uid = playerInfo.uid
  302. -- local curUserId = ManagerContainer.DataMgr.UserData:GetUserId()
  303. -- if int64.equals(curUserId, uid) then
  304. -- oneRank:SetActive(false)
  305. -- return
  306. -- end
  307. -- local mapId = playerInfo.mapId
  308. -- if mapId ~= self.showMapId then
  309. -- oneRank:SetActive(false)
  310. -- return
  311. -- end
  312. -- local mapLevel = playerInfo.mapLevel
  313. -- local pointPos = self.levelPoss[mapLevel]
  314. -- if not pointPos then
  315. -- oneRank:SetActive(false)
  316. -- return
  317. -- end
  318. -- oneRank:SetActive(true)
  319. -- oneRank.transform.position = pointPos
  320. -- end
  321. function BigMapView:_RefreshMapBg()
  322. local mapData = self.mapData
  323. local image = self.view.bottomImage.image
  324. image.sprite = nil
  325. image.enabled = false
  326. CommonUtil.LoadIcon(self, mapData.AreaPic, function (sprite)
  327. image.sprite = sprite
  328. image.enabled = true
  329. end, self, MapAreaIconAsyncIdx)
  330. self.view.bottomImage.rectTransform.sizeDelta = CommonUtil.TableToVector2(mapData.PicSize)
  331. local scrollSize = CommonUtil.TableToVector2(mapData.ScrollSize)
  332. self.view.content.rectTransform.sizeDelta = scrollSize
  333. end
  334. function BigMapView:_RefreshPoints()
  335. local uiPath = Constants.UIPath
  336. local iconDir = Constants.IconDir
  337. local loadSystem = self.loadSystem
  338. loadSystem:Cancel()
  339. loadSystem:RemoveLoadAllAsset()
  340. local cfgMgr = ManagerContainer.CfgMgr
  341. local showRect = self.showRect
  342. local line = self.view.linePath.uIBigMapLine
  343. local levelDatas = self.levelDatas
  344. local levelPoss = self.levelPoss
  345. local levelDataNum = #levelDatas
  346. local smallStartIdx = 1
  347. local smallEndIdx = levelDataNum
  348. local enterType = self.enterType
  349. local isOneStory = true
  350. line:ClearPoints()
  351. local startPos = self.levelStartPos
  352. if not showRect or showRect:Contains(startPos) then
  353. self.loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, PointStartItemPath)
  354. end
  355. line:AddPoint(startPos)
  356. local bigIdx = 1
  357. for i = 1, levelDataNum do
  358. local pointPos = levelPoss[i]
  359. line:AddPoint(pointPos)
  360. if not showRect or showRect:Contains(pointPos) then
  361. local levelData = levelDatas[i]
  362. local pointType = levelData.LevelPointType or 0
  363. if pointType == 0 then
  364. bigIdx = self:_GetBigPoint(bigIdx, pointPos)
  365. if self:_IsPassedPoint(i) then
  366. smallStartIdx = i + 1
  367. else
  368. if not smallEndIdx then
  369. smallEndIdx = i - 1
  370. end
  371. local storySection = levelData.StorySection
  372. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  373. if storySectionData then
  374. local artType = storySectionData.ArtType
  375. local artRes = storySectionData.ArtRes
  376. if artType == Enum.StorySectionArtType.Icon then
  377. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, PointIconItemPath)
  378. loadSystem:AddLoadAsset(Enum.ResourceType.Sprite, iconDir, artRes)
  379. else
  380. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, artRes)
  381. end
  382. if isOneStory and enterType == Enum.BigMapEnterType.DropPoint then
  383. isOneStory = false
  384. if storySectionData.StartDropPos and #storySectionData.StartDropPos > 0 then
  385. self:_AlginCenterPos(CommonUtil.TableToVector2(storySectionData.StartDropPos))
  386. end
  387. end
  388. end
  389. end
  390. end
  391. end
  392. end
  393. line:SetAllDirty()
  394. if self.curMapId ~= self.showMapId then
  395. line.passPointIdx = (self.curMapId > self.showMapId and levelDataNum or 0)
  396. else
  397. line.passPointIdx = self.curLevelId
  398. end
  399. local smallIdx = 1
  400. if self.enterType ~= Enum.BigMapEnterType.DropPoint then
  401. if smallStartIdx < smallEndIdx and smallEndIdx <= levelDataNum then
  402. for i = smallStartIdx, smallEndIdx do
  403. local levelData = levelDatas[i]
  404. local pointType = levelData.LevelPointType or 0
  405. if pointType == 0 then
  406. break
  407. end
  408. smallIdx = self:_GetSmallPoint(smallIdx, levelPoss[i])
  409. local storySection = levelData.StorySection
  410. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  411. if storySectionData then
  412. local artType = storySectionData.ArtType
  413. local artRes = storySectionData.ArtRes
  414. if artType == Enum.StorySectionArtType.Icon then
  415. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, PointIconItemPath)
  416. loadSystem:AddLoadAsset(Enum.ResourceType.Sprite, iconDir, artRes)
  417. else
  418. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, artRes)
  419. end
  420. end
  421. end
  422. end
  423. end
  424. for i = smallIdx, #self.smallPoints do
  425. self.smallPoints[i]:SetActive(false)
  426. end
  427. if self:_IsSelfAtCurMap() then
  428. if not self.selfPlayerLuaCtr then
  429. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, PointPlayerItemPath)
  430. end
  431. if isOneStory then
  432. self:AlginCenter()
  433. end
  434. else
  435. self:_DisposeSelfPlayerLuaCtr()
  436. end
  437. loadSystem:Begin()
  438. self:HardRef()
  439. end
  440. function BigMapView:_PreloadedAssets()
  441. local uiPath = Constants.UIPath
  442. local enterType = self.enterType
  443. local cfgMgr = ManagerContainer.CfgMgr
  444. local resMgr = ManagerContainer.ResMgr
  445. local showRect = self.showRect
  446. local levelDatas = self.levelDatas
  447. local levelPoss = self.levelPoss
  448. local levelDataNum = #levelDatas
  449. local isOneStory = true
  450. local uiStoryMgr = nil
  451. if enterType == Enum.BigMapEnterType.DropPoint then
  452. self.executeSequenceData = ExecuteSequenceData:new()
  453. uiStoryMgr = ManagerContainer.UIStoryMgr
  454. end
  455. local startPos = self.levelStartPos
  456. if self:_IsSelfAtCurMap() then
  457. if not self.selfPlayerLuaCtr then
  458. local selfGoItem = resMgr:GetGoFromPool(uiPath, PointPlayerItemPath)
  459. local iconImage, myRankGo, dscLeftGo, dscLeftTxt, dscRightGO, dscRightTxt, selfGoAnimator
  460. if selfGoItem then
  461. local selfGoItemTrans = selfGoItem.transform
  462. selfGoItemTrans:SetParent(self.view.selfContainer.transform, false)
  463. selfGoItemTrans.localPosition = startPos
  464. selfGoItemTrans.localRotation = Quaternion.identity
  465. selfGoItemTrans.localScale = Vector3.one
  466. iconImage = selfGoItemTrans:Find('Root/Item/Content/Icon'):GetComponent(Enum.TypeInfo.Image)
  467. myRankGo = selfGoItemTrans:Find('Root/Item/MyRank').gameObject
  468. dscLeftGo = selfGoItemTrans:Find('Root/DscLeft').gameObject
  469. dscLeftTxt = selfGoItemTrans:Find('Root/DscLeft/DesTxt'):GetComponent(Enum.TypeInfo.Text)
  470. dscRightGO = selfGoItemTrans:Find('Root/DscRight').gameObject
  471. dscRightTxt = selfGoItemTrans:Find('Root/DscRight/DesTxt'):GetComponent(Enum.TypeInfo.Text)
  472. selfGoAnimator = selfGoItem:GetComponent(Enum.TypeInfo.Animator)
  473. end
  474. local luaCtr = {}
  475. luaCtr.go = selfGoItem
  476. luaCtr.iconImage = iconImage
  477. luaCtr.myRankGo = myRankGo
  478. luaCtr.dscLeftGo = dscLeftGo
  479. if dscLeftGo then
  480. luaCtr.dscLeftRect = dscLeftGo:GetComponent(Enum.TypeInfo.RectTransform)
  481. end
  482. luaCtr.dscLeftTxt = dscLeftTxt
  483. luaCtr.dscRightGO = dscRightGO
  484. luaCtr.dscRightTxt = dscRightTxt
  485. luaCtr.animator = selfGoAnimator
  486. self.selfPlayerLuaCtr = luaCtr
  487. end
  488. self:RefreshSelfHead()
  489. self:RefreshSelfRank()
  490. self:RefreshSelfPos()
  491. if enterType ~= Enum.BigMapEnterType.DropPoint then
  492. self:AlginCenter()
  493. end
  494. end
  495. if not showRect or showRect:Contains(startPos) then
  496. self:_CreateStartPoint(startPos)
  497. end
  498. local smallStartIdx = 1
  499. local smallEndIdx = levelDataNum
  500. for i = 1, levelDataNum do
  501. local pointPos = levelPoss[i]
  502. if not showRect or showRect:Contains(pointPos) then
  503. if self:_IsPassedPoint(i) then
  504. smallStartIdx = i + 1
  505. else
  506. if not smallEndIdx then
  507. smallEndIdx = i - 1
  508. end
  509. local levelData = levelDatas[i]
  510. local pointType = levelData.LevelPointType or 0
  511. if pointType == 0 then
  512. local storySection = levelData.StorySection
  513. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  514. if storySectionData then
  515. if enterType == Enum.BigMapEnterType.DropPoint then
  516. local startDropMoveTime = storySectionData.StartDropMoveTime
  517. if storySectionData.StartDropPos and #storySectionData.StartDropPos > 0 then
  518. self.executeSequenceData:AppendFunc(false, self, self._AlginCenterPos, CommonUtil.TableToVector2(storySectionData.StartDropPos), startDropMoveTime)
  519. if (startDropMoveTime and startDropMoveTime > 0) then
  520. self.executeSequenceData:AppendInterval(startDropMoveTime)
  521. end
  522. end
  523. if isOneStory and self.selfPlayerLuaCtr then
  524. isOneStory = false
  525. if self.selfPlayerLuaCtr.go then
  526. self.selfPlayerLuaCtr.go:SetActive(false)
  527. end
  528. self.executeSequenceData:AppendFunc(false, self, self._PlayFallDownAnim, self.selfPlayerLuaCtr)
  529. self.executeSequenceData:AppendInterval(1)
  530. end
  531. if storySectionData.StartDropDlgId > 0 then
  532. -- 需要至少延迟一帧时间,避免对话框刚刚关闭就需要打开,导致逻辑混乱
  533. self.executeSequenceData:AppendFrameInterval(1)
  534. self.executeSequenceData:AppendFunc(false, uiStoryMgr, uiStoryMgr.MapStartStoryByStoryId, storySectionData.StartDropDlgId)
  535. self.executeSequenceData:AppendUIListener(Enum.UIPageName.UIStory, UIEventNames.UI_PAGE_OUT_END_NTF)
  536. end
  537. end
  538. local artType = storySectionData.ArtType
  539. local artRes = storySectionData.ArtRes
  540. if artType == Enum.StorySectionArtType.Icon then
  541. local luaCtr = self:_CreateStoryIconLuaCtr(i, artRes, pointPos)
  542. if enterType == Enum.BigMapEnterType.DropPoint then
  543. if luaCtr.go then
  544. luaCtr.go:SetActive(false)
  545. end
  546. self.executeSequenceData:AppendFunc(false, self, self._PlayFallDownAnim, luaCtr)
  547. elseif enterType == Enum.BigMapEnterType.Default then
  548. self.viewBase.uiBase:AddButtonUniqueEventListener(luaCtr.button, self, self._OnClickStoryItem, i)
  549. end
  550. else
  551. local luaCtr = self:_CreateStoryGoLuaCtr(i, artRes, pointPos)
  552. if enterType == Enum.BigMapEnterType.DropPoint then
  553. if luaCtr.go then
  554. luaCtr.go:SetActive(false)
  555. end
  556. self.executeSequenceData:AppendFunc(false, self, self._PlayFallDownAnim, luaCtr)
  557. elseif enterType == Enum.BigMapEnterType.Default then
  558. self.viewBase.uiBase:AddButtonUniqueEventListener(luaCtr.button, self, self._OnClickStoryItem, i)
  559. end
  560. end
  561. if enterType == Enum.BigMapEnterType.DropPoint then
  562. self.executeSequenceData:AppendInterval(1)
  563. if storySectionData.EndDropDlgId > 0 then
  564. self.executeSequenceData:AppendFunc(false, uiStoryMgr, uiStoryMgr.MapStartStoryByStoryId, storySectionData.EndDropDlgId)
  565. self.executeSequenceData:AppendUIListener(Enum.UIPageName.UIStory, UIEventNames.UI_PAGE_OUT_END_NTF)
  566. end
  567. end
  568. end
  569. end
  570. end
  571. end
  572. end
  573. if enterType ~= Enum.BigMapEnterType.DropPoint then
  574. if smallStartIdx < smallEndIdx and smallEndIdx <= levelDataNum then
  575. for i = smallStartIdx, smallEndIdx do
  576. local levelData = levelDatas[i]
  577. local pointType = levelData.LevelPointType or 0
  578. if pointType == 0 then
  579. break
  580. end
  581. if not self:_IsPassedPoint(i) then
  582. local storySection = levelData.StorySection
  583. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  584. if storySectionData then
  585. local artType = storySectionData.ArtType
  586. local artRes = storySectionData.ArtRes
  587. local pointPos = levelPoss[i]
  588. local luaCtr = nil
  589. if artType == Enum.StorySectionArtType.Icon then
  590. luaCtr = self:_CreateStoryIconLuaCtr(i, artRes, pointPos)
  591. else
  592. luaCtr = self:_CreateStoryGoLuaCtr(i, artRes, pointPos)
  593. end
  594. if luaCtr and enterType == Enum.BigMapEnterType.Default then
  595. self.viewBase.uiBase:AddButtonUniqueEventListener(luaCtr.button, self, self._OnClickStoryItem, i)
  596. end
  597. end
  598. end
  599. end
  600. end
  601. end
  602. if enterType == Enum.BigMapEnterType.DropPoint then
  603. if not self.executeSequenceData:HasDelayMethod() then
  604. self.executeSequenceData:AppendInterval(1)
  605. end
  606. self.executeSequenceData:AppendFunc(false, self, self._FallDownComplete)
  607. if self.isExecutePlayEffect then
  608. ManagerContainer.ExecuteSequenceMgr:Execute(self.executeSequenceData)
  609. end
  610. elseif enterType == Enum.BigMapEnterType.NextLevel then
  611. self:_PlayNextLevelEffect()
  612. end
  613. end
  614. function BigMapView:_OnClickStoryItem(btn, params)
  615. local levelId = params[0]
  616. local levelData = self.levelDatas[levelId]
  617. if not levelData then return end
  618. local storySection = levelData.StorySection
  619. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  620. if not storySectionData then return end
  621. if storySectionData.ClickDlgId > 0 then
  622. ManagerContainer.UIStoryMgr:MapStartStoryByStoryId(storySectionData.ClickDlgId)
  623. end
  624. end
  625. function BigMapView:_PlayFallDownAnim(luaCtr)
  626. if luaCtr.go then
  627. luaCtr.go:SetActive(true)
  628. end
  629. self:_PlayAnim(luaCtr, 'PointDropDown')
  630. end
  631. function BigMapView:_PlayAnim(luaCtr, animName)
  632. if luaCtr.animator then
  633. luaCtr.animator:Play(animName)
  634. end
  635. end
  636. function BigMapView:_FallDownComplete()
  637. self.viewBase:BigMapViewComplete()
  638. end
  639. function BigMapView:_PlayNextLevelEffect()
  640. if not self:_IsSelfAtCurMap() then return end
  641. local nextLevelId = self.curLevelId + 1
  642. local levelData = self.levelDatas[nextLevelId]
  643. if not levelData then return end
  644. if not self.selfPlayerLuaCtr then return end
  645. local pointUpAnimTime = 0.2
  646. local pointFlyAnimTime = 1
  647. local pointDownTime = 2
  648. if self.selfPlayerLuaCtr.animator then
  649. local runtimeAnimatorController = self.selfPlayerLuaCtr.animator.runtimeAnimatorController
  650. if runtimeAnimatorController then
  651. if runtimeAnimatorController:GetType() == typeof(UnityEngine.AnimatorOverrideController) then
  652. runtimeAnimatorController = runtimeAnimatorController.this
  653. local clip = runtimeAnimatorController:get('PointUp')
  654. if clip then pointUpAnimTime = clip.length end
  655. clip = runtimeAnimatorController:get('PointFly')
  656. if clip then pointFlyAnimTime = clip.length end
  657. clip = runtimeAnimatorController:get('PointDown')
  658. if clip then pointDownTime = clip.length end
  659. else
  660. local clips = runtimeAnimatorController.animationClips
  661. for i = 0, clips.Length - 1 do
  662. local clip = clips[i]
  663. if clip then
  664. local clipName = clip.name
  665. if clipName == 'PointUp' then
  666. pointUpAnimTime = clip.length
  667. elseif clipName == 'PointFly' then
  668. pointFlyAnimTime = clip.length
  669. elseif clipName == 'PointDown' then
  670. pointDownTime = clip.length
  671. end
  672. end
  673. end
  674. end
  675. end
  676. end
  677. self.executeSequenceData = ExecuteSequenceData:new()
  678. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointUp')
  679. self.executeSequenceData:AppendInterval(pointUpAnimTime)
  680. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointFly')
  681. self.executeSequenceData:AppendFunc(false, self, self._PlayMoveToNextLevel, pointFlyAnimTime)
  682. self.executeSequenceData:AppendInterval(pointFlyAnimTime)
  683. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointDown')
  684. self.executeSequenceData:AppendFunc(false, self, self._MoveToNextLevelDeleteStorySection)
  685. self.executeSequenceData:AppendInterval(pointDownTime)
  686. self.executeSequenceData:AppendFunc(false, self, self._MoveToNextLevelComplete)
  687. if self.isExecutePlayEffect then
  688. ManagerContainer.ExecuteSequenceMgr:Execute(self.executeSequenceData)
  689. end
  690. end
  691. function BigMapView:_PlayMoveToNextLevel(time)
  692. local nextLevelId = self.curLevelId + 1
  693. local levelPos = self.levelPoss[nextLevelId]
  694. if not levelPos then return end
  695. if not self.selfPlayerLuaCtr then return end
  696. if not self.selfPlayerLuaCtr.go then return end
  697. self.selfPlayerLuaCtr.go.transform:DOLocalMove(levelPos, time)
  698. end
  699. function BigMapView:_MoveToNextLevelDeleteStorySection()
  700. local nextLevelId = self.curLevelId + 1
  701. self.view.linePath.uIBigMapLine.passPointIdx = nextLevelId
  702. local levelData = self.levelDatas[nextLevelId]
  703. if not levelData then return end
  704. local storySection = levelData.StorySection
  705. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  706. if not storySectionData then return end
  707. local artType = storySectionData.ArtType
  708. if artType == Enum.StorySectionArtType.Icon then
  709. -- self:_DisposeStoryIconLuaCtr(self.curLevelId + 1)
  710. local luaCtr = self.storyIconLuaCtrs[nextLevelId]
  711. if luaCtr then
  712. if luaCtr.go then
  713. luaCtr.go:SetActive(false)
  714. end
  715. local levelPos = nil
  716. if luaCtr.image then
  717. levelPos = luaCtr.image.transform.position
  718. end
  719. if not levelPos then
  720. levelPos = self.levelPoss[nextLevelId]
  721. levelPos = self.view.content.rectTransform:TransformPoint(levelPos)
  722. end
  723. -- 为了完美衔接道具掉落的表现
  724. if not ManagerContainer.LuaBattleMgr:IsShowDifficultyTxt() and
  725. (storySectionData.Type == Enum.StorySectionEventType.GotItem
  726. or storySectionData.Type == Enum.StorySectionEventType.UnlockHangBox
  727. or storySectionData.Type == Enum.StorySectionEventType.UnlockTask) then
  728. self.executeSequenceData:InsertNextUIListener(Enum.UIPageName.UIPopGotSingle, UIEventNames.UI_PAGE_IN_END_NTF)
  729. self.hasNextStory = ManagerContainer.StoryMgr:StartStorySection(storySection, levelPos)
  730. end
  731. end
  732. else
  733. -- self:_DisposeStoryGoLuaCtr(self.curLevelId + 1)
  734. local luaCtr = self.storyGoLuaCtrs[nextLevelId]
  735. if luaCtr then
  736. if luaCtr.go then
  737. luaCtr.go:SetActive(false)
  738. end
  739. end
  740. end
  741. end
  742. function BigMapView:_MoveToNextLevelComplete()
  743. local nextLevelId = self.curLevelId + 1
  744. local levelData = self.levelDatas[nextLevelId]
  745. if levelData then
  746. local luaCtr = self.storyIconLuaCtrs[nextLevelId]
  747. local levelPos = nil
  748. if luaCtr and luaCtr.image then
  749. levelPos = luaCtr.image.transform.position
  750. end
  751. if not levelPos then
  752. levelPos = self.levelPoss[nextLevelId]
  753. levelPos = self.view.content.rectTransform:TransformPoint(levelPos)
  754. end
  755. local storySection = levelData.StorySection
  756. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  757. if storySectionData then
  758. if storySectionData.Type ~= Enum.StorySectionEventType.GotItem
  759. and storySectionData.Type ~= Enum.StorySectionEventType.UnlockHangBox
  760. and storySectionData.Type ~= Enum.StorySectionEventType.UnlockTask then
  761. self.hasNextStory = ManagerContainer.StoryMgr:StartStorySection(storySection, levelPos)
  762. self:_DisposeStoryIconLuaCtr(nextLevelId)
  763. self:_DisposeStoryGoLuaCtr(nextLevelId)
  764. self.viewBase:BigMapViewComplete(self.hasNextStory)
  765. return
  766. end
  767. end
  768. end
  769. self:_DisposeStoryIconLuaCtr(nextLevelId)
  770. self:_DisposeStoryGoLuaCtr(nextLevelId)
  771. self.viewBase:BigMapViewComplete(self.hasNextStory)
  772. --ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_OVER, true)
  773. end
  774. function BigMapView:_GetBigPoint(idx, pointPos)
  775. local point = self.bigPoints[idx]
  776. if not point then
  777. point = CommonUtil.Instantiate(self.bigPointGo, self.view.bigPoints.transform)
  778. if tolua.getpeer(point) == nil then
  779. tolua.setpeer(point, {})
  780. end
  781. -- point.button = point:GetComponent(Enum.TypeInfo.Button)
  782. self.bigPoints[idx] = point
  783. end
  784. point:SetActive(true)
  785. point.transform.localPosition = pointPos
  786. return idx + 1
  787. end
  788. function BigMapView:_DisposeBigPoints()
  789. for _, bigPoint in pairs(self.bigPoints) do
  790. if bigPoint then
  791. CommonUtil.DestroyGO(bigPoint)
  792. if tolua.getpeer(bigPoint) ~= nil then
  793. tolua.setpeer(bigPoint, nil)
  794. end
  795. end
  796. end
  797. end
  798. function BigMapView:_GetSmallPoint(idx, pointPos)
  799. local point = self.smallPoints[idx]
  800. if not point then
  801. point = CommonUtil.Instantiate(self.smallPointGo, self.view.smallPoints.transform)
  802. if tolua.getpeer(point) == nil then
  803. tolua.setpeer(point, {})
  804. end
  805. -- point.button = point:GetComponent(Enum.TypeInfo.Button)
  806. self.smallPoints[idx] = point
  807. end
  808. -- if ManagerContainer.LuaBattleMgr:IsShowDifficultyTxt() then
  809. -- LogError("------------smallIdx------------------------")
  810. -- point:SetActive(false)
  811. -- else
  812. -- end
  813. point:SetActive(true)
  814. point.transform.localPosition = pointPos
  815. return idx + 1
  816. end
  817. function BigMapView:_DisposeSmallPoints()
  818. for _, smallPoint in pairs(self.smallPoints) do
  819. if smallPoint then
  820. CommonUtil.DestroyGO(smallPoint)
  821. if tolua.getpeer(smallPoint) ~= nil then
  822. tolua.setpeer(smallPoint, nil)
  823. end
  824. end
  825. end
  826. end
  827. function BigMapView:_CreateStartPoint(pointPos)
  828. if not self.startPoint then
  829. local startItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, PointStartItemPath)
  830. self.startPoint = startItem
  831. end
  832. if self.startPoint then
  833. local startItemTrans = self.startPoint.transform
  834. startItemTrans:SetParent(self.view.startPoint.transform, false)
  835. startItemTrans.localPosition = pointPos
  836. startItemTrans.localRotation = Quaternion.identity
  837. startItemTrans.localScale = Vector3.one
  838. self.startPoint:SetActive(true)
  839. end
  840. end
  841. function BigMapView:_DisposeStartPoint()
  842. if self.startPoint then
  843. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointStartItemPath, self.startPoint)
  844. self.startPoint = nil
  845. end
  846. end
  847. function BigMapView:_CreateStoryIconLuaCtr(levelId, artRes, pointPos)
  848. local iconItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, PointIconItemPath)
  849. local iconAnimator, iconImage, button
  850. if iconItem then
  851. local iconItemTrans = iconItem.transform
  852. iconItemTrans:SetParent(self.view.storyPoints.transform, false)
  853. iconItem:SetActive(true)
  854. iconItemTrans.localPosition = pointPos
  855. iconItemTrans.localRotation = Quaternion.identity
  856. iconItemTrans.localScale = Vector3.one
  857. iconAnimator = iconItem:GetComponent(Enum.TypeInfo.Animator)
  858. iconImage = iconItemTrans:Find('Root/Item/Content/Icon'):GetComponent(Enum.TypeInfo.Image)
  859. button = iconItemTrans:Find('Root/Button'):GetComponent(Enum.TypeInfo.Button)
  860. iconImage.sprite = ManagerContainer.ResMgr:GetAsset(Constants.IconDir, artRes)
  861. iconAnimator:Play('PointKeep')
  862. end
  863. local luaCtr = {}
  864. luaCtr.go = iconItem
  865. luaCtr.image = iconImage
  866. luaCtr.button = button
  867. luaCtr.animator = iconAnimator
  868. luaCtr.isIcon = true
  869. self.storyIconLuaCtrs[levelId] = luaCtr
  870. return luaCtr
  871. end
  872. function BigMapView:_DisposeStoryIconLuaCtrs()
  873. for i = #self.levelDatas, 1, -1 do
  874. self:_DisposeStoryIconLuaCtr(i)
  875. end
  876. end
  877. function BigMapView:_DisposeStoryIconLuaCtr(levelId)
  878. local luaCtr = self.storyIconLuaCtrs[levelId]
  879. if luaCtr then
  880. if luaCtr.go then
  881. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointIconItemPath, luaCtr.go)
  882. end
  883. if luaCtr.image then
  884. luaCtr.image.sprite = nil
  885. end
  886. luaCtr.go = nil
  887. luaCtr.image = nil
  888. luaCtr.animator = nil
  889. self.storyIconLuaCtrs[levelId] = nil
  890. end
  891. end
  892. function BigMapView:_CreateStoryGoLuaCtr(levelId, artRes, pointPos)
  893. local goItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, artRes)
  894. local goAnimator, button
  895. if goItem then
  896. local goItemTrans = goItem.transform
  897. goItemTrans:SetParent(self.view.storyPoints.transform, false)
  898. goItem:SetActive(true)
  899. goItemTrans.localPosition = pointPos
  900. goItemTrans.localRotation = Quaternion.identity
  901. goItemTrans.localScale = Vector3.one
  902. goAnimator = goItem:GetComponent(Enum.TypeInfo.Animator)
  903. button = goItemTrans:Find('Root/Button'):GetComponent(Enum.TypeInfo.Button)
  904. goAnimator:Play('PointKeep')
  905. end
  906. local luaCtr = {}
  907. luaCtr.go = goItem
  908. luaCtr.assetName = artRes
  909. luaCtr.button = button
  910. luaCtr.animator = goAnimator
  911. self.storyGoLuaCtrs[levelId] = luaCtr
  912. return luaCtr
  913. end
  914. function BigMapView:_DisposeStoryGoLuaCtrs()
  915. for i = #self.levelDatas, 1, -1 do
  916. self:_DisposeStoryGoLuaCtr(i)
  917. end
  918. end
  919. function BigMapView:_DisposeStoryGoLuaCtr(levelId)
  920. local luaCtr = self.storyGoLuaCtrs[levelId]
  921. if luaCtr then
  922. if luaCtr.go then
  923. ManagerContainer.ResMgr:RecycleGO(uiPath, luaCtr.assetName, luaCtr.go)
  924. end
  925. luaCtr.go = nil
  926. luaCtr.assetName = nil
  927. luaCtr.animator = nil
  928. self.storyGoLuaCtrs[levelId] = nil
  929. end
  930. end
  931. function BigMapView:_DisposeSelfPlayerLuaCtr()
  932. if not self.selfPlayerLuaCtr then return end
  933. local luaCtr = self.selfPlayerLuaCtr
  934. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointPlayerItemPath, luaCtr.go)
  935. luaCtr.go = nil
  936. luaCtr.iconImage = nil
  937. luaCtr.myRankGo = nil
  938. luaCtr.dscLeftGo = nil
  939. luaCtr.dscLeftRect = nil
  940. luaCtr.dscLeftTxt = nil
  941. luaCtr.dscRightGO = nil
  942. luaCtr.dscRightTxt = nil
  943. luaCtr.animator = nil
  944. self.selfPlayerLuaCtr = nil
  945. end
  946. function BigMapView:_IsSelfAtCurMap()
  947. return self.showMapId == self.curMapId
  948. end
  949. function BigMapView:_IsPassedPoint(levelId)
  950. if self.showMapId == self.curMapId then
  951. return self.curLevelId >= levelId
  952. else
  953. return (self.curMapId > self.showMapId)
  954. end
  955. end
  956. function BigMapView:_RectTransformContain(a, b)
  957. if not a or not b then return false end
  958. local rectA = a.rect
  959. local minA = a:TransformPoint(rectA.min)
  960. local maxA = a:TransformPoint(rectA.max)
  961. local rectB = b.rect
  962. local minB = b:TransformPoint(rectB.min)
  963. local maxB = b:TransformPoint(rectB.max)
  964. return (minB.x >= minA.x and minB.x < maxA.x and minB.y >= minA.y and minB.y < maxA.y
  965. and maxB.x >= minA.x and maxB.x < maxA.x and maxB.y >= minA.y and maxB.y < maxA.y)
  966. end
  967. function BigMapView:HardRef()
  968. if ManagerContainer.LuaBattleMgr:IsShowDifficultyTxt() then
  969. self.view.storyPoints:SetActive(false)
  970. else
  971. self.view.storyPoints:SetActive(true)
  972. end
  973. end
  974. return BigMapView