源战役客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

170 lignes
4.3 KiB

il y a 4 semaines
  1. MouseInput = MouseInput or BaseClass()
  2. local MouseInput = MouseInput
  3. local Input = Input
  4. local os = os
  5. local TouchPhase = TouchPhase
  6. function MouseInput:__init()
  7. self.press_time = 0
  8. self.press_view_point = Vector2(0, 0)
  9. self.press_world_point = Vector2(0, 0)
  10. self.press_accept = false
  11. self.release_point = Vector2(0, 0)
  12. self.cur_exit_time = -1
  13. local func = function(hide)
  14. if SystemRuntimePlatform.IsAndroid() or SystemRuntimePlatform.IsIphone() then
  15. self.cur_exit_time = os.time()
  16. --切回游戏设置锁屏亮度
  17. if not hide then
  18. if self.last_bright then
  19. SDKUtil.SetBright(5)
  20. end
  21. else
  22. --切到桌面恢复手机亮度
  23. if self.last_bright then
  24. SDKUtil.SetBright(self.last_bright)
  25. end
  26. end
  27. end
  28. end
  29. GlobalEventSystem:Bind(SceneEventType.GAME_FOCUS_OR_PAUSE,func)
  30. local add_func = function()
  31. self:NormalScreenBright()
  32. end
  33. GlobalEventSystem:Bind(SceneEventType.SCREEN_BRIGHT_ADD_EVENT,add_func)
  34. if SystemRuntimePlatform.IsWindows() then
  35. self.is_window_system = true
  36. end
  37. local callfunc = function(module_name,func)
  38. if module_name == "mouseinput" then
  39. if func == "settime" then
  40. self.cur_exit_time = os.time() - 175
  41. self.last_bright = nil
  42. GlobalEventSystem:Fire(SceneEventType.SCREEN_BRIGHT_DEL_EVENT)
  43. end
  44. end
  45. end
  46. GlobalEventSystem:Bind(EventName.DO_MODULE_DEBUG_FUNC,callfunc)
  47. end
  48. function MouseInput:touch_begin_func_pri()
  49. GlobalUserOperateTime = Time.time
  50. GlobalEventSystem:Fire(GameInputManager.GameInputEvent.MOUSE_PRESS, screen_pos)
  51. if Status.NowTime - self.press_time < 0.3 then
  52. return
  53. end
  54. self.press_view_point = screen_pos
  55. self.press_time = Status.NowTime
  56. self.press_accept = true
  57. --GlobalEventSystem:Fire(SceneEventType.MAIN_ROLE_MOUSE_DOWN, screen_pos)
  58. end
  59. function MouseInput:touch_moved_func_pri()
  60. if self.fire_move_time == nil or self.fire_move_time ~= Status.NowTime then
  61. self.fire_move_time = Status.NowTime
  62. GlobalEventSystem:Fire(GameInputManager.GameInputEvent.MOUSE_MOVE, screen_pos)
  63. end
  64. end
  65. function MouseInput:touch_ended_func_pri()
  66. GlobalEventSystem:Fire(GameInputManager.GameInputEvent.MOUSE_RELEASE, screen_pos)
  67. if not self.press_accept then
  68. return
  69. end
  70. self.press_accept = false
  71. self:HandleMouseInput(screen_pos)
  72. end
  73. function MouseInput:NormalScreenBright()
  74. if self.last_bright then
  75. SDKUtil.SetBright(self.last_bright)
  76. self.last_bright = nil
  77. end
  78. -- if not lua_viewM.main_cancas_last_visible then
  79. SetGameFrameRate()
  80. -- else
  81. -- SetGameFrameRate()
  82. -- end
  83. end
  84. function MouseInput:CheckClick(pos)
  85. self:touch_begin_func_pri(pos)
  86. self.cur_exit_time = os.time()
  87. if self.last_bright then
  88. self:NormalScreenBright()
  89. end
  90. end
  91. function MouseInput:Update()
  92. if Input.touchCount > 0 then
  93. local pos = Input.GetTouch(0).position
  94. local cur_state = Input.GetTouch(0).phase
  95. if cur_state == TouchPhase.Began then -- 按下
  96. self:CheckClick(pos)
  97. elseif cur_state == TouchPhase.Moved then
  98. self:touch_moved_func_pri(pos)
  99. elseif cur_state == TouchPhase.Stationary then --手指静止在屏幕
  100. elseif cur_state == TouchPhase.Ended then
  101. self:touch_ended_func_pri(pos)
  102. self.cur_exit_time = os.time()
  103. elseif cur_state == TouchPhase.Canceled then --当超过五个点触摸时,系统取消响应
  104. end
  105. end
  106. if self.is_window_system and ( Input.GetMouseButtonDown(0) or Input.GetMouseButton(0)) then
  107. self:CheckClick()
  108. end
  109. -- if self.last_bright == nil and self.cur_exit_time ~= -1 and os.time() - self.cur_exit_time > 180 then
  110. -- self.last_bright = SDKUtil.CallIntFunc( "SystemBright", "GetBright", "" )
  111. -- local bright = 5
  112. -- if SystemRuntimePlatform.IsIphone() then
  113. -- bright = 15
  114. -- end
  115. -- SDKUtil.SetBright(bright)
  116. -- if SceneManager and SceneManager:getInstance().curr_scene_id > 0 then
  117. -- GlobalEventSystem:Fire(SceneEventType.SCREEN_BRIGHT_DEL_EVENT)
  118. -- end
  119. -- SetGameFrameRate(30)
  120. -- end
  121. end
  122. function MouseInput:HandleMouseInput(screen_pos)
  123. --[[
  124. local move_dir = screen_pos - self.press_view_point
  125. local distance = move_dir:Distance()
  126. if distance > 120 then
  127. if move_dir.y < -0.5 then
  128. --手指上滑
  129. elseif move_dir.y > 0.5 then
  130. --手指下滑
  131. end
  132. return
  133. end
  134. GlobalEventSystem:Fire(EventName.SCREEN_CLICK, screen_pos)
  135. ]]
  136. end
  137. function MouseInput:SetEnable(value)
  138. end
  139. function MouseInput:__delete()
  140. end