示例#1
0
 public void wheelCallback(byte ID, object Data)
 {
     newWheel = KerbalSimpitUtils.ByteArrayToStructure <WheelStruct>((byte[])Data);
     // Bit fields
     // steer = 1
     // throttle = 2
     if ((newWheel.mask & (byte)1) > 0)
     {
         myWheel.steer = newWheel.steer;
     }
     if ((newWheel.mask & (byte)2) > 0)
     {
         myWheel.throttle = newWheel.throttle;
     }
 }
示例#2
0
 public void vesselTranslationCallback(byte ID, object Data)
 {
     newTranslation = KerbalSimpitUtils.ByteArrayToStructure <TranslationalStruct>((byte[])Data);
     // Bit fields:
     // X = 1
     // Y = 2
     // Z = 4
     if ((newTranslation.mask & (byte)1) > 0)
     {
         myTranslation.X = newTranslation.X;
     }
     if ((newTranslation.mask & (byte)2) > 0)
     {
         myTranslation.Y = newTranslation.Y;
     }
     if ((newTranslation.mask & (byte)4) > 0)
     {
         myTranslation.Z = newTranslation.Z;
     }
 }
示例#3
0
 public void vesselRotationCallback(byte ID, object Data)
 {
     newRotation = KerbalSimpitUtils.ByteArrayToStructure <RotationalStruct>((byte[])Data);
     // Bit fields:
     // pitch = 1
     // roll = 2
     // yaw = 4
     if ((newRotation.mask & (byte)1) > 0)
     {
         myRotation.pitch = newRotation.pitch;
     }
     if ((newRotation.mask & (byte)2) > 0)
     {
         myRotation.roll = newRotation.roll;
     }
     if ((newRotation.mask & (byte)4) > 0)
     {
         myRotation.yaw = newRotation.yaw;
     }
 }
        public void customAxisCallback(byte ID, object Data)
        {
            newCustomAxis = KerbalSimpitUtils.ByteArrayToStructure <CustomAxixStruct>((byte[])Data);

            if ((newCustomAxis.mask & (byte)1) > 0)
            {
                myCustomAxis.custom1 = newCustomAxis.custom1;
            }
            if ((newCustomAxis.mask & (byte)2) > 0)
            {
                myCustomAxis.custom2 = newCustomAxis.custom2;
            }
            if ((newCustomAxis.mask & (byte)4) > 0)
            {
                myCustomAxis.custom3 = newCustomAxis.custom3;
            }
            if ((newCustomAxis.mask & (byte)8) > 0)
            {
                myCustomAxis.custom4 = newCustomAxis.custom4;
            }
        }
