BigMapView.lua 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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:GetBattleMode() == 1 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:GetBattleMode() == 1 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. end
  439. function BigMapView:_PreloadedAssets()
  440. local uiPath = Constants.UIPath
  441. local enterType = self.enterType
  442. local cfgMgr = ManagerContainer.CfgMgr
  443. local resMgr = ManagerContainer.ResMgr
  444. local showRect = self.showRect
  445. local levelDatas = self.levelDatas
  446. local levelPoss = self.levelPoss
  447. local levelDataNum = #levelDatas
  448. local isOneStory = true
  449. local uiStoryMgr = nil
  450. if enterType == Enum.BigMapEnterType.DropPoint then
  451. self.executeSequenceData = ExecuteSequenceData:new()
  452. uiStoryMgr = ManagerContainer.UIStoryMgr
  453. end
  454. local startPos = self.levelStartPos
  455. if self:_IsSelfAtCurMap() then
  456. if not self.selfPlayerLuaCtr then
  457. local selfGoItem = resMgr:GetGoFromPool(uiPath, PointPlayerItemPath)
  458. local iconImage, myRankGo, dscLeftGo, dscLeftTxt, dscRightGO, dscRightTxt, selfGoAnimator
  459. if selfGoItem then
  460. local selfGoItemTrans = selfGoItem.transform
  461. selfGoItemTrans:SetParent(self.view.selfContainer.transform, false)
  462. selfGoItemTrans.localPosition = startPos
  463. selfGoItemTrans.localRotation = Quaternion.identity
  464. selfGoItemTrans.localScale = Vector3.one
  465. iconImage = selfGoItemTrans:Find('Root/Item/Content/Icon'):GetComponent(Enum.TypeInfo.Image)
  466. myRankGo = selfGoItemTrans:Find('Root/Item/MyRank').gameObject
  467. dscLeftGo = selfGoItemTrans:Find('Root/DscLeft').gameObject
  468. dscLeftTxt = selfGoItemTrans:Find('Root/DscLeft/DesTxt'):GetComponent(Enum.TypeInfo.Text)
  469. dscRightGO = selfGoItemTrans:Find('Root/DscRight').gameObject
  470. dscRightTxt = selfGoItemTrans:Find('Root/DscRight/DesTxt'):GetComponent(Enum.TypeInfo.Text)
  471. selfGoAnimator = selfGoItem:GetComponent(Enum.TypeInfo.Animator)
  472. end
  473. local luaCtr = {}
  474. luaCtr.go = selfGoItem
  475. luaCtr.iconImage = iconImage
  476. luaCtr.myRankGo = myRankGo
  477. luaCtr.dscLeftGo = dscLeftGo
  478. if dscLeftGo then
  479. luaCtr.dscLeftRect = dscLeftGo:GetComponent(Enum.TypeInfo.RectTransform)
  480. end
  481. luaCtr.dscLeftTxt = dscLeftTxt
  482. luaCtr.dscRightGO = dscRightGO
  483. luaCtr.dscRightTxt = dscRightTxt
  484. luaCtr.animator = selfGoAnimator
  485. self.selfPlayerLuaCtr = luaCtr
  486. end
  487. self:RefreshSelfHead()
  488. self:RefreshSelfRank()
  489. self:RefreshSelfPos()
  490. if enterType ~= Enum.BigMapEnterType.DropPoint then
  491. self:AlginCenter()
  492. end
  493. end
  494. if not showRect or showRect:Contains(startPos) then
  495. self:_CreateStartPoint(startPos)
  496. end
  497. local smallStartIdx = 1
  498. local smallEndIdx = levelDataNum
  499. for i = 1, levelDataNum do
  500. local pointPos = levelPoss[i]
  501. if not showRect or showRect:Contains(pointPos) then
  502. if self:_IsPassedPoint(i) then
  503. smallStartIdx = i + 1
  504. else
  505. if not smallEndIdx then
  506. smallEndIdx = i - 1
  507. end
  508. local levelData = levelDatas[i]
  509. local pointType = levelData.LevelPointType or 0
  510. if pointType == 0 then
  511. local storySection = levelData.StorySection
  512. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  513. if storySectionData then
  514. if enterType == Enum.BigMapEnterType.DropPoint then
  515. local startDropMoveTime = storySectionData.StartDropMoveTime
  516. if storySectionData.StartDropPos and #storySectionData.StartDropPos > 0 then
  517. self.executeSequenceData:AppendFunc(false, self, self._AlginCenterPos, CommonUtil.TableToVector2(storySectionData.StartDropPos), startDropMoveTime)
  518. if (startDropMoveTime and startDropMoveTime > 0) then
  519. self.executeSequenceData:AppendInterval(startDropMoveTime)
  520. end
  521. end
  522. if isOneStory and self.selfPlayerLuaCtr then
  523. isOneStory = false
  524. if self.selfPlayerLuaCtr.go then
  525. self.selfPlayerLuaCtr.go:SetActive(false)
  526. end
  527. self.executeSequenceData:AppendFunc(false, self, self._PlayFallDownAnim, self.selfPlayerLuaCtr)
  528. self.executeSequenceData:AppendInterval(1)
  529. end
  530. if storySectionData.StartDropDlgId > 0 then
  531. -- 需要至少延迟一帧时间,避免对话框刚刚关闭就需要打开,导致逻辑混乱
  532. self.executeSequenceData:AppendFrameInterval(1)
  533. self.executeSequenceData:AppendFunc(false, uiStoryMgr, uiStoryMgr.MapStartStoryByStoryId, storySectionData.StartDropDlgId)
  534. self.executeSequenceData:AppendUIListener(Enum.UIPageName.UIStory, UIEventNames.UI_PAGE_OUT_END_NTF)
  535. end
  536. end
  537. local artType = storySectionData.ArtType
  538. local artRes = storySectionData.ArtRes
  539. if artType == Enum.StorySectionArtType.Icon then
  540. local luaCtr = self:_CreateStoryIconLuaCtr(i, artRes, pointPos)
  541. if enterType == Enum.BigMapEnterType.DropPoint then
  542. if luaCtr.go then
  543. luaCtr.go:SetActive(false)
  544. end
  545. self.executeSequenceData:AppendFunc(false, self, self._PlayFallDownAnim, luaCtr)
  546. elseif enterType == Enum.BigMapEnterType.Default then
  547. self.viewBase.uiBase:AddButtonUniqueEventListener(luaCtr.button, self, self._OnClickStoryItem, i)
  548. end
  549. else
  550. local luaCtr = self:_CreateStoryGoLuaCtr(i, artRes, pointPos)
  551. if enterType == Enum.BigMapEnterType.DropPoint then
  552. if luaCtr.go then
  553. luaCtr.go:SetActive(false)
  554. end
  555. self.executeSequenceData:AppendFunc(false, self, self._PlayFallDownAnim, luaCtr)
  556. elseif enterType == Enum.BigMapEnterType.Default then
  557. self.viewBase.uiBase:AddButtonUniqueEventListener(luaCtr.button, self, self._OnClickStoryItem, i)
  558. end
  559. end
  560. if enterType == Enum.BigMapEnterType.DropPoint then
  561. self.executeSequenceData:AppendInterval(1)
  562. if storySectionData.EndDropDlgId > 0 then
  563. self.executeSequenceData:AppendFunc(false, uiStoryMgr, uiStoryMgr.MapStartStoryByStoryId, storySectionData.EndDropDlgId)
  564. self.executeSequenceData:AppendUIListener(Enum.UIPageName.UIStory, UIEventNames.UI_PAGE_OUT_END_NTF)
  565. end
  566. end
  567. end
  568. end
  569. end
  570. end
  571. end
  572. if enterType ~= Enum.BigMapEnterType.DropPoint then
  573. if smallStartIdx < smallEndIdx and smallEndIdx <= levelDataNum then
  574. for i = smallStartIdx, smallEndIdx do
  575. local levelData = levelDatas[i]
  576. local pointType = levelData.LevelPointType or 0
  577. if pointType == 0 then
  578. break
  579. end
  580. if not self:_IsPassedPoint(i) then
  581. local storySection = levelData.StorySection
  582. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  583. if storySectionData then
  584. local artType = storySectionData.ArtType
  585. local artRes = storySectionData.ArtRes
  586. local pointPos = levelPoss[i]
  587. local luaCtr = nil
  588. if artType == Enum.StorySectionArtType.Icon then
  589. luaCtr = self:_CreateStoryIconLuaCtr(i, artRes, pointPos)
  590. else
  591. luaCtr = self:_CreateStoryGoLuaCtr(i, artRes, pointPos)
  592. end
  593. if luaCtr and enterType == Enum.BigMapEnterType.Default then
  594. self.viewBase.uiBase:AddButtonUniqueEventListener(luaCtr.button, self, self._OnClickStoryItem, i)
  595. end
  596. end
  597. end
  598. end
  599. end
  600. end
  601. if enterType == Enum.BigMapEnterType.DropPoint then
  602. if not self.executeSequenceData:HasDelayMethod() then
  603. self.executeSequenceData:AppendInterval(1)
  604. end
  605. self.executeSequenceData:AppendFunc(false, self, self._FallDownComplete)
  606. if self.isExecutePlayEffect then
  607. ManagerContainer.ExecuteSequenceMgr:Execute(self.executeSequenceData)
  608. end
  609. elseif enterType == Enum.BigMapEnterType.NextLevel then
  610. self:_PlayNextLevelEffect()
  611. end
  612. end
  613. function BigMapView:_OnClickStoryItem(btn, params)
  614. local levelId = params[0]
  615. local levelData = self.levelDatas[levelId]
  616. if not levelData then return end
  617. local storySection = levelData.StorySection
  618. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  619. if not storySectionData then return end
  620. if storySectionData.ClickDlgId > 0 then
  621. ManagerContainer.UIStoryMgr:MapStartStoryByStoryId(storySectionData.ClickDlgId)
  622. end
  623. end
  624. function BigMapView:_PlayFallDownAnim(luaCtr)
  625. if luaCtr.go then
  626. luaCtr.go:SetActive(true)
  627. end
  628. self:_PlayAnim(luaCtr, 'PointDropDown')
  629. end
  630. function BigMapView:_PlayAnim(luaCtr, animName)
  631. if luaCtr.animator then
  632. luaCtr.animator:Play(animName)
  633. end
  634. end
  635. function BigMapView:_FallDownComplete()
  636. self.viewBase:BigMapViewComplete()
  637. end
  638. function BigMapView:_PlayNextLevelEffect()
  639. if not self:_IsSelfAtCurMap() then return end
  640. local nextLevelId = self.curLevelId + 1
  641. local levelData = self.levelDatas[nextLevelId]
  642. if not levelData then return end
  643. if not self.selfPlayerLuaCtr then return end
  644. local pointUpAnimTime = 0.2
  645. local pointFlyAnimTime = 1
  646. local pointDownTime = 2
  647. if self.selfPlayerLuaCtr.animator then
  648. local runtimeAnimatorController = self.selfPlayerLuaCtr.animator.runtimeAnimatorController
  649. if runtimeAnimatorController then
  650. if runtimeAnimatorController:GetType() == typeof(UnityEngine.AnimatorOverrideController) then
  651. runtimeAnimatorController = runtimeAnimatorController.this
  652. local clip = runtimeAnimatorController:get('PointUp')
  653. if clip then pointUpAnimTime = clip.length end
  654. clip = runtimeAnimatorController:get('PointFly')
  655. if clip then pointFlyAnimTime = clip.length end
  656. clip = runtimeAnimatorController:get('PointDown')
  657. if clip then pointDownTime = clip.length end
  658. else
  659. local clips = runtimeAnimatorController.animationClips
  660. for i = 0, clips.Length - 1 do
  661. local clip = clips[i]
  662. if clip then
  663. local clipName = clip.name
  664. if clipName == 'PointUp' then
  665. pointUpAnimTime = clip.length
  666. elseif clipName == 'PointFly' then
  667. pointFlyAnimTime = clip.length
  668. elseif clipName == 'PointDown' then
  669. pointDownTime = clip.length
  670. end
  671. end
  672. end
  673. end
  674. end
  675. end
  676. self.executeSequenceData = ExecuteSequenceData:new()
  677. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointUp')
  678. self.executeSequenceData:AppendInterval(pointUpAnimTime)
  679. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointFly')
  680. self.executeSequenceData:AppendFunc(false, self, self._PlayMoveToNextLevel, pointFlyAnimTime)
  681. self.executeSequenceData:AppendInterval(pointFlyAnimTime)
  682. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointDown')
  683. self.executeSequenceData:AppendFunc(false, self, self._MoveToNextLevelDeleteStorySection)
  684. self.executeSequenceData:AppendInterval(pointDownTime)
  685. self.executeSequenceData:AppendFunc(false, self, self._MoveToNextLevelComplete)
  686. if self.isExecutePlayEffect then
  687. ManagerContainer.ExecuteSequenceMgr:Execute(self.executeSequenceData)
  688. end
  689. end
  690. function BigMapView:_PlayMoveToNextLevel(time)
  691. local nextLevelId = self.curLevelId + 1
  692. local levelPos = self.levelPoss[nextLevelId]
  693. if not levelPos then return end
  694. if not self.selfPlayerLuaCtr then return end
  695. if not self.selfPlayerLuaCtr.go then return end
  696. self.selfPlayerLuaCtr.go.transform:DOLocalMove(levelPos, time)
  697. end
  698. function BigMapView:_MoveToNextLevelDeleteStorySection()
  699. local nextLevelId = self.curLevelId + 1
  700. self.view.linePath.uIBigMapLine.passPointIdx = nextLevelId
  701. local levelData = self.levelDatas[nextLevelId]
  702. if not levelData then return end
  703. local storySection = levelData.StorySection
  704. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  705. if not storySectionData then return end
  706. local artType = storySectionData.ArtType
  707. if artType == Enum.StorySectionArtType.Icon then
  708. -- self:_DisposeStoryIconLuaCtr(self.curLevelId + 1)
  709. local luaCtr = self.storyIconLuaCtrs[nextLevelId]
  710. if luaCtr then
  711. if luaCtr.go then
  712. luaCtr.go:SetActive(false)
  713. end
  714. local levelPos = nil
  715. if luaCtr.image then
  716. levelPos = luaCtr.image.transform.position
  717. end
  718. if not levelPos then
  719. levelPos = self.levelPoss[nextLevelId]
  720. levelPos = self.view.content.rectTransform:TransformPoint(levelPos)
  721. end
  722. -- 为了完美衔接道具掉落的表现
  723. if storySectionData.Type == Enum.StorySectionEventType.GotItem
  724. or storySectionData.Type == Enum.StorySectionEventType.UnlockHangBox
  725. or storySectionData.Type == Enum.StorySectionEventType.UnlockTask then
  726. self.executeSequenceData:InsertNextUIListener(Enum.UIPageName.UIPopGotSingle, UIEventNames.UI_PAGE_IN_END_NTF)
  727. self.hasNextStory = ManagerContainer.StoryMgr:StartStorySection(storySection, levelPos)
  728. end
  729. end
  730. else
  731. -- self:_DisposeStoryGoLuaCtr(self.curLevelId + 1)
  732. local luaCtr = self.storyGoLuaCtrs[nextLevelId]
  733. if luaCtr then
  734. if luaCtr.go then
  735. luaCtr.go:SetActive(false)
  736. end
  737. end
  738. end
  739. end
  740. function BigMapView:_MoveToNextLevelComplete()
  741. local nextLevelId = self.curLevelId + 1
  742. local levelData = self.levelDatas[nextLevelId]
  743. if levelData then
  744. local luaCtr = self.storyIconLuaCtrs[nextLevelId]
  745. local levelPos = nil
  746. if luaCtr and luaCtr.image then
  747. levelPos = luaCtr.image.transform.position
  748. end
  749. if not levelPos then
  750. levelPos = self.levelPoss[nextLevelId]
  751. levelPos = self.view.content.rectTransform:TransformPoint(levelPos)
  752. end
  753. local storySection = levelData.StorySection
  754. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  755. if storySectionData then
  756. if storySectionData.Type ~= Enum.StorySectionEventType.GotItem
  757. and storySectionData.Type ~= Enum.StorySectionEventType.UnlockHangBox
  758. and storySectionData.Type ~= Enum.StorySectionEventType.UnlockTask then
  759. self.hasNextStory = ManagerContainer.StoryMgr:StartStorySection(storySection, levelPos)
  760. self:_DisposeStoryIconLuaCtr(nextLevelId)
  761. self:_DisposeStoryGoLuaCtr(nextLevelId)
  762. self.viewBase:BigMapViewComplete(self.hasNextStory)
  763. return
  764. end
  765. end
  766. end
  767. self:_DisposeStoryIconLuaCtr(nextLevelId)
  768. self:_DisposeStoryGoLuaCtr(nextLevelId)
  769. self.viewBase:BigMapViewComplete(self.hasNextStory)
  770. --ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_OVER, true)
  771. end
  772. function BigMapView:_GetBigPoint(idx, pointPos)
  773. local point = self.bigPoints[idx]
  774. if not point then
  775. point = CommonUtil.Instantiate(self.bigPointGo, self.view.bigPoints.transform)
  776. if tolua.getpeer(point) == nil then
  777. tolua.setpeer(point, {})
  778. end
  779. -- point.button = point:GetComponent(Enum.TypeInfo.Button)
  780. self.bigPoints[idx] = point
  781. end
  782. point:SetActive(true)
  783. point.transform.localPosition = pointPos
  784. return idx + 1
  785. end
  786. function BigMapView:_DisposeBigPoints()
  787. for _, bigPoint in pairs(self.bigPoints) do
  788. if bigPoint then
  789. CommonUtil.DestroyGO(bigPoint)
  790. if tolua.getpeer(bigPoint) ~= nil then
  791. tolua.setpeer(bigPoint, nil)
  792. end
  793. end
  794. end
  795. end
  796. function BigMapView:_GetSmallPoint(idx, pointPos)
  797. local point = self.smallPoints[idx]
  798. if not point then
  799. point = CommonUtil.Instantiate(self.smallPointGo, self.view.smallPoints.transform)
  800. if tolua.getpeer(point) == nil then
  801. tolua.setpeer(point, {})
  802. end
  803. -- point.button = point:GetComponent(Enum.TypeInfo.Button)
  804. self.smallPoints[idx] = point
  805. end
  806. point:SetActive(true)
  807. point.transform.localPosition = pointPos
  808. return idx + 1
  809. end
  810. function BigMapView:_DisposeSmallPoints()
  811. for _, smallPoint in pairs(self.smallPoints) do
  812. if smallPoint then
  813. CommonUtil.DestroyGO(smallPoint)
  814. if tolua.getpeer(smallPoint) ~= nil then
  815. tolua.setpeer(smallPoint, nil)
  816. end
  817. end
  818. end
  819. end
  820. function BigMapView:_CreateStartPoint(pointPos)
  821. if not self.startPoint then
  822. local startItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, PointStartItemPath)
  823. self.startPoint = startItem
  824. end
  825. if self.startPoint then
  826. local startItemTrans = self.startPoint.transform
  827. startItemTrans:SetParent(self.view.startPoint.transform, false)
  828. startItemTrans.localPosition = pointPos
  829. startItemTrans.localRotation = Quaternion.identity
  830. startItemTrans.localScale = Vector3.one
  831. self.startPoint:SetActive(true)
  832. end
  833. end
  834. function BigMapView:_DisposeStartPoint()
  835. if self.startPoint then
  836. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointStartItemPath, self.startPoint)
  837. self.startPoint = nil
  838. end
  839. end
  840. function BigMapView:_CreateStoryIconLuaCtr(levelId, artRes, pointPos)
  841. local iconItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, PointIconItemPath)
  842. local iconAnimator, iconImage, button
  843. if iconItem then
  844. local iconItemTrans = iconItem.transform
  845. iconItemTrans:SetParent(self.view.storyPoints.transform, false)
  846. iconItem:SetActive(true)
  847. iconItemTrans.localPosition = pointPos
  848. iconItemTrans.localRotation = Quaternion.identity
  849. iconItemTrans.localScale = Vector3.one
  850. iconAnimator = iconItem:GetComponent(Enum.TypeInfo.Animator)
  851. iconImage = iconItemTrans:Find('Root/Item/Content/Icon'):GetComponent(Enum.TypeInfo.Image)
  852. button = iconItemTrans:Find('Root/Button'):GetComponent(Enum.TypeInfo.Button)
  853. iconImage.sprite = ManagerContainer.ResMgr:GetAsset(Constants.IconDir, artRes)
  854. iconAnimator:Play('PointKeep')
  855. end
  856. local luaCtr = {}
  857. luaCtr.go = iconItem
  858. luaCtr.image = iconImage
  859. luaCtr.button = button
  860. luaCtr.animator = iconAnimator
  861. self.storyIconLuaCtrs[levelId] = luaCtr
  862. return luaCtr
  863. end
  864. function BigMapView:_DisposeStoryIconLuaCtrs()
  865. for i = #self.levelDatas, 1, -1 do
  866. self:_DisposeStoryIconLuaCtr(i)
  867. end
  868. end
  869. function BigMapView:_DisposeStoryIconLuaCtr(levelId)
  870. local luaCtr = self.storyIconLuaCtrs[levelId]
  871. if luaCtr then
  872. if luaCtr.go then
  873. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointIconItemPath, luaCtr.go)
  874. end
  875. if luaCtr.image then
  876. luaCtr.image.sprite = nil
  877. end
  878. luaCtr.go = nil
  879. luaCtr.image = nil
  880. luaCtr.animator = nil
  881. self.storyIconLuaCtrs[levelId] = nil
  882. end
  883. end
  884. function BigMapView:_CreateStoryGoLuaCtr(levelId, artRes, pointPos)
  885. local goItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, artRes)
  886. local goAnimator, button
  887. if goItem then
  888. local goItemTrans = goItem.transform
  889. goItemTrans:SetParent(self.view.storyPoints.transform, false)
  890. goItem:SetActive(true)
  891. goItemTrans.localPosition = pointPos
  892. goItemTrans.localRotation = Quaternion.identity
  893. goItemTrans.localScale = Vector3.one
  894. goAnimator = goItem:GetComponent(Enum.TypeInfo.Animator)
  895. button = goItemTrans:Find('Root/Button'):GetComponent(Enum.TypeInfo.Button)
  896. goAnimator:Play('PointKeep')
  897. end
  898. local luaCtr = {}
  899. luaCtr.go = goItem
  900. luaCtr.assetName = artRes
  901. luaCtr.button = button
  902. luaCtr.animator = goAnimator
  903. self.storyGoLuaCtrs[levelId] = luaCtr
  904. return luaCtr
  905. end
  906. function BigMapView:_DisposeStoryGoLuaCtrs()
  907. for i = #self.levelDatas, 1, -1 do
  908. self:_DisposeStoryGoLuaCtr(i)
  909. end
  910. end
  911. function BigMapView:_DisposeStoryGoLuaCtr(levelId)
  912. local luaCtr = self.storyGoLuaCtrs[levelId]
  913. if luaCtr then
  914. if luaCtr.go then
  915. ManagerContainer.ResMgr:RecycleGO(uiPath, luaCtr.assetName, luaCtr.go)
  916. end
  917. luaCtr.go = nil
  918. luaCtr.assetName = nil
  919. luaCtr.animator = nil
  920. self.storyGoLuaCtrs[levelId] = nil
  921. end
  922. end
  923. function BigMapView:_DisposeSelfPlayerLuaCtr()
  924. if not self.selfPlayerLuaCtr then return end
  925. local luaCtr = self.selfPlayerLuaCtr
  926. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointPlayerItemPath, luaCtr.go)
  927. luaCtr.go = nil
  928. luaCtr.iconImage = nil
  929. luaCtr.myRankGo = nil
  930. luaCtr.dscLeftGo = nil
  931. luaCtr.dscLeftRect = nil
  932. luaCtr.dscLeftTxt = nil
  933. luaCtr.dscRightGO = nil
  934. luaCtr.dscRightTxt = nil
  935. luaCtr.animator = nil
  936. self.selfPlayerLuaCtr = nil
  937. end
  938. function BigMapView:_IsSelfAtCurMap()
  939. return self.showMapId == self.curMapId
  940. end
  941. function BigMapView:_IsPassedPoint(levelId)
  942. if self.showMapId == self.curMapId then
  943. return self.curLevelId >= levelId
  944. else
  945. return (self.curMapId > self.showMapId)
  946. end
  947. end
  948. function BigMapView:_RectTransformContain(a, b)
  949. if not a or not b then return false end
  950. local rectA = a.rect
  951. local minA = a:TransformPoint(rectA.min)
  952. local maxA = a:TransformPoint(rectA.max)
  953. local rectB = b.rect
  954. local minB = b:TransformPoint(rectB.min)
  955. local maxB = b:TransformPoint(rectB.max)
  956. return (minB.x >= minA.x and minB.x < maxA.x and minB.y >= minA.y and minB.y < maxA.y
  957. and maxB.x >= minA.x and maxB.x < maxA.x and maxB.y >= minA.y and maxB.y < maxA.y)
  958. end
  959. return BigMapView