|
|
MouseInput = MouseInput or BaseClass()
|
|
local MouseInput = MouseInput
|
|
local Input = Input
|
|
local os = os
|
|
local TouchPhase = TouchPhase
|
|
|
|
function MouseInput:__init()
|
|
|
|
self.press_time = 0
|
|
self.press_view_point = Vector2(0, 0)
|
|
self.press_world_point = Vector2(0, 0)
|
|
self.press_accept = false
|
|
|
|
self.release_point = Vector2(0, 0)
|
|
self.cur_exit_time = -1
|
|
|
|
local func = function(hide)
|
|
if SystemRuntimePlatform.IsAndroid() or SystemRuntimePlatform.IsIphone() then
|
|
self.cur_exit_time = os.time()
|
|
--切回游戏设置锁屏亮度
|
|
if not hide then
|
|
if self.last_bright then
|
|
SDKUtil.SetBright(5)
|
|
end
|
|
else
|
|
--切到桌面恢复手机亮度
|
|
if self.last_bright then
|
|
SDKUtil.SetBright(self.last_bright)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
GlobalEventSystem:Bind(SceneEventType.GAME_FOCUS_OR_PAUSE,func)
|
|
|
|
local add_func = function()
|
|
self:NormalScreenBright()
|
|
end
|
|
GlobalEventSystem:Bind(SceneEventType.SCREEN_BRIGHT_ADD_EVENT,add_func)
|
|
|
|
if SystemRuntimePlatform.IsWindows() then
|
|
self.is_window_system = true
|
|
end
|
|
|
|
|
|
local callfunc = function(module_name,func)
|
|
if module_name == "mouseinput" then
|
|
if func == "settime" then
|
|
self.cur_exit_time = os.time() - 175
|
|
self.last_bright = nil
|
|
GlobalEventSystem:Fire(SceneEventType.SCREEN_BRIGHT_DEL_EVENT)
|
|
end
|
|
end
|
|
end
|
|
GlobalEventSystem:Bind(EventName.DO_MODULE_DEBUG_FUNC,callfunc)
|
|
end
|
|
|
|
function MouseInput:touch_begin_func_pri()
|
|
GlobalUserOperateTime = Time.time
|
|
GlobalEventSystem:Fire(GameInputManager.GameInputEvent.MOUSE_PRESS, screen_pos)
|
|
|
|
if Status.NowTime - self.press_time < 0.3 then
|
|
return
|
|
end
|
|
|
|
self.press_view_point = screen_pos
|
|
self.press_time = Status.NowTime
|
|
self.press_accept = true
|
|
|
|
--GlobalEventSystem:Fire(SceneEventType.MAIN_ROLE_MOUSE_DOWN, screen_pos)
|
|
end
|
|
|
|
function MouseInput:touch_moved_func_pri()
|
|
if self.fire_move_time == nil or self.fire_move_time ~= Status.NowTime then
|
|
self.fire_move_time = Status.NowTime
|
|
GlobalEventSystem:Fire(GameInputManager.GameInputEvent.MOUSE_MOVE, screen_pos)
|
|
end
|
|
end
|
|
|
|
function MouseInput:touch_ended_func_pri()
|
|
GlobalEventSystem:Fire(GameInputManager.GameInputEvent.MOUSE_RELEASE, screen_pos)
|
|
|
|
if not self.press_accept then
|
|
return
|
|
end
|
|
self.press_accept = false
|
|
|
|
self:HandleMouseInput(screen_pos)
|
|
end
|
|
|
|
function MouseInput:NormalScreenBright()
|
|
if self.last_bright then
|
|
SDKUtil.SetBright(self.last_bright)
|
|
self.last_bright = nil
|
|
end
|
|
|
|
-- if not lua_viewM.main_cancas_last_visible then
|
|
SetGameFrameRate()
|
|
-- else
|
|
-- SetGameFrameRate()
|
|
-- end
|
|
end
|
|
|
|
function MouseInput:CheckClick(pos)
|
|
self:touch_begin_func_pri(pos)
|
|
|
|
self.cur_exit_time = os.time()
|
|
if self.last_bright then
|
|
self:NormalScreenBright()
|
|
end
|
|
end
|
|
|
|
function MouseInput:Update()
|
|
if Input.touchCount > 0 then
|
|
local pos = Input.GetTouch(0).position
|
|
local cur_state = Input.GetTouch(0).phase
|
|
if cur_state == TouchPhase.Began then -- 按下
|
|
self:CheckClick(pos)
|
|
elseif cur_state == TouchPhase.Moved then
|
|
self:touch_moved_func_pri(pos)
|
|
elseif cur_state == TouchPhase.Stationary then --手指静止在屏幕
|
|
elseif cur_state == TouchPhase.Ended then
|
|
self:touch_ended_func_pri(pos)
|
|
|
|
self.cur_exit_time = os.time()
|
|
elseif cur_state == TouchPhase.Canceled then --当超过五个点触摸时,系统取消响应
|
|
end
|
|
end
|
|
|
|
if self.is_window_system and ( Input.GetMouseButtonDown(0) or Input.GetMouseButton(0)) then
|
|
self:CheckClick()
|
|
end
|
|
|
|
-- if self.last_bright == nil and self.cur_exit_time ~= -1 and os.time() - self.cur_exit_time > 180 then
|
|
-- self.last_bright = SDKUtil.CallIntFunc( "SystemBright", "GetBright", "" )
|
|
-- local bright = 5
|
|
-- if SystemRuntimePlatform.IsIphone() then
|
|
-- bright = 15
|
|
-- end
|
|
-- SDKUtil.SetBright(bright)
|
|
-- if SceneManager and SceneManager:getInstance().curr_scene_id > 0 then
|
|
-- GlobalEventSystem:Fire(SceneEventType.SCREEN_BRIGHT_DEL_EVENT)
|
|
-- end
|
|
-- SetGameFrameRate(30)
|
|
-- end
|
|
end
|
|
|
|
function MouseInput:HandleMouseInput(screen_pos)
|
|
--[[
|
|
local move_dir = screen_pos - self.press_view_point
|
|
local distance = move_dir:Distance()
|
|
|
|
if distance > 120 then
|
|
if move_dir.y < -0.5 then
|
|
--手指上滑
|
|
elseif move_dir.y > 0.5 then
|
|
--手指下滑
|
|
end
|
|
return
|
|
end
|
|
|
|
GlobalEventSystem:Fire(EventName.SCREEN_CLICK, screen_pos)
|
|
]]
|
|
end
|
|
|
|
function MouseInput:SetEnable(value)
|
|
end
|
|
|
|
function MouseInput:__delete()
|
|
end
|