/// <summary> /// Find the correct position to add a node. /// </summary> /// <param name="camera"></param> /// <param name="from"></param> /// <returns></returns> private Vector3 AddPosition(Camera camera, WayPoint.Node from) { bool asRoad = false; float height = from.RenderPosition(asRoad).Z; Vector2 pos = Vector2.Zero; TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { pos = touch.position; } Vector3 hit = TouchEdit.FindAtHeight(camera, TouchInput.GetAsPoint(pos), height); return(hit); }
} // end of PreGameRacingWithDesc c'tor public override void Update() { if (Active) { if (showingDescription) { // Waiting for A to be pressed. if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); showingDescription = false; startTime = Time.WallClockTotalSeconds; HelpOverlay.Pop(); // Don't let current pressed state leak into game. GamePadInput.IgnoreUntilReleased(Buttons.A); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { // Check if user click on bottom text. if (MouseInput.Left.WasPressed && HelpOverlay.MouseHitBottomText(MouseInput.Position)) { showingDescription = false; startTime = Time.WallClockTotalSeconds; HelpOverlay.Pop(); MouseInput.Left.ClearAllWasPressedState(); } } if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { // Check if user click on bottom text. if (TouchGestureManager.Get().TapGesture.WasTapped() && HelpOverlay.MouseHitBottomText(TouchInput.GetAsPoint(TouchInput.GetOldestTouch().position)) ) { showingDescription = false; startTime = Time.WallClockTotalSeconds; HelpOverlay.Pop(); } } } else { int oldPhase = phase; phase = (int)Math.Ceiling(startTime + duration - Time.WallClockTotalSeconds); if (oldPhase != phase) { if ((phase < cueNames.Length) && (phase >= 0)) { BokuGame.Audio.GetCue(cueNames[phase]).Play(); } } if (Time.WallClockTotalSeconds > startTime + duration) { // We're done. Active = false; } // Check if user click on bottom text. if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { // Check if user click on bottom text. if (TouchGestureManager.Get().TapGesture.WasTapped() && HelpOverlay.MouseHitBottomText(TouchInput.GetAsPoint(TouchInput.GetOldestTouch().position)) ) { Active = false; } } else if (MouseInput.Left.WasPressed && HelpOverlay.MouseHitBottomText(MouseInput.Position)) { Active = false; MouseInput.Left.ClearAllWasPressedState(); } } } base.Update(); } // end of PreGameRacingWithDesc Update()
/// <summary> /// Drag the current node/edge/path by mouse movement. Includes raise/lower /// as well as horizontal drag. /// </summary> /// <param name="camera"></param> private void DoDrag(Camera camera) { Vector2 pos = Vector2.Zero; Vector2 prevPos = Vector2.Zero; TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { pos = touch.position; prevPos = touch.previousPosition; } Vector3 newPosition = Vector3.Zero; if (mode == Mode.Drag) { newPosition = TouchEdit.FindAtHeight(camera, TouchInput.GetAsPoint(TouchGestureManager.Get().DragGesture.DragPosition), height); } Vector3 delta = Vector3.Zero; if (mode == Mode.Raise) { float dheight = MouseInput.Position.Y - MouseInput.PrevPosition.Y; float kUpDownSpeed = -0.002f; dheight *= kUpDownSpeed; Vector3 dragPos = camera.ActualFrom; bool asRoad = false; if (node != null) { dragPos = node.RenderPosition(asRoad); } if (edge != null) { dragPos = (edge.Node0.RenderPosition(asRoad) + edge.Node1.RenderPosition(asRoad)) * 0.5f; } float dist = Vector3.Distance(dragPos, camera.ActualFrom); dheight *= dist; delta.Z = dheight; } if (newPosition != Vector3.Zero && Path != null) { if (actOnPath) { if (node != null) { Path.Translate(newPosition - node.Position); } else if (edge != null) { Path.Translate(newPosition - edge.HandlePosition); } } else if (node != null) { node.Translate(newPosition - node.Position); } else if (edge != null) { edge.Translate(newPosition - edge.HandlePosition); } skeletonTimer = kSkeletonTime; } if ((delta != Vector3.Zero) && (Path != null)) { if (actOnPath) { MovePath(Path, delta); } else if (node != null) { MoveNode(node, delta); } else if (edge != null) { MoveEdge(edge, delta); } skeletonTimer = kSkeletonTime; } }