def processJoystickEvent(self, event): jSet = InputMapping.g_instance.joystickSettings if event.axis == jSet.ROLL_AXIS and (event.deviceId == jSet.ROLL_DEVICE or 0 == jSet.ROLL_DEVICE): rValue = -event.value if jSet.INVERT_ROLL else event.value rawValue = rValue if abs(rValue) <= jSet.ROLL_DEAD_ZONE: self.__profile.sendPrimaryAxis(ROLL_AXIS, 0.0, rawValue) else: rValue = math.copysign((abs(rValue) - jSet.ROLL_DEAD_ZONE) / (1.0 - jSet.ROLL_DEAD_ZONE), rValue) rValue = InputMapping.translateAxisValue( jSet.AXIS_X_CURVE, rValue) self.__profile.sendPrimaryAxis(ROLL_AXIS, clamp(-1.0, rValue, 1.0), rawValue) elif event.axis == jSet.G_VERTICAL_AXIS and ( event.deviceId == jSet.G_VERTICAL_DEVICE or 0 == jSet.G_VERTICAL_DEVICE): vValue = event.value if jSet.INVERT_G_VERTICAL else -event.value rawValue = vValue self.__rAxisValue[VERTICAL_AXIS] = vValue r = min(math.hypot(vValue, self.__rAxisValue[HORIZONTAL_AXIS]), 1) DEAD_ZONE = jSet.G_VERTICAL_DEAD_ZONE if r <= DEAD_ZONE: self.__profile.sendPrimaryAxis(VERTICAL_AXIS, 0.0, rawValue) else: r_DZ = (r - DEAD_ZONE) / (1 - DEAD_ZONE) cos = vValue / r r_ = InputMapping.translateAxisValue(jSet.AXIS_Y_CURVE, r_DZ) x = r_ * cos self.__profile.sendPrimaryAxis(VERTICAL_AXIS, clamp(-1.0, x, 1.0), rawValue) elif event.axis == jSet.G_HORIZONTAL_AXIS and ( event.deviceId == jSet.G_HORIZONTAL_DEVICE or 0 == jSet.G_HORIZONTAL_DEVICE): hValue = event.value if jSet.INVERT_HORIZONTAL else -event.value rawValue = hValue self.__rAxisValue[HORIZONTAL_AXIS] = hValue r = min(math.hypot(self.__rAxisValue[VERTICAL_AXIS], hValue), 1) DEAD_ZONE = jSet.G_VERTICAL_DEAD_ZONE if r <= DEAD_ZONE: self.__profile.sendPrimaryAxis(HORIZONTAL_AXIS, 0.0, rawValue) else: r_DZ = (r - DEAD_ZONE) / (1 - DEAD_ZONE) sin = hValue / r r_ = InputMapping.translateAxisValue(jSet.AXIS_Y_CURVE, r_DZ) y = r_ * sin self.__profile.sendPrimaryAxis(HORIZONTAL_AXIS, clamp(-1.0, y, 1.0), rawValue) elif event.axis == jSet.FORCE_AXIS and ( event.deviceId == jSet.FORCE_DEVICE or 0 == jSet.FORCE_DEVICE): fValue = -event.value if jSet.INVERT_FORCE else event.value rawValue = fValue if self.__isRawForceAxis: fValue = self.__renormalization(fValue) self.__profile.sendPrimaryAxis(FORCE_AXIS, fValue, rawValue)
def processJoystickEvent(self, event): jSet = InputMapping.g_instance.joystickSettings rValue = 0.0 vValue = 0.0 hValue = 0.0 fValue = 0.0 if event.axis == jSet.ROLL_AXIS and (event.deviceId == jSet.ROLL_DEVICE or 0 == jSet.ROLL_DEVICE): rValue = -event.value if jSet.INVERT_ROLL else event.value rawValue = rValue if abs(rValue) <= jSet.ROLL_DEAD_ZONE: self._profile.sendData(ROLL_AXIS, 0.0, -rawValue) else: rValue = self.__signalSmoothing(jSet.ROLL_AXIS, rValue, jSet.ROLL_SMOOTH_WINDOW) rValue = self.__signalDiscrete(jSet.ROLL_SENSITIVITY, rValue, event.deviceId, event.axis) rValue = math.copysign((abs(rValue) - jSet.ROLL_DEAD_ZONE) / (1.0 - jSet.ROLL_DEAD_ZONE), rValue) rValue = InputMapping.translateAxisValue(jSet.AXIS_X_CURVE, rValue) rValue = clamp(-1.0, -rValue, 1.0) self._profile.sendData(ROLL_AXIS, rValue, -rawValue) elif event.axis == jSet.VERTICAL_AXIS and (event.deviceId == jSet.VERTICAL_DEVICE or 0 == jSet.VERTICAL_DEVICE): vValue = -event.value if jSet.INVERT_VERTICAL else event.value rawValue = vValue if abs(vValue) <= jSet.VERTICAL_DEAD_ZONE: self._profile.sendData(VERTICAL_AXIS, 0.0, rawValue) else: vValue = self.__signalSmoothing(jSet.VERTICAL_AXIS, vValue, jSet.VERTICAL_SMOOTH_WINDOW) vValue = self.__signalDiscrete(jSet.VERTICAL_SENSITIVITY, vValue, event.deviceId, event.axis) vValue = math.copysign((abs(vValue) - jSet.VERTICAL_DEAD_ZONE) / (1 - jSet.VERTICAL_DEAD_ZONE), vValue) vValue = InputMapping.translateAxisValue(jSet.AXIS_Y_CURVE, vValue) vValue = clamp(-1.0, -vValue, 1.0) self._profile.sendData(VERTICAL_AXIS, vValue, -rawValue) elif event.axis == jSet.HORIZONTAL_AXIS and (event.deviceId == jSet.HORIZONTAL_DEVICE or 0 == jSet.HORIZONTAL_DEVICE): hValue = event.value if jSet.INVERT_HORIZONTAL else -event.value rawValue = hValue if abs(hValue) <= jSet.HORIZONTAL_DEAD_ZONE: self._profile.sendData(HORIZONTAL_AXIS, 0.0, rawValue) else: hValue = self.__signalSmoothing(jSet.HORIZONTAL_AXIS, hValue, jSet.HORIZONTAL_SMOOTH_WINDOW) hValue = self.__signalDiscrete(jSet.HORIZONTAL_SENSITIVITY, hValue, event.deviceId, event.axis) hValue = InputMapping.translateAxisValue(jSet.AXIS_Z_CURVE, hValue) hValue = math.copysign((abs(hValue) - jSet.HORIZONTAL_DEAD_ZONE) / (1 - jSet.HORIZONTAL_DEAD_ZONE), hValue) if InputMapping.g_instance.currentProfileType == INPUT_SYSTEM_STATE.GAMEPAD_DIRECT_CONTROL: hValue *= -1 hValue = clamp(-1.0, hValue, 1.0) self._profile.sendData(HORIZONTAL_AXIS, hValue, rawValue) elif event.axis == jSet.FORCE_AXIS and (event.deviceId == jSet.FORCE_DEVICE or 0 == jSet.FORCE_DEVICE): fValue = -event.value if jSet.INVERT_FORCE else event.value rawValue = fValue if self.__isRawForceAxis: fValue = self.__renormalization(fValue) self._profile.sendData(FORCE_AXIS, fValue, rawValue) self.__cameraStrategy.rotateCursor(vValue * 0.01, hValue * 0.01)
def handleKeyEvent(self, event): keyName = InputMapping.getKeyNameByCode(event.key) if keyName is not None and keyName not in DISABLED_KEYS: if self.__gameOptionsManager.root.signals.signalKey.isSignalActive: signalKeyVO = SignalKeyVO() signalKeyVO.id = keyName signalKeyVO.isKeyDown = event.isKeyDown() signalKeyVO.isSignalActive = True signalKeyVO.deviceId = str(event.deviceId) signalKeyVO.deviceName = BigWorld.getDeviceName(event.deviceId) signalKeyVO.label = InputMapping.getKeyLocalization(keyName) self.call_1('receive', 'signals.signalKey', signalKeyVO) return True return False
def prepareControlsGroup(mapping, groupID, controls): for cmdID, record in mapping.iteritems(): cmd = record['cmdName'] cmdLabel = InputMapping.getCommandLocalization(cmd) isHide = InputMapping.getCommandHideStatus(cmd) if cmdLabel is not None and not isHide and not ( (cmdID == InputMapping.CMD_PUSH_TO_TALK or cmdID == InputMapping.CMD_PUSH_TO_TALK_SQUAD or cmdID == InputMapping.CMD_TOGGLE_ARENA_VOICE_CHANNEL) and not VOIP.api().voipSupported): LOG_DEBUG('__ prepareControlsGroup : show ', cmd) if groupID == InputMapping.g_descriptions.getCommandGroupID( cmd) or groupID == 'SETTINGS_BASIC' and record['isBase']: commandVO = CommandVO() commandVO.id = cmdID commandVO.title = cmdLabel commandVO.switchingStyle = record['switchingStyle'] commandVO.enabled = cmd not in Settings.g_instance.cmdFilter isFireAxis = len(record['linkedAxisName']) <= 0 commandVO.axes.sign = record['fireAxisSign'] if not isFireAxis: commandVO.axes.axisDeadzone = record['linkedAxisDeadZone'] commandVO.axes.axisInverted = record['linkedAxisInverted'] commandVO.axes.axisSensitivity = record[ 'linkedAxisSensitivity'] commandVO.axes.axisGroup = record['linkedAxisName'] commandVO.axes.axisSmoothing = record[ 'linkedAxisSmoothWindow'] commandVO.axes.axisDeviceId = str(record[ 'fireAxisDevice' if isFireAxis else 'linkedAxisDevice']) commandVO.axes.axisDeviceName = record[ 'fireAxisDeviceName' if isFireAxis else 'linkedAxisDeviceName'] commandVO.axes.axisId = record[ 'fireAxisIndex' if isFireAxis else 'linkedAxisIndex'] commandVO.axes.axisLabel = InputMapping.getAxisLocalization( commandVO.axes.axisId) for key in record['keyNames']: buttonEntryVO = ButtonEntryVO() buttonEntryVO.id = key['name'] buttonEntryVO.deviceId = str(key['device']) buttonEntryVO.label = InputMapping.getKeyLocalization( key['name']) commandVO.buttons.append(buttonEntryVO) controls.append(commandVO) return
def add(self, container, commandName, linkedAxisName, fireAxisIndex, fireAxisSign, fireAxisDevice, fireKeyNames, modifier, isBlock, isBase, switchingStyle): command = InputMapping.g_descriptions.getCommandIntID(commandName) if command is not None: container[command] = InputMapping.Command(commandName, linkedAxisName, fireAxisIndex, fireAxisSign, fireAxisDevice, fireKeyNames, modifier, isBlock, isBase, switchingStyle) return True else: return False return
def getKeyLocalization(cmdID, keyIndex = 0): keyName = '' keysControls = InputMapping.g_instance.getKeyControlsHelp([cmdID]) keysData = keysControls.get(cmdID, None) if keysData is not None and keysData['keys']: keyName = InputMapping.getKeyLocalization(keysData['keys'][keyIndex]) if keysData['isFireAxis'][keyIndex]: if keysData['axisSign'][keyIndex] == 1: keyName += '+' else: keyName += '-' return keyName
def handleAxisEvent(self, event): if self.__gameOptionsManager.root.signals.signalAxis.isSignalActive and abs( event.value) > AXIS_SETUP_THRESHOLD: signalAxis = SignalAxisVO() signalAxis.isSignalActive = True signalAxis.id = event.axis signalAxis.value = event.value signalAxis.deviceName = BigWorld.getDeviceName(event.deviceId) signalAxis.deviceId = str(event.deviceId) signalAxis.label = InputMapping.getAxisLocalization(event.axis) self.call_1('receive', 'signals.signalAxis', signalAxis) if self.__gameOptionsManager.root.signals.signalAxisPreview.isSignalActive: self.__currentAxisEvent(event) return True
def processJoystickEvent(self, event): event = self.__replacement(event) jSet = InputMapping.g_instance.joystickSettings if event.axis == jSet.ROLL_AXIS and (event.deviceId == jSet.ROLL_DEVICE or 0 == jSet.ROLL_DEVICE): rValue = InputMapping.translateAxisValue(jSet.AXIS_X_CURVE, event.value) if abs(rValue) <= jSet.ROLL_DEAD_ZONE: rValue = 0.0 else: rValue = math.copysign((abs(rValue) - jSet.ROLL_DEAD_ZONE) / (1.0 - jSet.ROLL_DEAD_ZONE), rValue) rValue = -rValue if jSet.INVERT_ROLL else rValue self.__profile.sendPrimaryAxis(ROLL_AXIS, clamp(-1.0, -rValue, 1.0)) elif event.axis == jSet.G_VERTICAL_AXIS and ( event.deviceId == jSet.G_VERTICAL_DEVICE or 0 == jSet.G_VERTICAL_DEVICE): vValue = -event.value if jSet.INVERT_G_VERTICAL else event.value self.__rAxisValue[VERTICAL_AXIS] = vValue r = min(math.hypot(vValue, self.__rAxisValue[HORIZONTAL_AXIS]), 1) DEAD_ZONE = jSet.G_VERTICAL_DEAD_ZONE if r <= DEAD_ZONE: self.__axisValue[VERTICAL_AXIS] = 0.0 else: r_DZ = (r - DEAD_ZONE) / (1 - DEAD_ZONE) cos = vValue / r r_ = math.pow(r_DZ, (1 - jSet.SENSITIVITY) * 3.0 + 1.0) x = r_ * cos self.__axisValue[VERTICAL_AXIS] = clamp(-1.0, x, 1.0) self.__setCursorSpeed() elif event.axis == jSet.G_HORIZONTAL_AXIS and ( event.deviceId == jSet.G_HORIZONTAL_DEVICE or 0 == jSet.G_HORIZONTAL_DEVICE): hValue = event.value self.__rAxisValue[HORIZONTAL_AXIS] = hValue r = min(math.hypot(self.__rAxisValue[VERTICAL_AXIS], hValue), 1) DEAD_ZONE = jSet.G_VERTICAL_DEAD_ZONE if r <= DEAD_ZONE: self.__axisValue[HORIZONTAL_AXIS] = 0.0 else: r_DZ = (r - DEAD_ZONE) / (1 - DEAD_ZONE) sin = hValue / r r_ = math.pow(r_DZ, (1 - jSet.SENSITIVITY) * 3.0 + 1.0) y = r_ * sin cursorDirection = self.__cameraStrategy.cursorDirection cameraDirection = self.__cameraStrategy.cameraDirection angle = cursorDirection.angle(cameraDirection) if angle > 0.75 * math.pi: y *= -1 self.__axisValue[HORIZONTAL_AXIS] = clamp(-1.0, y, 1.0) self.__setCursorSpeed() elif event.axis == jSet.FORCE_AXIS and ( event.deviceId == jSet.FORCE_DEVICE or 0 == jSet.FORCE_DEVICE): fValue = event.value if abs(fValue) < jSet.FORCE_DEAD_ZONE: fValue = 0.0 else: fValue = -fValue if jSet.INVERT_FORCE else fValue self.__profile.sendPrimaryAxis(FORCE_AXIS, fValue) elif event.axis == jSet.FREE_HORIZONTAL_CAM_GAMEPAD_AXIS and ( event.deviceId == jSet.FREE_HORIZONTAL_CAM_GAMEPAD_DEVICE or 0 == jSet.FREE_HORIZONTAL_CAM_GAMEPAD_DEVICE): hValue = event.value if abs(hValue) <= jSet.G_VERTICAL_DEAD_ZONE: self.__axisValue[FREE_HORIZONTAL_CAM] = 0.0 else: hValue = math.copysign( (abs(hValue) - jSet.G_VERTICAL_DEAD_ZONE) / (1 - jSet.G_VERTICAL_DEAD_ZONE), hValue) self.__axisValue[FREE_HORIZONTAL_CAM] = clamp( -1.0, hValue, 1.0) elif event.axis == jSet.FREE_VERTICAL_CAM_GAMEPAD_AXIS and ( event.deviceId == jSet.FREE_VERTICAL_CAM_GAMEPAD_DEVICE or 0 == jSet.FREE_VERTICAL_CAM_GAMEPAD_DEVICE): vValue = event.value if abs(vValue) <= jSet.G_VERTICAL_DEAD_ZONE: self.__axisValue[FREE_VERTICAL_CAM] = 0.0 else: vValue = math.copysign( (abs(vValue) - jSet.G_VERTICAL_DEAD_ZONE) / (1 - jSet.G_VERTICAL_DEAD_ZONE), vValue) vValue = vValue if jSet.INVERT_G_VERTICAL else -vValue self.__axisValue[FREE_VERTICAL_CAM] = clamp(-1.0, vValue, 1.0)