MainDigLayout.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. local MainDigLayout = class("MainDigLayout",
  2. function()
  3. return cc.Node:create()
  4. end
  5. )
  6. function MainDigLayout:ctor()
  7. self._targetID = nil
  8. end
  9. function MainDigLayout.create()
  10. local layout = MainDigLayout.new()
  11. if layout:Init() then
  12. return layout
  13. end
  14. return nil
  15. end
  16. function MainDigLayout:Init()
  17. return true
  18. end
  19. function MainDigLayout:InitGUI()
  20. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_DIG)
  21. MainDig.main()
  22. -- 挖肉按钮
  23. local function dig()
  24. if not self._targetID then
  25. return nil
  26. end
  27. local targetActor = global.actorManager:GetActor(self._targetID)
  28. if not targetActor then
  29. return nil
  30. end
  31. global.Facade:sendNotification(global.NoticeTable.ClearAllInputState)
  32. global.Facade:sendNotification(global.NoticeTable.ClearAllAutoState)
  33. global.Facade:sendNotification(global.NoticeTable.InputIdle)
  34. local authProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  35. authProxy:ClearAutoLock()
  36. authProxy:ClearAllState()
  37. authProxy:ClearAFKState()
  38. local worldPos = global.sceneManager:MapPos2WorldPos(targetActor:GetMapX(), targetActor:GetMapY(), true)
  39. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  40. inputProxy:SetDigDest(worldPos)
  41. end
  42. self._buttonDig = MainDig.Button_dig
  43. self._buttonDig:addTouchEventListener(function(_, eventType)
  44. if eventType == 0 then
  45. self._buttonDig:stopAllActions()
  46. schedule(self._buttonDig, dig, 0.5)
  47. dig()
  48. elseif eventType == 2 or eventType == 3 then
  49. self._buttonDig:stopAllActions()
  50. end
  51. end)
  52. self:HideDig()
  53. self:InitEditMode()
  54. end
  55. function MainDigLayout:InitEditMode()
  56. self._buttonDig.editMode = 1
  57. end
  58. function MainDigLayout:ShowDig(targetID)
  59. self._buttonDig:setVisible(true)
  60. self._targetID = targetID
  61. end
  62. function MainDigLayout:HideDig()
  63. self._buttonDig:setVisible(false)
  64. self._targetID = nil
  65. end
  66. return MainDigLayout