SGuideTask.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. local SGuideTask = class("SGuideTask")
  2. function SGuideTask:ctor(data--[[,config]])
  3. self._GuideFuncConfig = requireConfig("GuideWidgetConfig.lua")
  4. self._GuideEventConfig = requireConfig("GuideEventConfig.lua")
  5. self._data = data
  6. self._mainID = data and tonumber(data.id)
  7. self._uiID = data and tonumber(data.param)-- or data.param
  8. self._ssrWidget = data and data.guideWidget
  9. self._ssrParent = data and data.guideParent
  10. self._desc = data and data.guideDesc
  11. self._clickCallback = data and data.clickCB
  12. self._autoExcute = data and tonumber(data.autoExcute)
  13. self._isForce = data and data.isForce
  14. self._mainType = data and tonumber(data.mainIdx) -- 主界面
  15. self._hideMask = data and data.hideMask -- 禁止蒙版
  16. ----
  17. self._widget = nil
  18. self._parent = nil
  19. self._position = nil
  20. self._contenSize = nil
  21. self._active = true
  22. end
  23. function SGuideTask:GetWidget()
  24. return self._widget
  25. end
  26. function SGuideTask:GetParent()
  27. return self._parent
  28. end
  29. function SGuideTask:GetConfig()
  30. return self._data
  31. end
  32. function SGuideTask:IsForce()
  33. return self._isForce and true or false
  34. end
  35. function SGuideTask:SetAutoExcute( time )
  36. if time and tonumber(time) then
  37. self._autoExcute = tonumber(time)
  38. end
  39. end
  40. function SGuideTask:Start( ... )
  41. if not self._active then return end
  42. self._layoutBlack = ccui.Layout:create()
  43. self._layoutBlack:setContentSize(global.Director:getVisibleSize())
  44. self._layoutBlack:setTouchEnabled(true)
  45. self._layoutBlack:setSwallowTouches(true)
  46. self._layoutBlack:addTouchEventListener(function ( sender, eventType)
  47. if eventType == 0 then
  48. end
  49. end)
  50. global.Director:getRunningScene():addChild(self._layoutBlack,999)
  51. if self._mainID then
  52. local getNodesFunc = self._GuideFuncConfig[self._mainID]
  53. if not getNodesFunc then
  54. self._active = false
  55. return
  56. end
  57. local temp = { typeassist = self._uiID }
  58. self._widget, self._parent = getNodesFunc(temp)
  59. if self._mainID == 110 then--如果是任务就先把框漏出来
  60. global.Facade:sendNotification(global.NoticeTable.Layer_Assist_ChangeHide, true)
  61. elseif self._mainID == 109 then -- 按钮模块 切换
  62. global.Facade:sendNotification(global.NoticeTable.GuideEnterTransition, {name = "GUIDE_BEGIN_SKILL_BUTTON"})
  63. elseif self._mainID == 1 or self._mainID == 47 then -- 背包 英雄背包 的双击使用
  64. if self._mainID == 1 then
  65. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  66. self._BagPage = BagProxy:GetBagPageByMakeIndex(self._uiID)
  67. if self._BagPage and self._parent then --页数不对 得切换 一下
  68. local curPage = self._parent.GetSelectPage and self._parent:GetSelectPage() or SL:GetMetaValue("BAG_PAGE_CUR")
  69. if curPage ~= self._BagPage then
  70. global.Facade:sendNotification(global.NoticeTable.Layer_Bag_Open, {bag_page = self._BagPage})
  71. end
  72. end
  73. end
  74. if self._uiID ~= -1 then
  75. self._clickCallback = function ()
  76. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  77. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  78. local nowItemData = ItemManagerProxy:GetItemDataByMakeIndex(self._uiID)
  79. local ItemUseProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemUseProxy)
  80. if self._mainID == 1 then
  81. nowItemData.from = ItemMoveProxy.ItemFrom.BAG
  82. ItemUseProxy:UseItem(nowItemData)
  83. else
  84. nowItemData.from = ItemMoveProxy.ItemFrom.HERO_BAG
  85. ItemUseProxy:HeroUseItem(nowItemData)
  86. end
  87. end
  88. end
  89. end
  90. --关闭chat
  91. global.Facade:sendNotification(global.NoticeTable.Layer_Chat_Close)
  92. if not self._widget or not self._parent then
  93. self._scheduleId = PerformWithDelayGlobal(function()
  94. if self._layoutBlack then
  95. self._layoutBlack:removeFromParent()
  96. self._layoutBlack = nil
  97. end
  98. self._widget, self._parent = getNodesFunc(temp)
  99. if not self._widget or not self._parent then
  100. self._active = false
  101. return
  102. end
  103. global.Facade:sendNotification(global.NoticeTable.Layer_SGuide_Open, self)
  104. end, 1)
  105. else
  106. if self._layoutBlack then
  107. self._layoutBlack:removeFromParent()
  108. self._layoutBlack = nil
  109. end
  110. global.Facade:sendNotification(global.NoticeTable.Layer_SGuide_Open, self)
  111. end
  112. elseif self._ssrWidget and self._ssrParent and self._active then
  113. self._widget = self._ssrWidget
  114. self._parent = self._ssrParent
  115. if tolua.isnull(self._widget) or tolua.isnull(self._parent) then
  116. self._widget = nil
  117. self._parent = nil
  118. return
  119. end
  120. -- if not self._clickCallback then
  121. -- self._clickCallback = not tolua.isnull(self._widget) and global.ScriptHandlerMgr:getObjectHandler(self._widget)
  122. -- end
  123. if self._layoutBlack then
  124. self._layoutBlack:removeFromParent()
  125. self._layoutBlack = nil
  126. end
  127. global.Facade:sendNotification(global.NoticeTable.Layer_SGuide_Open, self)
  128. end
  129. end
  130. function SGuideTask:onGuideNodeChange(data)
  131. -- dump(data,"onGuideNodeChange___")
  132. if self._active then
  133. if data.widget then
  134. self._widget = data.widget
  135. else
  136. self._position = data.pos
  137. self._contentSize = data.size
  138. end
  139. -- self._widget = data.widget
  140. global.Facade:sendNotification(global.NoticeTable.Layer_SGuide_Open, self)
  141. if self._scheduleId then
  142. UnSchedule(self._scheduleId)
  143. self._scheduleId = nil
  144. end
  145. if self._layoutBlack then
  146. self._layoutBlack:removeFromParent()
  147. self._layoutBlack = nil
  148. end
  149. end
  150. end
  151. function SGuideTask:IsActive()
  152. return self._active
  153. end
  154. function SGuideTask:Exit()
  155. global.Facade:sendNotification(global.NoticeTable.Layer_SGuide_Close)
  156. -- self._active = false
  157. end
  158. function SGuideTask:Destory( ... )
  159. global.Facade:sendNotification(global.NoticeTable.Layer_SGuide_Close)
  160. self._active = false
  161. self._widget = nil
  162. self._parent = nil
  163. end
  164. return SGuideTask