private void HandleGamePadInput(Camera camera) { if (GamePadInput.ActiveMode != GamePadInput.InputMode.GamePad) { return; } GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); ToggleState(); } if (Actions.Cancel.WasPressed) { Actions.Cancel.ClearAllWasPressedState(); // Shut down. Deactivate(); Foley.PlayBack(); return; } // Handle input changes here. if (Actions.ComboDown.WasPressedOrRepeat) { ++curIndex; if (curIndex >= itemList.Count) { curIndex = 0; } Foley.PlayShuffle(); } if (Actions.ComboUp.WasPressedOrRepeat) { --curIndex; if (curIndex < 0) { curIndex = itemList.Count - 1; } Foley.PlayShuffle(); } // Don't let anyone else steal input while we're active. GamePadInput.ClearAllWasPressedState(); }
public void PlaceReflex(Object sender, EventArgs args) { Foley.PlayBack(); reflexBlock.Moving = false; UiCursor.ActiveCursor.Parent = this; // switch modes this.updateObjPending = this.updateObjEditReflex; this.renderObj.State = ControlRenderObj.idStateHot; AffixLineNumberToCurrentState(); BokuGame.objectListDirty = true; } // end of PlaceReflex()
public override bool HandleTouchInput(Camera camera) { float scaleY = Math.Min((float)BokuGame.ScreenSize.Y / 576.0f, 1.0f); AABB2D box = new AABB2D(new Vector2(0, (BokuGame.ScreenSize.Y - (200.0f) * scaleY)), BokuGame.ScreenSize); TouchContact focusedTouch = null; //Finger ID is focused finger if (m_FingerID < 0) { TouchContact[] touches = TouchInput.Touches; for (int i = 0; i < touches.Length; ++i) { if (TouchPhase.Began == touches[i].phase) { m_FingerID = touches[i].fingerId; m_bDraggable = box.Contains(touches[i].position); break; } } } else { focusedTouch = TouchInput.GetTouchContactByFingerId(m_FingerID); if (null != focusedTouch && TouchPhase.Ended != focusedTouch.phase) { if (TouchPhase.Moved == focusedTouch.phase) { m_DragDelta += focusedTouch.deltaPosition; } if (!m_bDragging && m_bDraggable) { //Check to see if the dragging threshold has been exceeded to change material. Vector2 distance = focusedTouch.position - focusedTouch.startPosition; //Did we start a drag? if (Math.Abs(distance.X) >= 20.0f) { m_bDragging = true; m_DragDelta = distance; } } if (m_bDragging) { while (Math.Abs(m_DragDelta.X) >= 200.0f) { if (m_DragDelta.X >= 200.0f) { DecrementFocus(); m_DragDelta.X -= 200.0f; } else if (m_DragDelta.X <= -200.0f) { IncrementFocus(); m_DragDelta.X += 200.0f; } } } } else { //When the focused touch is ended we check for selection if (!m_bDragging && null != focusedTouch) { Ray ray = new Ray(camera.From, camera.ScreenToWorldCoords(focusedTouch.position)); Matrix m = (grid.SelectionElement as UIGridMaterialElement).HitWorldMatrix; bool bSelectedMat = (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33))); if (bSelectedMat) { SelectCurrentChoice(); Foley.PlayPressA(); } else { //Didn't select the center piece. Check if we picked a material on the sides so we can go to it. for (int i = 0; (!bSelectedMat && i < grid.SelectionIndex.X); i++) { m = (grid.Get(i, 0) as UIGridMaterialElement).HitWorldMatrix; if (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33))) { int steps = grid.SelectionIndex.X - i; while (steps > 0) { DecrementFocus(); --steps; } bSelectedMat = true; break; } } for (int i = grid.SelectionIndex.X + 1; (!bSelectedMat && i < grid.ActualDimensions.X); i++) { m = (grid.Get(i, 0) as UIGridMaterialElement).HitWorldMatrix; if (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33))) { int steps = i - grid.SelectionIndex.X; while (steps > 0) { IncrementFocus(); --steps; } bSelectedMat = true; break; } } //Cancel this menu. if (!bSelectedMat && !box.Contains(focusedTouch.position) && (Time.WallClockTotalSeconds - focusedTouch.startTime <= 0.3)) { //If we didn't select anything and we are outside the drag area + didn't move a lot then cancel. RestorePreviousChoice(); Foley.PlayBack(); return(false); } } } m_bDraggable = false; m_bDragging = false; m_FingerID = -1; } } return(true); } // end of HandleTouchInput()
} // end of DeleteAll() public void Update(Camera camera, ref Matrix parentMatrix) { // Check for input. if (active && itemList.Count > 1 && !IgnoreInput && CommandStack.Peek() == commandMap) { bool selectionChanged = false; bool moveUp = false; bool moveDown = false; { // Mouse input if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { // If the mouse is over the menu, move the selection index to the item under the mouse. // On mouse down, make the item (if any) under the mouse the ClickedOnItem. // On mouse up, if the mouse is still over the ClickedOnItem, activate it. If not, just clear ClickedOnItem. Vector2 hitUV = MouseInput.GetHitUV(camera, ref invWorldMatrix, width, height, useRtCoords); // See if we're over anything. If so, set that item to being selected but only if we've moved the mouse. // This prevents the menu from feeling 'broken' if the mouse is over it and the user tries to use // the gamepad or keyboard. int mouseOverItem = -1; for (int i = 0; i < itemList.Count; i++) { if (itemList[i].UVBoundingBox != null && itemList[i].UVBoundingBox.Contains(hitUV)) { // Only update the current in-focus element when the mouse moves. if (MouseInput.Position != MouseInput.PrevPosition) { CurIndex = i; } mouseOverItem = i; } } if (MouseInput.Left.WasPressed && mouseOverItem != -1) { MouseInput.ClickedOnObject = itemList[mouseOverItem]; } if (MouseInput.Left.WasReleased && mouseOverItem != -1 && MouseInput.ClickedOnObject == itemList[mouseOverItem]) { // Normally this is already set except in the case where the app didn't have focus and a menu item is clicked. // In that case, the CurIndex value stays stuck at its previous position. In particular this was causing Kodu's // Main Menu to think RESUME was clicked even when it was one of the other menu items. CurIndex = mouseOverItem; if (onSelect != null) { onSelect(this); } Foley.PlayPressA(); return; } // Allow scroll wheel to cycle through elements. int wheel = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (wheel > 0) { moveUp = true; } else if (wheel < 0) { moveDown = true; } } // end if KeyboardMouse mode. if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { // Look for Tap gesture first. No need to care about touch response if we've got a tap. bool goodTapGesture = false; if (TouchGestureManager.Get().TapGesture.WasTapped()) { // Check if tap position hit any of the menu elements. Vector2 tapPosition = TouchGestureManager.Get().TapGesture.Position; Vector2 touchHitUV = TouchInput.GetHitUV(tapPosition, camera, ref invWorldMatrix, width, height, useRtCoords); for (int index = 0; index < itemList.Count; index++) { if (itemList[index].UVBoundingBox != null && itemList[index].UVBoundingBox.Contains(touchHitUV)) { CurIndex = index; if (onSelect != null) { onSelect(this); Foley.PlayPressA(); selectionChanged = true; goodTapGesture = true; } } } } // Look for touch events to change focus. Ignore this if we had a good tap gesture. if (!goodTapGesture) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); // Touch input // If the user touched the menu, move the selection index to the item under the touch. // On touch down, make the item (if any) under the contact the touchedItem. // On touch up, if the touch is still over the touchedItem, activate it. If not, just clear touchedItem. Vector2 touchHitUV = TouchInput.GetHitUV(touch.position, camera, ref invWorldMatrix, width, height, useRtCoords); // See what UI element we are over, if anything. If it hits, set that item to being selected but only if the touch has moved. // This emulates how the mouse is being handled by allowing the input to change only if the touch has moved. If a user moves // the gamepad or keyboard but doesn't move their touch contact, then the selection won't flicker back and forth and feel 'broken' int touchOverIndex = -1; for (int index = 0; index < itemList.Count; index++) { if (itemList[index].UVBoundingBox != null && itemList[index].UVBoundingBox.Contains(touchHitUV)) { touchOverIndex = index; } } if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { // Touch is down! if (touchOverIndex != -1) { touch.TouchedObject = itemList[touchOverIndex]; if (CurIndex != touchOverIndex) { selectionChanged = true; } CurIndex = touchOverIndex; } } else if (touch.phase == TouchPhase.Moved) { // Touch moved!!! Update Something!! if (CurIndex != touchOverIndex) { CurIndex = touchOverIndex; } } } } // end if not good tap gesture. if (selectionChanged) { if (onChange != null) { onChange(this); } dirty = true; //RecalcPositions(); // Ensure that the selected state of all items is correct. for (int i = 0; i < itemList.Count; i++) { itemList[i].Selected = i == CurIndex; } } } // end of touch mode processing. } if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad || GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { // Gamepad / Keyboard input. GamePadInput pad = GamePadInput.GetGamePad0(); if ((AcceptStartForCancel && Actions.Start.WasPressed) || Actions.Cancel.WasPressed) { Actions.Cancel.ClearAllWasPressedState(); if (onCancel != null) { onCancel(this); } Foley.PlayBack(); return; } if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); if (onSelect != null) { onSelect(this); } Foley.PlayPressA(); return; } int prevIndex = CurIndex; // Handle input changes here. if (Actions.ComboDown.WasPressedOrRepeat || moveDown) { ++CurIndex; if (CurIndex >= itemList.Count) { CurIndex = 0; } selectionChanged = true; } if (Actions.ComboUp.WasPressedOrRepeat || moveUp) { --CurIndex; if (CurIndex < 0) { CurIndex = itemList.Count - 1; } selectionChanged = true; } if (selectionChanged) { if (onChange != null) { onChange(this); } dirty = true; //RecalcPositions(); } // Ensure that the selected state of all items is correct. for (int i = 0; i < itemList.Count; i++) { itemList[i].Selected = i == CurIndex; } } } RefreshTexture(); } // end of UIGridModularMenu Update()
} // end of BasePicker RestorePreviousChoice() public virtual void Update(PerspectiveUICamera camera) { if (active) { if (hidden) { // Note, even though we're hidden we may still be rendering our fade out. double elapsedTime = Time.WallClockTotalSeconds - startFadeTime; if (elapsedTime >= fadeTime) { Alpha = 0.0f; } else { Alpha = 1.0f - (float)(elapsedTime / fadeTime); } } else { // Not hidden, so respond to user input. int scroll = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (Actions.PickerRight.WasPressedOrRepeat || scroll > 0) { Actions.PickerRight.ClearAllWasPressedState(); DecrementFocus(); } if (Actions.PickerLeft.WasPressedOrRepeat || scroll < 0) { Actions.PickerLeft.ClearAllWasPressedState(); IncrementFocus(); } if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); SelectCurrentChoice(); Foley.PlayPressA(); } if (Actions.Cancel.WasPressedOrRepeat) { Actions.Cancel.ClearAllWasPressedState(); RestorePreviousChoice(); Foley.PlayBack(); } bool handled = false; if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { handled = HandleTouchInput(camera); } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { handled = HandleMouseInput(camera); } if (!handled) { // If the user clicked but didn't hit any of the picker elements, close the picker. // If alt is pressed, they must be in eyedropper mode. if ((MouseInput.Left.WasPressed && !KeyboardInput.AltIsPressed) || (TouchGestureManager.Get().TapGesture.WasRecognized)) { SelectCurrentChoice(); Foley.PlayPressA(); } else if (Actions.Sample.WasPressed || MouseEdit.TriggerSample() || TouchEdit.TriggerSample()) { Actions.Sample.ClearAllWasPressedState(); int t = OnSampleType(); if (t >= 0) { OnSetType(t); Point selection = grid.SelectionIndex; selection.X = t; grid.SelectionIndex = selection; Foley.PlayCut(); } else { Foley.PlayNoBudget(); } } } grid.Update(ref worldMatrix); } } // end if active } // end of BasePicker Update()
} // end of ClearAllItems() public void Update(Camera camera, ref Matrix parentMatrix) { CommandMap map = CommandStack.Peek(); if (map != commandMap) { return; } // Check for input. if (active && itemList.Count > 0) { GamePadInput pad = GamePadInput.GetGamePad0(); bool mouseDown = false; bool mouseUp = false; bool mouseSelect = false; bool touchSelect = false; if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) // MouseInput { // Did user double click? If so, treat as a shortcut to play. if (MouseInput.Left.WasDoubleClicked) { // This works because we _know_ Play is the first one in the list. // Not exactly a great solution. curIndex = 0; mouseSelect = true; } Vector2 hit = MouseInput.GetMouseInRtCoords(); if (!mouseSelect) { if (itemList[CurIndex].hitBox.LeftPressed(hit)) { mouseSelect = true; } } // If mouse is over menu and moving, choose item under mouse as selection. if (!mouseSelect && MouseInput.Position != MouseInput.PrevPosition) { for (int i = 0; i < itemList.Count; i++) { if (itemList[i].hitBox.Contains(hit)) { CurIndex = i; break; } } } int scroll = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (scroll > 0) { mouseUp = true; } else if (scroll < 0) { mouseDown = true; } // If user clicks off of the popup, treat as Back. if (MouseInput.Left.WasPressed && MouseInput.ClickedOnObject == null) { Active = false; return; } } // end of mouse input. else if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) // TouchInput { TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { Vector2 hit = TouchInput.GetAspectRatioAdjustedPosition(touch.position, camera, true); bool hitSomething = false; // Check for a hit on any of the items. for (int i = 0; i < itemList.Count; i++) { if (itemList[i].hitBox.Contains(hit)) { CurIndex = i; hitSomething = true; } } if (touch.phase == TouchPhase.Ended) { if (hitSomething) { // We've touched off on an item so choose it. touchSelect = true; } else { // We touched off and didn't hit anything. if (touch.TouchedObject == this) { touch.TouchedObject = null; } else { Active = false; } } } } } // end of Touch input. if (Actions.Select.WasPressed || mouseSelect || touchSelect) { Actions.Select.ClearAllWasPressedState(); if (itemList[curIndex].OnSelect != null) { itemList[curIndex].OnSelect(); } Foley.PlayPressA(); return; } if (Actions.Cancel.WasPressed) { Actions.Cancel.ClearAllWasPressedState(); Active = false; Foley.PlayBack(); return; } int prevIndex = curIndex; // Handle input changes here. if (Actions.ComboDown.WasPressedOrRepeat || mouseDown) { ++curIndex; if (curIndex >= itemList.Count) { curIndex = 0; } Foley.PlayShuffle(); } if (Actions.ComboUp.WasPressedOrRepeat || mouseUp) { --curIndex; if (curIndex < 0) { curIndex = itemList.Count - 1; } Foley.PlayShuffle(); } // Ensure that the selected state of all items is correct. for (int i = 0; i < itemList.Count; i++) { itemList[i].Selected = i == CurIndex; } } } // end of LoadLevelPopup Update()
private void HandleTouchInput(Camera camera) { if (GamePadInput.ActiveMode != GamePadInput.InputMode.Touch) { return; } // Touch input // If the touch is over the menu, move the selection index to the item under the mouse. // On touch down, make the item (if any) under the touch the ClickedOnItem. // On tap, if the touch is still over the ClickedOnItem, activate it. If not, just clear ClickedOnItem. TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { Vector2 hitUV = TouchInput.GetHitUV(touch.position, camera, ref invWorldMatrix, width, height, useRtCoords: useRtCoords); // See if we're over anything. If so, set that item to being selected but only if we've moved the mouse. // This prevents the menu from feeling 'broken' if the mouse is over it and the user tries to use // the gamepad or keyboard. int touchItem = -1; for (int i = 0; i < itemList.Count; i++) { if (itemList[i].UVBoundingBox != null && itemList[i].UVBoundingBox.Contains(hitUV)) { // Only update the current in-focus element when the mouse moves. if (true) // touch.position != touch.previousPosition) { CurIndex = i; } touchItem = i; } } //if ( TouchInput.TapGesture.WasTapped() ) if (TouchInput.IsTouched) { if (touchItem != -1) { touch.TouchedObject = itemList[touchItem]; } } if (TouchGestureManager.Get().TapGesture.WasTapped()) { // Make sure we're still over the ClickedOnItem. if (touchItem != -1 && touch.TouchedObject == itemList[touchItem]) { ToggleState(); } } Vector2 hit = touch.position; if (useRtCoords) { hit = ScreenWarp.ScreenToRT(hit); } if (changeBox.Touched(touch, hit)) { ToggleState(); } if (backBox.Touched(touch, hit)) { Deactivate(); Foley.PlayBack(); } // Allow Swipeto cycle through elements. // Allow scroll wheel to cycle through elements. SwipeGestureRecognizer swipeGesture = TouchGestureManager.Get().SwipeGesture; if (swipeGesture.WasSwiped()) { if (swipeGesture.SwipeDirection == Boku.Programming.Directions.South) { curIndex -= 6; if (curIndex < 0) { curIndex = itemList.Count - 1; } Foley.PlayShuffle(); } else if (swipeGesture.SwipeDirection == Boku.Programming.Directions.North) { curIndex += 6; if (curIndex > (itemList.Count - 1)) { curIndex = 0; } Foley.PlayShuffle(); } } // If we click outside of the list, close it treating it as if select was chosen. //if (TouchInput.TapGesture.WasTapped() && touch.touchedObject == null) if (TouchInput.WasTouched && touch.TouchedObject == null) { Deactivate(); } } }
} // end of DeleteText() private void HandleMouseInput(Camera camera) { if (GamePadInput.ActiveMode != GamePadInput.InputMode.KeyboardMouse) { return; } // If the mouse is over the menu, move the selection index to the item under the mouse. // On mouse down, make the item (if any) under the mouse the ClickedOnItem. // On mouse up, if the mouse is still over the ClickedOnItem, activate it. If not, just clear ClickedOnItem. Vector2 hitUV = MouseInput.GetHitUV(camera, ref invWorldMatrix, width, height, useRtCoords: useRtCoords); // See if we're over anything. If so, set that item to being selected but only if we've moved the mouse. // This prevents the menu from feeling 'broken' if the mouse is over it and the user tries to use // the gamepad or keyboard. int mouseOverItem = -1; for (int i = 0; i < itemList.Count; i++) { if (itemList[i].UVBoundingBox != null && itemList[i].UVBoundingBox.Contains(hitUV)) { // Only update the current in-focus element when the mouse moves. if (MouseInput.Position != MouseInput.PrevPosition) { CurIndex = i; } mouseOverItem = i; } } if (MouseInput.Left.WasPressed) { if (mouseOverItem != -1) { MouseInput.ClickedOnObject = itemList[mouseOverItem]; } } if (MouseInput.Left.WasReleased) { // Make sure we're still over the ClickedOnItem. if (mouseOverItem != -1 && MouseInput.ClickedOnObject == itemList[mouseOverItem]) { ToggleState(); } } Vector2 hit = MouseInput.PositionVec; if (useRtCoords) { hit = ScreenWarp.ScreenToRT(hit); } if (changeBox.LeftPressed(hit)) { ToggleState(); } if (backBox.LeftPressed(hit)) { Deactivate(); Foley.PlayBack(); } // Allow scroll wheel to cycle through elements. int wheel = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (wheel > 0) { --curIndex; if (curIndex < 0) { curIndex = itemList.Count - 1; } Foley.PlayShuffle(); } else if (wheel < 0) { ++curIndex; if (curIndex >= itemList.Count) { curIndex = 0; } Foley.PlayShuffle(); } // If we click outside of the list, close it treating it as if select was chosen. if (MouseInput.Left.WasPressed && MouseInput.ClickedOnObject == null) { Deactivate(); } }
} // 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()