Vector2Int GestureToDir(TouchGesture gesture) { Vector2Int moveDir = new Vector2Int(0, 0); switch (gesture) { case TouchGesture.Left: moveDir.x = -1; break; case TouchGesture.Up: moveDir.y = 1; break; case TouchGesture.Right: moveDir.x = 1; break; case TouchGesture.Down: moveDir.y = -1; break; } return(moveDir); }
public void informGestureRecognizedEvent(TouchGesture recognizedGesture) { if (gestureRecognizedListener != null) { gestureRecognizedListener(recognizedGesture); } }
public TouchGestureEventArgs(TouchGesture direction) { this.m_direction = direction; this.m_handled = false; this.m_difference = 0; this.m_type = TouchGestureType.Gesture; }
private void FinalizeTouchGesture(TouchGesture gesture) { foreach (TouchGestureListener listener in listeners) { listener.OnTouchGesture(gesture); } }
void OnTouchMove(int num) { if (num == 0) { if (touchPosCurrent != null) { touchPosBefore = touchPosCurrent; } if (touchPosAnchor == null) { touchPosAnchor = TouchInput.GetTouchPosition(num); } else { touchPosBefore = TouchInput.GetTouchPosition(num); } touchPosCurrent = TouchInput.GetTouchPosition(num); //タッチアンカー値制限 if (touchPosAnchor != null && touchPosCurrent != null) { Vector2 dist = (Vector2)touchPosCurrent - (Vector2)touchPosAnchor; if (dist.magnitude >= 40) { touchPosAnchor = touchPosCurrent - dist.normalized * 40; } } TouchGesture gesture = PositionToGesture((Vector2)touchPosAnchor, (Vector2)touchPosCurrent); EventManager.Invoke(ref EventManager.OnTouchGestureMove, num, gesture); } }
/// /// Emulate multitouch gestures - By pressing CTRL+x (where x is one of the keyboard keys in the switch statement below). /// This currently enables all multitouch gestures supported by .Net MF. /// protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.Control && m_currentGesture == TouchGesture.NoGesture) { switch (e.KeyCode) { case Keys.NumPad2: m_GestureNumKeysPressed = 2; break; case Keys.NumPad3: m_GestureNumKeysPressed = 3; break; case Keys.P: m_currentGesture = TouchGesture.Pan; break; case Keys.Z: m_currentGesture = TouchGesture.Zoom; break; case Keys.R: m_currentGesture = TouchGesture.Rotate; break; case Keys.T: m_currentGesture = TouchGesture.TwoFingerTap; break; case Keys.O: m_currentGesture = TouchGesture.Rollover; break; } if (m_currentGesture != TouchGesture.NoGesture) { touchPort.PostGesture((int)TouchGesture.Begin, lastMouseDownX, lastMouseDownY, 0); if (m_currentGesture == TouchGesture.TwoFingerTap || m_currentGesture == TouchGesture.Rollover) { touchPort.PostGesture((int)m_currentGesture, lastMouseDownX, lastMouseDownY, 0); } } } }
// Use this for initialization void Start() { Messenger.AddListener <GameObject> ("exitObstacle", exitedCollider); Messenger.AddListener <GameObject> ("disappear", disappearObstacle); Messenger.AddListener <GameObject> ("enteredObstacle", enteredCollider); Messenger.AddListener("clearOutLane", clearOutLane); Messenger.AddListener("ranOutOfHealth", ranOutOfHealth); Messenger.AddListener("landed", landed); Messenger.AddListener("jumped", jumped); Messenger.AddListener <bool> ("isLaneEnabled", laneEnabled); Messenger.AddListener("hitPowerBox", hitPowerBox); cam = Camera.main; scoreController = new ScoreController(); timerController = new TimerController(() => TimesUp()); cameraScript = cam.GetComponent <CameraScript> (); bounds = CameraExtensions.OrthographicBounds(cam); audioScript = GameObject.FindGameObjectWithTag("AudioController").GetComponent <AudioScript> (); soundEffectScript = GameObject.FindGameObjectWithTag("SoundEffectsController").GetComponent <SoundEffectsScript> (); currentGameLevel = LevelManager.Instance.getCurrentLevelDetail(); timerController.beginTimer(currentGameLevel.lengthInSeconds * 1000); #if UNITY_ANDROID touch = new TouchGesture(this.gestureSetting); StartCoroutine(touch.CheckHorizontalSwipes( onLeftSwipe: () => { moveRight(); }, onRightSwipe: () => { moveLeft(); } )); #endif }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (m_currentGesture != TouchGesture.NoGesture) { HandleGesture(e.X, e.Y, true); m_currentGesture = TouchGesture.NoGesture; touchPort.PostGesture((int)TouchGesture.End, lastMouseDownX, lastMouseDownY, 0); } flags = TouchSampleValidFlag | TouchSamplePreviousDownFlag; touchPort.WriteTouchData(flags, 0, e.X, e.Y); switch (m_GestureNumKeysPressed) { case 2: touchPort.WriteTouchData(flags, 1, e.X, e.Y); break; case 3: touchPort.WriteTouchData(flags, 1, e.X, e.Y); touchPort.WriteTouchData(flags, 2, e.X, e.Y); break; } m_GestureNumKeysPressed = 0; lastAngle = 0.0; lastDist = 0.0; lastMouseDownX = 0; lastMouseDownY = 0; }
/// <summary> /// タッチ角度をジェスチャーに変換 /// </summary> /// <param name="angle"></param> /// <returns></returns> TouchGesture AngleToGesture(float angle) { TouchGesture ret = TouchGesture.None; float sin = Mathf.Sin(angle * Mathf.PI / 180); float cos = Mathf.Cos(angle * Mathf.PI / 180); if (Mathf.Abs(sin) > Mathf.Abs(cos)) { if (sin >= 0) { ret = TouchGesture.Up; } if (sin < 0) { ret = TouchGesture.Down; } } else { if (cos < 0) { ret = TouchGesture.Left; } if (cos >= 0) { ret = TouchGesture.Right; } } //Debug.Log("" + ret); return(ret); }
void Start() { forwardDirection = transform.forward; touch = new TouchGesture(this.GestureSetting); StartCoroutine(touch.CheckHorizontalSwipes( onLeftSwipe: () => { Vector3 tempDir = Quaternion.Euler(0, 90, 0) * forwardDirection; float angle = Vector3.Dot(tempDir, new Vector3(0.0f, 0.0f, 1.0f)); if (angle > 0.0f) { targetDir = Quaternion.Euler(0, 90, 0) * forwardDirection; forwardDirection = tempDir; } }, onRightSwipe: () => { Vector3 tempDir = Quaternion.Euler(0, -90, 0) * forwardDirection; float angle = Vector3.Dot(tempDir, new Vector3(0.0f, 0.0f, 1.0f)); if (angle > 0.0f) { targetDir = Quaternion.Euler(0, -90, 0) * forwardDirection; forwardDirection = tempDir; } } )); }
void GetTouchGesture(int i, TouchGesture gesture) { if (i == 0) { // //_moveDirection = gesture; ChangeDirection((MoveDirection)gesture); /* * //Normal * if (gesture != TouchGesture.None) * { * if (_moveDirection == TouchGesture.None) * {//最初だけ * ChangeDirection((MoveDirection)gesture); * _moveDirection = gesture; * } * * //if (_moveBuffer == TouchGesture.None) * {//次に行く方向 * _moveBuffer = gesture; * } * } * else * { * ChangeDirection((MoveDirection)gesture); * _moveDirection = gesture; * _moveBuffer = gesture; * }*/ } }
protected override void OnAttached() { if (!_attached) { var holdTime = HoldTapEffect.GetHoldTime(Element); _holdGesture = new TouchGesture(holdTime) { OnRing = () => { var commandCustom = HoldTapEffect.GetCommand(Element); commandCustom?.Execute(HoldTapEffect.GetCommandParameter(Element)); } }; if (Control != null) { Control.Touch += Control_Touched; } else { Container.Touch += Control_Touched; } _attached = true; } }
/// <summary> /// Creates a new TouchGestureEventArgs. /// </summary> /// <param name="gesture">Touch gesture.</param> /// <param name="x">X-axis position.</param> /// <param name="y">Y-axis position.</param> /// <param name="arguments">Touch gesture arguments.</param> /// <param name="timestamp">Time the event occured.</param> public TouchGestureEventArgs(TouchGesture gesture, int x, int y, ushort arguments, DateTime timestamp) { Gesture = gesture; X = x; Y = y; Arguments = arguments; Timestamp = timestamp; }
public void OnTouchGestureTest() { PrivateObject param0 = null; // TODO: Initialize to an appropriate value D2DViewControl_Accessor target = new D2DViewControl_Accessor(param0); // TODO: Initialize to an appropriate value TouchGesture pTouchGesture = null; // TODO: Initialize to an appropriate value target.OnTouchGesture(pTouchGesture); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public static IScriptCommand IfTouchGesture(TouchGesture gesture, IScriptCommand nextCommand = null, IScriptCommand otherwiseCommand = null) { string TouchGestureVariable = "{IfTouchGesture-Gesture}"; return (ScriptCommands.Assign(TouchGestureVariable, gesture, false, HubScriptCommands.IfTouchGesture(TouchGestureVariable, nextCommand, otherwiseCommand))); }
private static void PopulateDrag(Touch touch, TouchGesture gesture) { if (!gesture.IsTouching) { gesture.StartScreenPoint = touch.position; } gesture.CurrentScreenPoint = touch.position; gesture.IsTouching = true; }
void OnTouchEnd(int num) { if (num == 0) { TouchGesture gesture = PositionToGesture((Vector2)touchPosAnchor, (Vector2)touchPosCurrent); EventManager.Invoke(ref EventManager.OnTouchGestureEnd, num, gesture); touchPosBefore = null; touchPosCurrent = null; touchPosAnchor = null; } }
/// <summary> /// Initializes a new instance of the <see cref="Client.Common.Views.TileTouchHandler"/> class. /// </summary> /// <param name="worldLayer">World layer.</param> public TileTouchHandler(WorldLayerHex worldLayer) { m_timer = new Stopwatch(); Gesture = TouchGesture.None; m_worldLayer = worldLayer; m_startLocation = new CCPoint(1, 1); TouchHandler.Instance.ListenBegan(m_worldLayer, OnTouchesBegan); TouchHandler.Instance.ListenEnded(m_worldLayer, OnTouchesEnded); TouchHandler.Instance.ListenMoved(m_worldLayer, OnTouchesMoved); }
void Start() { ps = GameObject.FindObjectOfType<PlayerScript>(); touch = new TouchGesture(this.GestureSetting); StartCoroutine(touch.CheckHorizontalSwipes( onLeftSwipe: () => { onLeftSwipe(); }, onRightSwipe: () => { onRightSwipe(); }, onUpSwipe: () => {onUpSwipe();}, onDownSwipe: () => {onDownSwipe();} )); }
public void OnTouchGesture(TouchGesture gesture) { if (placingBuildingBehavior != null) { // Debug.Log("got a placingBuildingBehavior"); if (gesture.type == TouchGestureType.Tap) { Debug.Log("Tap at " + gesture.endPosition); RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(gesture.endPosition), Vector2.zero); if (hitInfo) { if (hitInfo.transform.CompareTag("Confirm")) { ConfirmPlacement(); } else if (hitInfo.transform.CompareTag("Cancel")) { CancelPlacement(); } } } else if (gesture.type == TouchGestureType.Drag) { // Debug.Log("drag at " + gesture.endPosition); Vector2 endPoint = Camera.main.ScreenToWorldPoint(gesture.endPosition); Vector2 placePoint = new Vector2(endPoint.x, endPoint.y + 0.3f); if (placingBuildingBehavior.IsDragging()) { placingBuildingBehavior.gameObject.transform.position = placePoint; } else { if (placingBuildingBehavior != null) { RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(gesture.startPosition), Vector2.zero); if (hitInfo && hitInfo.collider.gameObject == placingBuildingBehavior.gameObject) { placingBuildingBehavior.gameObject.transform.position = placePoint; placingBuildingBehavior.SetDragging(true); } } } } else if (gesture.type == TouchGestureType.DragEnd) { if (placingBuildingBehavior != null) { placingBuildingBehavior.SetDragging(false); } } } }
// Use this for initialization void Start() { //var shootScript = GetComponent<PlayerShooting>(); touch = new TouchGesture(this.GestureSetting); //StartCoroutine(touch.CheckHorizontalSwipes( // onLeftSwipe: () => { ChangeLane(laneNumber - 1); }, // onRightSwipe: () => { ChangeLane(laneNumber + 1); }, // onStationary: () => { shootScript.shootRequest = true; } //)); }
bool recognizePadPanningGesture(TouchPointerData[] avaiPointers, out TouchGesture recognizedGesture) { recognizedGesture = new TouchGesture(); TouchPointerData anchorFinger = null; TouchPointerData[] movingFingers = new TouchPointerData[2]; int movingFingersIdx = 0; //classifying anchor and moving fingers for (int i = 0; i < avaiPointers.Length; i++) { if (Math.Abs(avaiPointers[i].RelVeloX) < 0.0001 && Math.Abs(avaiPointers[i].RelVeloY) < 0.0001) { anchorFinger = avaiPointers[i]; } else { if (movingFingersIdx < movingFingers.Length) { movingFingers[movingFingersIdx++] = avaiPointers[i]; } } } //check movement of moving fingers to see if they are moving in the same direction if (anchorFinger == null || movingFingersIdx != movingFingers.Length) { return(false); } if (movingFingers[0].RelVeloX * movingFingers[1].RelVeloX < 0 || movingFingers[0].RelVeloY * movingFingers[1].RelVeloY < 0) { return(false); } else { Vector2 anchorPos = new Vector2(anchorFinger.RelX, anchorFinger.RelY); Vector2 avgMovingVelo = new Vector2(); avgMovingVelo.x = (movingFingers[0].RelVeloX + movingFingers[1].RelVeloX) / 2; avgMovingVelo.y = (movingFingers[0].RelVeloY + movingFingers[1].RelVeloY) / 2; Vector2 curMovingCenter = new Vector2(); curMovingCenter.x = (movingFingers[0].RelX + movingFingers[1].RelX) / 2; curMovingCenter.y = (movingFingers[0].RelY + movingFingers[1].RelY) / 2; Vector2 futureMovingCenter = new Vector2(); futureMovingCenter.x = curMovingCenter.x + avgMovingVelo.x / TOUCH_REFRESH_RATE; futureMovingCenter.y = curMovingCenter.y + avgMovingVelo.y / TOUCH_REFRESH_RATE; float curDistanceToAnchor = Vector2.Distance(curMovingCenter, anchorPos); float futureDistanceToAnchor = Vector2.Distance(futureMovingCenter, anchorPos); Vector2 scaleRatio = new Vector2(futureDistanceToAnchor / curDistanceToAnchor, futureDistanceToAnchor / curDistanceToAnchor); recognizedGesture.GestureType = TouchGestureType.PAD_SCALING; recognizedGesture.MetaData = scaleRatio; return(true); } }
private void ExecuteEvent(TouchGesture touchEvent) { if (touchEvent != null) { touchEvent(); } else { #if VERBOSE_LOGGING Debug.LogWarning("Cannot execute event: " + typeof(TouchGesture).ToString() + " has no subscribers!"); #endif } }
/// <summary> ///タッチ座標(始点、終点)をジェスチャーに /// </summary> /// <param name="pos1">アンカー(始点)</param> /// <param name="pos2">終点</param> /// <returns></returns> TouchGesture PositionToGesture(Vector2 pos1, Vector2 pos2) { Vector2 touchDist = pos2 - pos1; TouchGesture gesture = TouchGesture.None; if (touchDist.magnitude > 10) { float angle = MathUtil.GetAim(pos1, pos2); gesture = AngleToGesture(angle); } return(gesture); }
void Start() { Performance_Counter_TextLabel.color = Color.green; touchside = Application.persistentDataPath; Debug.Log(Application.persistentDataPath); touch = new TouchGesture(this.GestureSetting); StartCoroutine(touch.CheckHorizontalSwipes( onLeftSwipe: () => { touchside = "left"; }, onRightSwipe: () => { touchside = "right"; }, onUpSwipe: () => { touchside = "Up"; }, onDownSwipe: () => { touchside = "Down"; } )); }
void Start() { Performance_Counter_TextLabel.color = Color.green; touchside =Application.persistentDataPath; Debug.Log(Application.persistentDataPath); touch = new TouchGesture(this.GestureSetting); StartCoroutine(touch.CheckHorizontalSwipes( onLeftSwipe: () => { touchside = "left"; }, onRightSwipe: () => { touchside = "right"; }, onUpSwipe: () => { touchside = "Up"; }, onDownSwipe: () => { touchside = "Down"; } )); }
protected override void OnTouchGesture(TouchGesture pTouchGesture) { if (pTouchGesture.Gesture == GestureType.Click) { if (Click != null) { Click(this, new EventArgs()); } if (Trigger != null) { Trigger(null); } } }
void RunMobileInput() { if (canMove) { return; } touch = new TouchGesture(); StartCoroutine(touch.CheckHorizontalSwipes( onLeftSwipe: () => { MoveTowards(TileDirection.Left); }, onRightSwipe: () => { MoveTowards(TileDirection.Right); }, onDownSwipe: () => { MoveTowards(TileDirection.Down); }, onUpSwipe: () => { MoveTowards(TileDirection.Up); } )); }
private void HandleTouch(int touchFignerId, Vector2 pos, TouchPhase touchPhase) { // TODO: Track multiple fingers. if (touchFignerId != 0) { return; } if (touchPhase == TouchPhase.Began) { touchGesture = new TouchGesture(); touchGesture.startPosition = pos; touchGesture.startTime = DateTime.Now; touchGesture.endPosition = pos; touchGesture.type = TouchGestureType.Tap; //Debug.Log("Setting tap"); } else if (touchPhase == TouchPhase.Moved || touchPhase == TouchPhase.Stationary) { touchGesture.endPosition = pos; if (touchGesture.type == TouchGestureType.Tap && DateTime.Now.Subtract(touchGesture.startTime).TotalSeconds >= TAP_TIME) { touchGesture.type = TouchGestureType.None; } if (Vector2.Distance(touchGesture.startPosition, touchGesture.endPosition) >= DRAG_DISTANCE) { touchGesture.type = TouchGestureType.Drag; FinalizeTouchGesture(touchGesture); } } else if (touchPhase == TouchPhase.Ended) { //Debug.Log("touch ended"); touchGesture.endPosition = pos; if (touchGesture.type == TouchGestureType.Drag) { touchGesture.type = TouchGestureType.DragEnd; FinalizeTouchGesture(touchGesture); } else if (touchGesture.type == TouchGestureType.Tap) { FinalizeTouchGesture(touchGesture); } } }
public override IScriptCommand Execute(ParameterDic pm) { TouchEventArgs TouchEvent = pm.GetValue <TouchEventArgs>(RoutedEventArgsKey); IUIInput input = pm.GetValue <IUIInput>(InputKey); TouchGesture inputGesture = input.GetTouchGesture(); TouchGesture gesture = pm.GetValue <TouchGesture>(TouchGestureKey); if (inputGesture == null || gesture == null || inputGesture.TouchDevice == UIInputState.NotApplied) { return(OtherwiseCommand); } bool match = (gesture.TouchAction == UITouchGesture.NotApplied || inputGesture.TouchAction == gesture.TouchAction) && (gesture.TouchDevice == UIInputState.NotApplied || inputGesture.TouchDevice == gesture.TouchDevice); return(match ? NextCommand : OtherwiseCommand); }
protected override void OnLostFocus(EventArgs e) { base.OnLostFocus(e); if (0 != (flags & TouchSampleDownFlag)) { if (m_currentGesture != TouchGesture.NoGesture) { m_currentGesture = TouchGesture.NoGesture; touchPort.PostGesture((int)TouchGesture.End, lastMouseDownX, lastMouseDownY, 0); } MouseEventArgs mea = new MouseEventArgs(MouseButtons.Left, 1, lastMouseDownX, lastMouseDownY, 0); OnMouseUp(mea); } }
public AndroidCustomTapEffect() { _touchGesture = new TouchGesture(FAST_TIME_CLICK) { OnRing = () => { _currentNumberOfTaps = 0; }, OnClicked = () => { if (CustomTapEffect.GetNumberOfTaps(Element) == ++_currentNumberOfTaps) { var command = CustomTapEffect.GetCommand(Element); _currentNumberOfTaps = 0; command?.Execute(CustomTapEffect.GetCommandParameter(Element)); } } }; }
private void InitializeGesture() { // disable on map since we're handling gestures ourselves PitchEnabled = false; RotateEnabled = false; ZoomEnabled = false; if (_gesture == null) { _gesture = new TouchGesture(); _gesture.TouchBegin += HandleTouchBegin; _gesture.TouchMove += HandleTouchMove; _gesture.TouchEndOrCancel += HandleTouchEnded; AddGestureRecognizer(_gesture); var pinchRecognizer = new UIPinchGestureRecognizer { ShouldRecognizeSimultaneously = (g1, g2) => !(g2 is UITapGestureRecognizer) }; pinchRecognizer.AddTarget(() => OnPinch(pinchRecognizer)); AddGestureRecognizer(pinchRecognizer); var doubleTapRecognizer = new UITapGestureRecognizer() { ShouldRecognizeSimultaneously = (g1, g2) => false, NumberOfTapsRequired = 2 }; doubleTapRecognizer.AddTarget(() => this.ChangeZoomLevel(true)); AddGestureRecognizer(doubleTapRecognizer); var doubleTapMultitouchRecognizer = new UITapGestureRecognizer { ShouldRecognizeSimultaneously = (g1, g2) => false, NumberOfTapsRequired = 2, NumberOfTouchesRequired = 2 }; doubleTapMultitouchRecognizer.AddTarget(() => this.ChangeZoomLevel(false)); AddGestureRecognizer(doubleTapMultitouchRecognizer); } }
void Start() { activeScreen = GameObject.Find ("Main Camera").GetComponent<ActiveScreen> (); touch = new TouchGesture(this.GestureSetting); StartCoroutine(touch.CheckHorizontalSwipes( onDownSwipe: () => { if (activeScreen.timeScreen) { timeScreenToggleUp = GameObject.Find ("Time Screen Toggle U").GetComponent<Toggle>(); timeScreenToggleUp.isOn = true; timeScreenToggleUp.isOn = false; } }, onUpSwipe: () => { if (activeScreen.homeScreen) { homeScreenToggleDown = GameObject.Find ("Home Screen Toggle D").GetComponent<Toggle>(); homeScreenToggleDown.isOn = true; homeScreenToggleDown.isOn = false; } }, onRightSwipe: () => { if (activeScreen.homeScreen) { homeScreenToggleRight = GameObject.Find ("Home Screen Toggle R").GetComponent<Toggle>(); homeScreenToggleRight.isOn = true; homeScreenToggleRight.isOn = false; } if (activeScreen.profileScreen) { profileScreenToggleRight = GameObject.Find ("Profile Screen Toggle R").GetComponent<Toggle>(); profileScreenToggleRight.isOn = true; profileScreenToggleRight.isOn = false; } if (activeScreen.achievementsScreen) { achievementsScreenToggleRight = GameObject.Find ("Achievements Screen Toggle R").GetComponent<Toggle>(); achievementsScreenToggleRight.isOn = true; achievementsScreenToggleRight.isOn = false; } if (activeScreen.staticticsScreen) { statisticsScreenToggle = GameObject.Find ("Statistics Screen Toggle").GetComponent<Toggle>(); statisticsScreenToggle.isOn = true; statisticsScreenToggle.isOn = false; } if (activeScreen.sessionScreen) { sessionScreenToggleRight = GameObject.Find ("Session Screen Toggle R").GetComponent<Toggle>(); sessionScreenToggleRight.isOn = true; sessionScreenToggleRight.isOn = false; } if (activeScreen.instructionsScreen) { instructionsScreenToggle = GameObject.Find ("Instructions Screen Toggle").GetComponent<Toggle>(); instructionsScreenToggle.isOn = true; instructionsScreenToggle.isOn = false; } }, onLeftSwipe: () => { if (activeScreen.homeScreen) { homeScreenToggleLeft = GameObject.Find ("Home Screen Toggle L").GetComponent<Toggle>(); homeScreenToggleLeft.isOn = true; homeScreenToggleLeft.isOn = false; } if (activeScreen.settingsScreen) { settingsScreenToggle = GameObject.Find ("Settings Screen Toggle").GetComponent<Toggle>(); settingsScreenToggle.isOn = true; settingsScreenToggle.isOn = false; } if (activeScreen.profileScreen) { profileScreenToggleLeft = GameObject.Find ("Profile Screen Toggle L").GetComponent<Toggle>(); profileScreenToggleLeft.isOn = true; profileScreenToggleLeft.isOn = false; } if (activeScreen.achievementsScreen) { achievementsScreenToggleLeft = GameObject.Find ("Achievements Screen Toggle L").GetComponent<Toggle>(); achievementsScreenToggleLeft.isOn = true; achievementsScreenToggleLeft.isOn = false; } if (activeScreen.timeScreen) { timeScreenToggleLeft = GameObject.Find ("Time Screen Toggle L").GetComponent<Toggle>(); timeScreenToggleLeft.isOn = true; timeScreenToggleLeft.isOn = false; } if (activeScreen.sessionScreen) { sessionScreenToggleLeft = GameObject.Find ("Session Screen Toggle L").GetComponent<Toggle>(); sessionScreenToggleLeft.isOn = true; sessionScreenToggleLeft.isOn = false; } } )); }
public GestureDetectedEventArgs(TouchGesture gesture, object gestureparameter) { _gesture = gesture; _gestureparameter = gestureparameter; }
private void _observeGesture() { if (_fingers.Count > 1) { double a0 = _fingers[0].PathAngle; double a1 = _fingers[1].PathAngle; double l0 = _fingers[0].PathLength; double l1 = _fingers[1].PathLength; if (l0 > _slidesensitivity && l1 > _slidesensitivity) { if (((a0 > 340 && a0 <= 360) || (a0 >= 0 && a0 < 20)) && ((a1 > 340 && a1 <= 360) || (a1 >= 0 && a1 < 20))) { _lastdetectedgesture = TouchGesture.SLIDE_EAST; _gslideamount++; } else if (a0 > 160 && a0 < 200 && a1 > 160 && a1 < 200) { _lastdetectedgesture = TouchGesture.SLIDE_WEST; _gslideamount++; } else if (a0 > 250 && a0 < 290 && a1 > 250 && a1 < 290) { _lastdetectedgesture = TouchGesture.SLIDE_NORTH; _gslideamount++; } else if (a0 > 70 && a0 < 110 && a1 > 70 && a1 < 110) { _lastdetectedgesture = TouchGesture.SLIDE_SOUTH; _gslideamount++; } else if (a0 > 210 && a0 < 270 && a1 > 210 && a1 < 270) { _lastdetectedgesture = TouchGesture.SLIDE_NORTHWEST; _gslideamount++; } else if (a0 > 290 && a0 < 340 && a1 > 290 && a1 < 340) { _lastdetectedgesture = TouchGesture.SLIDE_NORTHEAST; _gslideamount++; } else if (a0 > 110 && a0 < 160 && a1 > 110 && a1 < 160) { _lastdetectedgesture = TouchGesture.SLIDE_SOUTHWEST; _gslideamount++; } else if (a0 > 20 && a0 < 70 && a1 > 20 && a1 < 70) { _lastdetectedgesture = TouchGesture.SLIDE_SOUTHEAST; _gslideamount++; } } else { // _lastdetectedgesture = Gestures.NONE; } } else if (!_twofingersgesture && _fingers.Count == 1) { double a0 = _fingers[0].PathAngle; double l0 = _fingers[0].PathLength; if (l0 > 5) //_slidesensitivity / 2) { if (((a0 > 340 && a0 <= 360) || (a0 >= 0 && a0 < 20))) { _lastdetectedgesture = TouchGesture.MOVE_EAST; _gmoveamount++; } else if (a0 > 160 && a0 < 200) { _lastdetectedgesture = TouchGesture.MOVE_WEST; _gmoveamount++; } else if (a0 > 250 && a0 < 290) { _lastdetectedgesture = TouchGesture.MOVE_NORTH; _gmoveamount++; } else if (a0 > 70 && a0 < 110) { _lastdetectedgesture = TouchGesture.MOVE_SOUTH; _gmoveamount++; } else if (a0 > 210 && a0 < 270) { _lastdetectedgesture = TouchGesture.MOVE_NORTHWEST; _gmoveamount++; } else if (a0 > 290 && a0 < 340) { _lastdetectedgesture = TouchGesture.MOVE_NORTHEAST; _gmoveamount++; } else if (a0 > 110 && a0 < 160) { _lastdetectedgesture = TouchGesture.MOVE_SOUTHWEST; _gmoveamount++; } else if (a0 > 20 && a0 < 70) { _lastdetectedgesture = TouchGesture.MOVE_SOUTHEAST; _gmoveamount++; } } else { // _lastdetectedgesture = Gestures.NONE; } } //////////////////////////// if (!_twofingersgesture && _lastdetectedgesture >= TouchGesture.MOVE_WEST && _lastdetectedgesture <= TouchGesture.MOVE_SOUTHEAST) { _currentgesture = _lastdetectedgesture; } else if ((Math.Abs(_gscaleamount) < 0.5 || Math.Abs(_gscaleamount) > 1.7) /*&& Math.Abs(_grotateamount) < 35*/ && _gslideamount < 3) { _currentgesture = TouchGesture.SCALE; // param = _gscaleamount; } else if (Math.Abs(_grotateamount) >= 35 && _gslideamount < 8) { _currentgesture = TouchGesture.ROTATE; // param = _grotateamount; } else if (_gslideamount >= 3) { _currentgesture = _lastdetectedgesture; } //else //{ // _currentgesture = Gestures.NONE; //} }
private void _detectgesture() { //if (_targetelement.FindName("DEBUG") != null) //{ // _targetelement.Dispatcher.BeginInvoke(() => // { // TextBlock debug = _targetelement.FindName("DEBUG") as TextBlock; // debug.Text = "S " + _gscaleamount + " R " + _grotateamount + " L " + _gslideamount; // }); //} object param = null; if (!_twofingersgesture && _lastdetectedgesture >= TouchGesture.MOVE_WEST && _lastdetectedgesture <= TouchGesture.MOVE_SOUTHEAST) { _currentgesture = _lastdetectedgesture; } else if ((Math.Abs(_gscaleamount) < 0.6 || Math.Abs(_gscaleamount) > 1.7) /* && Math.Abs(_grotateamount) < 35 */ && _gslideamount < 3) { _currentgesture = TouchGesture.SCALE; param = _gscaleamount; } else if (Math.Abs(_grotateamount) >= 35 && _gslideamount < 3) { _currentgesture = TouchGesture.ROTATE; param = _grotateamount; } else if (_gslideamount >= 2) { _currentgesture = _lastdetectedgesture; } else { _currentgesture = TouchGesture.NONE; } //if (_currentgesture != Gestures.NONE) // if (GestureDetected != null) GestureDetected(_currentgesture, param); // if (_gscaleamount > 40) // ... ; _currentgestureparam = param; _gscaleamount = 1; _grotateamount = 0; _gslideamount = 0; _lastdetectedgesture = TouchGesture.NONE; }
// Use this for initialization void Start() { resetRotation = new Quaternion(0, 0, 0, 0); CubeAnimation = GetComponent<Animation>(); Mixer = GameObject.Find("Slider").GetComponent<ColourMixer>(); MixerSlider = GameObject.Find("Slider").GetComponent<Slider>(); touch = GetComponent<TouchGesture>(); StartCoroutine(touch.CheckHorizontalSwipes( onLeftSwipe: () => { MoveLeft(); }, onRightSwipe: () => { MoveRight(); } )); StartCoroutine(touch.CheckVerticalSwipes( onUpSwipe: () => { MoveUp(); }, onDownSwipe: () => { MoveDown(); } )); }
void _simulategesture(TouchGesture gesture) { //FrameworkElement hookedel = _elementhook(GetElementInView(), gesture); //if (hookedel == null) { Point t = new Point(); Point p1 = this.TransformToVisual(_scrollerpanel).Transform(new Point()); Point p2 = this.TransformToVisual(_scrollerpanel).Transform(new Point(this.RenderSize.Width, this.RenderSize.Height)); double szx = p2.X - p1.X; double szy = p2.Y - p1.Y; if (gesture == TouchGesture.MOVE_NORTH || gesture == TouchGesture.MOVE_NORTHEAST || gesture == TouchGesture.MOVE_NORTHWEST) { t.Y = -szy; } if (gesture == TouchGesture.MOVE_SOUTH || gesture == TouchGesture.MOVE_SOUTHEAST || gesture == TouchGesture.MOVE_SOUTHWEST) { t.Y = szy; } if (gesture == TouchGesture.MOVE_EAST || gesture == TouchGesture.MOVE_NORTHEAST || gesture == TouchGesture.MOVE_SOUTHEAST) { t.X = szx; } if (gesture == TouchGesture.MOVE_WEST || gesture == TouchGesture.MOVE_NORTHWEST || gesture == TouchGesture.MOVE_SOUTHWEST) { t.X = -szx; } _translate(t); } }
protected override void OnKeyUp(KeyEventArgs e) { switch (e.KeyCode) { case Keys.NumPad2: case Keys.NumPad3: m_GestureNumKeysPressed = 0; break; case Keys.P: case Keys.Z: case Keys.R: case Keys.T: case Keys.O: m_currentGesture = TouchGesture.NoGesture; touchPort.PostGesture((int)TouchGesture.End, lastMouseDownX, lastMouseDownY, 0); break; } base.OnKeyUp(e); }
/// /// Emulate multitouch gestures - By pressing CTRL+x (where x is one of the keyboard keys in the switch statement below). /// This currently enables all multitouch gestures supported by .Net MF. /// protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.Control && m_currentGesture == TouchGesture.NoGesture) { switch (e.KeyCode) { case Keys.NumPad2: m_GestureNumKeysPressed = 2; break; case Keys.NumPad3: m_GestureNumKeysPressed = 3; break; case Keys.P: m_currentGesture = TouchGesture.Pan; break; case Keys.Z: m_currentGesture = TouchGesture.Zoom; break; case Keys.R: m_currentGesture = TouchGesture.Rotate; break; case Keys.T: m_currentGesture = TouchGesture.TwoFingerTap; break; case Keys.O: m_currentGesture = TouchGesture.Rollover; break; } if (m_currentGesture != TouchGesture.NoGesture) { touchPort.PostGesture((int)TouchGesture.Begin, lastMouseDownX, lastMouseDownY, 0); if (m_currentGesture == TouchGesture.TwoFingerTap || m_currentGesture == TouchGesture.Rollover) touchPort.PostGesture((int)m_currentGesture, lastMouseDownX, lastMouseDownY, 0); } } }
public void FingerUpdate(String identifier, Point p) { PointCollection vertexes = _getvertexes(); Point cn = _getcentroid(); //_detectgesture(); _observeGesture(); _centroid = cn; if (_fingers.Count == 2) { // effettuiamo traslazione e rotazione // sullo shsape in base alla nuova // posizione degli fingers Point p1 = _fingers[0].Position; Point p2 = _fingers[1].Position; // E ORA DOBBIAMO CALCOLARE LA NUOVA // POSIZIONE DEL punto C double aaab = Vector2D.GetAngle(_fingerstartinfoa.A, _fingerstartinfoa.C); double seg_ab = Vector2D.Distance(_fingerstartinfoa.A, _fingerstartinfoa.B); double seg_ac = Vector2D.Distance(_fingerstartinfoa.A, _fingerstartinfoa.C); double seg_ppab = Vector2D.Distance(p1, p2); double seg_ppac = seg_ac * (seg_ppab / seg_ab); Point c = Vector2D.GetPoint(p1, seg_ppac, aaab * Math.PI / 180); double papb = Vector2D.GetAngle(p1, p2); double angolo = papb - Vector2D.GetAngle(_fingerstartinfoa.A, _fingerstartinfoa.B); c = Vector2D.Rotate(c, p1, angolo * Math.PI / 180); papb = Vector2D.GetAngle(p1, c); _fingersstartinfob.A = p1; _fingersstartinfob.B = p2; _fingersstartinfob.C = c; double newAngle = papb - aaab; double newScale = (seg_ppab / seg_ab); Point newTranslate = _adjusttoparentscale( new Point(c.X - _fingerstartinfoa.C.X, c.Y - _fingerstartinfoa.C.Y) ); /// _grotateamount += newAngle; if (newScale != 0) _gscaleamount *= newScale; /// if (Rotate != null && newAngle != 0) { Rotate(this, new GestureRotateEventArgs(_fingers[0].Clone(), _fingers[1].Clone(), newAngle)); } if (Scale != null && newScale != 0) { Scale(this, new GestureScaleEventArgs(_fingers[0].Clone(), _fingers[1].Clone(), newScale)); } if (Translate != null && (newTranslate.X != 0 || newTranslate.Y != 0)) { Translate(this, new GestureTranslateEventArgs(_fingers[0].Clone(), newTranslate)); } //if (DataChanged != null) // DataChanged(newTranslate, newAngle, newScale); _fingerstartinfoa = new FingersStartInfo(p1, p2, c); _observeGesture(); // _gesturesobserver.Change(350, 0); } else if (_fingers.Count == 1) { if (identifier == _fingers[0].Identifier) { Point pc = _fingers[0].Position; Point newTranslate = _adjusttoparentscale(new Point((p.X - pc.X), (p.Y - pc.Y))); if (Translate != null && (newTranslate.X != 0 || newTranslate.Y != 0)) { Translate(this, new GestureTranslateEventArgs(_fingers[0].Clone(), newTranslate)); } } } else { } int h = GetFingerById(identifier); if (h != -1) { _fingers[h].Position = p; //if (h == 0 && _fingers.Count > 1 && _fingers[1].Id == "H") // _fingers[1].Update(Vector2D.Rotate(p, centroid, 45 * Math.PI / 180)); } else if (_fingers.Count < 2) { _currentgesture = TouchGesture.NONE; if (_fingers.Count == 0) _twofingersgesture = false; else if (_fingers.Count == 1) _twofingersgesture = true; _fingers.Add(new Finger(identifier, p)); _gesturegap = DateTime.Now; if (_fingers.Count == 1) { _singleaction = true; _lastdetectedgesture = TouchGesture.NONE; _observeGesture(); //_gesturesobserver.Change(250, 0); // // controllo coordinate se collidono con uno dei angoli // in fururo generalizzare per <n> vertexes (non solo x 4) // if (NearBy(vertexes[0], p) || NearBy(vertexes[1], p) || NearBy(vertexes[2], p) || NearBy(vertexes[3], p) ) { _singleaction = false; _fingers.Add(new Finger("H", _centroid)); } else { _fingerstartinfoa = new FingersStartInfo(p, new Point(0, 0), new Point(0, 0)); } // GestureHold Timer dispatcherTimer.Stop(); dispatcherTimer.Start(); } if (_fingers.Count == 2) { dispatcherTimer.Stop(); _singleaction = false; _currentgesture = _lastdetectedgesture = TouchGesture.NONE; // E STATO APPENA AGGIUNTO IL SECONDO FINGER // QUINDI SALVIAMO LA CONFIGURAZIONE INIZIALE DEL // TRIANGOLO A-B-C // DOVE A (p1) e B (p2) SONO I DUE FINGER // MENTRE C (center) è IL CENTRO DELLO SHAPE Point p1 = _fingers[0].Position; Point p2 = _fingers[1].Position; _fingerstartinfoa = new FingersStartInfo(p1, p2, _centroid); // _observeGesture(); //_gesturesobserver.Change(250, 0); } } if (_fingers.Count > 0 && !_speedometer.IsEnabled) { _speedometer.Start(); } if (_fingers.Count == 1) { double d = Utility.Vector2D.Distance(_fingerstartinfoa.A, _fingers[0].Position); if (_maxtapdistance < d || _maxtapdistance == double.PositiveInfinity) { _maxtapdistance = d; } } }
public void FingerRemove(string identifier) { dispatcherTimer.Stop(); TimeSpan diff = DateTime.Now - _gesturegap; if (_fingers.Count == 1) { _detectgesture(); if (GestureDetected != null && diff.TotalMilliseconds < 350) GestureDetected(this, new GestureDetectedEventArgs(_currentgesture, _currentgestureparam)); } int h = GetFingerById(identifier); if (h != -1) { if (h == 0 && _fingers.Count > 1 && _fingers[1].Identifier == "H") { _fingers.Remove(_fingers[1]); } else if (_fingers.Count == 1) { _speedometer.Stop(); } if (_fingers.Count == 1 && _maxtapdistance < 5 && _singleaction && diff.TotalMilliseconds < 150) { if (Tap != null) { Point p = _fingers[0].Position; //// adjust translate to scaling factor //// ... //FrameworkElement cs = canvas; //while (cs != null && cs.Parent != null && cs.Parent.GetType().IsSubclassOf(typeof(FrameworkElement))) //{ // cs = (FrameworkElement)cs.Parent; // TranslateTransform tt = Animations.TransformHelper.GetTranslateTransform(cs); // if (tt != null) // { // p.X = p.X - tt.X; // p.Y = p.Y - tt.Y; // } //} Tap(this, new GestureTapEventArgs(_fingers[0].Clone(), p)); } } else if (_fingers.Count == 1) { _maxtapdistance = double.PositiveInfinity; _twofingersgesture = false; // Release if (Release != null) Release(this); _currentgesture = _lastdetectedgesture = TouchGesture.NONE; } _fingers.Remove(_fingers[h]); _singleaction = false; } }
/// <summary> /// On the touches moved event. Set the gesture to move or scale and scale or move the map. /// </summary> /// <param name="touches">Touches, where the user touched.</param> /// <param name="touchEvent">Touch event.</param> /// <returns>Returns a true after processed the event. </returns> public bool OnTouchesMoved(List<CCTouch> touches, CCEvent touchEvent) { /* if (touches.Count == 1 && m_touchGesture == TouchGesture.Zoom) { m_touchGesture = TouchGesture.Move; } */ if (touches.Count >= 2 && Gesture == TouchGesture.Move) { Gesture = TouchGesture.Zoom; } if (touches.Count == 1 && (Gesture == TouchGesture.Start || Gesture == TouchGesture.Move)) { Gesture = TouchGesture.Move; m_worldLayer.ViewMode = WorldLayerHex.ViewModes.CameraPosition; // if there is more than one click (as example at zooming) then take the average for moving CCPoint realLocationOnScreen = CCPoint.Zero; CCPoint realStartLocationOnScreen = CCPoint.Zero; foreach (var touch in touches) { realLocationOnScreen += touch.LocationOnScreen; realStartLocationOnScreen += touch.StartLocationOnScreen; } realLocationOnScreen /= touches.Count; realStartLocationOnScreen /= touches.Count; var diff = realLocationOnScreen - realStartLocationOnScreen; var move = new CCPoint(-diff.X, diff.Y) * m_worldLayer.GetZoom(); var cameraDiff = realLocationOnScreen - m_worldLayer.Scene.VisibleBoundsScreenspace.Center; var cameraMove = new CCPoint(-cameraDiff.X, cameraDiff.Y) * m_worldLayer.GetZoom(); m_worldLayer.SetWorldPosition(m_startLocation + cameraMove + move); } else if (touches.Count >= 2 && (Gesture == TouchGesture.Start || Gesture == TouchGesture.Zoom)) { Gesture = TouchGesture.Zoom; CCPoint screenStart0 = touches[0].StartLocationOnScreen; CCPoint screenStart1 = touches[1].StartLocationOnScreen; // calculate Current Position CCPoint currentPoint0 = touches[0].LocationOnScreen; CCPoint currentPoint1 = touches[1].LocationOnScreen; var screen = new CCPoint( m_worldLayer.Scene.VisibleBoundsScreenspace.MaxX, m_worldLayer.Scene.VisibleBoundsScreenspace.MaxY); float startDistance = screenStart0.DistanceSquared(ref screenStart1); float currentDistance = currentPoint0.DistanceSquared(ref currentPoint1); float screenDistance = screen.LengthSquared; float relation = (startDistance - currentDistance) / screenDistance; m_newZoom = m_zoom + (relation * m_newZoom); m_worldLayer.ZoomWorld(m_newZoom); } return true; }
FrameworkElement _elementhook(FrameworkElement source, TouchGesture gesturedirection) { if (source == null) return null; Point cornertest = new Point(); double hookdistance = 100; cornertest.X = source.ActualWidth / 2; cornertest.Y = source.ActualHeight / 2; if (gesturedirection == TouchGesture.MOVE_NORTH || gesturedirection == TouchGesture.MOVE_NORTHEAST || gesturedirection == TouchGesture.MOVE_NORTHWEST) { cornertest.Y = source.ActualHeight + hookdistance; } if (gesturedirection == TouchGesture.MOVE_SOUTH || gesturedirection == TouchGesture.MOVE_SOUTHEAST || gesturedirection == TouchGesture.MOVE_SOUTHWEST) { cornertest.Y = -hookdistance; } if (gesturedirection == TouchGesture.MOVE_EAST || gesturedirection == TouchGesture.MOVE_NORTHEAST || gesturedirection == TouchGesture.MOVE_SOUTHEAST) { cornertest.X = -hookdistance; } if (gesturedirection == TouchGesture.MOVE_WEST || gesturedirection == TouchGesture.MOVE_NORTHWEST || gesturedirection == TouchGesture.MOVE_SOUTHWEST) { cornertest.X = source.ActualWidth + hookdistance; } this.Clip = null; FrameworkElement hookedelement = null; Point ht = source.TransformToVisual(Application.Current.RootVisual).Transform(cornertest); Rect rht = new Rect() { X = ht.X - 10, Y = ht.Y - 10, Width = 20, Height = 20 }; IEnumerable<UIElement> hitsn = VisualTreeHelper.FindElementsInHostCoordinates(rht, Application.Current.RootVisual); foreach (FrameworkElement el in hitsn) { bool hookable = (bool)el.GetValue(HookableProperty); if (el.Parent != null /* && !el.Equals(_scrollercanvas) */ && hookable) { hookedelement = el; break; } } // _clipview(); // if (hookedelement != null) { ZoomToElement(hookedelement); } return hookedelement; }
private void HandleGesture(int x, int y, bool fForce) { if (m_currentGesture != TouchGesture.NoGesture) { ushort data = 0; int xCenter = lastMouseDownX, yCenter = lastMouseDownY; switch (m_currentGesture) { case TouchGesture.Pan: case TouchGesture.Zoom: double dist = Math.Sqrt(Math.Pow(x - xCenter, 2.0) + Math.Pow(yCenter - y, 2.0)); if (Math.Abs(dist - lastDist) > 10 || fForce) { if (x < xCenter && yCenter < y) { m_currentGesture = TouchGesture.Pan; data = (ushort)dist; lastDist = dist; } else if (x > xCenter && yCenter > y) { m_currentGesture = TouchGesture.Zoom; data = (ushort)dist; lastDist = dist; } } break; case TouchGesture.Rotate: xCenter -= c_GestureRotateXOffset; double dx = (x - xCenter); double dy = (yCenter - y); double angle = 180.0 * Math.Atan(Math.Abs(dy) / Math.Abs(dx)) / Math.PI; if (dx < 0) { if (dy < 0) angle += 180; else angle = 180 - angle; } else if (dx > 0 && dy < 0) angle = 360 - angle; if (angle < 0) angle += 360.0; // switch to clockwise rotational angle angle = 360.0 - angle; if ((Math.Abs(angle - lastAngle) > c_GestureRotateXOffset && (360.0 - (angle - lastAngle)) > c_GestureRotateXOffset) || fForce) { data = (ushort)(angle); lastAngle = angle; } break; } if (data != 0) touchPort.PostGesture((int)m_currentGesture, xCenter, yCenter, data); } }
/// <summary> /// On the touches began event. /// </summary> /// <param name="touches">Touches, where the user touched.</param> /// <param name="touchEvent">Touch event.</param> /// <returns> Returns true after processing the touches.</returns> public bool OnTouchesBegan(List<CCTouch> touches, CCEvent touchEvent) { var oldWorldPosition = m_startLocation; var oldGamePositionI = Helper.PositionHelper.WorldspaceToPositionI(oldWorldPosition, m_worldLayer); m_startLocation = m_worldLayer.ConvertToWorldspace(touches[0].Location); var gamePositionI = Helper.PositionHelper.WorldspaceToPositionI(m_startLocation, m_worldLayer); switch (Gesture) { case TouchGesture.Area: m_indicator.RemoveIndicator(); Gesture = TouchGesture.None; break; case TouchGesture.MoveUnit: var action = ActionHelper.MoveUnit(oldGamePositionI, gamePositionI); var actionC = (Core.Controllers.Actions.Action)action.Control; var possible = actionC.Possible(); if (possible) { m_worldLayer.DoAction(action); } m_indicator.RemoveIndicator(); Gesture = TouchGesture.None; break; case TouchGesture.Menu: var def = m_menuView.GetSelectedDefinition(gamePositionI); if (def != null) { var action2 = ActionHelper.CreateEntity(m_menuView.GetCenterPosition(), def, GameAppDelegate.Account); var actionC2 = (Core.Controllers.Actions.Action)action2.Control; if (actionC2.Possible()) { m_worldLayer.DoAction(action2); } } if (m_menuView.IsExtended()) { // var regionView = m_worldLayer.GetRegionViewHex(gamePositionI.RegionPosition); var gid = m_menuView.GetSelectedKategory(gamePositionI); switch (gid.Gid) { case Client.Common.Constants.BuildingMenuGid.MILITARY: case Client.Common.Constants.BuildingMenuGid.CIVIL: case Client.Common.Constants.BuildingMenuGid.UPGRADE: case Client.Common.Constants.BuildingMenuGid.RESOURCES: case Client.Common.Constants.BuildingMenuGid.STORAGE: m_menuView.ExtendMenu((short)gid.Gid, gamePositionI); break; default: m_menuView.CloseMenu(); m_menuView = null; Gesture = TouchGesture.None; break; } } else { m_menuView.CloseMenu(); Gesture = TouchGesture.None; } m_worldLayer.UglyDraw(); return true; case TouchGesture.None: Gesture = TouchGesture.Start; break; } m_timer.Reset(); m_timer.Start(); m_zoom = m_worldLayer.GetZoom(); m_worldLayer.UglyDraw(); return true; }
/// <summary> /// On the touches ended event. /// </summary> /// <param name="touches">Touches, where the user touched.</param> /// <param name="touchEvent">Touch event.</param> /// <returns>Return true after processing the touch events and drawing.</returns> public bool OnTouchesEnded(List<CCTouch> touches, CCEvent touchEvent) { m_timer.Stop(); var startPosI = Helper.PositionHelper.WorldspaceToPositionI(m_startLocation, m_worldLayer); switch (Gesture) { case TouchGesture.Zoom: // Set Current Scale m_worldLayer.ZoomWorld(m_newZoom); Gesture = TouchGesture.None; break; case TouchGesture.Move: Gesture = TouchGesture.None; break; case TouchGesture.Start: var region = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(startPosI.RegionPosition); var entity = region.GetEntity(startPosI.CellPosition); int range = 0; Area area = Area.Movement; m_indicator = new IndicatorView(m_worldLayer); if (entity != null && entity.Definition.Category == Category.Unit) { Gesture = TouchGesture.MoveUnit; range = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(startPosI.RegionPosition).GetEntity(startPosI.CellPosition).Move; m_indicator.ShowUnitIndicator(startPosI, range, area); } else if (entity != null && (entity.Definition.SubType == EntityType.Headquarter || entity.Definition.SubType == EntityType.GuardTower)) { Gesture = TouchGesture.Area; var owner = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(startPosI.RegionPosition).GetEntity(startPosI.CellPosition).Owner; area = Area.OwnTerritory; if (owner != GameAppDelegate.Account) { area = Area.EnemyTerritory; } m_indicator.ShowBuildingIndicator(startPosI, area); } else if (entity != null && entity.DefinitionID == (long)EntityType.Barracks && entity.Owner == GameAppDelegate.Account) { m_menuView = new MenuView(m_worldLayer, startPosI, MenuView.MenuType.Unity); m_menuView.DrawMenu(MenuView.MenuType.Unity); Gesture = TouchGesture.Menu; } else if (entity == null) { var defM = Core.Models.World.Instance.DefinitionManager; var action = ActionHelper.CreateEntity(startPosI, defM.GetDefinition(EntityType.Headquarter), GameAppDelegate.Account); var actionC = (Core.Controllers.Actions.CreateTerritoryBuilding)action.Control; if (actionC.Possible()) { m_menuView = new MenuView(m_worldLayer, startPosI, MenuView.MenuType.Headquarter); m_menuView.DrawMenu(MenuView.MenuType.Headquarter); } else if (region.GetClaimedTerritory(startPosI) == action.Account) { m_menuView = new MenuView(m_worldLayer, startPosI, MenuView.MenuType.Major); m_menuView.DrawMenu(MenuView.MenuType.Major); } else { // create an empty menu but didnt show it and set the m_menuView for the next touche m_menuView = new MenuView(m_worldLayer, startPosI, MenuView.MenuType.Empty); Gesture = TouchGesture.None; return true; } Gesture = TouchGesture.Menu; } break; } m_worldLayer.UglyDraw(); return true; }