Example #1
0
        static bool Prefix(MouseLook __instance, MViewAndControl ____options, float ___minimumY, float ___maximumY)
        {
            cCameraControl      ccc = Main.cameraControl;
            FocusCameraSettings fcs = ccc?._externalCameraFocusSettings;

            // Note: If ccc or fcs is null, first condition fails.
            if (fcs?.PositionOfFocus != null && fcs.PositionOfFocus.Valid &&
                (ccc.CameraState == enumCameraState.detached ||
                 ccc.CameraState == enumCameraState.unparented) &&
                // As of time of writing, cCameraControl sets _mouseLookY
                // as the sole MouseLook handling both MouseXAndY axes.
                __instance.axes == enumRotationAxes.MouseXAndY &&
                !(FleetControlGUI.Instance.MenuActive && ____options.TopDownViewLocked))
            {
                if (Get.UserInput.MouseLookEnabled && __instance.DisableForAFewFrames.Since > 0.1f)
                {
                    // Record mouse intent to move.
                    float num        = (Time.timeScale == 0f) ? 1f : Mathf.Clamp(Time.timeScale, 0f, 1f);
                    float newXIntent = Input.GetAxis("Mouse X") * __instance.sensitivityX * num;
                    if (Math.Abs(newXIntent) > Math.Abs(xIntent))
                    {
                        xIntent = newXIntent;
                    }
                    float newYIntent = Input.GetAxis("Mouse Y") * __instance.sensitivityY * num *
                                       ____options.GetMouseInvertSign();
                    if (Math.Abs(newYIntent) > Math.Abs(yIntent))
                    {
                        yIntent = newYIntent;
                    }
                    Vector2 v = ____options.GetMouseSpeed();
                    __instance.sensitivityX = 15f * v.x;
                    __instance.sensitivityY = 15f * v.y;
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #2
0
        static bool Prefix(cCameraControl __instance, KeyDef ____zoomIn, KeyDef ____zoomOut, MViewAndControl ____options, MouseLook ____mouseLookY)
        {
            /*if (lastTime != Time.timeScale)
             * {
             *  lastTime = Time.timeScale;
             *  AdvLogger.LogInfo("Time.timeScale changed to " + lastTime);
             * }*/
            Transform           cam = __instance.Cam;
            FocusCameraSettings fcs = __instance._externalCameraFocusSettings;

            if (fcs?.PositionOfFocus == null || !fcs.PositionOfFocus.Valid ||
                __instance.CameraState != enumCameraState.detached &&
                __instance.CameraState != enumCameraState.unparented)
            {
                __instance.CancelExternalCameraFocus();
            }
            else if (____mouseLookY.axes == enumRotationAxes.MouseXAndY)
            {
                // Check if user is doing top-down strategic map and don't rotate if so.
                Vector3 myPos   = fcs.PositionOfFocus.Position;
                bool    topdown = FleetControlGUI.Instance.MenuActive && ____options.TopDownViewLocked;
                if (!topdown)
                {
                    // TODO: Integrate Ace Combat style camera into new camera mode.

                    /*MainConstruct target = Main.subject != null ? getTarget(Main.subject) : null;
                     * if (target != null && !target.Destroyed)
                     * {
                     *  Vector3 up = Main.subject.SafeUp;
                     *  myPos += up * Main.subject.AllBasics.GetActualHeight();
                     *  Vector3 diff = target.SafePosition - myPos;
                     *  Quaternion look = Quaternion.LookRotation(diff, up);
                     *  // Vector3 ea = look.eulerAngles;
                     *  ____mouseLookY.transform.localEulerAngles = look.eulerAngles; // new Vector3(ea.x, ea.y, 0f);
                     *  ____mouseLookY.rotationX = ____mouseLookY.transform.localEulerAngles.y;
                     *  ____mouseLookY.rotationY = 0f;
                     * }
                     * else
                     * {*/
                    // Record rotational change if any.
                    // Unity euler angles are Z, X, Y.
                    float xChange = 0f;
                    if (Main.rotation != null && Main.rotation.Valid)
                    {
                        Quaternion rot = Main.rotation.Rotation;
                        xChange           = rot.eulerAngles.y - Main.lastRotation.eulerAngles.y;
                        Main.lastRotation = rot;
                    }
                    else
                    {
                        Main.rotation = null;
                    }
                    // TODO: Smoothing speed setting.
                    xRotVel = Mathf.Lerp(xRotVel, MouseLook_Update_Patch.xIntent, 0.02f);
                    yRotVel = Mathf.Lerp(yRotVel, MouseLook_Update_Patch.yIntent, 0.02f);
                    ____mouseLookY.rotationX  = ____mouseLookY.transform.localEulerAngles.y + xChange + xRotVel;
                    ____mouseLookY.rotationY += yRotVel;
                    // The numbers -89 and 89 are hard-coded/unmodified values from vanilla.
                    ____mouseLookY.rotationY = Mathf.Clamp(____mouseLookY.rotationY, -89f, 89f);
                    ____mouseLookY.transform.localEulerAngles = new Vector3(-____mouseLookY.rotationY, ____mouseLookY.rotationX, 0f);
                    //}
                    // Since DoingStrategicFocus inhibits zoom in/out, switch to another method.
                    fcs.DistanceMethod = fcs.DistanceMethod == DistanceChangeMethod.DoingStrategicFocus ?
                                         DistanceChangeMethod.MaintainCurrentFocusDistance : fcs.DistanceMethod;
                }
                else // Disallow focus camera zoom when in strategic view.
                {
                    fcs.DistanceMethod = DistanceChangeMethod.DoingStrategicFocus;
                }
                // Done with mouse input for this frame, so remove it.
                MouseLook_Update_Patch.xIntent = MouseLook_Update_Patch.yIntent = 0f;

                // Copied from vanilla function.
                Vector3 focus   = myPos;
                Vector3 forward = cam.forward;
                Vector3 b       = focus - forward * fcs.Distance;

                // Don't move the camera's altitude if strategic view is already setting it.
                if (topdown)
                {
                    b.y = cam.position.y;
                }
                else
                {
                    // TODO: Clamp altitude of b based on terrain.
                }

                __instance.Cam.position = b; // Removed lerp.
                // Again copied from vanilla function.
                float axis = Input.GetAxis("Mouse ScrollWheel");
                if (____zoomIn.IsKey(KeyInputEventType.Held, ModifierAllows.AllowShift) ||
                    axis > 0f)
                {
                    // TODO: Possibly check keybinding instead?
                    int num = OptionsListener.ShiftHeld ? 4 : 1;
                    ____options.FocusCameraDistance -= 0.1f * (float)num;
                    ____options.FocusCameraDistance *= 1f - 0.02f * (float)num;
                    ____options.FocusCameraDistance  = Clamping.Clamp(____options.FocusCameraDistance, 1f, 1000f);
                }
                else if (____zoomOut.IsKey(KeyInputEventType.Held, ModifierAllows.AllowShift) ||
                         axis < 0f)
                {
                    int num = OptionsListener.ShiftHeld ? 4 : 1;
                    ____options.FocusCameraDistance += 0.1f * (float)num;
                    ____options.FocusCameraDistance *= 1f + 0.02f * (float)num;
                    ____options.FocusCameraDistance  = Clamping.Clamp(____options.FocusCameraDistance, 1f, 1000f);
                }
            }
            return(false);
        }