--玩家输入管理器 local LuaInputManager = {} local EventSystem = require('Event/EventSystem') local this = LuaInputManager local CacheVirtualAngle = 0 local sqrt = math.sqrt local acos = math.acos local pi = math.pi local floor = math.floor local SpecialCommandType=LuaConst.SpecialCommandType local newV2=FP.newV2 --键盘控制的旋转速度 local RotatingSpeed = 240 function LuaInputManager.Init() --在LevelManager的private.InitLevel里被调用,实际命名应该是OnInitLevel this.KeyPress = false--当前帧是否按下攻击键 --当前帧是否放开攻击键 --这个标志位是为了防止一直按着技能键不放,进入cd后,还能释放 this.KeyRelease = false --当前帧按下的技能按键 this.KeyPosition = 0 -- 当前摇杆的幅度是否在一半内(0半摇杆1全摇杆) ; 其他配合spc的组合 this.MoveType = 1 --当前摇杆朝向 this.FixVirtualMoveDir = newV2(0,0) --当前特殊指定 this.SpecialCommand = 0 --this.SkillJoystickDirAngle = 3610 this.UseJoyStickType = LuaConst.UseJoystickType.None this.SkillJoystickWorldOffsetX = 0 this.SkillJoystickWorldOffsetZ = 0 this.KeyPosResetAfterUse = false this.isInSkillCancelArea = false this.skillJoystickInterruptFlag = nil this.waitingSpecialCommands = {} --等待响应的specialCommand列表 EventSystem.Regist(EventID.SendSpecialCommand, LuaInputManager.OnSendSpecialCommand) end local function GetAngleFromDir(x,z) if x==0 and z==0 then return 0 end local cos = (x*z)/(sqrt(x^2+z^2)) local angle = (acos(cos)*180)/pi if (x>=0 and z>=0) then angle = angle + 270 elseif(x>=0 and z<=0)then angle = angle elseif(x<=0 and z>=0)then angle = angle + 180 elseif(x<=0 and z<=0)then angle = angle + 90 end return floor(angle/10) end --[[ Tick --]] function LuaInputManager.OnUpdate() if #this.waitingSpecialCommands > 0 then LuaInputManager.SetSpecialCommand(this.waitingSpecialCommands[1]) else --重置数据 if this.SpecialCommand == LuaConst.SpecialCommandType.JoystickSetTarget then this.KeyPosition = 0 end LuaInputManager.SetSpecialCommand(SpecialCommandType.None) end end local frameCount = 0 local TEAMLEADER_FORCE_SEND_POS_INTERVAL = 15 --[[ 推动摇杆 --]] function LuaInputManager.SetKeyboardMoveDir(dx,dy) EventSystem.Dispatch(EventID.UI_KeyboardControl_MoveDir,dx,dy) --LuaInputManager.SetVirtualMoveDir(x,z) end function LuaInputManager.ReleaseCurEntityMoveDir() EventSystem.Dispatch(EventID.UI_KeyboardControl_MoveRelease) end function LuaInputManager.SetVirtualMoveDir(x,z) this.FixVirtualMoveDir:Reset(x, z) local tempAngle = GetAngleFromDir(x,z) frameCount = frameCount + 1 if tempAngle>0 and tempAngle ~= CacheVirtualAngle or ((CTL.Team.IsTeamLeader(BattleDataGetter.GetAcID()) or MDL.Team.GetFollowIndexByAcid(BattleDataGetter.GetAcID())) and frameCount >= TEAMLEADER_FORCE_SEND_POS_INTERVAL) then --如果是队长,或者在组队跟随中,则无脑上传 CacheVirtualAngle = tempAngle --朝向角度改变同步一次位置 SyncMoveManager.ForceC2SRoleMove() frameCount = 0 end end -- 走路摇杆,是否大于一半 function LuaInputManager.SetVirtualMoveHalf(isHalfStretch) if this.MoveType <= LuaConst.CmdMoveTypeBaseEnum.HalfStretchMax then -- 如果有特殊的cmd用了MoveType则其值一定大于HalfStretchMax 。原因filtermanager中特殊cmd优先级大于移动摇杆,移动功能不会执行的。 this.MoveType = isHalfStretch and 0 or 1 end end function LuaInputManager.SetSkillJoystickInfo(worldOffsetX, worldOffsetZ, specialCommand) --this.SkillJoystickDirAngle = math.floor(dirAngle * 10 + 0.5) this.SkillJoystickWorldOffsetX = floor(worldOffsetX * 100 + 0.5) this.SkillJoystickWorldOffsetZ = floor(worldOffsetZ * 100 + 0.5) -- logging.error(LTAG.ERROR, "HYW : SetSkillJoystickInfo : ", tostring(dirAngle), -- " , ", tostring(this.SkillJoystickWorldOffsetX), " , ", tostring(this.SkillJoystickWorldOffsetZ)) if specialCommand then LuaInputManager.SetSpecialCommand(specialCommand) end end function LuaInputManager.CmdRunToPosByIndex(index) LuaInputManager.EnqueueSpecialCommand(SpecialCommandType.RunToPosByIndex) this.posIndex = index end function LuaInputManager.GetPosIndex() return this.posIndex end function LuaInputManager.StepOnAccelerator() this.UseJoyStickType = LuaConst.UseJoystickType.DriveAccelerator end function LuaInputManager.ReleaseAccelerator() this.UseJoyStickType = LuaConst.UseJoystickType.None end function LuaInputManager.ClearSkillJoystickInfo() --this.SkillJoystickDirAngle = 3610 this.SkillJoystickWorldOffsetX = 0 this.SkillJoystickWorldOffsetZ = 0 end --[[ 按下键盘 --]] function LuaInputManager.PressKeyboard(key) if key < 20 then EventSystem.Dispatch(EventID.UI_KeyboardControl_Skill_Press,key) elseif key == LuaConst.KeyMapEnum.EW_KEYMAP_TEAM_MIDDLE then EventSystem.Dispatch(EventID.UI_KeyboardControl_Switch_Team,2) elseif key == LuaConst.KeyMapEnum.EW_KEYMAP_TEAM_REAR then EventSystem.Dispatch(EventID.UI_KeyboardControl_Switch_Team,3) elseif key == LuaConst.KeyMapEnum.EW_KEYMAP_SETTINGS then LuaInputManager.PressSettingKey() elseif key == LuaConst.KeyMapEnum.EW_KEYMAP_ENTER then EventSystem.Dispatch(EventID.UI_KeyboardControl_Enter) elseif key == LuaConst.KeyMapEnum.EW_KEYMAP_ROTATECAMERA_LEFT then EventSystem.Dispatch(EventID.UI_KeyboardControl_Rotating, -RotatingSpeed * Time.deltaTime, 0) elseif key == LuaConst.KeyMapEnum.EW_KEYMAP_ROTATECAMERA_RIGHT then EventSystem.Dispatch(EventID.UI_KeyboardControl_Rotating, RotatingSpeed * Time.deltaTime, 0) end end local rotateVec = Vector2.New(0, 0) function LuaInputManager.RotatingCameraByManual(speed) rotateVec.x = speed CameraController.Instance:RotatingByManual(rotateVec); end --[[ 反馈攻击事件 --]] function LuaInputManager.PressAttackKey(key) this.KeyPress = true LuaInputManager.SetKeyPosition(key) end function LuaInputManager.TryKeyPosResetAfterUse(entity, skillID) if entity:IsPlayerSelf() then if skillID > 0 then local skillData = entity:GetSkillData(skillID) if skillData.KeyPosition == LuaInputManager.KeyPosition then LuaInputManager.SetKeyPosition(0, false) end end end end function LuaInputManager.SetKeyPosition(key, needResetAfterUse) this.KeyPosition = key if this.KeyPosition > 0 then this.KeyRelease = false end this.KeyPosResetAfterUse = needResetAfterUse end --[[ 松开键盘 --]] function LuaInputManager.ReleaseKeyboard(key) EventSystem.Dispatch(EventID.UI_KeyboardControl_Skill_Release,key) end --[[ 反馈松开事件 --]] function LuaInputManager.ReleaseAttackKey() this.KeyRelease = true end function LuaInputManager.ReleaseAttackKeyIfPressing(keyPostion) if this.KeyPosition == keyPostion and this.KeyRelease == false then this.KeyRelease = true end end function LuaInputManager.ReleaseAttackKeyHard() this.KeyPress = false LuaInputManager.SetKeyPosition(0) this.KeyRelease = true end --[[ 按下副将技 --]] function LuaInputManager.PressAdjutantKey() LuaInputManager.SetSpecialCommand(SpecialCommandType.Adjutant) end --[[ 按下计略技能 --]] function LuaInputManager.PressStratagemKey() LuaInputManager.SetSpecialCommand(SpecialCommandType.Stratagem) end --[[ 按下道具按键 --]] function LuaInputManager.PressBattlePropKey(btnIndex) LuaInputManager.SetSpecialCommand(SpecialCommandType.UseBattleProp) LuaInputManager.SetMoveType(btnIndex + LuaConst.CmdMoveTypeBaseEnum.UseBattlePropBase) end --- 肉鸽按下了选择某技能 function LuaInputManager.PressRogueSkillSelect(btnIndex) LuaInputManager.SetSpecialCommand(SpecialCommandType.RogueLikeSelect) LuaInputManager.SetMoveType(btnIndex + LuaConst.CmdMoveTypeBaseEnum.RogueLikeSelectBase) end function LuaInputManager.PressBuffSkillKey(buffSkillBtnIndex) LuaInputManager.SetSpecialCommand(SpecialCommandType["BuffSkill" .. buffSkillBtnIndex]) end --[[ 按下进入驾驶键 --]] function LuaInputManager.PressDriveKey() LuaInputManager.SetSpecialCommand(SpecialCommandType.InDrive) end --[[ 按下离开驾驶键 --]] function LuaInputManager.PressOffDriveKey() LuaInputManager.SetSpecialCommand(SpecialCommandType.OffDrive) end function LuaInputManager.PressAutoFightBtn() LuaInputManager.SetSpecialCommand(SpecialCommandType.AutoFight) end function LuaInputManager.PressSelectBornItemIndex(index) LuaInputManager.SetSpecialCommand(SpecialCommandType.SetBornItemIDByIndex) LuaInputManager.SetMoveType(index) end -- 相机锁定某人的处理(entityID 大约0 锁定 ;等于0 结束锁定) function LuaInputManager.CameraLockTarget(entityID) LuaInputManager.SetSpecialCommand(SpecialCommandType.CameraLockTarget) local shortNum = LuaConst.BinaryFlag.MaxShort local low = entityID % shortNum local high = (entityID - low) / shortNum this.SkillJoystickWorldOffsetX = high this.SkillJoystickWorldOffsetZ = low end function LuaInputManager.SetSpecialCommand(cmdType) this.SpecialCommand = cmdType end function LuaInputManager.GetSpecialCommand() return this.SpecialCommand end --把SpecialCommand加入队列,由LuaInputManager保证这个command在关卡没有结束的情况下一定被Filter function LuaInputManager.EnqueueSpecialCommand(cmdType) this.waitingSpecialCommands[#this.waitingSpecialCommands + 1] = cmdType end function LuaInputManager.OnSendSpecialCommand(cmdType) if this.waitingSpecialCommands[1] == cmdType then table.remove(this.waitingSpecialCommands, 1) end end function LuaInputManager.SetMoveType(moveType) this.MoveType = moveType end --[[ 在遍历前,设置输入信息 --]] function LuaInputManager.SetInputBeforeTraversal() --在之前的逻辑帧按下,在当前逻辑帧放开 if not this.KeyPress and this.KeyRelease and not this.KeyPosResetAfterUse then LuaInputManager.SetKeyPosition(0) end end --[[ 在遍历后,设置输入信息 --]] function LuaInputManager.SetInputAfterTraversal() --在当前逻辑帧放开 if this.KeyRelease and not this.KeyPosResetAfterUse then LuaInputManager.SetKeyPosition(0) end --重置 this.KeyPress = false this.KeyRelease = false end function LuaInputManager.SetIsInSkillCancelArea(isInSkillCancelArea) this.isInSkillCancelArea = isInSkillCancelArea end function LuaInputManager.SetSkillJoystickInterruptFlag(value) this.skillJoystickInterruptFlag = value end function LuaInputManager.GetSkillJoystickInterruptFlag() return this.skillJoystickInterruptFlag end function LuaInputManager.GetIsInSkillCancelArea() return this.isInSkillCancelArea end function LuaInputManager.ShowExitGameMessageBox() --登录界面退出的时候,还没有初始化BattleDataGetter if BattleDataGetter and BattleDataGetter.GetCurLevelType() == LuaConst.LevelType.NORMAL then CTL.Setting.BackToTown() else if BattleDataGetter and BattleDataGetter.IsStandaloneBattleLevel() then UTL.MessageBox.ShowSettingOKCancelBox("", UIUtils.GetLocalizedTxt(Const_IDS.IDS_QUIT_PROMPT), function() SDKUtil.ExitForce() end, nil, nil, nil, UTL.MessageBox.DisplayType.ExitGameTip) else UTL.MessageBox.ShowOKCancelBox("", UIUtils.GetLocalizedTxt(Const_IDS.IDS_QUIT_PROMPT), function() SDKUtil.ExitForce() end, nil, nil, nil, UTL.MessageBox.DisplayType.ExitGameTip) end end end function LuaInputManager.ScalingCameraByManual(isEnlarge) EventSystem.Dispatch(EventID.Camera_ScalingCameraByManual, isEnlarge) end function LuaInputManager.PressSettingKey() local levelData = LevelManager.GetCurInfoData() local levelFeatureType = DataSheetManager.LevelFeatureData:GetDataByLevelFeatureID(levelData.LevelType).LevelFeatureType --即 主城,动态主城,战区静态主城,战区动态主城 if levelFeatureType <= LuaConst.LevelFeatureType.CrossDynamicTown then if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISettingMainPanel) then UIManager.OpenView(Const_UI_Lua.UIEnum.UISettingMainPanel) end end end return LuaInputManager