示例#5
0
        public void KeyboardEmulatorCallback(byte ID, object Data)
        {
            try
            {
                KeyboardEmulatorStruct payload = KerbalSimpitUtils.ByteArrayToStructure <KeyboardEmulatorStruct>((byte[])Data);

                Int32 key32 = payload.key; //To cast it in the enum, we need a Int32 but only a Int16 is sent

                if (Enum.IsDefined(typeof(VirtualKeyCode), key32))
                {
                    VirtualKeyCode key = (VirtualKeyCode)key32;
                    if ((payload.modifier & KeyboardEmulatorModifier.ALT_MOD) != 0)
                    {
                        input.Keyboard.KeyDown(VirtualKeyCode.MENU);
                    }

                    if ((payload.modifier & KeyboardEmulatorModifier.CTRL_MOD) != 0)
                    {
                        input.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    }

                    if ((payload.modifier & KeyboardEmulatorModifier.SHIFT_MOD) != 0)
                    {
                        // Use LSHIFT instead of SHIFT since some function (like SHIFT+Tab to cycle through bodies in map view) only work with left shift.
                        // This requires a custom version of the WindowsInput library to properly handle it.
                        input.Keyboard.KeyDown(VirtualKeyCode.LSHIFT);
                    }

                    if ((payload.modifier & KeyboardEmulatorModifier.KEY_DOWN_MOD) != 0)
                    {
                        Debug.Log("Simpit emulates key down of " + key);
                        input.Keyboard.KeyDown(key);
                    }
                    else if ((payload.modifier & KeyboardEmulatorModifier.KEY_UP_MOD) != 0)
                    {
                        Debug.Log("Simpit emulates key up of " + key);
                        input.Keyboard.KeyUp(key);
                    }
                    else
                    {
                        Debug.Log("Simpit emulates keypress of " + key);
                        input.Keyboard.KeyPress(key);
                    }

                    if ((payload.modifier & KeyboardEmulatorModifier.ALT_MOD) != 0)
                    {
                        input.Keyboard.KeyUp(VirtualKeyCode.MENU);
                    }

                    if ((payload.modifier & KeyboardEmulatorModifier.CTRL_MOD) != 0)
                    {
                        input.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    }

                    if ((payload.modifier & KeyboardEmulatorModifier.SHIFT_MOD) != 0)
                    {
                        input.Keyboard.KeyUp(VirtualKeyCode.LSHIFT);
                    }
                }
                else
                {
                    Debug.Log("Simpit : I received a message to emulate a keypress of key " + payload.key + " but I do not recognize it. I ignore it.");
                }
            }
            catch (DllNotFoundException exception)
            {
                Debug.LogWarning("Simpit : I received a message to emulate a keypress. This is currently only available on Windows. I ignore it.");
                if (KSPit.Config.Verbose)
                {
                    Debug.LogWarning(exception.Message);
                    Debug.LogWarning(exception.ToString());
                }
            }
        }
        public void cameraRotationCallback(byte ID, object Data)
        {
            //Debug.Log("Camera Rotation Callback");
            newCameraRotation = KerbalSimpitUtils.ByteArrayToStructure <CameraRotationalStruct>((byte[])Data);
            // Bit fields:
            // pitch = 1
            // roll = 2
            // yaw = 4
            switch (cameraManager.currentCameraMode)
            {
            case CameraManager.CameraMode.Flight:
                FlightCamera flightCamera = FlightCamera.fetch;
                if ((newCameraRotation.mask & (byte)1) > 0)
                {
                    myCameraRotation.pitch = newCameraRotation.pitch;
                    // Debug.Log("Rotation Message Seen");
                    float newPitch = flightCamera.camPitch + (myCameraRotation.pitch * flightCameraPitchMultiplier);
                    if (newPitch > flightCamera.maxPitch)
                    {
                        flightCamera.camPitch = flightCamera.maxPitch;
                    }
                    else if (newPitch < flightCamera.minPitch)
                    {
                        flightCamera.camPitch = flightCamera.minPitch;
                    }
                    else
                    {
                        flightCamera.camPitch = newPitch;
                    }
                }
                if ((newCameraRotation.mask & (byte)2) > 0)
                {
                    myCameraRotation.roll = newCameraRotation.roll;
                }
                if ((newCameraRotation.mask & (byte)4) > 0)
                {
                    myCameraRotation.yaw = newCameraRotation.yaw;
                    // Debug.Log("Yaw Message Seen");
                    float newHdg = flightCamera.camHdg + (myCameraRotation.yaw * flightCameraYawMultiplier);
                    flightCamera.camHdg = newHdg;
                }
                if ((newCameraRotation.mask & (byte)8) > 0)
                {
                    myCameraRotation.zoom = newCameraRotation.zoom;
                    float newZoom = flightCamera.Distance + (myCameraRotation.zoom * flightCameraZoomMultiplier);
                    if (newZoom > flightCamera.maxDistance)
                    {
                        newZoom = flightCamera.maxDistance;
                    }
                    else if (newZoom < flightCamera.minDistance)
                    {
                        newZoom = flightCamera.minDistance;
                    }
                    flightCamera.SetDistance(newZoom);
                }
                break;

            case CameraManager.CameraMode.IVA:
            case CameraManager.CameraMode.Internal:
                Kerbal ivaKerbal = cameraManager.IVACameraActiveKerbal;

                if (ivaKerbal == null)
                {
                    Debug.Log("Kerbal is null");
                }

                InternalCamera ivaCamera = InternalCamera.Instance;
                ivaCamera.mouseLocked = false;

                if (ivaCamera == null)
                {
                    Debug.Log("IVA Camera is null");
                }
                else
                {
                    float newPitch = (float)ivaPitchField.GetValue(ivaCamera);
                    float newYaw   = (float)ivaYawField.GetValue(ivaCamera);

                    if ((newCameraRotation.mask & (byte)1) > 0)
                    {
                        myCameraRotation.pitch = newCameraRotation.pitch;
                        //Debug.Log("IVA Rotation Message Seen");
                        newPitch += (myCameraRotation.pitch * ivaCameraMultiplier);

                        if (newPitch > ivaCamera.maxPitch)
                        {
                            newPitch = ivaCamera.maxPitch;
                        }
                        else if (newPitch < ivaCamera.minPitch)
                        {
                            newPitch = ivaCamera.minPitch;
                        }
                    }
                    if ((newCameraRotation.mask & (byte)2) > 0)
                    {
                        myCameraRotation.roll = newCameraRotation.roll;
                    }
                    if ((newCameraRotation.mask & (byte)4) > 0)
                    {
                        myCameraRotation.yaw = newCameraRotation.yaw;
                        //Debug.Log("IVA Yaw Message Seen");
                        newYaw += (myCameraRotation.yaw * ivaCameraMultiplier);
                        if (newYaw > 120f)
                        {
                            newYaw = 120f;
                        }
                        else if (newYaw < -120f)
                        {
                            newYaw = -120f;
                        }
                    }
                    //Debug.Log("Before set angle");
                    if (this.ivaCamFieldsLoaded)
                    {
                        ivaPitchField.SetValue(ivaCamera, newPitch);
                        ivaYawField.SetValue(ivaCamera, newYaw);
                        // Debug.Log("Camera vector: " + ivaCamera.transform.localEulerAngles.ToString());
                        FlightCamera.fetch.transform.rotation = InternalSpace.InternalToWorld(InternalCamera.Instance.transform.rotation);
                    }
                }
                break;

            default:
                Debug.Log("Kerbal Simpit does not support this camera mode: " + cameraManager.currentCameraMode.ToString());
                break;
            }
        }