BigMapView.lua 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. end
  203. if luaCtr.dscRightGO then
  204. luaCtr.dscRightGO:SetActive(false)
  205. end
  206. else
  207. if luaCtr.dscLeftGo then
  208. luaCtr.dscLeftGo:SetActive(false)
  209. end
  210. if luaCtr.dscRightGO then
  211. luaCtr.dscRightGO:SetActive(true)
  212. end
  213. end
  214. end
  215. function BigMapView:AlginCenter()
  216. if self.showMapId ~= self.curMapId then
  217. return
  218. end
  219. self:_AlginCenterLevelId(self.curLevelId)
  220. end
  221. function BigMapView:OnPageInEnd()
  222. if self.isExecutePlayEffect then return end
  223. if self.targetAlginPointPos then
  224. self.view.scrollRect.normalizedPosition = self:_CalcAlginNormalizedPosition(self.targetAlginPointPos)
  225. if self.pageOpenFrameTimer then
  226. self.pageOpenFrameTimer.duration = 1
  227. self.pageOpenFrameTimer.loop = 1
  228. self.pageOpenFrameTimer.count = Time.frameCount + 1
  229. else
  230. self.pageOpenFrameTimer = FrameTimer.New(function()
  231. if self.targetAlginPointPos then
  232. local normalizedPosition = self:_CalcAlginNormalizedPosition(self.targetAlginPointPos)
  233. self.view.scrollRect.normalizedPosition = normalizedPosition
  234. end
  235. end, 1)
  236. end
  237. else
  238. self:_EndPageOpenFrameTimer()
  239. end
  240. self.isExecutePlayEffect = true
  241. if self.executeSequenceData then
  242. ManagerContainer.ExecuteSequenceMgr:Execute(self.executeSequenceData)
  243. end
  244. end
  245. function BigMapView:_AlginCenterLevelId(levelId, moveTime)
  246. local pointPos = self.levelPoss[levelId]
  247. if not pointPos then
  248. return
  249. end
  250. self:_AlginCenterPos(pointPos, moveTime)
  251. end
  252. function BigMapView:_AlginCenterPos(pointPos, moveTime)
  253. if self.isExecutePlayEffect then
  254. local normalizedPosition = self:_CalcAlginNormalizedPosition(pointPos)
  255. if moveTime and moveTime > 0 then
  256. self.view.scrollRect:DONormalizedPos(normalizedPosition, moveTime)
  257. else
  258. self.view.scrollRect.normalizedPosition = normalizedPosition
  259. end
  260. else
  261. self.targetAlginPointPos = pointPos
  262. end
  263. end
  264. function BigMapView:_CalcAlginNormalizedPosition(pointPos)
  265. local scrollRect = self.view.scrollRect
  266. local viewport = scrollRect.viewport
  267. local content = scrollRect.content
  268. local viewportRect = viewport.rect
  269. local contentRect = content.rect
  270. local viewportW = viewportRect.width
  271. local contentW = contentRect.width
  272. local vaildW = contentW - viewportW
  273. local viewportH = viewportRect.height
  274. local contentH = contentRect.height
  275. local vaildH = contentH - viewportH
  276. local valW = Mathf.Clamp01((pointPos.x / vaildW) + 0.5)
  277. local valH = Mathf.Clamp01((pointPos.y / vaildH) + 0.5)
  278. return Vector2(valW, valH)
  279. end
  280. -- function BigMapView:RefreshTopPlayerRankAndPos(playerList)
  281. -- local oneRank = self.view.oneRank
  282. -- if not playerList then
  283. -- oneRank:SetActive(false)
  284. -- return
  285. -- end
  286. -- local playerInfo = playerList[1]
  287. -- if not playerInfo then
  288. -- oneRank:SetActive(false)
  289. -- return
  290. -- end
  291. -- local uid = playerInfo.uid
  292. -- local curUserId = ManagerContainer.DataMgr.UserData:GetUserId()
  293. -- if int64.equals(curUserId, uid) then
  294. -- oneRank:SetActive(false)
  295. -- return
  296. -- end
  297. -- local mapId = playerInfo.mapId
  298. -- if mapId ~= self.showMapId then
  299. -- oneRank:SetActive(false)
  300. -- return
  301. -- end
  302. -- local mapLevel = playerInfo.mapLevel
  303. -- local pointPos = self.levelPoss[mapLevel]
  304. -- if not pointPos then
  305. -- oneRank:SetActive(false)
  306. -- return
  307. -- end
  308. -- oneRank:SetActive(true)
  309. -- oneRank.transform.position = pointPos
  310. -- end
  311. function BigMapView:_RefreshMapBg()
  312. local mapData = self.mapData
  313. local image = self.view.bottomImage.image
  314. image.sprite = nil
  315. image.enabled = false
  316. CommonUtil.LoadIcon(self, mapData.AreaPic, function (sprite)
  317. image.sprite = sprite
  318. image.enabled = true
  319. end, self, MapAreaIconAsyncIdx)
  320. self.view.bottomImage.rectTransform.sizeDelta = CommonUtil.TableToVector2(mapData.PicSize)
  321. local scrollSize = CommonUtil.TableToVector2(mapData.ScrollSize)
  322. self.view.content.rectTransform.sizeDelta = scrollSize
  323. end
  324. function BigMapView:_RefreshPoints()
  325. local uiPath = Constants.UIPath
  326. local iconDir = Constants.IconDir
  327. local loadSystem = self.loadSystem
  328. loadSystem:Cancel()
  329. loadSystem:RemoveLoadAllAsset()
  330. local cfgMgr = ManagerContainer.CfgMgr
  331. local showRect = self.showRect
  332. local line = self.view.linePath.uIBigMapLine
  333. local levelDatas = self.levelDatas
  334. local levelPoss = self.levelPoss
  335. local levelDataNum = #levelDatas
  336. local smallStartIdx = 1
  337. local smallEndIdx = levelDataNum
  338. local enterType = self.enterType
  339. local isOneStory = true
  340. line:ClearPoints()
  341. local startPos = self.levelStartPos
  342. if not showRect or showRect:Contains(startPos) then
  343. self.loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, PointStartItemPath)
  344. end
  345. line:AddPoint(startPos)
  346. local bigIdx = 1
  347. for i = 1, levelDataNum do
  348. local pointPos = levelPoss[i]
  349. line:AddPoint(pointPos)
  350. if not showRect or showRect:Contains(pointPos) then
  351. local levelData = levelDatas[i]
  352. local pointType = levelData.LevelPointType or 0
  353. if pointType == 0 then
  354. bigIdx = self:_GetBigPoint(bigIdx, pointPos)
  355. if self:_IsPassedPoint(i) then
  356. smallStartIdx = i + 1
  357. else
  358. if not smallEndIdx then
  359. smallEndIdx = i - 1
  360. end
  361. local storySection = levelData.StorySection
  362. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  363. if storySectionData then
  364. local artType = storySectionData.ArtType
  365. local artRes = storySectionData.ArtRes
  366. if artType == Enum.StorySectionArtType.Icon then
  367. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, PointIconItemPath)
  368. loadSystem:AddLoadAsset(Enum.ResourceType.Sprite, iconDir, artRes)
  369. else
  370. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, artRes)
  371. end
  372. if isOneStory and enterType == Enum.BigMapEnterType.DropPoint then
  373. isOneStory = false
  374. if storySectionData.StartDropPos and #storySectionData.StartDropPos > 0 then
  375. self:_AlginCenterPos(CommonUtil.TableToVector2(storySectionData.StartDropPos))
  376. end
  377. end
  378. end
  379. end
  380. end
  381. end
  382. end
  383. line:SetAllDirty()
  384. if self.curMapId ~= self.showMapId then
  385. line.passPointIdx = (self.curMapId > self.showMapId and levelDataNum or 0)
  386. else
  387. line.passPointIdx = self.curLevelId
  388. end
  389. local smallIdx = 1
  390. if self.enterType ~= Enum.BigMapEnterType.DropPoint then
  391. if smallStartIdx < smallEndIdx and smallEndIdx <= levelDataNum then
  392. for i = smallStartIdx, smallEndIdx do
  393. local levelData = levelDatas[i]
  394. local pointType = levelData.LevelPointType or 0
  395. if pointType == 0 then
  396. break
  397. end
  398. smallIdx = self:_GetSmallPoint(smallIdx, levelPoss[i])
  399. local storySection = levelData.StorySection
  400. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  401. if storySectionData then
  402. local artType = storySectionData.ArtType
  403. local artRes = storySectionData.ArtRes
  404. if artType == Enum.StorySectionArtType.Icon then
  405. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, PointIconItemPath)
  406. loadSystem:AddLoadAsset(Enum.ResourceType.Sprite, iconDir, artRes)
  407. else
  408. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, artRes)
  409. end
  410. end
  411. end
  412. end
  413. end
  414. for i = smallIdx, #self.smallPoints do
  415. self.smallPoints[i]:SetActive(false)
  416. end
  417. if self:_IsSelfAtCurMap() then
  418. if not self.selfPlayerLuaCtr then
  419. loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, uiPath, PointPlayerItemPath)
  420. end
  421. if isOneStory then
  422. self:AlginCenter()
  423. end
  424. else
  425. self:_DisposeSelfPlayerLuaCtr()
  426. end
  427. loadSystem:Begin()
  428. end
  429. function BigMapView:_PreloadedAssets()
  430. local uiPath = Constants.UIPath
  431. local enterType = self.enterType
  432. local cfgMgr = ManagerContainer.CfgMgr
  433. local resMgr = ManagerContainer.ResMgr
  434. local showRect = self.showRect
  435. local levelDatas = self.levelDatas
  436. local levelPoss = self.levelPoss
  437. local levelDataNum = #levelDatas
  438. local isOneStory = true
  439. local uiStoryMgr = nil
  440. if enterType == Enum.BigMapEnterType.DropPoint then
  441. self.executeSequenceData = ExecuteSequenceData:new()
  442. uiStoryMgr = ManagerContainer.UIStoryMgr
  443. end
  444. local startPos = self.levelStartPos
  445. if self:_IsSelfAtCurMap() then
  446. if not self.selfPlayerLuaCtr then
  447. local selfGoItem = resMgr:GetGoFromPool(uiPath, PointPlayerItemPath)
  448. local iconImage, myRankGo, dscLeftGo, dscLeftTxt, dscRightGO, dscRightTxt, selfGoAnimator
  449. if selfGoItem then
  450. local selfGoItemTrans = selfGoItem.transform
  451. selfGoItemTrans:SetParent(self.view.selfContainer.transform, false)
  452. selfGoItemTrans.localPosition = startPos
  453. selfGoItemTrans.localRotation = Quaternion.identity
  454. selfGoItemTrans.localScale = Vector3.one
  455. iconImage = selfGoItemTrans:Find('Root/Item/Content/Icon'):GetComponent(Enum.TypeInfo.Image)
  456. myRankGo = selfGoItemTrans:Find('Root/Item/MyRank').gameObject
  457. dscLeftGo = selfGoItemTrans:Find('Root/DscLeft').gameObject
  458. dscLeftTxt = selfGoItemTrans:Find('Root/DscLeft/DesTxt'):GetComponent(Enum.TypeInfo.Text)
  459. dscRightGO = selfGoItemTrans:Find('Root/DscRight').gameObject
  460. dscRightTxt = selfGoItemTrans:Find('Root/DscRight/DesTxt'):GetComponent(Enum.TypeInfo.Text)
  461. selfGoAnimator = selfGoItem:GetComponent(Enum.TypeInfo.Animator)
  462. end
  463. local luaCtr = {}
  464. luaCtr.go = selfGoItem
  465. luaCtr.iconImage = iconImage
  466. luaCtr.myRankGo = myRankGo
  467. luaCtr.dscLeftGo = dscLeftGo
  468. if dscLeftGo then
  469. luaCtr.dscLeftRect = dscLeftGo:GetComponent(Enum.TypeInfo.RectTransform)
  470. end
  471. luaCtr.dscLeftTxt = dscLeftTxt
  472. luaCtr.dscRightGO = dscRightGO
  473. luaCtr.dscRightTxt = dscRightTxt
  474. luaCtr.animator = selfGoAnimator
  475. self.selfPlayerLuaCtr = luaCtr
  476. end
  477. self:RefreshSelfHead()
  478. self:RefreshSelfRank()
  479. self:RefreshSelfPos()
  480. if enterType ~= Enum.BigMapEnterType.DropPoint then
  481. self:AlginCenter()
  482. end
  483. end
  484. if not showRect or showRect:Contains(startPos) then
  485. self:_CreateStartPoint(startPos)
  486. end
  487. local smallStartIdx = 1
  488. local smallEndIdx = levelDataNum
  489. for i = 1, levelDataNum do
  490. local pointPos = levelPoss[i]
  491. if not showRect or showRect:Contains(pointPos) then
  492. if self:_IsPassedPoint(i) then
  493. smallStartIdx = i + 1
  494. else
  495. if not smallEndIdx then
  496. smallEndIdx = i - 1
  497. end
  498. local levelData = levelDatas[i]
  499. local pointType = levelData.LevelPointType or 0
  500. if pointType == 0 then
  501. local storySection = levelData.StorySection
  502. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  503. if storySectionData then
  504. if enterType == Enum.BigMapEnterType.DropPoint then
  505. local startDropMoveTime = storySectionData.StartDropMoveTime
  506. if storySectionData.StartDropPos and #storySectionData.StartDropPos > 0 then
  507. self.executeSequenceData:AppendFunc(false, self, self._AlginCenterPos, CommonUtil.TableToVector2(storySectionData.StartDropPos), startDropMoveTime)
  508. if (startDropMoveTime and startDropMoveTime > 0) then
  509. self.executeSequenceData:AppendInterval(startDropMoveTime)
  510. end
  511. end
  512. if isOneStory and self.selfPlayerLuaCtr then
  513. isOneStory = false
  514. if self.selfPlayerLuaCtr.go then
  515. self.selfPlayerLuaCtr.go:SetActive(false)
  516. end
  517. self.executeSequenceData:AppendFunc(false, self, self._PlayFallDownAnim, self.selfPlayerLuaCtr)
  518. self.executeSequenceData:AppendInterval(1)
  519. end
  520. if storySectionData.StartDropDlgId > 0 then
  521. -- 需要至少延迟一帧时间,避免对话框刚刚关闭就需要打开,导致逻辑混乱
  522. self.executeSequenceData:AppendFrameInterval(1)
  523. self.executeSequenceData:AppendFunc(false, uiStoryMgr, uiStoryMgr.MapStartStoryByStoryId, storySectionData.StartDropDlgId)
  524. self.executeSequenceData:AppendUIListener(Enum.UIPageName.UIStory, UIEventNames.UI_PAGE_OUT_END_NTF)
  525. end
  526. end
  527. local artType = storySectionData.ArtType
  528. local artRes = storySectionData.ArtRes
  529. if artType == Enum.StorySectionArtType.Icon then
  530. local luaCtr = self:_CreateStoryIconLuaCtr(i, artRes, pointPos)
  531. if enterType == Enum.BigMapEnterType.DropPoint then
  532. if luaCtr.go then
  533. luaCtr.go:SetActive(false)
  534. end
  535. self.executeSequenceData:AppendFunc(false, self, self._PlayFallDownAnim, luaCtr)
  536. elseif enterType == Enum.BigMapEnterType.Default then
  537. self.viewBase.uiBase:AddButtonUniqueEventListener(luaCtr.button, self, self._OnClickStoryItem, i)
  538. end
  539. else
  540. local luaCtr = self:_CreateStoryGoLuaCtr(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. end
  550. if enterType == Enum.BigMapEnterType.DropPoint then
  551. self.executeSequenceData:AppendInterval(1)
  552. if storySectionData.EndDropDlgId > 0 then
  553. self.executeSequenceData:AppendFunc(false, uiStoryMgr, uiStoryMgr.MapStartStoryByStoryId, storySectionData.EndDropDlgId)
  554. self.executeSequenceData:AppendUIListener(Enum.UIPageName.UIStory, UIEventNames.UI_PAGE_OUT_END_NTF)
  555. end
  556. end
  557. end
  558. end
  559. end
  560. end
  561. end
  562. if enterType ~= Enum.BigMapEnterType.DropPoint then
  563. if smallStartIdx < smallEndIdx and smallEndIdx <= levelDataNum then
  564. for i = smallStartIdx, smallEndIdx do
  565. local levelData = levelDatas[i]
  566. local pointType = levelData.LevelPointType or 0
  567. if pointType == 0 then
  568. break
  569. end
  570. if not self:_IsPassedPoint(i) then
  571. local storySection = levelData.StorySection
  572. local storySectionData = cfgMgr:GetStorySectionById(storySection)
  573. if storySectionData then
  574. local artType = storySectionData.ArtType
  575. local artRes = storySectionData.ArtRes
  576. local pointPos = levelPoss[i]
  577. local luaCtr = nil
  578. if artType == Enum.StorySectionArtType.Icon then
  579. luaCtr = self:_CreateStoryIconLuaCtr(i, artRes, pointPos)
  580. else
  581. luaCtr = self:_CreateStoryGoLuaCtr(i, artRes, pointPos)
  582. end
  583. if luaCtr and enterType == Enum.BigMapEnterType.Default then
  584. self.viewBase.uiBase:AddButtonUniqueEventListener(luaCtr.button, self, self._OnClickStoryItem, i)
  585. end
  586. end
  587. end
  588. end
  589. end
  590. end
  591. if enterType == Enum.BigMapEnterType.DropPoint then
  592. if not self.executeSequenceData:HasDelayMethod() then
  593. self.executeSequenceData:AppendInterval(1)
  594. end
  595. self.executeSequenceData:AppendFunc(false, self, self._FallDownComplete)
  596. if self.isExecutePlayEffect then
  597. ManagerContainer.ExecuteSequenceMgr:Execute(self.executeSequenceData)
  598. end
  599. elseif enterType == Enum.BigMapEnterType.NextLevel then
  600. self:_PlayNextLevelEffect()
  601. end
  602. end
  603. function BigMapView:_OnClickStoryItem(btn, params)
  604. local levelId = params[0]
  605. local levelData = self.levelDatas[levelId]
  606. if not levelData then return end
  607. local storySection = levelData.StorySection
  608. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  609. if not storySectionData then return end
  610. if storySectionData.ClickDlgId > 0 then
  611. ManagerContainer.UIStoryMgr:MapStartStoryByStoryId(storySectionData.ClickDlgId)
  612. end
  613. end
  614. function BigMapView:_PlayFallDownAnim(luaCtr)
  615. if luaCtr.go then
  616. luaCtr.go:SetActive(true)
  617. end
  618. self:_PlayAnim(luaCtr, 'PointDropDown')
  619. end
  620. function BigMapView:_PlayAnim(luaCtr, animName)
  621. if luaCtr.animator then
  622. luaCtr.animator:Play(animName)
  623. end
  624. end
  625. function BigMapView:_FallDownComplete()
  626. self.viewBase:BigMapViewComplete()
  627. end
  628. function BigMapView:_PlayNextLevelEffect()
  629. if not self:_IsSelfAtCurMap() then return end
  630. local nextLevelId = self.curLevelId + 1
  631. local levelData = self.levelDatas[nextLevelId]
  632. if not levelData then return end
  633. if not self.selfPlayerLuaCtr then return end
  634. local pointUpAnimTime = 0.2
  635. local pointFlyAnimTime = 1
  636. local pointDownTime = 2
  637. if self.selfPlayerLuaCtr.animator then
  638. local runtimeAnimatorController = self.selfPlayerLuaCtr.animator.runtimeAnimatorController
  639. if runtimeAnimatorController then
  640. if runtimeAnimatorController:GetType() == typeof(UnityEngine.AnimatorOverrideController) then
  641. runtimeAnimatorController = runtimeAnimatorController.this
  642. local clip = runtimeAnimatorController:get('PointUp')
  643. if clip then pointUpAnimTime = clip.length end
  644. clip = runtimeAnimatorController:get('PointFly')
  645. if clip then pointFlyAnimTime = clip.length end
  646. clip = runtimeAnimatorController:get('PointDown')
  647. if clip then pointDownTime = clip.length end
  648. else
  649. local clips = runtimeAnimatorController.animationClips
  650. for i = 0, clips.Length - 1 do
  651. local clip = clips[i]
  652. if clip then
  653. local clipName = clip.name
  654. if clipName == 'PointUp' then
  655. pointUpAnimTime = clip.length
  656. elseif clipName == 'PointFly' then
  657. pointFlyAnimTime = clip.length
  658. elseif clipName == 'PointDown' then
  659. pointDownTime = clip.length
  660. end
  661. end
  662. end
  663. end
  664. end
  665. end
  666. self.executeSequenceData = ExecuteSequenceData:new()
  667. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointUp')
  668. self.executeSequenceData:AppendInterval(pointUpAnimTime)
  669. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointFly')
  670. self.executeSequenceData:AppendFunc(false, self, self._PlayMoveToNextLevel, pointFlyAnimTime)
  671. self.executeSequenceData:AppendInterval(pointFlyAnimTime)
  672. self.executeSequenceData:AppendFunc(false, self, self._PlayAnim, self.selfPlayerLuaCtr, 'PointDown')
  673. self.executeSequenceData:AppendFunc(false, self, self._MoveToNextLevelDeleteStorySection)
  674. self.executeSequenceData:AppendInterval(pointDownTime)
  675. self.executeSequenceData:AppendFunc(false, self, self._MoveToNextLevelComplete)
  676. if self.isExecutePlayEffect then
  677. ManagerContainer.ExecuteSequenceMgr:Execute(self.executeSequenceData)
  678. end
  679. end
  680. function BigMapView:_PlayMoveToNextLevel(time)
  681. local nextLevelId = self.curLevelId + 1
  682. local levelPos = self.levelPoss[nextLevelId]
  683. if not levelPos then return end
  684. if not self.selfPlayerLuaCtr then return end
  685. if not self.selfPlayerLuaCtr.go then return end
  686. self.selfPlayerLuaCtr.go.transform:DOLocalMove(levelPos, time)
  687. end
  688. function BigMapView:_MoveToNextLevelDeleteStorySection()
  689. local nextLevelId = self.curLevelId + 1
  690. self.view.linePath.uIBigMapLine.passPointIdx = nextLevelId
  691. local levelData = self.levelDatas[nextLevelId]
  692. if not levelData then return end
  693. local storySection = levelData.StorySection
  694. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  695. if not storySectionData then return end
  696. local artType = storySectionData.ArtType
  697. if artType == Enum.StorySectionArtType.Icon then
  698. -- self:_DisposeStoryIconLuaCtr(self.curLevelId + 1)
  699. local luaCtr = self.storyIconLuaCtrs[nextLevelId]
  700. if luaCtr then
  701. if luaCtr.go then
  702. luaCtr.go:SetActive(false)
  703. end
  704. local levelPos = nil
  705. if luaCtr.image then
  706. levelPos = luaCtr.image.transform.position
  707. end
  708. if not levelPos then
  709. levelPos = self.levelPoss[nextLevelId]
  710. levelPos = self.view.content.rectTransform:TransformPoint(levelPos)
  711. end
  712. -- 为了完美衔接道具掉落的表现
  713. if storySectionData.Type == Enum.StorySectionEventType.GotItem
  714. or storySectionData.Type == Enum.StorySectionEventType.UnlockHangBox
  715. or storySectionData.Type == Enum.StorySectionEventType.UnlockTask then
  716. self.executeSequenceData:InsertNextUIListener(Enum.UIPageName.UIPopGotSingle, UIEventNames.UI_PAGE_IN_END_NTF)
  717. self.hasNextStory = ManagerContainer.StoryMgr:StartStorySection(storySection, levelPos)
  718. end
  719. end
  720. else
  721. -- self:_DisposeStoryGoLuaCtr(self.curLevelId + 1)
  722. local luaCtr = self.storyGoLuaCtrs[nextLevelId]
  723. if luaCtr then
  724. if luaCtr.go then
  725. luaCtr.go:SetActive(false)
  726. end
  727. end
  728. end
  729. end
  730. function BigMapView:_MoveToNextLevelComplete()
  731. local nextLevelId = self.curLevelId + 1
  732. local levelData = self.levelDatas[nextLevelId]
  733. if levelData then
  734. local luaCtr = self.storyIconLuaCtrs[nextLevelId]
  735. local levelPos = nil
  736. if luaCtr and luaCtr.image then
  737. levelPos = luaCtr.image.transform.position
  738. end
  739. if not levelPos then
  740. levelPos = self.levelPoss[nextLevelId]
  741. levelPos = self.view.content.rectTransform:TransformPoint(levelPos)
  742. end
  743. local storySection = levelData.StorySection
  744. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySection)
  745. if storySectionData then
  746. if storySectionData.Type ~= Enum.StorySectionEventType.GotItem
  747. and storySectionData.Type ~= Enum.StorySectionEventType.UnlockHangBox
  748. and storySectionData.Type ~= Enum.StorySectionEventType.UnlockTask then
  749. self.hasNextStory = ManagerContainer.StoryMgr:StartStorySection(storySection, levelPos)
  750. self:_DisposeStoryIconLuaCtr(nextLevelId)
  751. self:_DisposeStoryGoLuaCtr(nextLevelId)
  752. self.viewBase:BigMapViewComplete(self.hasNextStory)
  753. return
  754. end
  755. end
  756. end
  757. self:_DisposeStoryIconLuaCtr(nextLevelId)
  758. self:_DisposeStoryGoLuaCtr(nextLevelId)
  759. self.viewBase:BigMapViewComplete(self.hasNextStory)
  760. --ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_OVER, true)
  761. end
  762. function BigMapView:_GetBigPoint(idx, pointPos)
  763. local point = self.bigPoints[idx]
  764. if not point then
  765. point = CommonUtil.Instantiate(self.bigPointGo, self.view.bigPoints.transform)
  766. if tolua.getpeer(point) == nil then
  767. tolua.setpeer(point, {})
  768. end
  769. -- point.button = point:GetComponent(Enum.TypeInfo.Button)
  770. self.bigPoints[idx] = point
  771. end
  772. point:SetActive(true)
  773. point.transform.localPosition = pointPos
  774. return idx + 1
  775. end
  776. function BigMapView:_DisposeBigPoints()
  777. for _, bigPoint in pairs(self.bigPoints) do
  778. if bigPoint then
  779. CommonUtil.DestroyGO(bigPoint)
  780. if tolua.getpeer(bigPoint) ~= nil then
  781. tolua.setpeer(bigPoint, nil)
  782. end
  783. end
  784. end
  785. end
  786. function BigMapView:_GetSmallPoint(idx, pointPos)
  787. local point = self.smallPoints[idx]
  788. if not point then
  789. point = CommonUtil.Instantiate(self.smallPointGo, self.view.smallPoints.transform)
  790. if tolua.getpeer(point) == nil then
  791. tolua.setpeer(point, {})
  792. end
  793. -- point.button = point:GetComponent(Enum.TypeInfo.Button)
  794. self.smallPoints[idx] = point
  795. end
  796. point:SetActive(true)
  797. point.transform.localPosition = pointPos
  798. return idx + 1
  799. end
  800. function BigMapView:_DisposeSmallPoints()
  801. for _, smallPoint in pairs(self.smallPoints) do
  802. if smallPoint then
  803. CommonUtil.DestroyGO(smallPoint)
  804. if tolua.getpeer(smallPoint) ~= nil then
  805. tolua.setpeer(smallPoint, nil)
  806. end
  807. end
  808. end
  809. end
  810. function BigMapView:_CreateStartPoint(pointPos)
  811. if not self.startPoint then
  812. local startItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, PointStartItemPath)
  813. self.startPoint = startItem
  814. end
  815. if self.startPoint then
  816. local startItemTrans = self.startPoint.transform
  817. startItemTrans:SetParent(self.view.startPoint.transform, false)
  818. startItemTrans.localPosition = pointPos
  819. startItemTrans.localRotation = Quaternion.identity
  820. startItemTrans.localScale = Vector3.one
  821. self.startPoint:SetActive(true)
  822. end
  823. end
  824. function BigMapView:_DisposeStartPoint()
  825. if self.startPoint then
  826. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointStartItemPath, self.startPoint)
  827. self.startPoint = nil
  828. end
  829. end
  830. function BigMapView:_CreateStoryIconLuaCtr(levelId, artRes, pointPos)
  831. local iconItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, PointIconItemPath)
  832. local iconAnimator, iconImage, button
  833. if iconItem then
  834. local iconItemTrans = iconItem.transform
  835. iconItemTrans:SetParent(self.view.storyPoints.transform, false)
  836. iconItem:SetActive(true)
  837. iconItemTrans.localPosition = pointPos
  838. iconItemTrans.localRotation = Quaternion.identity
  839. iconItemTrans.localScale = Vector3.one
  840. iconAnimator = iconItem:GetComponent(Enum.TypeInfo.Animator)
  841. iconImage = iconItemTrans:Find('Root/Item/Content/Icon'):GetComponent(Enum.TypeInfo.Image)
  842. button = iconItemTrans:Find('Root/Button'):GetComponent(Enum.TypeInfo.Button)
  843. iconImage.sprite = ManagerContainer.ResMgr:GetAsset(Constants.IconDir, artRes)
  844. iconAnimator:Play('PointKeep')
  845. end
  846. local luaCtr = {}
  847. luaCtr.go = iconItem
  848. luaCtr.image = iconImage
  849. luaCtr.button = button
  850. luaCtr.animator = iconAnimator
  851. self.storyIconLuaCtrs[levelId] = luaCtr
  852. return luaCtr
  853. end
  854. function BigMapView:_DisposeStoryIconLuaCtrs()
  855. for i = #self.levelDatas, 1, -1 do
  856. self:_DisposeStoryIconLuaCtr(i)
  857. end
  858. end
  859. function BigMapView:_DisposeStoryIconLuaCtr(levelId)
  860. local luaCtr = self.storyIconLuaCtrs[levelId]
  861. if luaCtr then
  862. if luaCtr.go then
  863. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointIconItemPath, luaCtr.go)
  864. end
  865. if luaCtr.image then
  866. luaCtr.image.sprite = nil
  867. end
  868. luaCtr.go = nil
  869. luaCtr.image = nil
  870. luaCtr.animator = nil
  871. self.storyIconLuaCtrs[levelId] = nil
  872. end
  873. end
  874. function BigMapView:_CreateStoryGoLuaCtr(levelId, artRes, pointPos)
  875. local goItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, artRes)
  876. local goAnimator, button
  877. if goItem then
  878. local goItemTrans = goItem.transform
  879. goItemTrans:SetParent(self.view.storyPoints.transform, false)
  880. goItem:SetActive(true)
  881. goItemTrans.localPosition = pointPos
  882. goItemTrans.localRotation = Quaternion.identity
  883. goItemTrans.localScale = Vector3.one
  884. goAnimator = goItem:GetComponent(Enum.TypeInfo.Animator)
  885. button = goItemTrans:Find('Root/Button'):GetComponent(Enum.TypeInfo.Button)
  886. goAnimator:Play('PointKeep')
  887. end
  888. local luaCtr = {}
  889. luaCtr.go = goItem
  890. luaCtr.assetName = artRes
  891. luaCtr.button = button
  892. luaCtr.animator = goAnimator
  893. self.storyGoLuaCtrs[levelId] = luaCtr
  894. return luaCtr
  895. end
  896. function BigMapView:_DisposeStoryGoLuaCtrs()
  897. for i = #self.levelDatas, 1, -1 do
  898. self:_DisposeStoryGoLuaCtr(i)
  899. end
  900. end
  901. function BigMapView:_DisposeStoryGoLuaCtr(levelId)
  902. local luaCtr = self.storyGoLuaCtrs[levelId]
  903. if luaCtr then
  904. if luaCtr.go then
  905. ManagerContainer.ResMgr:RecycleGO(uiPath, luaCtr.assetName, luaCtr.go)
  906. end
  907. luaCtr.go = nil
  908. luaCtr.assetName = nil
  909. luaCtr.animator = nil
  910. self.storyGoLuaCtrs[levelId] = nil
  911. end
  912. end
  913. function BigMapView:_DisposeSelfPlayerLuaCtr()
  914. if not self.selfPlayerLuaCtr then return end
  915. local luaCtr = self.selfPlayerLuaCtr
  916. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, PointPlayerItemPath, luaCtr.go)
  917. luaCtr.go = nil
  918. luaCtr.iconImage = nil
  919. luaCtr.myRankGo = nil
  920. luaCtr.dscLeftGo = nil
  921. luaCtr.dscLeftRect = nil
  922. luaCtr.dscLeftTxt = nil
  923. luaCtr.dscRightGO = nil
  924. luaCtr.dscRightTxt = nil
  925. luaCtr.animator = nil
  926. self.selfPlayerLuaCtr = nil
  927. end
  928. function BigMapView:_IsSelfAtCurMap()
  929. return self.showMapId == self.curMapId
  930. end
  931. function BigMapView:_IsPassedPoint(levelId)
  932. if self.showMapId == self.curMapId then
  933. return self.curLevelId >= levelId
  934. else
  935. return (self.curMapId > self.showMapId)
  936. end
  937. end
  938. function BigMapView:_RectTransformContain(a, b)
  939. if not a or not b then return false end
  940. local rectA = a.rect
  941. local minA = a:TransformPoint(rectA.min)
  942. local maxA = a:TransformPoint(rectA.max)
  943. local rectB = b.rect
  944. local minB = b:TransformPoint(rectB.min)
  945. local maxB = b:TransformPoint(rectB.max)
  946. return (minB.x >= minA.x and minB.x < maxA.x and minB.y >= minA.y and minB.y < maxA.y
  947. and maxB.x >= minA.x and maxB.x < maxA.x and maxB.y >= minA.y and maxB.y < maxA.y)
  948. end
  949. return BigMapView