예제 #1
0
        public override bool Refresh(List <UpdateObject> updateList, List <RenderObject> renderList)
        {
            bool result = false;

            if (state != pendingState)
            {
                if (pendingState == States.Active)
                {
                    updateList.Add(updateObj);
                    updateObj.Activate();
                    renderList.Add(renderObj);
                    renderObj.Activate();

                    shared.menu.Active = true;

                    // If we were in first person mode, reset things as needed.  Need to
                    // do this here instead of in Activate since there we still need to
                    // render another frame.
                    if (CameraInfo.FirstPersonActive)
                    {
                        CameraInfo.FirstPersonActor.SetFirstPerson(false);
                        CameraInfo.ResetAllLists();
                        CameraInfo.Mode = CameraInfo.Modes.Edit;
                        InGame.inGame.Camera.FollowCameraDistance = 10.0f;
                    }
                }
                else
                {
                    shared.menu.Active = false;

                    renderObj.Deactivate();
                    renderList.Remove(renderObj);
                    updateObj.Deactivate();
                    updateList.Remove(updateObj);
                }

                state = pendingState;
            }

            return(result);
        }
예제 #2
0
            }   // end of UpdateCamera()

            /// <summary>
            /// Common camera controls for edit modes.
            /// </summary>
            /// <param name="preventZoom">Lock the zoom.  This is kind of a hack used
            /// by the tool palette since that palette uses the shoulder buttons to
            /// cycle through it.  Without locking the zoom we'd zoom in and out
            /// as we're moving though the tool options.</param>
            public void UpdateCamera(bool preventZoom)
            {
                float secs = Time.WallClockFrameSeconds;

                Vector3 lookAt   = parent.Camera.At;
                Vector3 lookFrom = parent.Camera.From;

                // If we were in first person mode, reset things as needed.
                if (CameraInfo.FirstPersonActive)
                {
                    CameraInfo.FirstPersonActor.SetFirstPerson(false);
                    CameraInfo.ResetAllLists();
                    CameraInfo.Mode = CameraInfo.Modes.Edit;
                    InGame.inGame.Camera.FollowCameraDistance = 10.0f;
                }

                // Check if we have input focus.  Don't do any input
                // related update if we don't.
                if (CommandStack.Peek() == commandMap)
                {
                    // Grab the current state of the gamepad.
                    GamePadInput pad = GamePadInput.GetGamePad0();

                    // From all edit modes, <back> should bring up the tool menu.
                    if (Actions.ToolMenu.WasPressed)
                    {
                        Actions.ToolMenu.ClearAllWasPressedState();

                        Foley.PlayBack();
                        parent.CurrentUpdateMode = UpdateMode.ToolMenu;

                        return;
                    }

                    // From all edit modes, <start> should to to the mini-hub.
                    if (Actions.MiniHub.WasPressed)
                    {
                        Actions.MiniHub.ClearAllWasPressedState();

                        Foley.PlayPressStart();
                        parent.SwitchToMiniHub();

                        return;
                    }

                    // From all edit modes the B button should activate the ToolMenu.
                    // Edit object handles the B button itself since it may be in Waypoint mode.
                    if (Actions.AltToolMenu.WasPressed && parent.CurrentUpdateMode != UpdateMode.EditObject)
                    {
                        Actions.AltToolMenu.ClearAllWasPressedState();
                        parent.CurrentUpdateMode = UpdateMode.ToolMenu;

                        return;
                    }

                    // If the ToolMenu is active and it's modal, don't allow the camera to move.
                    if (InGame.inGame.toolMenuUpdateObj.active && XmlOptionsData.ModalToolMenu)
                    {
                        return;
                    }

                    //
                    // Use common camera controls for all edit modes.
                    //

                    const float cursorSpeed = 20.0f;    // Meters per second.
                    const float orbitSpeed  = 2.0f;     // Radians per second.
                    const float zoomFactor  = 1.1f;

                    // Right stick to orbit around cursor.
                    float drot   = GamePadInput.InvertCamX() ? -pad.RightStick.X : pad.RightStick.X;
                    float dpitch = GamePadInput.InvertCamY() ? -pad.RightStick.Y : pad.RightStick.Y;
                    parent.Camera.DesiredRotation += drot * Time.WallClockFrameSeconds * orbitSpeed;
                    parent.Camera.DesiredPitch    -= dpitch * Time.WallClockFrameSeconds * orbitSpeed;

                    // Left/right arrow keys also orbit but not if the tool menu or a picker is up.
                    //if (inGame.CurrentUpdateMode != UpdateMode.ToolMenu && !HelpOverlay.Peek().EndsWith("Picker") )
                    //{
                    //    if (KeyboardInput.IsPressed(Keys.Left))
                    //    {
                    //        parent.Camera.DesiredRotation -= 1.0f * Time.WallClockFrameSeconds * orbitSpeed;
                    //    }
                    //    else if (KeyboardInput.IsPressed(Keys.Right))
                    //    {
                    //        parent.Camera.DesiredRotation += 1.0f * Time.WallClockFrameSeconds * orbitSpeed;
                    //    }
                    //}

                    // Shoulder buttons track camera in/out.
                    if (!preventZoom)
                    {
                        if (Actions.ZoomOut.IsPressed)
                        {
                            parent.Camera.DesiredDistance *= 1.0f + Time.WallClockFrameSeconds * zoomFactor;
                        }
                        if (Actions.ZoomIn.IsPressed)
                        {
                            float desiredDistance = parent.Camera.DesiredDistance * (1.0f - Time.WallClockFrameSeconds * zoomFactor);
                            // If not in RunSim mode, don't allow the camera to get closer than 4 meters.
                            if (InGame.inGame.CurrentUpdateMode != UpdateMode.RunSim)
                            {
                                desiredDistance = Math.Max(4.0f, desiredDistance);
                            }
                            parent.Camera.DesiredDistance = desiredDistance;
                        }
                        parent.MouseEdit.DoZoom(parent.Camera);
                    }

                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                    {
                        parent.MouseEdit.DoCamera(parent.Camera);
                    }

                    // Left stick to control cursor position.
                    // Cursor movement is relative to view heading.
                    // Cursor speed grows with view distance.
                    Vector2 position    = new Vector2(shared.CursorPosition.X, shared.CursorPosition.Y);
                    Vector2 forward     = new Vector2((float)Math.Cos(parent.Camera.Rotation), (float)Math.Sin(parent.Camera.Rotation));
                    Vector2 right       = new Vector2(forward.Y, -forward.X);
                    float   speedFactor = (parent.Camera.Distance - 10.0f) / 50.0f;     // At 10 meters out start growing the speedFactor.
                    speedFactor = MathHelper.Clamp(speedFactor, 1.0f, 3.0f);
                    position   += forward * pad.LeftStick.Y * Time.WallClockFrameSeconds * cursorSpeed * speedFactor;
                    position   += right * pad.LeftStick.X * Time.WallClockFrameSeconds * cursorSpeed * speedFactor;

                    // Numpad controls cursor position. NumLock must be on!
                    float y = KeyboardInput.IsPressed(Keys.NumPad7) || KeyboardInput.IsPressed(Keys.NumPad8) || KeyboardInput.IsPressed(Keys.NumPad9) ? 1.0f : 0.0f;
                    y += KeyboardInput.IsPressed(Keys.NumPad1) || KeyboardInput.IsPressed(Keys.NumPad2) || KeyboardInput.IsPressed(Keys.NumPad3) ? -1.0f : 0.0f;
                    float x = KeyboardInput.IsPressed(Keys.NumPad3) || KeyboardInput.IsPressed(Keys.NumPad6) || KeyboardInput.IsPressed(Keys.NumPad9) ? 1.0f : 0.0f;
                    x        += KeyboardInput.IsPressed(Keys.NumPad1) || KeyboardInput.IsPressed(Keys.NumPad4) || KeyboardInput.IsPressed(Keys.NumPad7) ? -1.0f : 0.0f;
                    position += forward * y * Time.WallClockFrameSeconds * cursorSpeed * speedFactor;
                    position += right * x * Time.WallClockFrameSeconds * cursorSpeed * speedFactor;

                    // Allow LeftStickClick RightStickClick to cycle though actors.
                    if (inGame.gameThingList.Count > 0)
                    {
                        // Move to next actor
                        if (Actions.NextActor.WasPressed)
                        {
                            Actions.NextActor.ClearAllWasPressedState();

                            // If we have an actor in focus, find index.
                            GameActor focusActor = InGame.inGame.EditFocusObject;
                            if (focusActor != null)
                            {
                                for (int i = 0; i < inGame.gameThingList.Count; i++)
                                {
                                    if (focusActor == inGame.gameThingList[i])
                                    {
                                        actorTabIndex = i;
                                        break;
                                    }
                                }
                            }

                            // Increment index.
                            actorTabIndex = (actorTabIndex + 1) % inGame.gameThingList.Count;

                            Vector3 actorPos = inGame.gameThingList[actorTabIndex].Movement.Position;
                            Vector2 delta    = new Vector2(actorPos.X - position.X, actorPos.Y - position.Y);
                            position += delta;
                        }

                        // Move to prev actor
                        if (Actions.PrevActor.WasPressed)
                        {
                            Actions.PrevActor.ClearAllWasPressedState();

                            // If we have an actor in focus, find index.
                            GameActor focusActor = InGame.inGame.EditFocusObject;
                            if (focusActor != null)
                            {
                                for (int i = 0; i < inGame.gameThingList.Count; i++)
                                {
                                    if (focusActor == inGame.gameThingList[i])
                                    {
                                        actorTabIndex = i;
                                        break;
                                    }
                                }
                            }

                            // Decrement index.
                            actorTabIndex = (actorTabIndex + inGame.gameThingList.Count - 1) % inGame.gameThingList.Count;

                            Vector3 actorPos = inGame.gameThingList[actorTabIndex].Movement.Position;
                            Vector2 delta    = new Vector2(actorPos.X - position.X, actorPos.Y - position.Y);
                            position += delta;
                        }
                    }

                    if (!shared.editWayPoint.Dragging)
                    {
                        // TODO (mouse)  Why was this here?
                        //position = parent.MouseEdit.DoCursor(parent.Camera, position);
                    }
                    position = shared.editWayPoint.DoCursor(position);

                    // Keep cursor within 50 units of existing terrain.
                    float   maxBrush = InGame.kMaxBrushRadius;
                    Vector2 min      = new Vector2(InGame.inGame.totalBounds.Min.X, InGame.inGame.totalBounds.Min.Y) - new Vector2(maxBrush, maxBrush);
                    Vector2 max      = new Vector2(InGame.inGame.totalBounds.Max.X, InGame.inGame.totalBounds.Max.Y) + new Vector2(maxBrush, maxBrush);

                    position.X = MathHelper.Clamp(position.X, min.X, max.X);
                    position.Y = MathHelper.Clamp(position.Y, min.Y, max.Y);

                    shared.CursorPosition = new Vector3(position, shared.CursorPosition.Z);
                }   // end if we have input focus.

                // Keep the camera from going into the ground.
                shared.KeepCameraAboveGround();

                // Update camera based on new position/orientation.
                parent.Camera.DesiredAt = shared.CursorPosition;

                // Finally, call Update on the camera to let all the changes filter through.
                parent.Camera.Update();
            }   // end of BaseEditUpdateObj UpdateCamera()