KLRookieGuidePanel.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. ---@class KLRookieGuidePanel:UIKmlLuaPanelBase
  2. ---@field view KLRookieGuidePanelView
  3. local KLRookieGuidePanel = class(UIKmlLuaPanelBase)
  4. local this = KLRookieGuidePanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.arrowPos = { [1] = self.view.TopArrow, [2] = self.view.DownArrow, [3] = self.view.LeftArrow, [4] = self.view.RightArrow }
  8. self.comp_Rect = SL:GetRectGuideMaskComp(GUI:GetGameObject(self.view.RectMask_Real))
  9. end
  10. ---创建或者刷新界面数据时调用
  11. function this:Refresh()
  12. self:Reset()
  13. self:ShowGuideKml(self.args.guideId)
  14. end
  15. ---注册UI事件和服务器消息
  16. function this:RegistEvents()
  17. end
  18. function this:Close()
  19. self:Reset()
  20. end
  21. ---@param id number
  22. function this:ShowGuideKml(id)
  23. self.cort = Coroutine.Start(this.ShowGuideBaseKml, self, id)
  24. end
  25. function this:Reset()
  26. GUI:SetActive(self.view.TipsGo, false)
  27. GUI:SetActive(self.view.HighlightGo, false)
  28. GUI:SetActive(self.view.CircleGo, false)
  29. GUI:setVisible(self.view.RectMask, false)
  30. self:HidePointControlGuide()
  31. if self.cort then
  32. Coroutine.Stop(self.cort)
  33. self.cort = nil
  34. end
  35. if self.moveY then
  36. GUI:DOKill(self.moveY)
  37. self.moveY = nil
  38. end
  39. if self.moveX then
  40. GUI:DOKill(self.moveX)
  41. self.moveX = nil
  42. end
  43. if self.clone_Highlight then
  44. SL:DestroyObjectImmediate(self.clone_Highlight)
  45. self.clone_Highlight = nil
  46. end
  47. if self.highlightClone then
  48. SL:DestroyObjectImmediate(self.highlightClone)
  49. self.highlightClone = nil
  50. end
  51. if self.contentClone then
  52. SL:DestroyObjectImmediate(self.contentClone)
  53. self.contentClone = nil
  54. end
  55. if self.panelId then
  56. GUI:DelCloneControl(self.panelId, self.contrName .. "_clonePanel")
  57. end
  58. self.pointPanelId = nil
  59. self.pointContrId = nil
  60. end
  61. function this:CheckIsLastGuideEnd(rearId)
  62. if rearId then
  63. if rearId == KLGuideManager.getMaxGuideId() then
  64. --引导结束
  65. SL.SDKMgr:SubmitGameData(ESubmitDataType.Event, "gameTutorial")
  66. end
  67. end
  68. end
  69. function this:ShowGuideBaseKml(id)
  70. Coroutine.WaitForEndOfFrame()
  71. local clm = SL:GetConfig('cfg_rookie_guide', id)
  72. local address = clm.uiAddress
  73. local addrSplit = string.split(address, '&')
  74. local panelId = addrSplit[1]
  75. local contrName = addrSplit[2]
  76. local contrTransform
  77. if contrName then
  78. contrTransform = GUI:GetControlTransform(panelId, contrName)
  79. end
  80. if contrTransform == nil and not table.contains(clm.showType, EGuideShowType.ToProp) then
  81. return
  82. end
  83. for i, showType in ipairs(clm.showType) do
  84. if showType == EGuideShowType.Content then
  85. GUI:Text_setString(self.view.Desc, clm.guideText)
  86. local p_width, p_height = GUI:GetTextPreferredWH(self.view.Desc)
  87. if contrTransform then
  88. GUI:setContentSize(self.view.GuideBG, p_width + 100, p_height + 50)
  89. local _, _, posZ = GUI:GetWorldPosition(self.view.GuideBG)
  90. --获取UI的中心点坐标
  91. ---@type Vector4
  92. local vec4 = SL:GetWorldCorners(contrTransform)
  93. local x = (vec4.x + vec4.z) / 2
  94. local y = (vec4.y + vec4.w) / 2
  95. --获取中心点坐标的屏幕坐标
  96. local scrPoint = SL:ConvertWorldPos2Screen(x, y)
  97. local bool, endPos = GUI:ScreenPointToLocalPointInRectangle(self.view.TipsGo, scrPoint)
  98. if bool then
  99. if clm.arrowPosition == 1 or clm.arrowPosition == 2 then
  100. GUI:setPosition(self.view.GuideBG, endPos.x, clm.arrowPosition == 1 and endPos.y - (p_height + 80) or endPos.y + (p_height + 80))
  101. else
  102. GUI:setPosition(self.view.GuideBG, endPos.x, endPos.y)
  103. local ax, ay = GUI:getPosition(self.view.GuideBG)
  104. if clm.arrowPosition == 3 then
  105. ax = ax + contrTransform.rect.width / 2 + (p_width + 100) / 2 + 50
  106. GUI:setPosition(self.view.GuideBG, ax, ay)
  107. else
  108. ax = ax - contrTransform.rect.width / 2 - (p_width + 100) / 2 - 50
  109. GUI:setPosition(self.view.GuideBG, ax, ay)
  110. end
  111. end
  112. end
  113. end
  114. for k, arrow in pairs(self.arrowPos) do
  115. GUI:SetActive(arrow, k == clm.arrowPosition)
  116. end
  117. GUI:SetActive(self.view.Left_People, clm.guidePeople == 1)
  118. GUI:SetActive(self.view.Right_People, clm.guidePeople == 2)
  119. local delta = clm.guidePeople == 0 and 0 or (clm.guidePeople == 1 and 50 or -50)
  120. GUI:setPositionX(self.view.Desc, delta)
  121. local obj = GUI:GetGameObject(self.view.TipsGo)
  122. self.contentClone = SL:GameObjectInstantiate(obj, contrTransform.parent, true)
  123. self.contentClone:SetActive(true)
  124. ---@type UnityEngine.RectTransform
  125. local contentTrans = SL:GetRectTransfomComp(self.contentClone)
  126. --Dotween动画
  127. local contentX = contentTrans.anchoredPosition.x
  128. local contentY = contentTrans.anchoredPosition.y
  129. if clm.arrowPosition == 1 or clm.arrowPosition == 2 then
  130. self.moveY = GUI:DOAnchorPosY(contentTrans, contentY + 5, 0.6)
  131. GUI:TweenSetLoops(self.moveY, math.maxinteger)
  132. GUI:TweenSetEase(self.moveY, ELeanTweenType.pingPong)
  133. else
  134. self.moveX = GUI:DOAnchorPosX(contentTrans, contentX + 5, 0.6)
  135. GUI:TweenSetLoops(self.moveX, math.maxinteger)
  136. GUI:TweenSetEase(self.moveX, ELeanTweenType.pingPong)
  137. end
  138. elseif showType == EGuideShowType.Highlight then
  139. --控件高亮
  140. if contrTransform then
  141. ---@type Vector4
  142. local vec4 = SL:GetWorldCorners(contrTransform)
  143. local center_x = (vec4.x + vec4.z) / 2
  144. local center_y = (vec4.y + vec4.w) / 2
  145. if clm.highlightType == 0 then
  146. GUI:setContentSize(self.view.RawImage, clm.highlightScale[1], clm.highlightScale[2])
  147. GUI:setPosition(self.view.RawImage, clm.highlightPosition[1], clm.highlightPosition[2])
  148. local _, _, worldZ = GUI:GetWorldPosition(self.view.Effect)
  149. GUI:SetWorldPosition(self.view.Effect, center_x, center_y, worldZ)
  150. local obj = GUI:GetGameObject(self.view.Effect)
  151. self.highlightClone = SL:GameObjectInstantiate(obj, contrTransform.parent, true)
  152. self.highlightClone:SetActive(true)
  153. else
  154. local _, _, worldZ = GUI:GetWorldPosition(self.view.Effect)
  155. GUI:SetWorldPosition(self.view.CircleGo, center_x, center_y, worldZ)
  156. GUI:setContentSize(self.view.RawImage, clm.highlightScale[1], clm.highlightScale[2])
  157. GUI:setPosition(self.view.RawImage, clm.highlightPosition[1], clm.highlightPosition[2])
  158. local obj = GUI:GetGameObject(self.view.CircleGo)
  159. self.highlightClone = SL:GameObjectInstantiate(obj, contrTransform.parent, true)
  160. self.highlightClone:SetActive(true)
  161. end
  162. end
  163. elseif showType == EGuideShowType.Mask then
  164. self:ShowRectMask(contrTransform)
  165. elseif showType == EGuideShowType.ToProp then
  166. if string.startsWith(clm.uiAddress, "KLShopMallPanel") then
  167. local itemShowIdList = clm.itemShowId
  168. local showId
  169. for _, itemShowIdInfo in pairs(itemShowIdList) do
  170. local itemId = itemShowIdInfo[1]
  171. local needCareer = itemShowIdInfo[2]
  172. if SL:MeData_GetCareer().baseCareer == needCareer or needCareer == nil then
  173. showId = itemId
  174. break
  175. end
  176. end
  177. if showId then
  178. local panel = GUI:GetUI("dev/ui/ShopMall/Panel/KLShopMall/KLShopMallPanel")
  179. if panel then
  180. if panel.hasInit then
  181. panel:GotoItemSubPage(showId, id)
  182. else
  183. SL:ScheduleOnce(1, function()
  184. panel:GotoItemSubPage(showId, id)
  185. end)
  186. end
  187. end
  188. end
  189. elseif string.startsWith(clm.uiAddress, "KLUIBagPanel") then
  190. local itemShowIdList = clm.itemShowId
  191. local showId
  192. for _, itemShowIdInfo in pairs(itemShowIdList) do
  193. local itemId = itemShowIdInfo[1]
  194. local needCareer = itemShowIdInfo[2]
  195. if SL:MeData_GetCareer().baseCareer == needCareer or needCareer == nil then
  196. showId = itemId
  197. break
  198. end
  199. end
  200. if showId then
  201. local panel = GUI:GetUI("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  202. if panel then
  203. panel:GuideToShowItem(showId)
  204. end
  205. end
  206. end
  207. end
  208. end
  209. -- 有后置或者是强引导并且不是指向道具(指向道具要等相关模块确定指向了哪个在去处理)
  210. if (clm.rearGuide ~= 0 or clm.guideType == EGuideFinishType.ClickControl) and not table.contains(clm.showType, EGuideShowType.ToProp) then
  211. self.panelId = panelId
  212. self.contrName = contrName
  213. local index
  214. if clm.guideType == EGuideFinishType.ClickControl then
  215. index = 2000
  216. else
  217. index = 1700
  218. end
  219. if GUI:IsInScrollView(self.panelId,self.contrName) then
  220. index = 0
  221. end
  222. ---@type UIKmlLuaControl
  223. local cloneControl = GUI:CloneControl(self.panelId, self.contrName, index or 0, 1)
  224. local rearGuide = clm.rearGuide
  225. GUI:AddOnClickEvent(cloneControl, self, self.ClickCloneBtn, {rearGuide, self.panelId, self.contrName, contrTransform })
  226. end
  227. if clm.guideType == EGuideFinishType.AnyClick then
  228. GUI:setVisible(self.view.MaskGo, false)
  229. else
  230. GUI:setVisible(self.view.MaskGo, true)
  231. end
  232. self:CheckIsLastGuideEnd(id)
  233. end
  234. function this:ShowRectMask(uiCtrl)
  235. GUI:setVisible(self.view.RectMask, true)
  236. self.comp_Rect:SetTarget(uiCtrl.transform)
  237. end
  238. function this:AddPointControlGuide(panelId, contrId, guideId)
  239. local clm = SL:GetConfig('cfg_rookie_guide', guideId)
  240. if clm then
  241. local contrTransform = GUI:GetControlTransform(panelId, contrId)
  242. if contrTransform == nil then
  243. return
  244. end
  245. --控件高亮
  246. if contrTransform then
  247. ---@type Vector4
  248. local vec4 = SL:GetWorldCorners(contrTransform)
  249. local x = (vec4.x + vec4.z) / 2
  250. local y = (vec4.y + vec4.w) / 2
  251. local _, _, worldZ = GUI:GetWorldPosition(self.view.Effect)
  252. GUI:SetWorldPosition(self.view.Effect, x, y, worldZ)
  253. end
  254. GUI:setContentSize(self.view.RawImage, 230, 600)
  255. GUI:setPosition(self.view.RawImage, clm.highlightPosition[1], clm.highlightPosition[2])
  256. local obj = GUI:GetGameObject(self.view.RawImage)
  257. self.clone_Highlight = SL:GameObjectInstantiate(obj, contrTransform.parent)
  258. self.clone_Highlight:SetActive(true)
  259. GUI:setPosition(self.view.RawImage, 0, 0)
  260. ---@type UIKmlLuaControl
  261. local cloneControl = GUI:CloneControl(panelId, contrId, 2000, 1)
  262. local rearGuide = clm.rearGuide
  263. GUI:AddOnClickEvent(cloneControl, self, self.ClickCloneBtn, {rearGuide, self.panelId, self.contrName, contrTransform })
  264. self.pointPanelId = panelId
  265. self.pointContrId = contrId
  266. end
  267. end
  268. function this:HidePointControlGuide()
  269. if self.pointPanelId then
  270. GUI:DelCloneControl(self.pointPanelId, self.pointContrId .. "_clonePanel")
  271. if self.clone_Highlight then
  272. SL:DestroyObjectImmediate(self.clone_Highlight)
  273. self.clone_Highlight = nil
  274. end
  275. self.pointPanelId = nil
  276. self.pointContrId = nil
  277. end
  278. end
  279. function this:ClickCloneBtn(control, eventData)
  280. local rearGuide = eventData[1]
  281. local panelId = eventData[2]
  282. local contrName = eventData[3]
  283. local contrTransform = eventData[4]
  284. if rearGuide then
  285. KLGuideManager.SetNextGuide(rearGuide)
  286. end
  287. local btn = SL:GetButtonComp(contrTransform)
  288. btn.onClick:Invoke()
  289. GUI:DelCloneControl(panelId, contrName .. "_clonePanel")
  290. self.panelId = nil
  291. self.contrName = nil
  292. if self.clone_Highlight then
  293. SL:DestroyObjectImmediate(self.clone_Highlight)
  294. self.clone_Highlight = nil
  295. end
  296. if self.highlightClone then
  297. SL:DestroyObjectImmediate(self.highlightClone)
  298. self.highlightClone = nil
  299. end
  300. if self.contentClone then
  301. SL:DestroyObjectImmediate(self.contentClone)
  302. self.contentClone = nil
  303. end
  304. if self.moveY then
  305. GUI:DOKill(self.moveY)
  306. self.moveY = nil
  307. end
  308. if self.moveX then
  309. GUI:DOKill(self.moveX)
  310. self.moveX = nil
  311. end
  312. end
  313. return this